//---------------------------------------------------------------------------- void PolyhedronDistance::OnIdle () { if (MoveCamera()) { mCuller.ComputeVisibleSet(mScene); } if (mRenderer->PreDraw()) { mRenderer->ClearBuffers(); mRenderer->Draw(mCuller.GetVisibleSet()); char message[256]; sprintf(message, "separation = %3.2f", mSeparation/(Mathf::Sqrt(2.0)*mEdgeLength)); mRenderer->Draw(8, GetHeight()-8, mTextColor, message); sprintf(message, " small tetrahedron sides." ); mRenderer->Draw(140, GetHeight()-8, mTextColor, message); mRenderer->PostDraw(); mRenderer->DisplayColorBuffer(); } }
void CameraManager::ChangeLookAtBy(const vec3f& offset) { MoveCamera(mLookAt + offset, mOrigin + offset); }
void CameraManager::ChangeLookAtTo(const vec3f& newLookAt) { MoveCamera(newLookAt, mOrigin - mLookAt + newLookAt); }
//---------------------------------------------------------------------------- void BillboardNodes::OnIdle () { MeasureTime(); // Update set of visible objects. if (MoveCamera()) { mBillboard0->Update(); mBillboard1->Update(); mCuller.ComputeVisibleSet(mScene); } if (MoveObject()) { mScene->Update(); mCuller.ComputeVisibleSet(mScene); } #ifdef DEMONSTRATE_VIEWPORT_BOUNDING_RECTANGLE // Compute the bounding rectangle for the torus. VertexBuffer* vbuffer = mTorus->GetVertexBuffer(); char* vertices = vbuffer->GetData(); int numVertices = vbuffer->GetNumElements(); int stride = mTorus->GetVertexFormat()->GetStride(); const HMatrix& worldMatrix = mTorus->WorldTransform.Matrix(); float xmin, xmax, ymin, ymax; mCamera->ComputeBoundingAABB(numVertices, vertices, stride, worldMatrix, xmin, xmax, ymin, ymax); // Convert the normalized display coordinates to [0,1]^2 window // coordinates. xmin = 0.5f*(1.0f + xmin); xmax = 0.5f*(1.0f + xmax); ymin = 0.5f*(1.0f + ymin); ymax = 0.5f*(1.0f + ymax); // Update the screen rectangle. VertexBufferAccessor vba(mSSRectangle); vba.Position<Float3>(0) = Float3(xmin, ymin, 0.0f); vba.Position<Float3>(1) = Float3(xmax, ymin, 0.0f); vba.Position<Float3>(2) = Float3(xmax, ymax, 0.0f); vba.Position<Float3>(3) = Float3(xmin, ymax, 0.0f); mRenderer->Update(mSSRectangle->GetVertexBuffer()); #endif // Draw the scene. if (mRenderer->PreDraw()) { mRenderer->ClearBuffers(); mRenderer->Draw(mCuller.GetVisibleSet()); #ifdef DEMONSTRATE_VIEWPORT_BOUNDING_RECTANGLE // Draw the screen rectangle. mRenderer->SetCamera(mSSCamera); mCullState->Enabled = false; mRenderer->Draw(mSSRectangle); mCullState->Enabled = true; mRenderer->SetCamera(mCamera); #endif DrawFrameRate(8, GetHeight()-8, mTextColor); mRenderer->PostDraw(); mRenderer->DisplayColorBuffer(); } UpdateFrameCount(); }
//---------------------------------------------------------------------------- //#define DUMP_RENDER_TARGETS //---------------------------------------------------------------------------- void ShadowMaps::OnIdle () { MeasureTime(); if (MoveCamera()) { mCuller.ComputeVisibleSet(mScene); } if (MoveObject()) { mScene->Update(); mCuller.ComputeVisibleSet(mScene); } if (mRenderer->PreDraw()) { // Draw the scene from the light's perspective, writing the depths // from the light into the render target. mRenderer->Enable(mShadowTarget); mRenderer->SetClearColor(mShadowClear); mRenderer->ClearBuffers(); mRenderer->Draw(mCuller.GetVisibleSet(), mShadowEffect); mRenderer->Disable(mShadowTarget); #ifdef DUMP_RENDER_TARGETS Texture2D* texture = mRenderer->Read(mShadowTarget); texture->SaveWMTF("ShadowTarget.wmtf"); delete0(texture); #endif // Draw the scene from the camera's perspective, using projected // texturing of the shadow map and determining which pixels are lit // and which are shadowed. mRenderer->ClearBuffers(); mRenderer->Enable(mUnlitTarget); mRenderer->SetClearColor(mUnlitClear); mRenderer->ClearBuffers(); mRenderer->Draw(mCuller.GetVisibleSet(), mUnlitEffect); mRenderer->Disable(mUnlitTarget); #ifdef DUMP_RENDER_TARGETS texture = mRenderer->Read(mUnlitTarget); texture->SaveWMTF("UnlitTarget.wmtf"); delete0(texture); #endif // Do screen space drawing. mRenderer->SetCamera(mScreenCamera); // Horizontally blur the unlit render target. mScreenPolygon->SetEffectInstance(mHBlurInstance); mRenderer->Enable(mHBlurTarget); mRenderer->Draw(mScreenPolygon); mRenderer->Disable(mHBlurTarget); #ifdef DUMP_RENDER_TARGETS texture = mRenderer->Read(mHBlurTarget); texture->SaveWMTF("HBlurTarget.wmtf"); delete0(texture); #endif // Vertically blur the horizontal blur render target. mScreenPolygon->SetEffectInstance(mVBlurInstance); mRenderer->Enable(mVBlurTarget); mRenderer->Draw(mScreenPolygon); mRenderer->Disable(mVBlurTarget); #ifdef DUMP_RENDER_TARGETS texture = mRenderer->Read(mVBlurTarget); texture->SaveWMTF("VBlurTarget.wmtf"); delete0(texture); #endif // Draw the scene using regular textures, combining the shadow // information with the scene. mRenderer->SetCamera(mCamera); mRenderer->SetClearColor(mClearColor); mRenderer->ClearBuffers(); mRenderer->Draw(mCuller.GetVisibleSet()); DrawFrameRate(8, GetHeight()-8, mTextColor); mRenderer->PostDraw(); mRenderer->DisplayColorBuffer(); } UpdateFrameCount(); }
int Render3DEnvironment() { int ret; E3DGetKeyboardCnt( keybuf ); ret = MoveChara(); _ASSERT( !ret ); ret = MoveCamera(); _ASSERT( !ret ); int frameno; ret = E3DSetNewPose( hsid1, &frameno ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DBeginScene( scid, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } //視野内チェック int status; ret = E3DChkInView( scid, hsid0, &status ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DChkInView( scid, hsid1, &status ); if( ret ){ _ASSERT( 0 ); return 1; } //当たり判定( ChkInViewより後で呼ぶ ) ret = ChkConf(); _ASSERT( !ret ); //不透明部分をレンダー ret = E3DRender( scid, hsid0, 0, 1, 0, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DRender( scid, hsid1, 0, 1, 0, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } //半透明部分をレンダー ret = E3DRender( scid, hsid0, 1, 1, 1, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DRender( scid, hsid1, 1, 1, 1, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DRenderBillboard( scid, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } //モーションブラーの描画 if( rendercnt == 0 ){ //E3DSetMotinBlurをしてから初回のレンダー時には必ず必要。 //SetではなくてInitであるところに注意。 ret = E3DInitBeforeBlur( hsid0 ); _ASSERT( !ret ); ret = E3DInitBeforeBlur( hsid1 ); _ASSERT( !ret ); ret = E3DInitBeforeBlur( -1 ); _ASSERT( !ret ); } ret = E3DRenderMotionBlur( scid, blurdisp, 3 ); if( ret ){ _ASSERT( 0 ); return 1; } rendercnt++; //毎フレーム呼び出す E3DSetBeforeBlur( hsid0 ); E3DSetBeforeBlur( hsid1 ); E3DSetBeforeBlur( -1 ); ret = DrawText(); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DEndScene(); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DPresent( scid ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DWaitbyFPS( 60, &retfps ); if( ret ){ _ASSERT( 0 ); return 1; } //位置の記録 ret = E3DGetPos( hsid1, &curpos ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetBeforePos( hsid1 ); if( ret ){ _ASSERT( 0 ); return 1; } befpos = curpos; return 0; }
int main() { GLFWwindow* window = nullptr; glfwSetErrorCallback(error_callback); // Inititiating GLFW library if (!glfwInit()) exit(EXIT_FAILURE); // Sets hints for the next call to glfwCreateWindow - Keep these for future debugging glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); glfwWindowHint(GLFW_REFRESH_RATE, GLFW_DONT_CARE);// This hint is ignored for windowed mode windows. // Creating window window = glfwCreateWindow(640, 480, "Title", NULL, NULL); // Failure check - Creating window if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } else { fprintf(stderr, "GLFW Window initialized\n"); } // Bind key-inputs glfwSetKeyCallback(window, key_callback); // Fetch OpenGL version - Makes sure correct version is loaded from GLEW glfwMakeContextCurrent(window); // Inititiating GLEW library glewExperimental = true; GLenum err = glewInit(); // Failure check - Inititiating GLEW if (GLEW_OK != err) { fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } else { fprintf(stderr, "GLEW initialized\n"); } #ifdef _DEBUG if (glDebugMessageCallback){ std::cout << "Register OpenGL debug callback " << std::endl; glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback((GLDEBUGPROC)openglCallbackFunction, nullptr); GLuint unusedIds = 0; glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, &unusedIds, true); } else { std::cout << "glDebugMessageCallback not available" << std::endl; } #endif // VSync glfwSwapInterval(1); //////////////////////////////////////////////////////////// // Engine classes Graphics ge = Graphics(); Physics ph = Physics(); InitMeshes(&ge); InitCameras(); ge.SetCamera(&cameras[cameraIndex]); fpsCounter fpsC; int tickCounter = 400; //////////////////////////////////////////////////////////// while (!glfwWindowShouldClose(window)) { std::stringstream ss; ss << fpsC.get(); glfwSetWindowTitle(window, ss.str().c_str()); KeyEvents(window, &ge, &ph); UpdateProjections(window); RotateCamera(&cameras[cameraIndex], window); MoveCamera(&cameras[cameraIndex], window); if (fpsC.deltaTime() > 0 && tickCounter < 1) { //ph.move(&mustangHigh, &fpsC); ph.move(&EndOfLine, &fpsC); } else { tickCounter--; } Collision(&EndOfLine, &target); Collision(&EndOfLine, &target2); ge.PrepareRender(); ge.Render(&mustang); ge.Render(&mustang2); ge.Render(&mustang3); ge.Render(&mustang4); ge.Render(&mustangHigh); ge.Render(&ground); ge.Render(&target); ge.Render(&target2); ge.Render(&EndOfLine); fpsC.tick(); Sleep(1000 / 120); glfwSwapBuffers(window); glfwPollEvents();// Processes all pending events } //////////////////////////////////////////////////////////// glfwDestroyWindow(window); glfwTerminate(); return 0; }
void Ragdolls::HandleUpdate(float timeStep) { // Move the camera, scale movement with time step MoveCamera(timeStep); }
//---------------------------------------------------------------------------- void Skinning::OnIdle () { MeasureTime(); MoveCamera(); m_fTime = GetTimeInSeconds(); Matrix3f kTemp; // create some arbitrary skinning transformations const float fFactor = Mathf::PI/1.25f; int iDiv = (int)(m_fTime/fFactor); // the angle now ranges from -factor/4 to +factor/4 float fAngle = Mathf::FAbs(m_fTime-iDiv*fFactor-fFactor/2.0f)- fFactor/4.0f; for( int i = 0; i < 4; i++ ) { if ( (int)(m_fTime/fFactor+0.25f)%2 ) { kTemp.FromEulerAnglesZXY (Mathf::FAbs((float)i-1.5f)*fAngle, 0,0); } else { kTemp.FromEulerAnglesZXY (((float)i-1.5f)*fAngle, 0,0); } m_akSkinMat[i][0][0] = kTemp[0][0]; m_akSkinMat[i][0][1] = kTemp[0][1]; m_akSkinMat[i][0][2] = kTemp[0][2]; m_akSkinMat[i][0][3] = 0.0f; m_akSkinMat[i][1][0] = kTemp[1][0]; m_akSkinMat[i][1][1] = kTemp[1][1]; m_akSkinMat[i][1][2] = kTemp[1][2]; m_akSkinMat[i][1][3] = 10*Mathf::Sin(m_fTime+0.5f*(float)i); m_akSkinMat[i][2][0] = kTemp[2][0]; m_akSkinMat[i][2][1] = kTemp[2][1]; m_akSkinMat[i][2][2] = kTemp[2][2]; m_akSkinMat[i][2][3] = 0.0f; m_akSkinMat[i][3][0] = 0.0f; m_akSkinMat[i][3][1] = 0.0f; m_akSkinMat[i][3][2] = 0.0f; m_akSkinMat[i][3][3] = 1.0f; } // Set the skinning matrices in the shader if ( m_bShaderEnabled ) { m_spkTriMesh->GetVertexConst("SkinningMat[0]")-> SetData(m_akSkinMat[0]); m_spkTriMesh->GetVertexConst("SkinningMat[1]")-> SetData(m_akSkinMat[1]); m_spkTriMesh->GetVertexConst("SkinningMat[2]")-> SetData(m_akSkinMat[2]); m_spkTriMesh->GetVertexConst("SkinningMat[3]")-> SetData(m_akSkinMat[3]); } if ( MoveObject() ) m_spkScene->UpdateGS(0.0f); ms_spkRenderer->ClearBuffers(); if ( ms_spkRenderer->BeginScene() ) { if ( m_bInitialized ) { ms_spkRenderer->Draw(m_spkScene); DrawFrameRate(8,GetHeight()-8,ColorRGB::WHITE); } else { ms_spkRenderer->Draw(8,32,ColorRGB::WHITE, "Load of skinning.wvs failed." ); ms_spkRenderer->Draw(8,48,ColorRGB::WHITE, "Make sure these files are in the same directory as the " "executable."); } ms_spkRenderer->EndScene(); } ms_spkRenderer->DisplayBackBuffer(); UpdateClicks(); }
//Main program loop - Run gets called until it returns false bool Run() { //Main loop - get keypresses and interpret them keystate=GetRemoteKeys(); if(keystate & KEY_HOME) { return false; } switch(mode) { case 0: { //Splash screen if (keystate & KEY_INPUT2) { //Button B //Start game InitialiseGame(); PlaySound(SOUND_BEEP); } if (keystate & KEY_INPUT1) { //Button A //show help ShowHelp(); PlaySound(SOUND_BEEP); } } break; case 2: { //Help - wait for 'OK' press if (keystate & KEY_INPUT2) { //Button B //Reset back to splash screen ResetTimer(); mode=0; Splash(); PlaySound(SOUND_BEEP); } } break; case 1: { //Game if (keystate & KEY_INPUT1) { //Button A //Reset back to splash screen ResetTimer(); mode=0; Splash(); } if (keystate & KEY_RUN) { //Go button //Fire! PlaySound(SOUND_SHOOT); refreshCount = 0; int hit; hit = LineHitsObject(cameraPos, cameraAngle); if (hit == tankObjectIndex) { //we hit the tank! score += 100; CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); DrawExplosion(); DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); SetTextColor(CYAN); DrawText(6,100,"Quit"); Show(); PlaySound(SOUND_EXPLOSION); PlaceTank(cameraPos, cameraAngle); } } //Have the movement sticks changed? This bit doesn't care about buttons if((keystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD)) != (oldKeystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD))) { MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate); arrowRefAngle=cameraAngle.y; baselinePos=cameraPos; ResetTimer(); oldKeystate = keystate; if (keystate==0) //we've just stopped moving refreshCount=0; } if (mode==1) { if (sweepStepCount == SWEEPSTEPS) sweepStepCount=0; if (--behaviourCount<0) ChooseBehaviour(); MoveTank(); MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate); //is it time to reset the tank model? Otherwise it gradually gets distorted if (--resetCount<0) { //Refresh the tank model which is prone to getting distorted //due to cumulative inaccuracies of sin/cos approximations Point3d angle=world.objects[tankObjectIndex].heading; Point3d tankPos=world.objects[tankObjectIndex].centre; world.objects[tankObjectIndex]=tank; MoveObject(&(world.objects[tankObjectIndex]), tankPos); RotateObjectYAxis(&(world.objects[tankObjectIndex]), angle.y); resetCount=50; } //Is it time to redraw the world? if (--refreshCount<0) { //Seems a bit brutal to have to close graphics but it's //the only way to clear the screen that'll let us draw //on it properly again - ClearScreen or ClearRectangle mess up CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); refreshCount=2; } DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); SetTextColor(CYAN); DrawText(6,100,"Quit"); Show(); //just in case we changed mode... if (mode==0) Splash(); } } } Sleep(50); return true; }
int Render3DEnvironment() { int ret; ret = E3DGetKeyboardState( keybuf ); _ASSERT( !ret ); if( keybuf[VK_ESCAPE] == 1 ){ return 1; } ret = MoveChara(); if( ret ){ _ASSERT( 0 ); return 1; } ret = MoveCamera(); if( ret ){ _ASSERT( 0 ); return 1; } int curframe; ret = E3DSetNewPose( hsid1, &curframe ); if( ret ){ _ASSERT( 0 ); return 1; } int status0, status1, status2; ret = E3DChkInView( scid, hsid0, &status0 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DChkInView( scid, hsid1, &status1 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DChkInView( scid, hsid2, &status2 );//壁もChkInViewが必要 if( ret ){ _ASSERT( 0 ); return 1; } ret = ChkConf(); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DBeginScene( scid, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } //不透明 ret = E3DRender( scid, hsid0, 0, 1, 0, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DRender( scid, hsid1, 0, 1, 0, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } //半透明 ret = E3DRender( scid, hsid0, 1, 1, 1, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DRender( scid, hsid1, 1, 1, 1, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = DrawText(); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DEndScene(); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DPresent( scid ); if( ret ){ _ASSERT( 0 ); return 1; } befpos1 = pos1; ret = E3DGetPos( hsid1, &pos1 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetBeforePos( hsid1 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DPCWait( 60, &retfps ); if( ret ){ _ASSERT( 0 ); return 1; } return 0; }
int FrameMove() { int ret; E3DGetKeyboardCnt( keybuf ); if( gameflag == 0 ){ ret = MoveChara( CHARA_RED, CHARA_BLUE, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, 'B', 'N', 'M' ); if( ret ){ _ASSERT( 0 ); return 1; } ret = MoveChara( CHARA_BLUE, CHARA_RED, 'W', 'S', 'A', 'D', 'Z', 'X', 'C' ); if( ret ){ _ASSERT( 0 ); return 1; } ret = MoveCamera(); if( ret ){ _ASSERT( 0 ); return 1; } } int stat; ret = E3DChkInView( scid, groundhsid, &stat ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DChkInView( scid, ci[CHARA_RED].hsid, &stat ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DChkInView( scid, ci[CHARA_BLUE].hsid, &stat ); if( ret ){ _ASSERT( 0 ); return 1; } if( gameflag == 0 ){ ret = ChkConfChara(); if( ret ){ _ASSERT( 0 ); return 1; } ret = ChangeHP( CHARA_RED, CHARA_BLUE ); if( ret ){ _ASSERT( 0 ); return 1; } ret = ChangeHP( CHARA_BLUE, CHARA_RED ); if( ret ){ _ASSERT( 0 ); return 1; } ret = ChkGameOver(); if( ret ){ _ASSERT( 0 ); return 1; } } return 0; }
void ofxSpriteRenderer::MoveCamera(float x, float z) { MoveCamera(ofVec2f(x, z)); }
void SignedDistanceFieldText::HandleUpdate(float timeStep) { // Move the camera, scale movement with time step MoveCamera(timeStep); }
void CCamera::CheckForMovement() { // Once we have the frame interval, we find the current speed float speed = (float)(kSpeed * g_FrameInterval); // Store the last position and view of the camera CVector3 vOldPosition = Position(); CVector3 vOldView = View(); // Use a flag to see if we movement backwards or not bool bMovedBack = false; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Here is where we subtract the gravity acceleration from our velocity vector. // We then add that velocity vector to our camera to effect our camera (or player) // This is also how we handle the jump velocity when we hit space bar. // Notice that we multiply the gravity by the frame interval (dt). This makes // it so faster video cards don't do a 2 frame jump, while TNT2 cards do 20 frames :) // This is necessary to make every computer use the same movement and jump speed. g_vVelocity.y -= (float)(kGravity * g_FrameInterval); m_vPosition = m_vPosition + g_vVelocity; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Check if we hit the Up arrow or the 'w' key if(GetKeyState(VK_UP) & 0x80 || GetKeyState('W') & 0x80) { // Move our camera forward by a positive SPEED MoveCamera(speed); } // Check if we hit the Down arrow or the 's' key if(GetKeyState(VK_DOWN) & 0x80 || GetKeyState('S') & 0x80) { // Move our camera backward by a negative SPEED MoveCamera(-speed); bMovedBack = true; } // Check if we hit the Left arrow or the 'a' key if(GetKeyState(VK_LEFT) & 0x80 || GetKeyState('A') & 0x80) { // Strafe the camera left StrafeCamera(-speed); } // Check if we hit the Right arrow or the 'd' key if(GetKeyState(VK_RIGHT) & 0x80 || GetKeyState('D') & 0x80) { // Strafe the camera right StrafeCamera(speed); } // Now that we moved, let's get the current position and test our movement // vector against the level data to see if there is a collision. CVector3 vCurrentPosition = Position(); // Check for collision with AABB's and grab the new position CVector3 vNewPosition = g_Level.TraceBox(vOldPosition, vCurrentPosition, CVector3(-20, -50, -20), CVector3(20, 50, 20)); // Check if we collided and we moved backwards if(g_Level.Collided() && bMovedBack) { // If or x or y didn't move, then we are backed into a wall so restore the view vector if(vNewPosition.x == vOldPosition.x || vNewPosition.z == vOldPosition.z) m_vView = vOldView; } // Set the new position that was returned from our trace function m_vPosition = vNewPosition; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // After we check for collision, we only want to add the velocity vector to // our view vector when we are falling. If we aren't on the ground then // we don't want to push the the camera view down to the ground. It's okay // if the position goes down because the collision detection fixes that so // we don't go through the ground, however, it's not natural to push the view // down too. Well, assuming is strong enough to push our face down to the ground :) if(!g_Level.IsOnGround()) m_vView = m_vView + g_vVelocity; else { // If we ARE on the ground, we want to get rid of the jump acceleration // that we add when the user hits the space bar. Below we check to see // if our velocity is below 0 then we are done with our jump and can just // float back to the ground by the gravity. We do also add our gravity // acceleration to the velocity every frame, so this resets this to zero // for that as well. if(g_vVelocity.y < 0) g_vVelocity.y = 0; } /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * }
void CCamera::CheckForMovement() { // Once we have the frame interval, we find the current speed float speed = (float)(kSpeed * g_FrameInterval); // Before we move our camera we want to store the old position. We then use // this data to test collision detection. CVector3 vOldPosition = Position(); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Store the old view vector to restore it if we collided backwards CVector3 vOldView = View(); // Use a flag to see if we movement backwards or not bool bMovedBack = false; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Check if we hit the Up arrow or the 'w' key if(GetKeyState(VK_UP) & 0x80 || GetKeyState('W') & 0x80) { // Move our camera forward by a positive SPEED MoveCamera(speed); } // Check if we hit the Down arrow or the 's' key if(GetKeyState(VK_DOWN) & 0x80 || GetKeyState('S') & 0x80) { // Move our camera backward by a negative SPEED MoveCamera(-speed); bMovedBack = true; } // Check if we hit the Left arrow or the 'a' key if(GetKeyState(VK_LEFT) & 0x80 || GetKeyState('A') & 0x80) { // Strafe the camera left StrafeCamera(-speed); } // Check if we hit the Right arrow or the 'd' key if(GetKeyState(VK_RIGHT) & 0x80 || GetKeyState('D') & 0x80) { // Strafe the camera right StrafeCamera(speed); } // Now that we moved, let's get the current position and test our movement // vector against the level data to see if there is a collision. CVector3 vCurrentPosition = Position(); // We will not use sphere collision from now on, but AABB collision (box) // CVector3 vNewPosition = g_Level.TraceSphere(vOldPosition, vCurrentPosition, 25.0f); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // We are now using AABB collision now, so we no longer use sphere checks. // Below we pass into the TraceBox() function some generic Min and Max values // for our bounding box. We then get the new position if we collided CVector3 vNewPosition = g_Level.TraceBox(vOldPosition, vCurrentPosition, CVector3(-20, -50, -20), CVector3(20, 50, 20)); // We add some code below to make it so when we back into a wall, our view vector // doesn't keep going backwards, since we aren't moving backwards. If we don't // do this check, it will turn our camera around and look like a glitch. Not desired! // Check if we collided and we moved backwards if(g_Level.Collided() && bMovedBack) { // If or x or y didn't move, then we are backed into a wall so restore the view vector if(vNewPosition.x == vOldPosition.x || vNewPosition.z == vOldPosition.z) m_vView = vOldView; } /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set the new position that was returned from our trace function m_vPosition = vNewPosition; }
bool DEMO_APP::Run() { theTime.Signal(); float dt = (float)theTime.Delta(); devContext->OMSetRenderTargets(1, &anotherView, DepthStencilView); devContext->RSSetViewports(1, &viewPort); float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; devContext->ClearRenderTargetView(anotherView, ClearColor); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); scene[0] = Inverse4x4(secondCamera); D3D11_MAPPED_SUBRESOURCE sceneMap; ZeroMemory(&sceneMap, sizeof(sceneMap)); devContext->Map(sceneMatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sceneMap); memcpy(sceneMap.pData, scene, sizeof(scene)); devContext->Unmap(sceneMatrixBuffer, 0); devContext->VSSetConstantBuffers(1, 1, &sceneMatrixBuffer); devContext->PSSetConstantBuffers(0, 1, &lightBuff); devContext->PSSetConstantBuffers(1, 1, &ambientBuff); devContext->PSSetConstantBuffers(2, 1, &ptltBuff); devContext->PSSetConstantBuffers(3, 1, &spotBuff); devContext->GSSetConstantBuffers(1, 1, &sceneMatrixBuffer); //Pyramid.worldMatrices[0] = RotateY(50.0f * dt) * Pyramid.worldMatrices[0]; //Pyramid.worldMatrices[1] = RotateZ(50.0f * dt) * Pyramid.worldMatrices[1]; //Pyramid.worldMatrices[2] = RotateX(50.0f * dt) * Pyramid.worldMatrices[2]; //Pyramid.worldMatrices[3] = RotateY(200.0f * dt) * RotateZ(200.0f * dt) * RotateX(200.0f * dt) * Pyramid.worldMatrices[3]; //SKYBOX RENDERING///// devContext->RSSetState(pOtherState); //SkyBox.worldMatrix = viewMatrix; SkyBox.worldMatrix.M[3][0] = secondCamera.M[3][0]; SkyBox.worldMatrix.M[3][1] = secondCamera.M[3][1]; SkyBox.worldMatrix.M[3][2] = secondCamera.M[3][2]; SkyBox.Render(); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); /////////////////////// devContext->RSSetState(pRasterState); Pyramid.Render(); Quad.Render(); Tree.Render(); Tree2.Render(); Tree1.Render(); devContext->ResolveSubresource(fixerTexture, D3D11CalcSubresource(0, 0, 1), renderTexture, D3D11CalcSubresource(0, 0, 1), DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); QuadSeed.Render(); devContext->GenerateMips(QuadSeed.pShaderResource); ///////////////////////////////////////////////////////////////////////////////////////////////////////// devContext->OMSetRenderTargets(1, &postProcessView, DepthStencilView); devContext->RSSetViewports(1, &viewPort); //float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; devContext->ClearRenderTargetView(postProcessView, ClearColor); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); scene[0] = Inverse4x4(viewMatrix); //D3D11_MAPPED_SUBRESOURCE sceneMap; ZeroMemory(&sceneMap, sizeof(sceneMap)); devContext->Map(sceneMatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sceneMap); memcpy(sceneMap.pData, scene, sizeof(scene)); devContext->Unmap(sceneMatrixBuffer, 0); devContext->VSSetConstantBuffers(1, 1, &sceneMatrixBuffer); devContext->PSSetConstantBuffers(0, 1, &lightBuff); devContext->PSSetConstantBuffers(1, 1, &ambientBuff); devContext->PSSetConstantBuffers(2, 1, &ptltBuff); devContext->PSSetConstantBuffers(3, 1, &spotBuff); devContext->GSSetConstantBuffers(1, 1, &sceneMatrixBuffer); //Pyramid.worldMatrices[0] = RotateY(50.0f * dt) * Pyramid.worldMatrices[0]; //Pyramid.worldMatrices[1] = RotateZ(50.0f * dt) * Pyramid.worldMatrices[1]; //Pyramid.worldMatrices[2] = RotateX(50.0f * dt) * Pyramid.worldMatrices[2]; //Pyramid.worldMatrices[3] = RotateY(200.0f * dt) * RotateZ(200.0f * dt) * RotateX(200.0f * dt) * Pyramid.worldMatrices[3]; //SKYBOX RENDERING///// devContext->RSSetState(pOtherState); //SkyBox.worldMatrix = viewMatrix; SkyBox.worldMatrix.M[3][0] = viewMatrix.M[3][0]; SkyBox.worldMatrix.M[3][1] = viewMatrix.M[3][1]; SkyBox.worldMatrix.M[3][2] = viewMatrix.M[3][2]; SkyBox.Render(); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); /////////////////////// devContext->RSSetState(pRasterState); Pyramid.Render(); Quad.Render(); Tree.Render(); Tree1.Render(); Tree2.Render(); devContext->ResolveSubresource(fixerTexture, D3D11CalcSubresource(0, 0, 1), renderTexture, D3D11CalcSubresource(0, 0, 1), DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); QuadSeed.Render(); devContext->GenerateMips(QuadSeed.pShaderResource); devContext->ResolveSubresource(fixerTexture, D3D11CalcSubresource(0, 0, 1), postTexture, D3D11CalcSubresource(0, 0, 1), DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); PostQuad.Render(); ///////////////////////////////////////////////////////////////// devContext->OMSetRenderTargets(1, &targetView, DepthStencilView); //devContext->RSSetViewports(1, &viewPort); //float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; devContext->ClearRenderTargetView(targetView, ClearColor); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); MoveCamera(5.0f, 200.0f, dt); D3D11_MAPPED_SUBRESOURCE ambMap; ZeroMemory(&ambMap, sizeof(ambMap)); devContext->Map(ambientBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &ambMap); memcpy(ambMap.pData, &ambientLight, sizeof(ambientLight)); devContext->Unmap(ambientBuff, 0); D3D11_MAPPED_SUBRESOURCE lightMap; ZeroMemory(&lightMap, sizeof(lightMap)); devContext->Map(lightBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &lightMap); memcpy(lightMap.pData, &theLight, sizeof(theLight)); devContext->Unmap(lightBuff, 0); D3D11_MAPPED_SUBRESOURCE ptLtMap; ZeroMemory(&ptLtMap, sizeof(ptLtMap)); devContext->Map(ptltBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &ptLtMap); memcpy(ptLtMap.pData, &thePtLight, sizeof(thePtLight)); devContext->Unmap(ptltBuff, 0); D3D11_MAPPED_SUBRESOURCE spotMap; ZeroMemory(&spotMap, sizeof(spotMap)); devContext->Map(spotBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &spotMap); memcpy(spotMap.pData, &theSpotLight, sizeof(theSpotLight)); devContext->Unmap(spotBuff, 0); scene[0] = Inverse4x4(viewMatrix); SkyBox.worldMatrix.M[3][0] = viewMatrix.M[3][0]; SkyBox.worldMatrix.M[3][1] = viewMatrix.M[3][1]; SkyBox.worldMatrix.M[3][2] = viewMatrix.M[3][2]; //D3D11_MAPPED_SUBRESOURCE sceneMap; ZeroMemory(&sceneMap, sizeof(sceneMap)); devContext->Map(sceneMatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sceneMap); memcpy(sceneMap.pData, scene, sizeof(scene)); devContext->Unmap(sceneMatrixBuffer, 0); devContext->VSSetConstantBuffers(1, 1, &sceneMatrixBuffer); devContext->PSSetConstantBuffers(0, 1, &lightBuff); devContext->PSSetConstantBuffers(1, 1, &ambientBuff); devContext->PSSetConstantBuffers(2, 1, &ptltBuff); devContext->PSSetConstantBuffers(3, 1, &spotBuff); devContext->GSSetConstantBuffers(1, 1, &sceneMatrixBuffer); //Pyramid.worldMatrices[0] = RotateY(50.0f * dt) * Pyramid.worldMatrices[0]; //Pyramid.worldMatrices[1] = RotateZ(50.0f * dt) * Pyramid.worldMatrices[1]; //Pyramid.worldMatrices[2] = RotateX(50.0f * dt) * Pyramid.worldMatrices[2]; //Pyramid.worldMatrices[3] = RotateY(200.0f * dt) * RotateZ(200.0f * dt) * RotateX(200.0f * dt) * Pyramid.worldMatrices[3]; //SKYBOX RENDERING///// devContext->RSSetState(pOtherState); //SkyBox.worldMatrix = viewMatrix; SkyBox.Render(); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); /////////////////////// devContext->RSSetState(pRasterState); Pyramid.Render(); Quad.Render(); Tree.Render(); Tree1.Render(); Tree2.Render(); devContext->ResolveSubresource(fixerTexture, D3D11CalcSubresource(0, 0, 1), renderTexture, D3D11CalcSubresource(0, 0, 1), DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); QuadSeed.Render(); devContext->GenerateMips(QuadSeed.pShaderResource); //WHY BROKEN? devContext->ResolveSubresource(fixerTexture, D3D11CalcSubresource(0, 0, 1), postTexture, D3D11CalcSubresource(0, 0, 1), DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); PostQuad.Render(); /////////////////////2nd VIEWPORT///////////////////////////////////////////////////////////////////////////////////////////////// devContext->OMSetRenderTargets(1, &anotherView, DepthStencilView); devContext->RSSetViewports(1, &otherPort); //float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; devContext->ClearRenderTargetView(anotherView, ClearColor); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); scene[0] = secondCamera; //D3D11_MAPPED_SUBRESOURCE sceneMap; ZeroMemory(&sceneMap, sizeof(sceneMap)); devContext->Map(sceneMatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sceneMap); memcpy(sceneMap.pData, scene, sizeof(scene)); devContext->Unmap(sceneMatrixBuffer, 0); devContext->VSSetConstantBuffers(1, 1, &sceneMatrixBuffer); devContext->PSSetConstantBuffers(0, 1, &lightBuff); devContext->PSSetConstantBuffers(1, 1, &ambientBuff); devContext->PSSetConstantBuffers(2, 1, &ptltBuff); devContext->PSSetConstantBuffers(3, 1, &spotBuff); devContext->GSSetConstantBuffers(1, 1, &sceneMatrixBuffer); //Pyramid.worldMatrices[0] = RotateY(50.0f * dt) * Pyramid.worldMatrices[0]; //Pyramid.worldMatrices[1] = RotateZ(50.0f * dt) * Pyramid.worldMatrices[1]; //Pyramid.worldMatrices[2] = RotateX(50.0f * dt) * Pyramid.worldMatrices[2]; //Pyramid.worldMatrices[3] = RotateY(200.0f * dt) * RotateZ(200.0f * dt) * RotateX(200.0f * dt) * Pyramid.worldMatrices[3]; //SKYBOX RENDERING///// devContext->RSSetState(pOtherState); //SkyBox.worldMatrix = viewMatrix; SkyBox.worldMatrix.M[3][0] = secondCamera.M[3][0]; SkyBox.worldMatrix.M[3][1] = secondCamera.M[3][1]; SkyBox.worldMatrix.M[3][2] = secondCamera.M[3][2]; SkyBox.Render(); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); /////////////////////// devContext->RSSetState(pRasterState); Pyramid.Render(); Quad.Render(); Tree.Render(); Tree1.Render(); Tree2.Render(); devContext->ResolveSubresource(fixerTexture, D3D11CalcSubresource(0, 0, 1), renderTexture, D3D11CalcSubresource(0, 0, 1), DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); QuadSeed.Render(); devContext->GenerateMips(QuadSeed.pShaderResource); //PostQuad.Render(); ///////////////////////////////////////////////////////////////// devContext->OMSetRenderTargets(1, &targetView, DepthStencilView); //devContext->RSSetViewports(1, &viewPort); //float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; //devContext->ClearRenderTargetView(targetView, ClearColor); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); //MoveCamera(5.0f, 200.0f, dt); //D3D11_MAPPED_SUBRESOURCE ambMap; ZeroMemory(&ambMap, sizeof(ambMap)); devContext->Map(ambientBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &ambMap); memcpy(ambMap.pData, &ambientLight, sizeof(ambientLight)); devContext->Unmap(ambientBuff, 0); //D3D11_MAPPED_SUBRESOURCE lightMap; ZeroMemory(&lightMap, sizeof(lightMap)); devContext->Map(lightBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &lightMap); memcpy(lightMap.pData, &theLight, sizeof(theLight)); devContext->Unmap(lightBuff, 0); //D3D11_MAPPED_SUBRESOURCE ptLtMap; ZeroMemory(&ptLtMap, sizeof(ptLtMap)); devContext->Map(ptltBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &ptLtMap); memcpy(ptLtMap.pData, &thePtLight, sizeof(thePtLight)); devContext->Unmap(ptltBuff, 0); //D3D11_MAPPED_SUBRESOURCE spotMap; ZeroMemory(&spotMap, sizeof(spotMap)); devContext->Map(spotBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &spotMap); memcpy(spotMap.pData, &theSpotLight, sizeof(theSpotLight)); devContext->Unmap(spotBuff, 0); scene[0] = secondCamera;//Inverse4x4(viewMatrix); //D3D11_MAPPED_SUBRESOURCE sceneMap; ZeroMemory(&sceneMap, sizeof(sceneMap)); devContext->Map(sceneMatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sceneMap); memcpy(sceneMap.pData, scene, sizeof(scene)); devContext->Unmap(sceneMatrixBuffer, 0); devContext->VSSetConstantBuffers(1, 1, &sceneMatrixBuffer); devContext->PSSetConstantBuffers(0, 1, &lightBuff); devContext->PSSetConstantBuffers(1, 1, &ambientBuff); devContext->PSSetConstantBuffers(2, 1, &ptltBuff); devContext->PSSetConstantBuffers(3, 1, &spotBuff); devContext->GSSetConstantBuffers(1, 1, &sceneMatrixBuffer); Pyramid.worldMatrices[0] = RotateY(50.0f * dt) * Pyramid.worldMatrices[0]; Pyramid.worldMatrices[1] = RotateZ(50.0f * dt) * Pyramid.worldMatrices[1]; Pyramid.worldMatrices[2] = RotateX(50.0f * dt) * Pyramid.worldMatrices[2]; Pyramid.worldMatrices[3] = RotateY(200.0f * dt) * RotateZ(200.0f * dt) * RotateX(200.0f * dt) * Pyramid.worldMatrices[3]; //SKYBOX RENDERING///// devContext->RSSetState(pOtherState); //SkyBox.worldMatrix = viewMatrix; SkyBox.worldMatrix.M[3][0] = secondCamera.M[3][0]; SkyBox.worldMatrix.M[3][1] = secondCamera.M[3][1]; SkyBox.worldMatrix.M[3][2] = secondCamera.M[3][2]; SkyBox.Render(); devContext->ClearDepthStencilView(DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); /////////////////////// devContext->RSSetState(pRasterState); Pyramid.Render(); Quad.Render(); Tree.Render(); Tree1.Render(); Tree2.Render(); devContext->ResolveSubresource(fixerTexture, D3D11CalcSubresource(0, 0, 1), renderTexture, D3D11CalcSubresource(0, 0, 1), DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); QuadSeed.Render(); devContext->GenerateMips(QuadSeed.pShaderResource); swapChain->Present(0, 0); return true; }
//---------------------------------------------------------------------------- void GeodesicHeightField::OnIdle () { MeasureTime(); if (MoveCamera()) { mCuller.ComputeVisibleSet(mScene); } if (MoveObject()) { mScene->Update(); mCuller.ComputeVisibleSet(mScene); } if (mSelected == 2) { int currQuantity = mGeodesic->GetCurrentQuantity(); if (currQuantity == 0) { currQuantity = mPQuantity; } // Clear the texture image to white. memset(mTexture->GetData(0), 0xFF, mTexture->GetNumLevelBytes(0)); // Draw the approximate path. int bound0 = mTexture->GetDimension(0, 0); int bound1 = mTexture->GetDimension(1, 0); int x0 = (int)(bound0*mPath[0][0] + 0.5); int y0 = (int)(bound1*mPath[0][1] + 0.5); for (int i = 1; i < currQuantity; ++i) { int x1 = (int)(bound0*mPath[i][0] + 0.5); int y1 = (int)(bound1*mPath[i][1] + 0.5); Line2D(x0, y0, x1, y1, DrawCallback); x0 = x1; y0 = y1; } mTexture->GenerateMipmaps(); } if (mRenderer->PreDraw()) { mRenderer->ClearBuffers(); mRenderer->Draw(mCuller.GetVisibleSet()); DrawFrameRate(8, GetHeight()-8, mTextColor); char message[256]; sprintf(message, "sub = %d, ref = %d, len = %15.12lf, avgcrv = %15.12lf", mGeodesic->GetSubdivisionStep(), mGeodesic->GetRefinementStep(), mDistance, mCurvature/mDistance); mRenderer->Draw(8, 16, mTextColor, message); mRenderer->PostDraw(); mRenderer->DisplayColorBuffer(); } UpdateFrameCount(); }
void CCamera::CheckForMovement() { // Once we have the frame interval, we find the current speed float speed = (float)(kSpeed * g_FrameInterval); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Before we move our camera we want to store the old position. We then use // this data to test collision detection. CVector3 vOldPosition = Position(); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Check if we hit the Up arrow or the 'w' key if(GetKeyState(VK_UP) & 0x80 || GetKeyState('W') & 0x80) { // Move our camera forward by a positive SPEED MoveCamera(speed); } // Check if we hit the Down arrow or the 's' key if(GetKeyState(VK_DOWN) & 0x80 || GetKeyState('S') & 0x80) { // Move our camera backward by a negative SPEED MoveCamera(-speed); } // Check if we hit the Left arrow or the 'a' key if(GetKeyState(VK_LEFT) & 0x80 || GetKeyState('A') & 0x80) { // Strafe the camera left StrafeCamera(-speed); } // Check if we hit the Right arrow or the 'd' key if(GetKeyState(VK_RIGHT) & 0x80 || GetKeyState('D') & 0x80) { // Strafe the camera right StrafeCamera(speed); } /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Now that we moved, let's get the current position and test our movement // vector against the level data to see if there is a collision. CVector3 vCurrentPosition = Position(); // Here we call our function TraceSphere() to check our movement vector (last // and current position) against the world. We pass in a radius for our sphere // of 25. If there is anything in the range of our sphere, then we collide. CVector3 vNewPosition = g_Level.TraceSphere(vOldPosition, vCurrentPosition, 25.0f); // Set the new position that was returned from our trace function m_vPosition = vNewPosition; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * }