camera movements

Started by
2 comments, last by prince_mnk 18 years ago
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 );


}

Advertisement
Hi,

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?

kp
------------------------------------------------------------Neo, the Matrix should be 16-byte aligned for better performance!
how i should compute the height of terrian?

if( m_vPosition.y < 1.0f )        m_vPosition.y = m_vPosition.y+heightmap;[/cource]what should be heightmap
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

This topic is closed to new replies.

Advertisement