10 changed files with 151 additions and 45 deletions
@ -0,0 +1,28 @@
|
||||
|
||||
#include "camera.h" |
||||
|
||||
|
||||
void |
||||
cameraInitPerspective(camera& cam, glm::vec3 position, glm::vec3 target, glm::vec3 up) |
||||
{ |
||||
cam.position = position; |
||||
cam.target = target; |
||||
cam.up = up; |
||||
cam.projection = glm::infinitePerspective(glm::radians(FOV), ASPECT_RATIO, NEAR_CLIP_PLANE); |
||||
|
||||
cam.hAngle = 0; |
||||
cam.vAngle = glm::atan((cam.target.z - cam.position.z) / (cam.target.y - cam.position.y)); |
||||
|
||||
// FIXME: bug, camera always starts with forward pointing at positive 'z' axis
|
||||
cam.forward = glm::normalize(glm::vec3( |
||||
glm::cos(cam.vAngle) * glm::sin(cam.hAngle), |
||||
glm::cos(cam.vAngle) * glm::cos(cam.hAngle), |
||||
glm::sin(cam.vAngle) |
||||
)); |
||||
cam.left = glm::normalize(glm::cross(cam.up, cam.forward)); |
||||
cam.up = glm::normalize(glm::cross(cam.forward, cam.left)); // get better "up" vector
|
||||
|
||||
cam.view = glm::lookAt(cam.position, cam.position + cam.forward, cam.up); |
||||
cam.model = glm::mat4(1.0f); |
||||
cam.MVP = cam.projection * cam.view * cam.model; |
||||
} |
||||
@ -0,0 +1,41 @@
|
||||
|
||||
#pragma once |
||||
#include <glm/glm.hpp> |
||||
#include <glm/gtc/matrix_transform.hpp> |
||||
#include "util.h" |
||||
|
||||
// TODO: move other camera functions here from renderer.h and pass in camera references
|
||||
// TODO: store scene matrices on camera struct instead of global in renderer.h
|
||||
|
||||
|
||||
#define FOV 60.f |
||||
#define ASPECT_RATIO 16.f/9.f |
||||
#define NEAR_CLIP_PLANE 0.1f |
||||
|
||||
struct camera |
||||
{ |
||||
glm::vec3 position; |
||||
float hAngle; |
||||
float vAngle; |
||||
glm::vec3 target; |
||||
glm::vec3 forward; |
||||
glm::vec3 up; |
||||
glm::vec3 left; |
||||
|
||||
glm::mat4 model; |
||||
glm::mat4 view; |
||||
glm::mat4 projection; |
||||
glm::mat4 MVP; |
||||
}; |
||||
|
||||
enum projection_type |
||||
{ |
||||
PERSPECTIVE, |
||||
ORTHOGRAPHIC, |
||||
}; |
||||
|
||||
|
||||
void cameraInitPerspective(camera& cam, glm::vec3 position, glm::vec3 target, glm::vec3 up); |
||||
void cameraMove(bool up, bool left, bool down, bool right, bool forward, bool backward); |
||||
void CameraRotate(int32 xrel, int32 yrel); |
||||
void cameraRoll(bool CW, bool CCW); |
||||
Loading…
Reference in new issue