Sign in to follow this  
Pushapjit

camera movements

Recommended Posts

I am making 3d virtual model of a city. I’m using directx9 APIs for this. Following UpdateCamera() function is used for camera interactivicty. I want my camera to move along the ground. My problem is that the camera moves at the same level irrespective of the ground.
//------------------------------------------------------------------------
//Name: UpdateCamera()
//Desc: This function takes input from the user and update the scene according to user input.
//------------------------------------------------------------------------
VOID CMyD3DApplication::UpdateCamera()
{
	FLOAT fElapsedTime;

    if( m_fElapsedTime > 0.0f )
        fElapsedTime = m_fElapsedTime;
    else
        fElapsedTime = 0.05f;

    FLOAT fSpeed        = 15.0f*fElapsedTime;
    FLOAT fAngularSpeed = 1.0f*fElapsedTime;

    // De-accelerate the camera movement (for smooth motion)
    m_vVelocity      *= 0.9f;
	m_fYawVelocity   *= 0.9f;
//    m_fPitchVelocity *= 0.9f;
 
    // Process keyboard input
    if( m_bKey[VK_RIGHT] )    m_vVelocity.x    += fSpeed; // Slide Right
    if( m_bKey[VK_LEFT] )     m_vVelocity.x    -= fSpeed; // Slide Left
    if( m_bKey[VK_UP] )       m_vVelocity.z    += fSpeed; // Move Forward 
    if( m_bKey[VK_DOWN] )     m_vVelocity.z    -= fSpeed; // Move Backward 
    if( m_bKey['E'] )		m_fYawVelocity   += fSpeed; // Turn Right
    if( m_bKey['Q'] )		m_fYawVelocity   -= fSpeed; // Turn Left
//	if( m_bKey['Z'] )		m_fPitchVelocity   += fSpeed; // Turn Down
//	if( m_bKey['A'] )		m_fPitchVelocity   -= fSpeed; // Turn Up

	

    // Update the position vector
   D3DXVECTOR3 vT = m_vVelocity * fSpeed;
   D3DXVec3TransformNormal( &vT, &vT, &m_matOrientation );
   m_vPosition += vT;
   if( m_vPosition.y < 1.0f )
        m_vPosition.y = 1.0f;

	 // Update the yaw-pitch-rotation vector
    m_fYaw   += fAngularSpeed * m_fYawVelocity;

    
    // Set the view matrix
   D3DXQUATERNION qR;
   D3DXQuaternionRotationYawPitchRoll( &qR, m_fYaw, NULL, 0.0f );
 //  D3DXMatrixAffineTransformation( &m_matView, 1.25f, NULL, &qR, &m_vPosition );
	D3DXMatrixAffineTransformation( &m_matOrientation, 1.25f, NULL, &qR, &m_vPosition );
    D3DXMatrixInverse( &m_matView, NULL, &m_matOrientation );

    m_pd3dDevice->SetTransform( D3DTS_VIEW,  &m_matView );


}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this