Jump to content
  • Advertisement
Sign in to follow this  

DXUT CFirstPersonCamera - how to set camera position manually

This topic is 3308 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'm taking the CFirstPersonCamera and backing off the vEye to the zoom amount with the following code:
D3DXVECTOR3 vEye = *g_Camera.GetEyePt();
D3DXVECTOR3 vAt = *g_Camera.GetLookAtPt();
D3DXVECTOR3 vCharPos = player->vector;
D3DXVECTOR3 vCharFacing = vEye - vAt;
D3DXVECTOR3 vUp( 0.0f, 1.0f, 0.0f );
vEye = D3DXVECTOR3( vCharPos.x, vCharPos.y + playerHeight, vCharPos.z );
vAt = D3DXVECTOR3( vCharPos.x, vCharPos.y + playerHeight, vCharPos.z );
vCharFacing.x *= cameraZoom; 
vCharFacing.y *= cameraZoom;
vCharFacing.z *= cameraZoom;

vEye += vCharFacing;
vAt -= vCharFacing;

I'm using D3DXIntersect to find the height of the terrain beneath the camera ( vEye ), but have trouble adjusting the camera position itself to stay above the terrain. I can adjust vEye but the camera object itself continues to move beyond the terrain. What is the correct way to set the height of the CFirstPersonCamera in this manner? Thanks!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!