PDA

View Full Version : CameraFirstPerson Shooter from 6DOF one

Pictar
12-15-2003, 04:22 PM
Hello.

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)...

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

Here, it's an exmple : http://www.iquebec.com/eraquila/test.exe

- 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 :|

A big thanks http://www.opengl.org/discussion_boards/ubb/smile.gif
Martin

soconne
12-15-2003, 05:57 PM
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 :-)

Pictar
12-15-2003, 06:07 PM