void CameraMovementController::update( float timeElapsed ) { float speedMul =m_uic->isKeyPressed( VK_SHIFT ) ? 4.0f : 1.0f; FastFloat movementSpeed; movementSpeed.setFromFloat( 10.0f * speedMul * timeElapsed ); FastFloat negMovementSpeed; negMovementSpeed.setNeg( movementSpeed ); float rotationSpeed = 0.1f * timeElapsed; // check which keys are pressed m_movementDir[MD_FRONT] = m_uic->isKeyPressed( 'W' ); m_movementDir[MD_BACK] = m_uic->isKeyPressed( 'S' ); m_movementDir[MD_LEFT] = m_uic->isKeyPressed( 'A' ); m_movementDir[MD_RIGHT] = m_uic->isKeyPressed( 'D' ); m_rotating = m_uic->isKeyPressed( VK_RBUTTON ); m_uic->setRelativeMouseMovement( m_rotating ); // process the keys Vector moveVec; if ( m_movementDir[MD_FRONT] ) { moveVec.setMul( m_cameraController->getLookVec(), movementSpeed ); m_cameraController->move( moveVec ); } if ( m_movementDir[MD_BACK] ) { moveVec.setMul( m_cameraController->getLookVec(), negMovementSpeed ); m_cameraController->move( moveVec ); } if ( m_movementDir[MD_LEFT] ) { moveVec.setMul( m_cameraController->getRightVec(), negMovementSpeed ); m_cameraController->move( moveVec ); } if ( m_movementDir[MD_RIGHT] ) { moveVec.setMul( m_cameraController->getRightVec(), movementSpeed ); m_cameraController->move( moveVec ); } if ( m_rotating ) { float mouseSpeedX = m_uic->getMouseSpeed().v[0] * rotationSpeed; float mouseSpeedY = m_uic->getMouseSpeed().v[1] * rotationSpeed; m_cameraController->rotate( mouseSpeedY, mouseSpeedX ); } }
bool Frustum::isInside( const Sphere& sphere ) const { FastFloat negSphereRad; negSphereRad.setNeg( sphere.radius ); for ( int i = 0; i < 6; ++i ) { const FastFloat n = planes[i].dotCoord( sphere.origin ); if ( n < negSphereRad ) { return false; } } return true; }
void Camera::lookAt( Entity& node, const FastFloat& distance, const Vector& upVec ) { const Matrix& targetNodeMtx = node.getGlobalMtx(); const Vector& targetNodePos = targetNodeMtx.position(); const Vector& targetNodeLookVec = targetNodeMtx.forwardVec(); // I used to normalize the look vector here, but is there a need to do it really? we assume // it's always normalized ASSERT_MSG( targetNodeLookVec.isNormalized(), "Look vector not normalized" ); FastFloat negDist; negDist.setNeg( distance ); Vector newPosition; newPosition.setMul( targetNodeLookVec, negDist ); newPosition.add( targetNodePos ); Matrix lookAtMtx; MatrixUtils::generateLookAtLH( newPosition, targetNodePos, upVec, lookAtMtx ); setLocalMtx( lookAtMtx ); }