76 lines
No EOL
1.8 KiB
C++
76 lines
No EOL
1.8 KiB
C++
#ifndef __CAMERA_H__
|
|
#define __CAMERA_H__
|
|
|
|
/*
|
|
* just a way to conviniently store camera data
|
|
* ->header only
|
|
*/
|
|
|
|
#define GLM_ENABLE_EXPERIMENTAL
|
|
|
|
#include <glm/ext/matrix_float4x4.hpp>
|
|
#include <glm/ext/matrix_transform.hpp>
|
|
#include <glm/ext/quaternion_common.hpp>
|
|
#include <glm/ext/quaternion_geometric.hpp>
|
|
#include <glm/ext/quaternion_trigonometric.hpp>
|
|
#include <glm/ext/vector_float3.hpp>
|
|
#include <glm/fwd.hpp>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
#include <glm/gtc/quaternion.hpp>
|
|
#include <glm/gtx/quaternion.hpp>
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
#include <glm/matrix.hpp>
|
|
#include <glm/trigonometric.hpp>
|
|
#include "largepos.hpp"
|
|
|
|
class camera{
|
|
public:
|
|
// view matrix (aka camera position)
|
|
glm::mat4 view;
|
|
|
|
// projection matrix (aka camera characteristics)
|
|
glm::mat4 proj;
|
|
|
|
glm::vec3 pos;
|
|
//glm::vec3 front;
|
|
//glm::vec3 up;
|
|
|
|
glm::quat rotation= glm::quat(0.f,0.f,0.f,1.f);
|
|
|
|
glm::vec3 forward;
|
|
glm::vec3 up;
|
|
glm::vec3 right;
|
|
|
|
largePos spacePos;
|
|
|
|
void update() {
|
|
// Z IS ALLWAYS UP
|
|
glm::quat corrRot=rotation*glm::angleAxis(glm::radians(90.f), glm::vec3(1.f, 0.f, 0.f) * rotation);
|
|
|
|
view = glm::translate(glm::toMat4(corrRot), pos);
|
|
|
|
forward = glm::vec3(0.f,1.f,0.f)*rotation;
|
|
|
|
//view = glm::lookAt(pos, forward+pos, glm::vec3(0.f,0.f,1.f));
|
|
|
|
up = glm::vec3(0.f,0.f,1.f)*rotation;
|
|
right = glm::vec3(1.f,0.f, 0.f)*rotation;
|
|
}
|
|
void rotate(float angle, const glm::vec3 &axis) {
|
|
rotation *= glm::angleAxis(angle, axis * rotation);
|
|
}
|
|
void rotate(float angle, float x, float y, float z) {
|
|
rotation *= glm::angleAxis(angle, glm::vec3(x, y, z) * rotation);
|
|
}
|
|
void rotateX(float angle) {
|
|
rotate(glm::radians(angle), 1.f,0.f,0.f);
|
|
}
|
|
void rotateY(float angle) {
|
|
rotate(glm::radians(angle), 0.f,1.f,0.f);
|
|
}
|
|
void rotateZ(float angle) {
|
|
rotate(glm::radians(angle), 0.f,0.f,1.f);
|
|
}
|
|
};
|
|
|
|
#endif |