int main() { Hondurato car1(20, 0, 20, 25); Hondurato car2(7, 20000, 18, 20); Hondurato car3(10, 120000, 15, 20); std::cout << "-- Car 1 --\nFuel: " << car1.get_fuel() << "/" << car1.get_tank_capacity() << "\n" << "Odometer: " << car1.get_odometer() << ", MPG: " << car1.get_mpg() << "\n"; std::cout << "-- Car 2 --\nFuel: " << car2.get_fuel() << "/" << car2.get_tank_capacity() << "\n" << "Odometer: " << car2.get_odometer() << ", MPG: " << car2.get_mpg() << "\n"; std::cout << "-- Car 3 --\nFuel: " << car3.get_fuel() << "/" << car3.get_tank_capacity() << "\n" << "Odometer: " << car3.get_odometer() << ", MPG: " << car3.get_mpg() << "\n"; std::cout << "\nCar 1 drives at 60mph for 45 minutes to it's destination.\nIt has " << car1.drive(60, 45) << " gallons of fuel left.\n"; std::cout << "Car 2 drives at 80mph for 1 hour and 20 minutes to it's destination.\nIt has " << car2.drive(80, 80) << " gallons of fuel left.\n"; std::cout << "Car 3 drives at 30mph for 30 minutes to it's destination.\nIt has " << car3.drive(30, 30) << " gallons of fuel left.\n"; std::cout << "Car 2 fuels up, it now has " << car2.addFuel(5) << " gallons in it's tank.\n"; std::cout << "Car 3 fuels up, it now has " << car3.addFuel(0) << " gallons in it's tank.\n"; return 0; }
void draw(void) { glDisable(GL_TEXTURE_2D); up_sider = up_sider + .05; sx = carx + (x_sl*cos(-temp) - 0.5*sin(-temp)); sy = cary + (x_sl*sin(-temp) + 0.5*cos(-temp)); tx = carx + (0.6*cos(temp) - 0.5*sin(-temp)); ty = cary + (0.6*sin(temp) + 0.5*cos(-temp)); r_tx = carx + (0.8*cos(temp) - 0.5*sin(-temp)); r_ty = cary + (0.8*sin(temp) + 0.5*cos(-temp)); keydown(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); if(FLAG==1) gluLookAt(R*cos(alpha)*sin(theta),R*sin(alpha)*sin(theta),-4 +R*cos(theta),0,0,-4,0,0,-1); if(FLAG==2) gluLookAt(carx - 3*sin(temp),cary - 3*cos(temp) ,-5.5,carx + 5*sin(temp) ,cary + 5*cos(temp) ,-4,0,0,-1); if(FLAG==3) { gluLookAt(carx + 0.14*sin(temp) ,cary + 0.14*cos(temp) ,-5.02,carx + 2*sin(temp) ,cary + 2*cos(temp) ,-4.9,0,0,-1); } if(FLAG==4) { gluLookAt(sx ,sy ,-5.51,sx + 3*sin(temp) ,sy + 3*cos(temp) ,-4.6,0,0,-1); } if(FLAG==5) { gluLookAt(sx ,sy,-6.00,sx + 2*sin(up_sider),sy + 2*cos(up_sider) ,-5.3,0,0,-1); } if(FLAG==6) { gluLookAt(tx,ty,-4.5,r_tx ,r_ty,-4.5,0,0,-1); } if(FLAG==7) { gluLookAt(car1x - 3*cos(temp1),car1y - 3*sin(temp1) ,-5.5,car1x + 5*cos(temp1) ,car1y + 5*sin(temp1) ,-4,0,0,-1); } glPushMatrix(); glColor3f(1.0,1.0,1.0); glTranslatef(0,0,-4); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,texture_id[1]); // glTexCoord2i(0,0); // glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); // glEnable(GL_TEXTURE_2D); // glBindTexture(GL_TEXTURE_2D,texture_id[1]); for(i=-200; i<200; i++) { for(p=-200; p<200; p++) { glTexCoord2i(0,0); glVertex3f(i,p,0.0); glTexCoord2i(1,0); glVertex3f(i+1,p,0.0); glTexCoord2i(1,1); glVertex3f(i+1,p+1,0.0); glTexCoord2i(0,1); glVertex3f(i,p+1,0.0); } } // glDisable(GL_TEXTURE_2D); glEnd(); glDisable(GL_TEXTURE_2D); car(); car1(); glPushMatrix(); sun(); // ******new track formation*********** glColor3f(1.0,1.0,1.0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,texture_id[2]); // glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); // glBindTexture(GL_TEXTURE_2D,texture_id[2]); glTexCoord2i(0,0); glVertex3f(-17.0,-27.0,-0.1); glTexCoord2i(0,1); glVertex3f(-11.0,-27.0,-0.1); glTexCoord2i(1,1); glVertex3f(-11.0,20.0,-0.1); glTexCoord2i(1,0); glVertex3f(-17.0,20.0,-0.1); glTexCoord2i(0,0); glVertex3f(-14.0,-13.0,-0.05); glTexCoord2i(0,1); glVertex3f(-14.0,-7.0,-0.05); glTexCoord2i(1,1); glVertex3f(10.0,-7.0,-0.05); glTexCoord2i(1,0); glVertex3f(10.0,-13.0,-0.05); /// elvated roof //****upper surface***** glColor3f(0.0,0.0,0.0); glVertex3f(-8.0,-12.5,-3.1); glVertex3f(-8.0,-7.5,-3.1); glVertex3f(7.0,-7.5,-3.1); glVertex3f(7.0,-12.5,-3.1); //*****side surfaces***** glVertex3f(-8.0,-7,-0.1); glVertex3f(-8.0,-7.5,-3.1); glVertex3f(7.0,-7.5,-3.1); glVertex3f(7.0,-7,-0.1); glVertex3f(-8.0,-13,-0.1); glVertex3f(-8.0,-12.5,-3.1); glVertex3f(7.0,-12.5,-3.1); glVertex3f(7.0,-13,-0.1); ///done glColor3f(1.0,1.0,1.0); glTexCoord2i(0,0); glVertex3f(16.0,-7.3,-0.1); glTexCoord2i(0,1); glVertex3f(10.0,-7.3,-0.1); glTexCoord2i(1,1); glVertex3f(10.0,20.4,-0.1); glTexCoord2i(1,0); glVertex3f(16.0,20.4,-0.1); glTexCoord2i(0,0); glVertex3f(16.0,20,-0.1); glTexCoord2i(0,1); glVertex3f(16.0,26.0,-0.1); glTexCoord2i(1,1); glVertex3f(26.0,26.0,-0.1); glTexCoord2i(1,0); glVertex3f(26.0,20.0,-0.1); glTexCoord2i(0,0); glVertex3f(29.0,20,-0.1); glTexCoord2i(0,1); glVertex3f(23.0,20.0,-0.1); glTexCoord2i(1,1); glVertex3f(23.0,-30.0,-0.1); glTexCoord2i(1,0); glVertex3f(29.0,-30.0,-0.1); glTexCoord2i(0,0); glVertex3f(23.0,-30,-0.1); glTexCoord2i(0,1); glVertex3f(23.0,-24,-0.1); glTexCoord2i(1,1); glVertex3f(-12.0,-24.0,-0.1); glTexCoord2i(1,0); glVertex3f(-12.0,-30.0,-0.1); glEnd(); glColor3f(0.0,0.0,0.0); glDisable(GL_TEXTURE_2D); glPushMatrix(); //turn glTranslatef(-14.0,-10.0,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<360; i++) { glVertex3f(6*cos(i*3.14/180),6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(10.0,-7.0,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(6*cos(i*3.14/180),-6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(16.0,20.0,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(-6*cos(i*3.14/180),6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(26.0,20.3,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(6*cos(i*3.14/180),-6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(26.0,25.7,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(-6*cos(i*3.14/180),6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(-11.0,-26,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(6*cos(i*3.14/180),-6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glLineWidth(5.0); glPushMatrix(); glTranslatef(10.0,-30.0,-0.01); while(M<6.0) { glBegin(GL_LINE_LOOP); for(i=0; i<180; i++) { glVertex3f((13+M)*cos(i*3.14/180),-(13+M)*sin(i*3.14/180),0.0); } glEnd(); M = M + .005; } glPopMatrix(); M=0; glLineWidth(1.0); // glTranslatef(0,0,-4); glPopMatrix(); //glRotatef(-60,1,0,0); //glRotatef(t,0,0,1); glPopMatrix(); // pc(); //t+=0.01; glutSwapBuffers(); }
int HSV::start(const std::vector<std::string> &args) { clan::SlotContainer cc; DisplayWindow window("ClanLib HSV Sprite", 1024, 768); cc.connect(window.sig_window_close(), clan::bind_member(this, &HSV::on_close)); cc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &HSV::on_input_up)); Canvas canvas(window); InputContext ic = window.get_ic(); clan::Font font(canvas, "Tahoma", -11); HSVSpriteBatch sprite_batcher(canvas); HSVSprite car1(canvas, &sprite_batcher, "../../Game/SpritesRTS/Gfx/spaceshoot_body_moving1.png"); HSVSprite car2(canvas, &sprite_batcher, "Resources/ferrari_maranello.png"); HSVSprite *cars[] = { &car1, &car2 }; ubyte64 last_fps_update = System::get_time(); ubyte64 last_time = last_fps_update; int fps = 0; std::string fps_text; float hue_offset = 0.0; while (!quit) { ubyte64 current_time = System::get_time(); float time_delta_ms = static_cast<float> (current_time - last_time); last_time = current_time; if (ic.get_keyboard().get_keycode(keycode_left)) hue_offset += 0.0005f * time_delta_ms; else if (ic.get_keyboard().get_keycode(keycode_right)) hue_offset -= 0.0005f * time_delta_ms; if (hue_offset < -1.0f) hue_offset += 1.0f; if (hue_offset > 1.0f) hue_offset -= 1.0f; canvas.clear(Colorf::darkslategrey); float car_hue = hue_offset; for (int y = 0; y < 10; y++) { for (int x = 0; x < 7; x++) { cars[(x+y)%2]->draw(canvas, 60+x*128, 60+y*64, car_hue); car_hue += 0.02f; if (car_hue < -1.0f) car_hue += 1.0f; if (car_hue > 1.0f) car_hue -= 1.0f; } } fps++; if (System::get_time() - last_fps_update > 2000) { fps_text = string_format("%1 fps", fps/2.0f); last_fps_update = System::get_time(); fps = 0; } Size fps_size = font.get_text_size(canvas, fps_text); font.draw_text(canvas, canvas.get_width()-10-fps_size.width, 16, fps_text); font.draw_text(canvas, 32, 730, "Use cursor keys left and right"); window.flip(0); KeepAlive::process(); } return 0; }
void display(){ //clear the display glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(BLACK, 0); //color black glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /******************** / set-up camera here ********************/ //load the correct matrix -- MODEL-VIEW matrix glMatrixMode(GL_MODELVIEW); //initialize the matrix glLoadIdentity(); //now give three info //1. where is the camera (viewer)? //2. where is the camera is looking? //3. Which direction is the camera's UP direction? //instead of CONSTANT information, we will define a circular path. gluLookAt(200*cos(cameraAngle), 200*sin(cameraAngle), 150, 0,0,0, 0,0,1); //NOTE: the camera still CONSTANTLY looks at the center // cameraAngle is in RADIAN, since you are using inside COS and SIN //again select MODEL-VIEW glMatrixMode(GL_MODELVIEW); /**************************** / Add your objects from here ****************************/ //border glColor3f(1,1,1); glBegin(GL_LINES);{ glVertex3f(-100, -100, 0); glVertex3f(-100, 100, 0); glVertex3f(-100, 100, 0); glVertex3f(100, 100, 0); glVertex3f(100, 100, 0); glVertex3f(100, -100, 0); glVertex3f(100, -100, 0); glVertex3f(-100, -100, 0); }glEnd(); //roads glColor3f(1,1,1); glBegin(GL_QUADS);{ glVertex3f(-100,-20,0); glVertex3f(-100,20,0); glVertex3f(100,20,0); glVertex3f(100,-20,0); }glEnd(); glColor3f(1,1,1); glBegin(GL_QUADS);{ glVertex3f(-20,100,0); glVertex3f(20,100,0); glVertex3f(20,-100,0); glVertex3f(-20,-100,0); }glEnd(); //moving car pos1 += .1; if(pos1>180) pos1 = 0; car1(pos1); pos2 += .05; if(pos2>180) pos2 = 0; car2(pos2); pos3 += .075; if(pos3>180) pos3 = 0; car3(pos3); //top left buildings 1st row drawBuilding(-90, -90, -90, -70, 50); drawBuilding(-90, -60, -90, -40, 30); //top left buildings 2nd row drawBuilding(-60, -90, -60, -70, 60); drawBuilding(-55, -60, -55, -40, 40); //top right buildings 1st row drawBuilding(-90, 90, -90, 70, 70); drawBuilding(-90, 60, -90, 40, 50); //top right buildings 2nd row drawBuilding(-60, 90, -60, 75, 80); drawBuilding(-60, 70, -60, 35, 45); //middle left buildings drawBuilding(40, -90, 40, -70, 40); drawBuilding(40, -60, 40, -40, 50); //middle right buildings drawBuilding(30, 90, 30, 70, 30); drawBuilding(30, 60, 30, 40, 50); //bottom left buildings drawBuilding(70, -90, 70, -70, 30); drawBuilding(75, -60, 75, -40, 30); //bottom right buildings drawBuilding(70, 90, 70, 70, 90); drawBuilding(70, 65, 70, 40, 30); //ADD this line in the end --- if you use double buffer (i.e. GL_DOUBLE) glutSwapBuffers(); }