void CCamera::Update() { // Initialize a variable for the cross product result CVector3 vCross = Cross(m_vView - m_vPosition, m_vUpVector); // Normalize the strafe vector m_vStrafe = Normalize(vCross); // Move the camera's view by the mouse SetViewByMouse(); // This checks to see if the keyboard was pressed CheckForMovement(); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // We stick this function in our camera source file so that we can move // time base movement and camera functionality together between tutorials // relatively easily. // We calculate our frame rate and set our frame interval for time based movement CalculateFrameRate(); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * }
void Camera::Update() { vec3 vCross = cross(viewVector - position, upVector); strVector = normalize(vCross); //position.y -= currentSpeed; //viewVector.y -= currentSpeed; //if(currentSpeed == 0.0) // currentSpeed = 0.005; //currentSpeed += 0.01*currentSpeed; previousViewMatrix = viewMatrix; previousDirection = direction; previousPosition = position; SetViewByMouse(); CheckForMovement(); viewMatrix = glm::lookAt(viewVector, position, upVector); inverseMatrix = inverse(projectionMatrix * viewMatrix); direction = viewVector - position; }
void MainLoop(void) { bool done = false; // is our job done ? not yet ! SDL_Event event; while(! done) // as long as our job's not done { while( SDL_PollEvent(& event) ) // look for events (like keystrokes, resizing etc.) { switch ( event.type ) // what kind of event have we got ? { case SDL_QUIT : // if user wishes to quit done = true; // this implies our job is done break; case SDL_KEYDOWN : // if the user has pressed a key HandleKeyPressEvent( & event. key.keysym ); // callback for handling keystrokes, arg is key pressed break; case SDL_KEYUP : HandleKeyReleaseEvent(& event.key.keysym) ; // callback for handling keystrokes, arg is key released break; case SDL_VIDEORESIZE : // if there is a resize event // request SDL to resize the window to the size and depth etc. that we specify MainWindow = SDL_SetVideoMode( event.resize.w, event.resize.h, SCREEN_DEPTH, VideoFlags ); SizeOpenGLScreen(event.resize.w, event.resize.h); // now resize the OpenGL viewport if(MainWindow == NULL) // if window resize has failed { cerr << " Failed resizing SDL window : " << SDL_GetError() << endl; // report error Quit(0); } break; default: // any other event break; // nothing to do } // switch } // while( SDL_ ... //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Here we check for mouse and key movements every frame g_Camera.SetViewByMouse(); // Move the camera by the mouse CheckForMovement(); // Check if we pressed a key RenderScene(); // Update the screen //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// } // while( ! done) }
void CCamera::Update() { // Initialize a variable for the cross product result CVector3 vCross = Cross(m_vView - m_vPosition, m_vUpVector); // Normalize the strafe vector m_vStrafe = Normalize(vCross); // Move the camera's view by the mouse SetViewByMouse(); // This checks to see if the keyboard was pressed CheckForMovement(); // Calculate our frame rate and set our frame interval for time based movement CalculateFrameRate(); }