The only functionality I’m missing on my camera is getting the forward vector using the pitch and yaw. I know I’ve calculated the Pitch and Yaw correctly because the camera rotates appropriately when moving my mouse, but my character won’t walk towards the direction I’m looking at. Just forward,back,left, and right relative to the world’s origin.
I have no idea how to get the fwd vector using my calculated pitch and yaw. Hope somebody can point me towards the right direction. Below I’ll share some of my implementation. Thanks!
Mat4 Camera::getOrientation() {
Mat4 xAxis = Trig::Rotate(X_AXIS, Vec3(-m_pitch, 0, 0));
Mat4 yAxis = Trig::Rotate(Y_AXIS, Vec3(0, m_yaw, 0));
return xAxis * yAxis;
}
Mat4 Camera::GetView() {
return getOrientation() * Trig::Translate(m_pos);
}
// When I move the mouse
Mat4 Camera::OffsetOrientation(float rightAngle, float upAngle) {
m_yaw += rightAngle;
m_pitch += upAngle;
normalizeAngles();
}
// Forward, back, left, right
void Camera::OffsetPos(Vec3 &offset) {
m_pos += offset;
}
Everything works perfectly up to now, but I’d love for the camera to move towards where I’m looking at.
Oh and if you want to check out Trig::Rotate, you can see it here.