int main() { std::atexit(press_any_key); asteroid aster(12345); spaceship ship("Alfa-Romeo"); object obj; object obj_aster = asteroid(67890); object obj_ship = spaceship("Omega-Juliette"); asteroid aster_obj = obj_aster; spaceship ship_obj = obj_ship; auto check_variables = [&]() { std::cout << std::boolalpha << "\n Test for null:" << "\n\t aster.is_null(): " << aster.is_null() << "\n\t ship.is_null(): " << ship.is_null() << "\n\t obj.is_null(): " << obj.is_null() << "\n\t obj_aster.is_null(): " << obj_aster.is_null() << "\n\t obj_ship.is_null(): " << obj_ship.is_null() << "\n\t aster_obj.is_null(): " << aster_obj.is_null() << "\n\t ship_obj.is_null(): " << ship_obj.is_null() << std::endl; std::cout << "\n Test for data class:" << "\n\t aster.data_class(): " << aster.data_class() << "\n\t ship.data_class(): " << ship.data_class() << "\n\t obj.data_class(): " << obj.data_class() << "\n\t obj_aster.data_class(): " << obj_aster.data_class() << "\n\t obj_ship.data_class(): " << obj_ship.data_class() << "\n\t aster_obj.data_class(): " << aster_obj.data_class() << "\n\t ship_obj.data_class(): " << ship_obj.data_class() << std::endl; std::cout << "\n Test identification:" << "\n\t aster.get_identifier(): " << aster.get_identifier() << "\n\t ship.get_name(): " << ship.get_name() << "\n\t aster_obj.get_identifier(): " << aster_obj.get_identifier() << "\n\t ship_obj.get_name(): " << ship_obj.get_name() << std::endl; }; std::cout << "\n ======== Check after constructors ========" << std::endl; check_variables(); aster = asteroid(335577); ship = spaceship("Ramambahara"); obj = object(); obj_aster = asteroid(446688); obj_ship = spaceship("Mamburu"); aster_obj = obj_aster; ship_obj = obj_ship; std::cout << "\n ======== Check after assignments ========" << std::endl; check_variables(); return 0; }
void nodes::set_nodes(int part_) { if (part_ == 0) { //type 0 = nodo rojo, 1 nodo azul, 2 estacion espacial Node* n1 = add_new_node(2,184,311); Node* n2 = add_new_node(0,167,157,n1); Node* n3 = add_new_node(0,348,53,n2); Node* n4 = add_new_node(0,348,259,n2); Node* n5 = add_new_node(0,450,157,n4); link_nodes(n5,n3); Node* n6 = add_new_node(0,638,107,n5); //Node* n7 = add_new_node(0,885,58,n6); //Node* n8 = add_new_node(0,845,345,n6); //Node* n9 = add_new_node(0,597,542,n8); //Node* n10 = add_new_node(0,807,536,n6); //Node* n11 = add_new_node(0,475,280,n9); Node* n12 = add_new_node(0,426,590,n6); Node* n13 = add_new_node(0,278,439,n12); Node* n14 = add_new_node(0,76,568,n13); //std::vector<CL_Vec2f> res = aStarNodeVersion(n5,n1); spaceships_.push_back(spaceship()); main_station_node_ = n1; spaceships_[0].set_current_pos(main_station_node_); //spaceships_[0].create_path(n9); } }
int main() { // Init GLFW and GLEW glfwInit(); CVK::useOpenGL33CoreProfile(); window = glfwCreateWindow(width, height, "AnSim Exercise 3", 0, 0); glfwSetWindowPos(window, 100, 50); glfwMakeContextCurrent(window); glfwSetWindowSizeCallback(window, resizeCallback); glfwSetKeyCallback(window, keyCallback); glewInit(); CVK::State::getInstance()->setBackgroundColor( white); glm::vec3 BgCol = CVK::State::getInstance()->getBackgroundColor(); glClearColor( BgCol.r, BgCol.g, BgCol.b, 0.0); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //load, compile and link Shader const char *shadernames[2] = { SHADERS_PATH "/Toon.vert", SHADERS_PATH "/Toon.frag" }; CVK::ShaderSpace spaceShader(VERTEX_SHADER_BIT | FRAGMENT_SHADER_BIT, shadernames); const char *skyboxShadernames[2] = {SHADERS_PATH "/Minimal.vert", SHADERS_PATH "/SimpleTexture.frag"}; ShaderSkybox skyboxShader(VERTEX_SHADER_BIT | FRAGMENT_SHADER_BIT, skyboxShadernames); //Camera glm::vec3 center(0.0f, 0.0f, 0.0f); camera.setCenter(¢er); camera.setRadius(6.0f); CVK::State::getInstance()->setCamera( &camera); //Light Sources CVK::Light light = CVK::Light(glm::vec4(0.0, 10.0, 0.0, 1.0), grey, glm::vec3(0, 0, 0), 1.0f, 0.0f); CVK::State::getInstance()->addLight(&light); CVK::State::getInstance()->updateSceneSettings(darkgrey, 0, white, 1, 10, 1); // Create skybox Skybox* skybox = new Skybox(15.0f); //Init scene nodes and mass points CVK::Node spaceship("Spaceship", RESOURCES_PATH "/spaceship.obj"); CVK::Node fish("Fish", RESOURCES_PATH "/fish.obj"); CVK::Node pig("Pig", RESOURCES_PATH "/piggy.obj"); //First mass point for the spaceship spaceShipMassPoint = CVK::MassPoint(glm::vec3(0.0f, 2.3f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 1.0); //Next ones for the pigs pigsMassPoints.push_back(CVK::MassPoint(glm::vec3(-2.0f, 2.3f, 2.0f), glm::vec3(-0.3f, 0.0f, -0.23f), 1.0)); pigsMassPoints.push_back(CVK::MassPoint(glm::vec3(2.0f, 2.3f, -2.0f), glm::vec3(0.0f, 0.0f, 0.4f), 2.0)); pigsMassPoints.push_back(CVK::MassPoint(glm::vec3(4.0f, 2.3f, 3.0f), glm::vec3(-0.23f, 0.0f, -0.1f), 3.0)); pigsMassPoints.push_back(CVK::MassPoint(glm::vec3(-5.0f, 0.0f, 6.0f), glm::vec3(-0.3f, 0.0f, -0.4f), 1.0)); pigsMassPoints.push_back(CVK::MassPoint(glm::vec3(5.0f, 2.3f, -3.0f), glm::vec3(0.2f, 0.0f, 0.2f), 2.0)); pigsMassPoints.push_back(CVK::MassPoint(glm::vec3(4.0f, 4.3f, 2.5f), glm::vec3(-0.4f, 0.0f, -0.2f), 3.0)); // TODO 4 (b) // Fuellen Sie den global definierten Vektor (quaternions) mit den gewünschten Orientierungen. float deltaTime = 0.0f; float oldTime = glfwGetTime(); float t = 0.0f; while(!glfwWindowShouldClose( window)) { float currentTime = glfwGetTime(); deltaTime = currentTime - oldTime; oldTime = currentTime; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Update Camera camera.update(window); glm::vec3 spaceShipPos=spaceShipMassPoint.getPosition(); camera.setCenter(&spaceShipPos); //Use the skybox shader program CVK::State::getInstance()->setShader(&skyboxShader); CVK::State::getInstance()->getShader()->update(); skybox->render(); //Use phong shader to render the scene CVK::State::getInstance()->setShader(&spaceShader); CVK::State::getInstance()->setLight(0, &light); spaceShader.update(); //Update and render spaceship spaceShipMassPoint.numericIntegration(deltaTime); glm::mat4 modelmatrix = glm::rotate(glm::mat4(1.0f), spaceShipRotAngle, glm::vec3(0.0f,1.0f,0.0f)); modelmatrix = glm::translate(modelmatrix, spaceShipMassPoint.getPosition()); modelmatrix = glm::scale(modelmatrix, glm::vec3(1.5,1.5,1.5)); spaceship.setModelMatrix(modelmatrix); spaceship.render(); //Update and render pigs for(CVK::MassPoint& mp : pigsMassPoints) { mp.numericIntegration(deltaTime); modelmatrix = glm::translate(glm::mat4(1.0f), mp.getPosition()); modelmatrix = glm::scale(modelmatrix, glm::vec3(0.5,0.5,0.5)); pig.setModelMatrix(modelmatrix); pig.render(); } t += deltaTime * 0.01f; //speed = 0.01 if(t >= 1.0) t = 0.0f; // TODO 4 (b) // Erweitern Sie die Modelmatrix um Translation und Rotation. // Anmerkung: Verwenden Sie die Variable t. modelmatrix = glm::scale(glm::mat4(1.0f), glm::vec3(0.1f, 0.1f, 0.1f)); fish.setModelMatrix(modelmatrix); fish.render(); glfwSwapBuffers( window); glfwPollEvents(); } glfwDestroyWindow( window); glfwTerminate(); return 0; }
/********************************************************** * * SUBROUTINE display() * * This is our main rendering subroutine, called each frame * *********************************************************/ void display(void) { int i; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue width = glutGet(GLUT_WINDOW_WIDTH); height = glutGet(GLUT_WINDOW_HEIGHT); glWindowPos2i(width - 100, height - 15); if(enter && flag3) { SwitchGameplay(2); glFlush(); // This force the execution of OpenGL commands glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer return; } Print("Score: %d", score); if(over) { SwitchGameplay(1); glFlush(); // This force the execution of OpenGL commands glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer return; } // Erase the window and the depth buffer glClearColor(0,0.3,0.7,0); Background(3.5*dim); // draw space like looking texture gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f,10000.0f); glMatrixMode(GL_MODELVIEW); // Modeling transformation glLoadIdentity(); // Initialize the model matrix as identity // Perspective - set eye position gluLookAt(Ex,Ey,Ez , Ox,Oy,Oz , Ux,Uy,Uz); for ( i = 0; i < NUM_STAR; i++ ) { stars(star[i].x, star[i].y, star[i].z, star[i].a, star[i].b, star[i].c); } // draw laser cannon if fired if(bullet == 1 && space == 1) { laser_bullet(bx,by,bz,5,5,400); } // check if spaceship is hit by enemy if(px > ex-40 && px < ex+40 && py > ey-40 && py < ey+40 && pz > ez-40 && pz < ez+40 ) { space = 0; CreateExplosion (); Mix_PlayMusic(blast,0); over = 1; enemy = 0; } // Check if spaceship hits the wall if(px >= wall_x-100 && px <= wall_x+100 && py >= wall_y-30 && py <= wall_y+10 && pz >= wall_z-100 && pz <= wall_z+100 ) { space = 0; CreateExplosion (); Mix_PlayMusic(blast,0); over = 1; } // gravity, check if the spaceship fell off the road if( (px > 200 || px < -200) ) { py -= 5; if( py < -40) { space = 0; gravity = 1; CreateExplosion (); Mix_PlayMusic(blast,0); over = 1; } } if(space) spaceship(px, py, pz, -90+up, side, 180,0.85,0.85,0.85); if(enemy == 1) spaceship(ex, ey, ez, -90, 0, 0,1,1,1); glLoadIdentity(); glTranslatef(fx,fy,fz); if (fuel > 0) { glPushMatrix (); glBegin (GL_POINTS); for (i = 0; i < NUM_PARTICLES; i++) { glColor3fv (particles[i].color); glVertex3fv (particles[i].position); } glEnd (); for (i = 0; i < NUM_DEBRIS; i++) { glPushMatrix (); glTranslatef (debris[i].position[0], debris[i].position[1], debris[i].position[2]); glRotatef (debris[i].orientation[0], 1.0, 0.0, 0.0); glRotatef (debris[i].orientation[1], 0.0, 1.0, 0.0); glRotatef (debris[i].orientation[2], 0.0, 0.0, 1.0); glScalef (debris[i].scale[0], debris[i].scale[1], debris[i].scale[2]); glBegin (GL_TRIANGLES); glColor3f(((float) rand ()) / ((float) RAND_MAX), ((float) rand ()) / ((float) RAND_MAX), 0.3); glVertex3f (0.0, 0.5, 0.0); glVertex3f (-0.25, 0.0, 0.0); glVertex3f (0.25, 0.0, 0.0); glEnd (); glPopMatrix (); } } Road(road_x, road_y, road_z); wall(wall_x, wall_y, wall_z); glFlush(); // This force the execution of OpenGL commands glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer flag3++; }