Commit e17e1dee authored by Ilya Prokhorov's avatar Ilya Prokhorov

Pre camera fix

parent 4127d71a
......@@ -12,9 +12,11 @@
*/
#include <glm/gtc/matrix_transform.hpp>
#include <iostream>
#include "FSGLCamera.h"
using namespace std;
FSGLCamera::FSGLCamera()
{
}
......@@ -24,11 +26,19 @@ glm::mat4 FSGLCamera::matrix()
auto cameraMatrix = FSGLObject::matrix();
auto cameraPositionVector = cameraMatrix * glm::vec4(0.f, 0.f, 0.f, 1.f);
auto directionMatrix = glm::translate(cameraMatrix, glm::vec3(0, 0,-1));
auto directionVectorPosition = directionMatrix * glm::vec4(0.f, 0.f, 0.f, 1.f);
auto yaw = glm::radians(cameraX - rotationVector->x);
auto pitch = glm::radians(cameraY - rotationVector->y);
glm::vec3 front;
front.x = cos(pitch) * cos(yaw);
front.y = sin(pitch);
front.z = cos(pitch) * sin(yaw);
auto cameraFront = glm::normalize(front);
auto targetPosition = glm::vec3(cameraPositionVector) + glm::vec3(cameraFront);
auto upVector = glm::normalize(glm::vec4(0.0f,1.0f,0.0f,0.0f));
cameraMatrix = glm::lookAt(glm::vec3(cameraPositionVector), glm::vec3(directionVectorPosition), glm::vec3(upVector));
cameraMatrix = glm::lookAt(glm::vec3(cameraPositionVector), targetPosition, glm::vec3(upVector));
return cameraMatrix;
}
......
......@@ -25,6 +25,8 @@ public:
virtual glm::mat4 matrix();
private:
float cameraX = -90.0f;
float cameraY = 0;
};
......
......@@ -51,7 +51,6 @@ void FSGLObject::playAnimationWithName(shared_ptr<string> animationName)
glm::mat4 FSGLObject::matrix()
{
auto matrix = glm::mat4(1.0);
matrix = glm::translate(matrix, glm::vec3(positionVector->x, positionVector->y, positionVector->z));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment