3d camera

Started by
14 comments, last by StiNKy 22 years, 7 months ago
the above method will suffer from gimbal lock (unless u limit the values passed)
check my camera rotation post below
Advertisement
I can do this if you only want to move along the y=0 plane, like in a first-person-shooter where you are only moving along the floor. I don''t know how to do full 3D, like counter-strike free-look-mode.

You want to know how much to add to the x and z coordinates of your camera position. Use Sine and Cosine. they give you the x and z coordinates of the point on a circle of radius 1. Just input your angle of rotation.

If your angle of rotation (Yaw) is measured from the Z axis...

Camera.PositionX += sinf( Camera.Yaw );
Camera.PositionZ += cosf( Camera.Yaw );

Hope this helps you
I can do this if you only want to move along the y=0 plane, like in a first-person-shooter where you are only moving along the floor. I don''t know how to do full 3D, like counter-strike free-look-mode.

You want to know how much to add to the x and z coordinates of your camera position. Use Sine and Cosine. they give you the x and z coordinates of the point on a circle of radius 1. Just input your angle of rotation.

If your angle of rotation (Yaw) is measured from the Z axis...

Camera.PositionX += sinf( Camera.Yaw );
Camera.PositionZ += cosf( Camera.Yaw );

Hope this helps you
ive never seen cs but if its anything like q3 when u do a flythrough with the camera.

it is possible just use
camPOS += camDIR;
ie not
camera.PositionX += sinf( Camera.Yaw );
Camera.PositionZ += cosf( Camera.Yaw );

the reason u can do this is the camera doesnt do roll or loop, thus u can get away with usiong eulars.
Using camPOS += camDIR recommends camDIR to be a unit-size vector which contains the rotation of the player. if you''re storing the rotation value around the x and y axis seperatly you could do it this way:

posx -= sinf(roty) * cosf(rotx);
posy -= sinf(rotx);
posz -= cosf(roty) * cosf(rotx);

The method Sir Melvalot posted just uses the Yaw value.

(you might have to change some of the -= operators to += operators)
I have a function in my game engine which does this, but it''s VB DirectX code, so you''ll have to translate it since I''m not too familiar with OpenGL.

Hopefully it is formatted correctly below.



'' gets the translation relative to the direction the frame is facing
Public Property Get RelativeVector(Velocity As D3DVECTOR, Optional deltaTime As Single = 1) As D3DVECTOR
Dim matView As D3DMATRIX, matTrans As D3DMATRIX, matRot As D3DMATRIX
Dim Translation As D3DVECTOR
On Error Resume Next
'' multiply matrices together to create rotation matrix
D3DXMatrixRotationYawPitchRoll matRot, vecOrientation.y, vecOrientation.x, vecOrientation.z
'' translate
D3DXVec3Scale Translation, Velocity, deltaTime
D3DXMatrixTranslation matTrans, Translation.x, Translation.y, Translation.z
'' multiply that translation and rotation
D3DXMatrixMultiply matView, matTrans, matRot
'' translate by matrix
D3DXVec3TransformCoord RelativeVector, RelativeVector, matView
End Property



You have to supply the direction you want the camera to move in as a velocity (for example (0,0,1) will move the camera foward 1 unit).

It returns the vector by which the frame (or camera) needs to be translated in order to move in the correct direction.

Explanations of variables out of scope of this function for you:

vecOrientation is the orientation (direction it is facing) of the frame (or in your case, camera).

The D3DX functions have long descriptive names I hope it''s clear what they do, and can be replaced with your own code?

I don''t think I''ve been too helpful but I hope that makes some sort of sense. I tried my best anyway.

This topic is closed to new replies.

Advertisement