Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _CAMERA_H_
- #define _CAMERA_H_
- #include <SFML/Graphics.hpp>
- #include <stdio.h>
- #include <glm/glm.hpp>
- #include <glm/gtc/matrix_transform.hpp>
- #include <glm/gtc/type_ptr.hpp>
- #define PI 3.14159265359
- #define PI_2 6.28318530718
- extern glm::vec3 UP_VECTOR;
- extern glm::vec3 DOWN_VECTOR;
- class Camera
- {
- public:
- Camera(glm::vec3 *position, float *pitch, float *yaw)
- {
- this->position = position;
- this->pitch = pitch;
- this->yaw = yaw;
- setupVectors();
- }
- glm::vec3 getLookVector()
- {
- return *lookVector;
- }
- glm::vec3 getUpVector()
- {
- return *upVector;
- }
- glm::vec3 getRightVector()
- {
- return *rightVector;
- }
- glm::vec3 getForwardVector()
- {
- return glm::cross(*rightVector, UP_VECTOR);
- }
- glm::mat4 getLookAt()
- {
- //return glm::lookAt(*position, *position + getLookVector(), getUpVector());
- glm::vec3 right = getRightVector();
- glm::vec3 up = getUpVector();
- glm::vec3 forward = getLookVector();
- glm::mat4 tmp = glm::mat4(
- right[0], up[0], forward[0], 0.0f,
- right[1], up[1], forward[1], 0.0f,
- right[2], up[2], forward[2], 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
- );
- return glm::translate(tmp, (*position));
- }
- void update()
- {
- matrix = glm::rotate(glm::mat4(1.0f), glm::degrees(*pitch), glm::vec3(1.0f, 0.0f, 0.0f));
- matrix = glm::rotate(matrix, glm::degrees(*yaw), glm::vec3(0.0f, 1.0f, 0.0f));
- matrix = glm::translate(matrix, *position);
- #define printvect(s, v) (printf("%s %f %f %f\n", s, v->x, v->y, v->z))
- printvect("right:", rightVector);
- printvect("up:", upVector);
- printvect("look", lookVector);
- }
- glm::mat4 *const getMatrixP()
- {
- return &matrix;
- }
- float *const getMatrixValueP()
- {
- return glm::value_ptr(matrix);
- }
- private:
- glm::vec3 *position;
- float *pitch, *yaw;
- glm::mat4 matrix;
- glm::vec3 *upVector, *lookVector, *rightVector;
- void setupVectors()
- {
- float (*p)[4] = (float (*)[4])glm::value_ptr(matrix);
- rightVector = (glm::vec3 *)&p[0];
- upVector = (glm::vec3 *)&p[1];
- lookVector = (glm::vec3 *)&p[2];
- }
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement