#### Archived

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

# Camera movement - someone must know?!

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

## Recommended Posts

Hi again, PLEASE Can anyone explain why I have to update all the camera''s x,y,z in order to move it forward as shown below : m_CameraPos.x += m_vVelocity.z * m_vLook.x; m_CameraPos.y += m_vVelocity.z * m_vLook.y; m_CameraPos.z += m_vVelocity.z * m_vLook.z; I thought I could just update the camera''s z position i.e. m_CameraPos.z += m_vVelocity.z; Kindest regards, sTeVe

##### Share on other sites
The camera position is specified in WORLD coordinates. Think of the 3D world as a giant cube, this is "world space" - the camera position is a point inside this cube, what the camera is looking at is also another point within the cube.

Changing the Z coordinate of the camera moves the camera position in the same direction as the Z axis [in or out] of the world (cube). What happens if you want to move the camera up or down (Y) or left and right (X) ?.

If you wanted to move the camera diagonally into the cube moving up and to the right, you''d need to change the X,Y and Z parts of the camera position. All the velocity values in that particular case would be positive numbers.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

##### Share on other sites
Thanks Simon,

This is the method in my camera class to move forward:

void CCamera::MoveForward(float steps)
{
m_CameraPos.x -= steps * m_vLook.x;
m_CameraPos.y -= steps * m_vLook.y;
m_CameraPos.z -= steps * m_vLook.z;
}

Here is my CCamera class :

class CCamera
{
public:
CCamera ();
void Reset();

void SetPitch(float pitch) { m_Pitch = pitch; }
void SetYaw(float yaw) { m_Yaw = yaw; }
void SetRoll(float roll) { m_Roll = roll; }

virtual void MoveForward(float steps);
virtual void MoveBackward(float steps);
virtual void StrafeLeft(float steps);
virtual void StrafeRight(float steps);
virtual void LookLeft(float steps);
virtual void LookRight(float steps);
virtual void LookUp(float steps);
virtual void LookDown(float steps);

virtual void Update();

inline D3DXMATRIX GetView() { return m_View; }

protected:
D3DXMATRIX m_View;
D3DXVECTOR3 m_vLook;
D3DXVECTOR3 m_vUp;
D3DXVECTOR3 m_vRight;
D3DXVECTOR3 m_CameraPos;

float m_Motion;
float m_Roll, m_Pitch, m_Yaw;
};

The m_View stores the view transformation vector which takes into account the camera position as such :

m_View._41 = -D3DXVec3Dot(&m_CameraPos, &m_vRight);
m_View._42 = -D3DXVec3Dot(&m_CameraPos, &m_vUp);
m_View._43 = -D3DXVec3Dot(&m_CameraPos, &m_vLook);

I''m still a little curious as to why I can''t just do the following to move the camera forward:

m_CameraPos.z += step;

Sorry if I sound a little slow on this, but I guess it is to do with the dot product calculation m_View._43 ?

Thanks as always for your input.

sTeVe

##### Share on other sites
Adding to the Z of the camera position WILL move the camera "from" position "forward" in its *world*. But usually you''ll want to move it in more interesting directions than just "forward".

Imagine a guy with a video camera stood inside your cube. He''s looking in the positive Z direction. You''re telling him to walk "forward" in the world. If you''re making a game based on tightrope walking or some other thing where the the camera only moves in one axis, that''s fine but usually its not!.

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
18

• 11
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×