void CameraClass::Render()
{
D3DXVECTOR3 vRotAxis, vDirection;
float yaw, pitch, roll;
int rotationFactor = 8;
D3DXMATRIX pitchMatrix, yawMatrix, rotationMatrix, movementMatrix;
//====================
// Rotational movement
//====================
// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
yaw = m_rotationX * 0.0174532925f;
pitch = m_rotationY * 0.0174532925f;
roll = m_rotationZ * 0.0174532925f;
// Create direction (forward)
D3DXVec3Normalize(&vDirection, &(m_vLookAtPt - m_vEyePt));
//strafe vector
D3DXVec3Cross(&vRotAxis,&vDirection,&m_vUp);
D3DXVec3Normalize(&vRotAxis, &vRotAxis);
//create rotation matrices
D3DXMatrixRotationAxis(&pitchMatrix, &vRotAxis, -(pitch / rotationFactor)); //rotate around x
D3DXMatrixRotationAxis(&yawMatrix, &m_vUp, (yaw / rotationFactor)); //rotate around y
//rotate direction
D3DXVec3TransformCoord(&vDirection, &vDirection, &(pitchMatrix * yawMatrix));
//rotate up vector
D3DXVec3TransformCoord(&m_vUp, &m_vUp, &(pitchMatrix * yawMatrix));
// Translate the rotated camera position to the location of the viewer.
m_vLookAtPt = vDirection + m_vEyePt;
//=====================
// Directional movement
//=====================
if (moveForward)
{
m_vEyePt += vDirection * m_fSpeed;
m_vLookAtPt += vDirection * m_fSpeed;
}
if (moveBackward)
{
m_vEyePt -= vDirection * m_fSpeed;
m_vLookAtPt -= vDirection * m_fSpeed;
}
if (moveLeft)
{
D3DXVec3Cross(&vDirection,&vDirection,&m_vUp); //create strafe vector
D3DXVec3Normalize(&vDirection,&vDirection);
m_vEyePt += vDirection * m_fSpeed;
m_vLookAtPt += vDirection * m_fSpeed;
}
if (moveRight)
{
D3DXVec3Cross(&vDirection,&vDirection,&m_vUp); //create strafe vector
D3DXVec3Normalize(&vDirection,&vDirection);
m_vEyePt -= vDirection * m_fSpeed;
m_vLookAtPt -= vDirection * m_fSpeed;
}
// Get the movement matrix
D3DXMatrixLookAtLH(&m_viewMatrix, &m_vEyePt, &m_vLookAtPt, &m_vUp);
return;
}
Rotating is ok on its own and so is moving. Even short bursts of both work ok too. I figure since its a standard camera class it'll either check out or not.
P.s. sorry for the inconsistent naming conventions, I hacked in a lot of different camera models before getting here. . . probably should clean it up a bit.