CameraFirstPerson Shooter from 6DOF one


Now, I already have a working Camera 6DOF, but maybe you’ll be able to help me to create a FirstPerson Shooter camera type following similar operation…
I already have two class for (Vector and Matrix).
Here is the way CCamera6DOF works :

Has 4 members for directions :

private :
CVector m_Position;
CVector m_Right;
CVector m_Up;
CVector m_View;

In the Camera constructor, these vectors are initialize a their default value so :

m_Position.Set( 0.0f, 0.0f, 0.0f );
m_Right.Set( 1.0f, 0.0, 0.0f );
m_Up.Set( 0.0f, 1.0, 0.0f );
m_View.Set( 0.0f, 0.0, 1.0f );

To move along each axis, the principle is the same, but pretend we want to move along the x axis :

void CCamera6DOF::moveX( float Speed )
m_Position.X = m_Position.X + m_Right.X * -(Speed);
m_Position.Y = m_Position.Y + m_Right.Y * -(Speed);
m_Position.Z = m_Position.Z + m_Right.Z * -(Speed);

Except that moving along others axis, the vector m_Right should be replaced to (m_Up or m_View)…

Now, the rotations :

void CCamera6DOF::rotationX( float Degres )
m_Right.freeAxeRotation( Degres, m_Right );
m_Up.freeAxeRotation( Degres, m_Right );
m_View.freeAxeRotation( Degres, m_Right );

To apply a rotation for others axis, m_Right sould be (m_Up or m_View)…

And finally, compute the final matrix to load with (glLoadMatrixf)

void update()
CMatrice fMatrix( m_Right, m_Up, m_View );

fMatrix[12] = fMatrix[0] * m_Position.X +
fMatrix[4] * m_Position.Y +
fMatrix[8] * m_Position.Z;
fMatrix[13] = fMatrix[1] * m_Position.X +
fMatrix[5] * m_Position.Y +
fMatrix[9] * m_Position.Z;
fMatrix[14] = fMatrix[2] * m_Position.X +
fMatrix[6] * m_Position.Y +
fMatrix[10]* m_Position.Z;
fMatrix[15] = 1.0f;

glMatrixMode( GL_MODELVIEW );
glLoadMatrixf( (GLfloat *)fMatrix );

Here, it’s an exmple :

  • To move use the keys [W, A, D et S]
  • To rotate on axis X and Y [ Arrow keyboard ]
  • To roll (z) use key [Z et X]

So my question is the following :

Although this camera seems well working, it there any ways to adapt it so that becomes a FirstPersonShooter camera ? Therefore, when one looks at upwards, it must continue to advance on the floor and not to rise towards the sky :expressionless:

PS : I don’t want to use gluLookAt.

A big thanks

you could still use most if not all of your previous code. the issue then becomes keeping around another vector to represent your final movement direction. this vector may or may not be the direction the camera is facing.