Sign in to follow this  

camera movements

Recommended Posts

Pushapjit    100
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
kovacsp    306

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
Pushapjit    100
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
prince_mnk    122
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

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