Jump to content
  • Advertisement
Sign in to follow this  

camera movements

This topic is 4466 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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;
        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
   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

why don't you just get the height of your ground below the camera and update the position of the camera accordingly? Or am I missing something?


Share this post

Link to post
Share on other sites
how i should compute the height of terrian?

if( m_vPosition.y < 1.0f )
m_vPosition.y = m_vPosition.y+heightmap;

what should be heightmap

Share this post

Link to post
Share on other sites
u can use the mesh.intersect(...) and give it the down direction and position and then u can know how much is the hieght of the camera and act acoording to it

good luck

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!