// stub boost::shared_ptr<Solid> Repository::newSolid(SolidEnum type) { switch(type) { case ROCK: { BitmapImage rockImage("images/rock.bmp"); NewtonianMass * pm = new NewtonianMass(1000,2000,20,Vector2d(120,120),Vector2d(0,.1),0.,.1); boost::shared_ptr<Solid> rock ( new SimpleSolid( pm, new BitmapImage(rockImage) ) ); return rock; } case BIG_ROCK: { BitmapImage rockImage("images/rock.bmp"); NewtonianMass * pm = new NewtonianMass(5000,10000,35,Vector2d(720,320),Vector2d(0,-.1),0.,.03); boost::shared_ptr<Solid> rock ( new SimpleSolid( pm, new BitmapImage(rockImage) ) ); return rock; } case ALIEN: { boost::shared_ptr<Image> pa1( new BitmapImage("images/alien1-1.bmp") ); boost::shared_ptr<Image> pa2( new BitmapImage("images/alien1-2.bmp") ); boost::shared_ptr<Image> pa3( new BitmapImage("images/alien1-3.bmp") ); AnimatedImage * pa( new AnimatedImage(pa1,5) ); pa->add(pa2); pa->add(pa3); NewtonianMass * pm = new NewtonianMass(100,2000,12,Vector2d(500,300), Vector2d(-.1,0),0,0) ; boost::shared_ptr<Mass> pBaseAlienMass( pm ); Mass * alienMass = new DamageMass(pBaseAlienMass, 1000); boost::shared_ptr<Solid> alien(new SimpleSolid( alienMass, pa) ); return alien; } default: throw(0); } }
void fn () { X x1(3.5); // WARNING - double to int X x2(3.5f); // WARNING - float to int X x3(1, 3.5); // WARNING - double to int X x4(1, 3.5f); // WARNING - float to int X x5(3.5, 1); // WARNING - double to int X x6(3.5f, 1); // WARNING - float to int X y1 = 3.5; // WARNING - double to int X y2 = 3.5f; // WARNING - float to int int j1 (3.5); // WARNING - double to int int j2 (3.5f); // WARNING - float to int int k1 = 3.5; // WARNING - double to int int k2 = 3.5f; // WARNING - float to int j1 = 3.5; // WARNING - double to int j2 = 3.5f; // WARNING - float to int foo (3.5); // WARNING - double to int foo (3.5f); // WARNING - float to int wibble (3.5); // WARNING - double to int wibble (3.5f); // WARNING - float to int wibble (1, 3.5); // WARNING - double to int wibble (1, 3.5f); // WARNING - float to int wibble (3.5, 1); // WARNING - double to int wibble (3.5f, 1); // WARNING - float to int punk (); // WARNING - double to int rock (1); // WARNING - double to int }
int main( int argc, char ** argv ) { for ( int i = 0; i < 3; ++i ){ computersThrow = computerThrow(); printf( "Your Score: %d\n", yourScore ); puts( "1. Rock" ); puts( "2. Paper" ); puts( "3. Scissors" ); printf( "%d: What do you want to throw? ", i ); fflush(stdout); fgets( response, max_length, stdin ); val = atoi( response ); if( val == 1 ){ rock(); } else if( val == 2 ){ paper(); } else if( val == 3){ scissors(); } else { puts( "Enter valid choice 1, 2 or 3" ); i -= 1; } } end_game(); return 0; }
// The MAIN function, from here we start our application and run our Game loop int main() { // Init GLFW glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); GLFWwindow* window = glfwCreateWindow(screenWidth, screenHeight, "LearnOpenGL", nullptr, nullptr); // Windowed glfwMakeContextCurrent(window); // Set the required callback functions glfwSetKeyCallback(window, key_callback); glfwSetCursorPosCallback(window, mouse_callback); // Options glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); // Initialize GLEW to setup the OpenGL Function pointers glewExperimental = GL_TRUE; glewInit(); // Define the viewport dimensions glViewport(0, 0, screenWidth, screenHeight); // Setup OpenGL options glEnable(GL_DEPTH_TEST); // Setup and compile our shaders Shader planetShader("planet.vs", "planet.frag"); Shader instanceShader("instanced_asteroids.vs", "instanced_asteroids.frag"); // Load models Model rock("../../../resources/objects/rock/rock.obj"); Model planet("../../../resources/objects/planet/planet.obj"); // Set projection matrix glm::mat4 projection = glm::perspective(45.0f, (GLfloat)screenWidth/(GLfloat)screenHeight, 1.0f, 10000.0f); planetShader.Use(); glUniformMatrix4fv(glGetUniformLocation(planetShader.Program, "projection"), 1, GL_FALSE, glm::value_ptr(projection)); // Also of instance shader instanceShader.Use(); glUniformMatrix4fv(glGetUniformLocation(instanceShader.Program, "projection"), 1, GL_FALSE, glm::value_ptr(projection)); // Generate a large list of semi-random model transformation matrices GLuint amount = 100000; glm::mat4* modelMatrices; modelMatrices = new glm::mat4[amount]; srand(glfwGetTime()); // initialize random seed GLfloat radius = 150.0f; GLfloat offset = 25.0f; for(GLuint i = 0; i < amount; i++) { glm::mat4 model; // 1. Translation: Randomly displace along circle with radius 'radius' in range [-offset, offset] GLfloat angle = (GLfloat)i / (GLfloat)amount * 360.0f; GLfloat displacement = (rand() % (GLint)(2 * offset * 100)) / 100.0f - offset; GLfloat x = sin(angle) * radius + displacement; displacement = (rand() % (GLint)(2 * offset * 100)) / 100.0f - offset; GLfloat y = -2.5f + displacement * 0.4f; // Keep height of asteroid field smaller compared to width of x and z displacement = (rand() % (GLint)(2 * offset * 100)) / 100.0f - offset; GLfloat z = cos(angle) * radius + displacement; model = glm::translate(model, glm::vec3(x, y, z)); // 2. Scale: Scale between 0.05 and 0.25f GLfloat scale = (rand() % 20) / 100.0f + 0.05; model = glm::scale(model, glm::vec3(scale)); // 3. Rotation: add random rotation around a (semi)randomly picked rotation axis vector GLfloat rotAngle = (rand() % 360); model = glm::rotate(model, rotAngle, glm::vec3(0.4f, 0.6f, 0.8f)); // 4. Now add to list of matrices modelMatrices[i] = model; } // Set transformation matrices as an instance vertex attribute (with divisor 1) // NOTE: We're cheating a little by taking the, now publicly declared, VAO of the model's mesh(es) and adding new vertexAttribPointers // Normally you'd want to do this in a more organized fashion, but for learning purposes this will do. for(GLuint i = 0; i < rock.meshes.size(); i++) { GLuint VAO = rock.meshes[i].VAO; GLuint buffer; glBindVertexArray(VAO); glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, amount * sizeof(glm::mat4), &modelMatrices[0], GL_STATIC_DRAW); // Set attribute pointers for matrix (4 times vec4) glEnableVertexAttribArray(3); glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (GLvoid*)0); glEnableVertexAttribArray(4); glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (GLvoid*)(sizeof(glm::vec4))); glEnableVertexAttribArray(5); glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (GLvoid*)(2 * sizeof(glm::vec4))); glEnableVertexAttribArray(6); glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (GLvoid*)(3 * sizeof(glm::vec4))); glVertexAttribDivisor(3, 1); glVertexAttribDivisor(4, 1); glVertexAttribDivisor(5, 1); glVertexAttribDivisor(6, 1); glBindVertexArray(0); } // Game loop while(!glfwWindowShouldClose(window)) { // Set frame time GLfloat currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; // Check and call events glfwPollEvents(); Do_Movement(); // Clear buffers glClearColor(0.03f, 0.03f, 0.03f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Add transformation matrices planetShader.Use(); glUniformMatrix4fv(glGetUniformLocation(planetShader.Program, "view"), 1, GL_FALSE, glm::value_ptr(camera.GetViewMatrix())); instanceShader.Use(); glUniformMatrix4fv(glGetUniformLocation(instanceShader.Program, "view"), 1, GL_FALSE, glm::value_ptr(camera.GetViewMatrix())); // Draw Planet planetShader.Use(); glm::mat4 model; model = glm::translate(model, glm::vec3(0.0f, -5.0f, 0.0f)); model = glm::scale(model, glm::vec3(4.0f, 4.0f, 4.0f)); glUniformMatrix4fv(glGetUniformLocation(planetShader.Program, "model"), 1, GL_FALSE, glm::value_ptr(model)); planet.Draw(planetShader); // Draw meteorites instanceShader.Use(); glBindTexture(GL_TEXTURE_2D, rock.textures_loaded[0].id); // Note we also made the textures_loaded vector public (instead of private) from the model class. for(GLuint i = 0; i < rock.meshes.size(); i++) { glBindVertexArray(rock.meshes[i].VAO); glDrawElementsInstanced(GL_TRIANGLES, rock.meshes[i].vertices.size(), GL_UNSIGNED_INT, 0, amount); glBindVertexArray(0); } // Swap the buffers glfwSwapBuffers(window); } delete[] modelMatrices; glfwTerminate(); return 0; }
std::vector< std::vector< std::vector<double> > > CorrelatedRockSamples::CreateSamplesExtended(int i_max, TimeLine & time_line, const std::vector<DistributionsRock*> & dist_rock) { std::list<int> time; time_line.GetAllTimes(time); int k_max = static_cast<int>(dist_rock.size()); // Set up time vectors, the same for all sets of correlated samples. time_line.ReSet(); int et_dummy, edi_dummy; double dt_year; std::vector< std::vector<double> > delta_time(k_max); for (int k = 0; k < k_max; ++k){ time_line.GetNextEvent(et_dummy, edi_dummy, dt_year); for (int l = k; l < k_max; ++l) delta_time[l].push_back(dt_year); } int nReservoirVariables = dist_rock[0]->GetNumberOfReservoirVariables(); // Set up data structures. // The order of indices is chosen to make extraction of all samples for a given time instance easy. std::vector< std::vector< std::vector<double> > > m(k_max); std::vector< std::vector< Rock * > > rock(k_max); for (int k = 0; k < k_max; ++k){ m[k].resize(i_max); rock[k].resize(i_max); for (int i = 0; i < i_max; ++i) m[k][i].resize(3+nReservoirVariables); } const std::vector<double> trend_params_dummy(2,0); std::vector<double>reservoirVariables(nReservoirVariables,0); // Finding the sets of correlated samples. // Each set of samples for a specific i are correlated in time. dist_rock[0]->SetResamplingLevel(DistributionWithTrend::Full); for (int i = 0; i < i_max; ++i){ rock[0][i] = dist_rock[0]->GenerateSampleAndReservoirVariables(trend_params_dummy,reservoirVariables); rock[0][i]->GetSeismicParams(m[0][i][0], m[0][i][1], m[0][i][2]); m[0][i][0]=std::log(m[0][i][0]); m[0][i][1]=std::log(m[0][i][1]); m[0][i][2]=std::log(m[0][i][2]); for(int l =0;l< nReservoirVariables;l++) m[0][i][l+3]=reservoirVariables[l]; std::vector< Rock * > rock_seen(1, rock[0][i]); for (int k = 1; k < k_max; ++k){ dist_rock[k]->SetResamplingLevel(DistributionWithTrend::Full); rock[k][i] = dist_rock[k]->EvolveSampleAndReservoirVaribles(delta_time[k][k], *(rock[k-1][i]),reservoirVariables); // delta_time info also for the rock to be found. rock[k][i]->GetSeismicParams(m[k][i][0], m[k][i][1], m[k][i][2]); m[k][i][0]=std::log(m[k][i][0]); m[k][i][1]=std::log(m[k][i][1]); m[k][i][2]=std::log(m[k][i][2]); for(int l =0;l< nReservoirVariables;l++) m[k][i][l+3]=reservoirVariables[l]; rock_seen.push_back(rock[k][i]); } } // Must delete memory allocated by classes DistributionsRock and Rock. for (int k = 0; k < k_max; ++k){ for (int i = 0; i < i_max; ++i){ if (rock[k][i] != NULL) delete rock[k][i]; } } return m; }
GLvoid InitGL(){ //All the stuff we need to draw std::string hero_geo_file = "geo/tank.obj"; std::string target_geo_file = "geo/target.obj"; std::string swivel_geo_file = "geo/turret.obj"; std::string barrel_geo_file = "geo/barrel.obj"; std::string environment_geo_file = "geo/cube.obj"; std::string enemy_geo_file = "geo/enemy.obj"; std::string tile_geo_file = "geo/tile.obj"; std::string tree_geo_file = "geo/tree.obj"; std::string rock_geo_file = "geo/rocks.obj"; std::string hero_tex_file = "tex/tank.ppm"; std::string target_tex_file = "tex/target.ppm"; std::string swivel_tex_file = "tex/turret.ppm"; std::string barrel_tex_file = "tex/barrel.ppm"; std::string environment_tex_file = "tex/cubemape.ppm"; std::string enemy_tex_file = "tex/enemy.ppm"; std::string tile_tex_file = "tex/naked_tile_baked.ppm"; std::string tree_tex_file = "tex/tree.ppm"; std::string rock_tex_file = "tex/rocks.ppm"; std::string tree_tile_tex = "tex/tree_tile.ppm"; std::string rock_tile_tex = "tex/rocky_tile.ppm"; std::string blob_tile_tex = "tex/blob_shadow.ppm"; mesh hero(hero_geo_file); mesh target(target_geo_file); mesh swivel(swivel_geo_file); mesh barrel(barrel_geo_file); mesh environment(environment_geo_file); mesh enemy(enemy_geo_file); mesh tile(tile_geo_file); mesh tree(tree_geo_file); mesh rock(rock_geo_file); HERO_ID = meshes.size(); meshes.push_back(hero); TARGET_ID = meshes.size(); meshes.push_back(target); SWIVEL_ID = meshes.size(); meshes.push_back(swivel); BARREL_ID = meshes.size(); meshes.push_back(barrel); ENVIRONMENT_ID = meshes.size(); meshes.push_back(environment); ENEMY_ID = meshes.size(); meshes.push_back(enemy); TILE_ID = meshes.size(); meshes.push_back(tile); TREE_ID = meshes.size(); meshes.push_back(tree); ROCK_ID = meshes.size(); meshes.push_back(rock); glEnable(GL_TEXTURE_2D); glGenTextures(1, &HERO_TEX); glGenTextures(1, &TARGET_TEX); glGenTextures(1, &SWIVEL_TEX); glGenTextures(1, &BARREL_TEX); glGenTextures(1, &ENVIRONMENT_TEX); glGenTextures(1, &ENEMY_TEX); glGenTextures(1, &TILE_TEX); glGenTextures(1, &TREE_TEX); glGenTextures(1, &ROCK_TEX); glGenTextures(1, &TREETILE_TEX); glGenTextures(1, &ROCKTILE_TEX); glGenTextures(1, &BLOBTILE_TEX); loadPPM(hero_tex_file.c_str(), HERO_TEX); loadPPM(target_tex_file.c_str(), TARGET_TEX); loadPPM(swivel_tex_file.c_str(), SWIVEL_TEX); loadPPM(barrel_tex_file.c_str(), BARREL_TEX); loadPPM(environment_tex_file.c_str(), ENVIRONMENT_TEX); loadPPM(enemy_tex_file.c_str(), ENEMY_TEX); loadPPM(tile_tex_file.c_str(), TILE_TEX); loadPPM(tree_tex_file.c_str(), TREE_TEX); loadPPM(rock_tex_file.c_str(), ROCK_TEX); loadPPM(tree_tile_tex.c_str(), TREETILE_TEX); loadPPM(rock_tile_tex.c_str(), ROCKTILE_TEX); loadPPM(blob_tile_tex.c_str(), BLOBTILE_TEX, true); camera = new game_object(-1,-1,-1); game_object *hero_character = new game_object(characters.size(), HERO_ID, HERO_TEX); characters.push_back(hero_character); game_object *target_character = new game_object(characters.size(), TARGET_ID, TARGET_TEX); target_character->transform.translate(0.0,0.0,-7.0); characters.push_back(target_character); game_object *swivel_character = new game_object(characters.size(), SWIVEL_ID, SWIVEL_TEX); swivel_character->transform.translate(0.0,0.4,0.0); characters.push_back(swivel_character); game_object *barrel_character = new game_object(characters.size(), BARREL_ID, BARREL_TEX); barrel_character->transform.translate(0.0,0.0,-0.15); barrel_character->parent_to(characters[SWIVEL_ID]); characters.push_back(barrel_character); game_object *environment_character = new game_object(characters.size(), ENVIRONMENT_ID, ENVIRONMENT_TEX); environment_character->transform.scale(TILES_DIMENSION,TILES_DIMENSION,TILES_DIMENSION); environment_character->parent_to(camera); characters.push_back(environment_character); // game_object *enemy_character = new game_object(characters.size(), ENEMY_ID, ENEMY_TEX); // enemy_character->transform.translate(0.0, 0.0, -7.0); // enemy_character->parent_to(camera); // characters.push_back(enemy_character); // bad_guys.push_back(ENEMY_ID); srand(time(NULL)); int spread = TILES_DIMENSION; for(int i=1; i<BAD_GUY_COUNT; i++) { game_object *enemyX = new game_object(characters.size(), ENEMY_ID, ENEMY_TEX); enemyX->transform.translate(rand()%spread-spread/2, 0.0, rand()%spread-spread/2); enemyX->transform.rotateY(rand()%180); enemyX->parent_to(camera); bad_guys.push_back(characters.size()); colliders.push_back(characters.size()); characters.push_back(enemyX); } double tile_width = meshes[TILE_ID].xmax - meshes[TILE_ID].xmin; double tile_length = meshes[TILE_ID].zmax - meshes[TILE_ID].zmin; for(int i=0; i<TILES_DIMENSION; i++) { int xmult = i - TILES_DIMENSION/2; for(int j=0; j<TILES_DIMENSION; j++) { int zmult = j - TILES_DIMENSION/2; double rot = rand() % 4 * 90.0; // std::cout << rot << std::endl; game_object *tileX = new game_object(characters.size(), TILE_ID, TILE_TEX); tileX->transform.rotateY(rot); tileX->transform.translate(tile_width*xmult, 0.0, tile_length*zmult); tileX->parent_to(camera); characters.push_back(tileX); int tile_type = rand() % 100; if(tile_type >= 96 && tile_type < 98) { tileX->tex = TREETILE_TEX; game_object *treeX = new game_object(characters.size(), TREE_ID, TREE_TEX); treeX->transform = tileX->transform; treeX->parent_to(camera); bad_guys.push_back(characters.size()); colliders.push_back(characters.size()); characters.push_back(treeX); } else if(tile_type >= 98) { tileX->tex = ROCKTILE_TEX; game_object *rockX = new game_object(characters.size(), ROCK_ID, ROCK_TEX); rockX->transform = tileX->transform; rockX->parent_to(camera); bad_guys.push_back(characters.size()); colliders.push_back(characters.size()); characters.push_back(rockX); } } } game_object *blob_character = new game_object(characters.size(), TILE_ID, BLOBTILE_TEX); blob_character->transform.translate(0.0,0.001,0.0); blob_character->transform.scale(2.0, 1.0, 3.0); characters.push_back(blob_character); last_update = (double)clock() / ((double)CLOCKS_PER_SEC); //GL boilerplate initialization glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(0.5f, 0.5f, 0.5f, 0.5f); // grey Background glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glEnable(GL_CULL_FACE); glShadeModel(GL_SMOOTH); glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glEnable(GL_COLOR_MATERIAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); }