Jump to content
  • Advertisement
Sign in to follow this  

1st person camera design

This topic is 3580 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

hello guys.I'm new in DirectX9.0 game programming.I have designed a 1st person camera in my 3d world. Now I want to add a gun to my camera so that the gun & the camera will move in the 3d world properly. Can any one tell me how to do this? Thanks in advance. Here's my code for camera: Camera::Camera() { up=D3DXVECTOR3(0.0f, 1.0f, 0.0f); look=D3DXVECTOR3(0.0f, 0.0f, 1.0f); right=D3DXVECTOR3(1.0f, 0.0f, 0.0f); position=D3DXVECTOR3(0.0f, 0.0f, 0.0f); } void Camera::Strafe(float u) { position+=right*u; return; }//end Strafe. void Camera::Fly(float u) { position+=up*u; return; }//end Fly. void Camera::Walk(float u) { position+=look*u; return; }//end Walk. void Camera::RotateAroundRightVector(float angle) { D3DXMATRIX R; D3DXMatrixRotationAxis(&R, &right, angle); D3DXVec3TransformCoord(&up, &up, &R); D3DXVec3TransformCoord(&look, &look, &R); return; }//end RotateAroundRight. void Camera::RotateAroundUpVector(float angle) { D3DXMATRIX R; D3DXMatrixRotationAxis(&R, &up, angle); D3DXVec3TransformCoord(&right, &right, &R); D3DXVec3TransformCoord(&look, &look, &R); return; }//end RotateAroundUp. void Camera::RotateAroundLookVector(float angle) { D3DXMATRIX R; D3DXMatrixRotationAxis(&R, &look, angle); D3DXVec3TransformCoord(&right, &right, &R); D3DXVec3TransformCoord(&up, &up, &R); return; }//end RotateAroundLook. void Camera::GetViewMatrix(D3DXMATRIX *v) { D3DXVec3Normalize(&look, &look); D3DXVec3Cross(&up, &look, &right); D3DXVec3Normalize(&up,&up); D3DXVec3Cross(&right, &up, &look); D3DXVec3Normalize(&right, &right); (*v)(0,0)=right.x; (*v)(0,1)=up.x; (*v)(0,2)=look.x; (*v)(0,3)=0; (*v)(1,0)=right.y; (*v)(1,1)=up.y; (*v)(1,2)=look.y; (*v)(1,3)=0; (*v)(2,0)=right.z; (*v)(2,1)=up.z; (*v)(2,2)=look.z; (*v)(2,3)=0; (*v)(3,0)=-D3DXVec3Dot(&right, &position); (*v)(3,1)=-D3DXVec3Dot(&up, &position); (*v)(3,2)=-D3DXVec3Dot(&look, &position); (*v)(3,3)=1; return; }//end GetViewMatrix. [Edited by - navid on January 24, 2009 8:41:40 AM]

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!