-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b539ce
commit bb8e666
Showing
6 changed files
with
163 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
name: MacOS build | ||
|
||
on: [push] | ||
|
||
jobs: | ||
macos-build: | ||
runs-on: macos-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
name: Ubuntu build | ||
|
||
on: [push] | ||
|
||
jobs: | ||
ubuntu-build: | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
name: Windows build | ||
|
||
on: [push] | ||
|
||
jobs: | ||
windows-build: | ||
runs-on: windows-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
#include "glad/glad.h" | ||
#include "glm/glm.hpp" | ||
#include "glm/gtc/matrix_transform.hpp" | ||
|
||
#include <vector> | ||
|
||
enum CameraMovement { | ||
FORWARD, | ||
BACKWARD, | ||
LEFT, | ||
RIGHT | ||
}; | ||
|
||
const float YAW = -90.0f; | ||
const float PITCH = 0.0f; | ||
const float SPEED = 2.5f; | ||
const float SENSITIVITY = 0.1f; | ||
const float ZOOM = 45.0f; | ||
|
||
class Camera { | ||
public: | ||
// Camera attributes | ||
glm::vec3 position; | ||
glm::vec3 front; | ||
glm::vec3 up; | ||
glm::vec3 right; | ||
glm::vec3 worldUp; | ||
|
||
// Euler angles | ||
float yaw; | ||
float pitch; | ||
|
||
// Options | ||
float movementSpeed; | ||
float mouseSensitivity; | ||
float zoom; | ||
|
||
// Constructor with vector | ||
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH); | ||
|
||
// Constructor with scalars | ||
Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch); | ||
|
||
glm::mat4 getViewMatrix(); | ||
|
||
void processKeyboard(CameraMovement direction, float deltaTime); | ||
void processMouseMovement(float xoffset, float yoffset, bool constrainPitch = true); | ||
void processMouseScoll(float yoffset); | ||
|
||
private: | ||
void updateCameraVectors(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include "Camera.hpp" | ||
|
||
Camera::Camera(glm::vec3 position, glm::vec3 up, float yaw, float pitch) { | ||
front = glm::vec3(0.0f, 0.0f, -1.0f); | ||
movementSpeed = SPEED; | ||
mouseSensitivity = SENSITIVITY; | ||
zoom = ZOOM; | ||
this->position = position; | ||
worldUp = up; | ||
this->yaw = yaw; | ||
this->pitch = pitch; | ||
updateCameraVectors(); | ||
} | ||
|
||
Camera::Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch) { | ||
front = glm::vec3(0.0f, 0.0f, -1.0f); | ||
movementSpeed = SPEED; | ||
mouseSensitivity = SENSITIVITY; | ||
zoom = ZOOM; | ||
position = glm::vec3(posX, posY, posZ); | ||
worldUp = glm::vec3(upX, upY, upZ); | ||
this->yaw = yaw; | ||
this->pitch = pitch; | ||
updateCameraVectors(); | ||
} | ||
|
||
glm::mat4 Camera::getViewMatrix() { | ||
return glm::lookAt(position, position + front, up); | ||
} | ||
|
||
void Camera::processKeyboard(CameraMovement direction, float deltaTime) { | ||
float velocity = movementSpeed * deltaTime; | ||
switch (direction) { | ||
case FORWARD: | ||
position += front * velocity; | ||
break; | ||
case BACKWARD: | ||
position -= front * velocity; | ||
break; | ||
case LEFT: | ||
position -= right * velocity; | ||
break; | ||
case RIGHT: | ||
position += right * velocity; | ||
break; | ||
} | ||
} | ||
|
||
void Camera::processMouseMovement(float xoffset, float yoffset, bool constrainPitch) { | ||
xoffset *= mouseSensitivity; | ||
yoffset *= mouseSensitivity; | ||
|
||
yaw += xoffset; | ||
pitch += yoffset; | ||
|
||
if (constrainPitch) { | ||
if (pitch > 89.0f) { pitch = 89.0f; } | ||
if (pitch < -89.0f) { pitch = -89.0f; } | ||
} | ||
|
||
updateCameraVectors(); | ||
} | ||
|
||
void Camera::processMouseScoll(float yoffset) { | ||
zoom -= yoffset; | ||
if (zoom < 1.0f ) { zoom = 1.0f; } | ||
if (zoom > 45.0f ) { zoom = 45.0f; } | ||
} | ||
|
||
void Camera::updateCameraVectors() { | ||
glm::vec3 tmpFront; | ||
tmpFront.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); | ||
tmpFront.y = sin(glm::radians(pitch)); | ||
tmpFront.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); | ||
front = glm::normalize(tmpFront); | ||
right = glm::normalize(glm::cross(front, worldUp)); | ||
up = glm::normalize(glm::cross(right, front)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters