Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bose

Floating Camera Problems!

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

Hi, I am having trouble creating a free-floating QUAKE3 style camera. My main problem is that it won''t float directly straight. Here is the equation I am using to fly: vecPosition.x -= fVelocity * (float)sin(D3DXToRadian(vecVelocityAngle.y)); vecPosition.y += fVelocity * (float)sin(D3DXToRadian(vecVelocityAngle.x)); vecPosition.z += fVelocity * ((float)cos(D3DXToRadian(vecVelocityAngle.x)) * (float)cos(D3DXToRadian(vecVelocityAngle.y))); It does work, but it is slightly off. If I am facing directly straight it will go perfect, but if i turn to the side, it will float forward but slightly to the right or left off center from what it should be. Does anyone know what I am doing wrong? Or maybe another solution entirely? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Try these:

// Move forward
vecPosition.x -= fVelocity * sinf(D3DXToRadian(vecVelocityAngle.y));
vecPosition.y += fVelocity * sinf(D3DXToRadian(vecVelocityAngle.x));
vecPosition.z += fVelocity * cosf(D3DXToRadian(vecVelocityAngle.y));

// Move back
vecPosition.x += fVelocity * sinf(D3DXToRadian(vecVelocityAngle.y));
vecPosition.y -= fVelocity * sinf(D3DXToRadian(vecVelocityAngle.x));
vecPosition.z -= fVelocity * cosf(D3DXToRadian(vecVelocityAngle.y));

// Strafe left
vecPosition.x -= fVelocity * sinf(D3DXToRadian(vecVelocityAngle.y + 90.0f));
vecPosition.z += fVelocity * cosf(D3DXToRadian(vecVelocityAngle.y + 90.0f));

// Strafe right
vecPosition.x -= fVelocity * sinf(D3DXToRadian(vecVelocityAngle.y - 90.0f));
vecPosition.z += fVelocity * cosf(D3DXToRadian(vecVelocityAngle.y - 90.0f));

// View Transformation
D3DXVECTOR3 vecEyePoint;
D3DXVECTOR3 vecLookatPoint;
D3DXVECTOR3 vecUp;
D3DXMATRIX matRotationX;
D3DXMATRIX matRotationY;
D3DXMATRIX matRotation;
D3DXMATRIX matView;

vecEyePoint = D3DXVECTOR3(g_fPosX, g_fPosY, g_fPosZ);
vecLookatPoint = D3DXVECTOR3(g_fPosX, g_fPosY, g_fPosZ + 0.1f);
vecUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(&matView, &vecEyePoint, &vecLookatPoint, &vecUp);

D3DXMatrixRotationX(&matRotationX, D3DXToRadian(g_fAngleX));
D3DXMatrixRotationY(&matRotationY, D3DXToRadian(g_fAngleY));
D3DXMatrixMultiply(&matRotation, &matRotationY, &matRotationX);
D3DXMatrixMultiply(&matView, &matView, &matRotation);

Share this post


Link to post
Share on other sites
Oh! sorry I forgot to multiple cosf() to the z position

// Move forward
vecPosition.x -= fVelocity * sinf(D3DXToRadian(vecVelocityAngle.y));
vecPosition.y += fVelocity * sinf(D3DXToRadian(vecVelocityAngle.x));
vecPosition.z += fVelocity * cosf(D3DXToRadian(vecVelocityAngle.y)) * cosf(D3DXToRadian(vecVelocityAngle.x));

// Move back
vecPosition.x += fVelocity * sinf(D3DXToRadian(vecVelocityAngle.y));
vecPosition.y -= fVelocity * sinf(D3DXToRadian(vecVelocityAngle.x));
vecPosition.z -= fVelocity * cosf(D3DXToRadian(vecVelocityAngle.y)) * cosf(D3DXToRadian(vecVelocityAngle.x));


Happy Flying =)
http://www.cwinapp.com

Share this post


Link to post
Share on other sites
Oh! sorry again =P
You have to multiple cosf() to the x position also

// Move forward
vecPosition.x -= fVelocity * sinf(D3DXToRadian(vecVelocityAngle.y)) * cosf(D3DXToRadian(vecVelocityAngle.x));
vecPosition.y += fVelocity * sinf(D3DXToRadian(vecVelocityAngle.x));
vecPosition.z += fVelocity * cosf(D3DXToRadian(vecVelocityAngle.y)) * cosf(D3DXToRadian(vecVelocityAngle.x));

// Move back
vecPosition.x += fVelocity * sinf(D3DXToRadian(vecVelocityAngle.y)) * cosf(D3DXToRadian(vecVelocityAngle.x));
vecPosition.y -= fVelocity * sinf(D3DXToRadian(vecVelocityAngle.x));
vecPosition.z -= fVelocity * cosf(D3DXToRadian(vecVelocityAngle.y)) * cosf(D3DXToRadian(vecVelocityAngle.x));


Happy Flying =)
http://www.cwinapp.com

Share this post


Link to post
Share on other sites

  • 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!