voidMyPerspectCamera::move(CAMERA_DIRECTION dir, float deltaTime){ if (dir == CAMERA_DIRECTION::CAMERA_UP) { Position += Front * deltaTime; } elseif (dir == CAMERA_DIRECTION::CAMERA_DOWN) { Position -= Front * deltaTime; }
if (dir == CAMERA_DIRECTION::CAMERA_LEFT) { Position -= Right * deltaTime; } elseif (dir == CAMERA_DIRECTION::CAMERA_RIGHT) { Position += Right * deltaTime; } }
// make sure that when pitch is out of bounds, screen doesn't get flipped if (constrainPitch) { if (Pitch > 89.0f) Pitch = 89.0f; if (Pitch < -89.0f) Pitch = -89.0f; }
// update Front, Right and Up Vectors using the updated Euler angles update();
voidMyPerspectCamera::update() { // calculate the new Front vector glm::vec3 front; front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch)); front.y = sin(glm::radians(Pitch)); front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch)); Front = glm::normalize(front); // also re-calculate the Right and Up vector Right = glm::normalize(glm::cross(Front, WorldUp)); // normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement. Up = glm::normalize(glm::cross(Right, Front)); }