I've been trying to create a Camera class that uses Quaternion and Vector3 to create a view matrix but I haven't been having trouble with the math. I'm hoping someone can direct me to a text book or some topics I can look up.
This is what I have right now:
class Camera
{
public:
Camera();
Vector3 Right() const { return mRight; }
Vector3 Up() const { return mUp; }
Vector3 Forward() const { return mForward; }
Vector3 Position() const { return mPosition; }
void SetPosition(const Vector3& position)
{
mPosition = position;
Internal_Recalculate();
}
Quaternion Rotation() const { return mRotation; }
void SetRotation(const Quaternion& rotation)
{
mRotation = rotation;
Internal_Recalculate();
}
private:
void Internal_Recalculate();
Quaternion mRotation;
Vector3 mPosition;
Vector3 mRight;
Vector3 mUp;
Vector3 mForward;
};
Camera::Camera()
{
mPosition = Vector3(0.0f, 0.0f, 0.0f);
mRotation = Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
}
void Camera::Internal_Recalculate()
{
const Vector3 kForward = Vector3(0.0f, 0.0f, 1.0f);
const Vector3 kUp = Vector3(0.0f, -1.0f, 0.0f);
const Vector3 KRight = Vector3(1.0f, 0.0f, 0.0f);
mForward = mRotation * kForward;
mRight = mRotation * KRight;
mUp = mRotation * kUp;
}
float xRotate = camYRotRate * mGamePad.GetAxis(GamePadAxis::TmbRgtX) * -1 * dt;
rotation = glm::rotate(rotation, xRotate, mCamera.Up());
mCamera.SetRotation(rotation);
float yRotate = camYRotRate * mGamePad.GetAxis(GamePadAxis::TmbRgtY) * dt;
rotation = glm::rotate(rotation, yRotate, mCamera.Right());
mCamera.SetRotation(rotation);
The first code segment is the camera class, and the second segment is the code I'm using to rotate the camera around. I'm just looking for any pointers, I've been stuck on this for weeks. I'm using the glm math library and directx 11