void GameMap::extraInit() { floorLayer = this->getLayer("floor"); initWall(); initActor(); }
/* ---------------------- MAZE MAIN CONTROLLER -----------------------------*/ void playMaze(){ int c; int x = 10; int y = 21; int readytomove = 0; int startmove = 1; int direction; box1(3,3,78,48,GOINGDOWN,BLACK,5); textcolor(WHITE); gotoxy(41,9); cprintf(" this is Dencie"); gotoxy(39,30); cprintf(" this is Mark"); gotoxy(30,45); textcolor(RED); cprintf("Press ESC to back to Main..."); initWall(); char s; // zergslocation(); gotoxy(12,1); textcolor(YELLOW|BLINK); cprintf(""); gotoxy(x,y-1); textcolor(WHITE); cprintf(""); while((c=getch())!=27 && startmove!=0) { map(); gotoxy(12,1); textcolor(YELLOW|BLINK); cprintf(""); switch(c){ case 80: // down y++; direction = fromDown; break; case 75: // left x--; direction = fromLeft; break; case 72: // up y--; direction = fromUp; break; case 77: // right x++; direction = fromRight; break; case 115: zergslocation(); break; } if ((matrix[x][y])==1 || (matrix[x][y])== -1 || (matrix[x][y]) == -2 ){ gotoxy(x,y); textcolor(15); cprintf(""); readytomove = 1; if ((matrix[x][y])== -1) { // REACH ITS MAZE ENDING PT. window(1,1,80,50); box1(30,18,49,22,GOINGLEFT,BROWN,10); drawbox(30,18,49,22,YELLOW); gotoxy(32,19); textcolor(WHITE|BLINK); cprintf("CONGRATULATIONS!"); gotoxy(33,20); textcolor(YELLOW); cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"); gotoxy(34,21); textcolor(GREEN); cprintf("Youve made it!"); startmove = 0; } if ((matrix[x][y])== -2) { // ZERGLINGS ATTACKED window(1,1,80,50); box1(30,18,49,22,GOINGLEFT,BROWN,10); drawbox(30,18,49,22,YELLOW); gotoxy(32,19); textcolor(WHITE|BLINK); cprintf("ZERGLINGS ATTACK"); gotoxy(33,20); textcolor(YELLOW); cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"); gotoxy(34,21); textcolor(GREEN); cprintf("You failed!"); startmove = 0; } } else { if(readytomove){ switch(direction){ case fromDown: y--; break; case fromUp : y++; break; case fromLeft : x++; break; case fromRight : x--; break; } gotoxy(x,y); textcolor(RED); cprintf(""); } } //gotoxy(20,22); printf("x:%d, y:%d ",x,y); //gotoxy(20,23); printf("px:%d, py:%d ",prevx,prevy); //gotoxy(20,24); printf("matrix[%d][%d] : %d ",x,y,matrix[x][y]); }//endwhile while(1){ c=getch(); if (c==ESC) break; } window(1,1,80,50); box1(3,3,78,48,GOINGDOWN,BLACK,5); }
void initWalls(point* p, point* back, wall** w) { w[0][0] = initWall(&p[0], &p[1], &p[6], &p[7]); w[0][1] = initWall(&p[1], &p[2], &p[5], &p[6]); w[0][2] = initWall(&p[2], &p[3], &p[4], &p[5]); w[0][3] = initWall(&p[11], &p[3], &p[4], &p[12]); w[0][4] = initWall(&p[19], &p[20], &p[12], &p[11]); w[0][5] = initWall(&p[27], &p[19], &p[20], &p[28]); w[0][6] = initWall(&p[26], &p[27], &p[28], &p[29]); w[0][7] = initWall(&p[25], &p[26], &p[29], &p[30]); w[0][8] = initWall(&p[24], &p[25], &p[30], &p[31]); w[0][9] = initWall(&p[24], &p[31], &p[23], &p[16]); w[0][10] = initWall(&p[16], &p[8], &p[15], &p[23]); w[0][11] = initWall(&p[8], &p[0], &p[7], &p[15]); w[1][0] = initWall(&p[9], &p[1], &p[6], &p[14]); w[1][1] = initWall(&p[8], &p[9], &p[14], &p[15]); w[1][2] = initWall(&p[16], &p[17], &p[22], &p[23]); w[1][3] = initWall(&p[25], &p[17], &p[22], &p[30]); w[1][4] = initWall(&p[26], &p[18], &p[21], &p[29]); w[1][5] = initWall(&p[18], &p[19], &p[20], &p[21]); w[1][6] = initWall(&p[10], &p[11], &p[12], &p[13]); w[1][7] = initWall(&p[10], &p[2], &p[5], &p[13]); w[2][0] = initWall(&p[9], &p[10], &p[13], &p[14]); w[2][1] = initWall(&p[17], &p[9], &p[14], &p[22]); w[2][2] = initWall(&p[17], &p[18], &p[21], &p[22]); w[2][3] = initWall(&p[18], &p[10], &p[13], &p[21]); w[3][0] = initWall(&back[0], &back[1], &back[6], &back[7]); w[3][1] = initWall(&back[1], &back[2], &back[5], &back[6]); w[3][2] = initWall(&back[2], &back[3], &back[4], &back[5]); w[3][3] = initWall(&back[1], &p[1], &p[6], &back[6]); w[3][4] = initWall(&back[2], &p[2], &p[5], &back[5]); }
int main( void ) { //init bullet initBullet(); // Initialise GLFW if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); return -1; } glfwWindowHint(GLFW_SAMPLES, 4); // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //screen resolution GLFW const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); int w = mode->width; int h = mode->height; if(MessageBox(NULL, L"Would you like to run in fullscreen?", L"Fullscreen", MB_ICONQUESTION | MB_YESNO) == IDYES) { window = glfwCreateWindow( w, h, "Ray Tracing - Alfonso Oricchio", glfwGetPrimaryMonitor(), NULL); printf("fullscreen\n"); } else { window = glfwCreateWindow( WINDOW_WIDTH, WINDOW_HEIGHT, "Ray Tracing - Alfonso Oricchio", NULL, NULL); printf("window\n"); } // Open a window and create its OpenGL context if( window == NULL ){ fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" ); glfwTerminate(); return -1; } glfwMakeContextCurrent(window); // Initialize GLEW glewExperimental = true; // Needed for core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } // Ensure we can capture the escape key being pressed below glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); glfwSetCursorPos(window, WINDOW_WIDTH/2, WINDOW_HEIGHT/2); // Dark blue background glClearColor(0.0f, 0.0f, 0.4f, 0.0f); // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LESS); // Cull triangles which normal is not towards the camera //glEnable(GL_CULL_FACE); GLuint VertexArrayID; glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); // Create and compile our GLSL program from the shaders GLuint depthProgramID = LoadShaders( "DepthRTT.vertexshader", "DepthRTT.fragmentshader" ); // Get a handle for our "MVP" uniform GLuint depthMatrixID = glGetUniformLocation(depthProgramID, "depthMVP"); // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer. GLuint FramebufferName = 0; glGenFramebuffers(1, &FramebufferName); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); // Depth texture. Slower than a depth buffer, but you can sample it later in your shader GLuint depthTexture; glGenTextures(1, &depthTexture); glBindTexture(GL_TEXTURE_2D, depthTexture); glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT16, 1024, 1024, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, 0); // No color output in the bound framebuffer, only depth. glDrawBuffer(GL_NONE); // Always check that our framebuffer is ok if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return false; /***********************************************************/ // The quad's FBO. Used only for visualizing the shadowmap. static const GLfloat g_quad_vertex_buffer_data[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, }; GLuint quad_vertexbuffer; glGenBuffers(1, &quad_vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW); // Create and compile our GLSL program from the shaders GLuint quad_programID = LoadShaders( "Passthrough.vertexshader", "SimpleTexture.fragmentshader" ); GLuint texID = glGetUniformLocation(quad_programID, "texture"); /**********************************************************/ // Create and compile our GLSL program from the shaders GLuint programID = LoadShaders( "TransformVertexShader.vertexshader", "ColorFragmentShader.fragmentshader" ); // Get a handle for our "MVP" uniform GLuint MatrixID = glGetUniformLocation(programID, "MVP"); GLuint ViewMatrixID = glGetUniformLocation(programID, "V"); GLuint ModelMatrixID = glGetUniformLocation(programID, "M"); GLuint DepthBiasID = glGetUniformLocation(programID, "DepthBiasMVP"); GLuint ShadowMapID = glGetUniformLocation(programID, "shadowMap"); // Get a handle for our "LightPosition" uniform GLuint lightInvDirID = glGetUniformLocation(programID, "LightInvDirection_worldspace"); //CUBO1 addBox(2,2,2,0,0,0,1.0); //CUBO2 addBox2(2,2,2,0,6,0,1.0); //FLOOR initFloor(); //WALL initWall(); //BALL addScene(); do{ world->stepSimulation(1/60.f); if (glfwGetKey( window, GLFW_KEY_SPACE ) == GLFW_PRESS){ btRigidBody* ball = addBall(1.0,CamGetPosition().x,CamGetPosition().y,CamGetPosition().z,2.0); ball->setLinearVelocity(btVector3((CamGetDirection().x*50),(CamGetDirection().y*50),(CamGetDirection().z*50))); } // Render to our framebuffer glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glViewport(0,0,1024,1024); // Render on the whole framebuffer, complete from the lower left corner to the upper right // Clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ////////////////////////////// // Use our shader //SHADOW RENDER glUseProgram(depthProgramID); glm::vec3 lightInvDir = glm::vec3(0.5f,2,2); // Compute the MVP matrix from the light's point of view glm::mat4 depthProjectionMatrix = glm::ortho<float>(-10,10,-10,10,-10,20); glm::mat4 depthViewMatrix = glm::lookAt(lightInvDir, glm::vec3(0,0,0), glm::vec3(0,1,0)); // or, for spot light : //glm::vec3 lightPos(5, 20, 20); //glm::mat4 depthProjectionMatrix = glm::perspective<float>(45.0f, 1.0f, 2.0f, 50.0f); //glm::mat4 depthViewMatrix = glm::lookAt(lightPos, lightPos-lightInvDir, glm::vec3(0,1,0)); glm::mat4 depthModelMatrix = glm::mat4(1.0); glm::mat4 depthMVP = depthProjectionMatrix * depthViewMatrix * depthModelMatrix; // Send our transformation to the currently bound shader, // in the "MVP" uniform glUniformMatrix4fv(depthMatrixID, 1, GL_FALSE, &depthMVP[0][0]); // CUBE1 ------------------------------------------------------------------------- renderBox(bodies[0],true); //just a cube not really needed //CUBE2 -------------------------------------------------------------------------- renderBox2(bodies[1],true); //just a cube not really needed //FLOOR -------------------------------------------------------------------------- renderPlane(bodies[2],true); //floor //WALL --------------------------------------------------------------------------- renderWall(bodies[3],true); //back wall //CASTLE ------------------------------------------------------------------------- renderScene(true); //castle, main scene //BALL --------------------------------------------------------------------------- int iv; for(iv = 4; iv < bodies.size();iv++) { renderBall(bodies[iv],(iv - 4),true); //"cannon balls" shooted from the camera } ////////////////////////////// //STANDARD RENDER // Compute the MVP matrix from keyboard and mouse input // Clear the screen // Render to the screen glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0,0,1024,768); // Render on the whole framebuffer, complete from the lower left corner to the upper right glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Use our shader glUseProgram(programID); computeMatricesFromInputs(); glm::mat4 ProjectionMatrix = getProjectionMatrix(); glm::mat4 ViewMatrix = getViewMatrix(); glm::mat4 ModelMatrix = glm::mat4(1.0); glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix; glm::mat4 biasMatrix( 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0 ); glm::mat4 depthBiasMVP = biasMatrix*depthMVP; // Send our transformation to the currently bound shader, // in the "MVP" uniform glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &ModelMatrix[0][0]); glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &ViewMatrix[0][0]); glUniformMatrix4fv(DepthBiasID, 1, GL_FALSE, &depthBiasMVP[0][0]); glUniform3f(lightInvDirID, lightInvDir.x, lightInvDir.y, lightInvDir.z); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, depthTexture); glUniform1i(ShadowMapID, 0); // CUBE1 ------------------------------------------------------------------------- renderBox(bodies[0],false); //just a cube not really needed //CUBE2 -------------------------------------------------------------------------- renderBox2(bodies[1],false); //just a cube not really needed //FLOOR -------------------------------------------------------------------------- renderPlane(bodies[2],false); //floor //WALL --------------------------------------------------------------------------- renderWall(bodies[3],false); //back wall //CASTLE ------------------------------------------------------------------------- renderScene(false); //castle, main scene //BALL --------------------------------------------------------------------------- // int iv; for(iv = 4; iv < bodies.size();iv++) { renderBall(bodies[iv],(iv - 4),false); //"cannon balls" shooted from the camera } /*--------------------------------------------------*/ // Optionally render the shadowmap (for debug only) // Render only on a corner of the window (or we we won't see the real rendering...) glViewport(0,0,512,512); // Use our shader glUseProgram(quad_programID); // Bind our texture in Texture Unit 0 glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, depthTexture); // Set our "renderedTexture" sampler to user Texture Unit 0 glUniform1i(texID, 0); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); glVertexAttribPointer( 0, // attribute 0. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! // You have to disable GL_COMPARE_R_TO_TEXTURE above in order to see anything ! //glDrawArrays(GL_TRIANGLES, 0, 6); // 2*3 indices starting at 0 -> 2 triangles glDisableVertexAttribArray(0); /*--------------------------------------------------*/ // Swap buffers glfwSwapBuffers(window); glfwPollEvents(); } // Check if the ESC key was pressed or the window was closed while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 ); deleteALL(); glDeleteProgram(programID); glDeleteVertexArrays(1, &VertexArrayID); // Close OpenGL window and terminate GLFW glfwTerminate(); return 0; }