Hi All,
I'm having some difficulties creating a DOOM-like first person
shootemup camera and would
be grateful for some pointers:
The camera allows Yaw (rotate head left/right) and
Pitch (pitch head up and down)but I'm having difficulty in
implementing forward and strafe left and right.
This is how I'm "trying" to do it:
NB - My Matrix is defined as follows:
struct Matrix4{
// Member variables
union
{
struct{
float _11, _12, _13, _14; // X-axis (i.e. right)
float _21, _22, _23, _24; // Y-axis (i.e. up)
float _31, _32, _33, _34; // Z-axis (i.e. forward)
float _41, _42, _43, _44; // Position
};
float m_fdata[4][4];
};
};
// ============================================================
// This code is taken from my camera class and is based on
// a non-FPS Quaternion camera tutorial at the NeHe site.
// ============================================================
// Ref types
Quaternion qPitch;
Quaternion qYaw;
Quaternion qTmp;
Matrix4 matTmp;
// Val types
// ============================================================
// Construct the quaternions that will represent our rotations
// ============================================================
qPitch.FromAxisAngle(1.0f, 0.0f, 0.0f, m_Pitch); // Camera's Pitch
qYaw.FromAxisAngle(0.0f, 1.0f, 0.0f, m_Yaw); // Camera's Yaw
// ============================================================
// Combine the pitch and yaw quaternions
// Convert to a matrix
// Set this as our camera's local matrix
// ============================================================
qTmp = qPitch * qYaw;
Quaternion::ToMatrix(qTmp, &m_matLocal);
// ============================================================
// Questions
// ============================================================
1 - Is the m_matLocal matrix a view matrix i.e. do I have to invert
it?
2 - How do I walk "forward"? By forward I mean if I pitch the camera
up, my forward axis is now tilted upwards?
3 - How do I strafe left and right?
If anyone has implemented a doom like camera that allows the camera to
be pitched up/down and yawed left and right
as well as support for strafe left and right i'd be grateful if you
could give me some pointers.
Many thanks in advance,
Ben.
|