#### Archived

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

# Floating Camera Problems!

This topic is 6263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Try these:

// Move forward

// Move back

// 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);

D3DXMatrixMultiply(&matRotation, &matRotationY, &matRotationX);
D3DXMatrixMultiply(&matView, &matView, &matRotation);

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

// Move forward

// Move back

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

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

// Move forward

// Move back

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

##### Share on other sites
Perfect ! Thank You !

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633289
• Total Posts
3011227
• ### Who's Online (See full list)

There are no registered users currently online

×