Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "camera.h"
- #include <iostream>
- #include <glm/glm.hpp>
- #include <glm/gtx/transform.hpp>
- #include <SDL2\SDL.h>
- Camera::Camera(const glm::vec3& position, float fov, float aspect, float near, float far)
- {
- m_position = position;
- m_up = glm::vec3(0, 1, 0);
- m_direction = glm::vec3(0, 0, 1);
- m_projMatrix = glm::perspective(fov, aspect, near, far);
- m_moveSpeed = 0.01f;
- //SDL_ShowCursor(SDL_DISABLE);
- }
- void Camera::update(float delta)
- {
- }
- void Camera::onMouseMove(const glm::vec2& mouse)
- {
- glm::vec2 delta = mouse - m_oldMouse;
- m_rotation.x = delta.x * 0.001f;
- m_rotation.y = delta.y * 0.001f;
- m_direction = glm::mat3(glm::rotate(m_rotation.x, m_up)) * m_direction;
- m_direction = glm::mat3(glm::rotate(m_rotation.y, glm::cross(m_direction, m_up))) * m_direction;
- m_oldMouse = mouse;
- }
- void Camera::onKeyboard(const SDL_KeyboardEvent& event)
- {
- if (event.keysym.scancode == Keys::FORWARD) {
- m_position += m_moveSpeed * m_direction;
- }
- if (event.keysym.scancode == Keys::BACKWARD) {
- m_position += -m_moveSpeed * m_direction;
- }
- if (event.keysym.scancode == Keys::LEFT) {
- m_position += -m_moveSpeed * glm::cross(m_direction, m_up);
- }
- if (event.keysym.scancode == Keys::RIGHT) {
- m_position += m_moveSpeed * glm::cross(m_direction, m_up);
- }
- if (event.keysym.scancode == Keys::UP) {
- m_position += m_moveSpeed * m_up;
- }
- if (event.keysym.scancode == Keys::DOWN) {
- m_position += -m_moveSpeed * m_up;
- }
- }
- Camera::~Camera()
- {
- SDL_ShowCursor(SDL_ENABLE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement