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:

A big thanks

You could try using gluLookAt instead of actually creating a matrix and applying that to OpenGL.

All you would have to do is do the following:

gluLookAt(m_Position.x, m_Position.y, m_Position.z, m_View.x, m_View.y, m_View.z, 0, 1, 0);

The last (0,1,0) is the Up vector or something, basically having a 1 in the middle and 0’s in the x and z positions, tell it to basically act like a first person camera. This should solve your problem, I think :slight_smile:

Thanks for your help [oconnellseanm].

I already know how to do this with gluLookAt but I don’t want to use GLU.

I must use my own vector/matrix for some practicals reasons. Do you think may I post my question to the Math forum ?

Thanks for you help.