Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "camera.h"
- #include "generic/debug.h"
- namespace SF::Engine
- {
- Camera::Camera(glm::vec3 position) :
- m_position(position),
- m_pitch(0.0f),
- m_yaw(-90),
- m_fov(45),
- m_aspectRation(4.0f / 3.0f),
- m_nearPlane(0.1f),
- m_farPlane(100.0f),
- m_speed(2.5f),
- m_sensivity(0.1f)
- {
- updateCameraVector();
- }
- Camera::~Camera()
- {
- }
- glm::mat4 Camera::getViewMatrix()
- {
- return glm::lookAt(m_position, m_position + m_front, m_up);
- }
- glm::mat4 Camera::getProjectionMatrix()
- {
- return glm::perspective(glm::radians(m_fov), m_aspectRation, m_nearPlane, m_farPlane);
- }
- float Camera::getFOV() const
- {
- return m_fov;
- }
- void Camera::setFOV(const float a_fov)
- {
- m_fov = a_fov;
- }
- void Camera::setAspectRatio(const float a_aspectRatio)
- {
- m_aspectRation = a_aspectRatio;
- }
- void Camera::setClippingDistance(const float a_nearPlane, const float a_farPlane)
- {
- m_nearPlane = a_nearPlane;
- m_farPlane = a_farPlane;
- }
- float Camera::getSpeed() const
- {
- return m_speed;
- }
- void Camera::setSpeed(const float a_speed)
- {
- m_speed = a_speed;
- }
- void Camera::processKeyboard(Direction key, float deltaTime)
- {
- float velocity = m_speed * deltaTime;
- switch (key)
- {
- case FORWARD:
- m_position += m_front * velocity;
- break;
- case BACKWARD:
- m_position -= m_front * velocity;
- break;
- case LEFT:
- m_position -= m_right * velocity;
- break;
- case RIGHT:
- m_position += m_right * velocity;
- break;
- case UP:
- m_position += m_up * velocity;
- break;
- case DOWN:
- m_position -= m_up * velocity;
- break;
- default:
- break;
- }
- }
- void Camera::processMouse(float xoffset, float yoffset)
- {
- xoffset *= m_sensivity;
- yoffset *= m_sensivity;
- m_pitch += yoffset;
- m_pitch = std::clamp(m_pitch, -89.0f, 89.0f);
- m_yaw = glm::mod(m_yaw - xoffset, 360.0f);
- updateCameraVector();
- }
- float Camera::getPitch() const
- {
- return m_pitch;
- }
- float Camera::getYaw() const
- {
- return m_yaw;
- }
- float Camera::getRoll() const
- {
- return 0; // TODO;
- }
- void Camera::setRotation(float a_yaw, float a_pitch, float a_roll)
- {
- m_yaw = a_yaw;
- m_pitch = a_pitch;
- //m_roll = 0;
- updateCameraVector();
- }
- glm::vec3 Camera::getPosition()
- {
- return m_position;
- }
- void Camera::setPosition(const glm::vec3 & a_position)
- {
- m_position = a_position;
- }
- glm::vec3 Camera::getFront()
- {
- return m_front;
- }
- void Camera::updateCameraVector()
- {
- glm::vec3 front;
- front.x = cos(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
- //front.y = sin(glm::radians(m_pitch));
- //front.z = sin(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
- front.z = sin(glm::radians(m_pitch));
- front.y = sin(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
- //front = glm::vec3(0, -1, 0);
- glm::vec3 up(0, 0, 1);
- m_front = glm::normalize(front);
- m_right = glm::normalize(glm::cross(m_front, up));
- m_up = glm::normalize(glm::cross(m_right, m_front));
- static int x = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment