Add camera as class
This commit is contained in:
parent
5ac6e2dab5
commit
a0f76d35d7
|
@ -0,0 +1,8 @@
|
||||||
|
#include "camera.hpp"
|
||||||
|
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
glm::mat4 Camera::transformation() const
|
||||||
|
{
|
||||||
|
return projection * glm::inverse(Transformation::transformation());
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef _CAMERA_HPP_
|
||||||
|
#define _CAMERA_HPP_
|
||||||
|
|
||||||
|
#include "transformation.hpp"
|
||||||
|
|
||||||
|
class Camera :
|
||||||
|
public Transformation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
glm::mat4 transformation() const;
|
||||||
|
|
||||||
|
glm::mat4 projection;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _CAMERA_HPP_
|
|
@ -1,7 +1,7 @@
|
||||||
#include "gl.hpp"
|
#include "gl.hpp"
|
||||||
#include "program.hpp"
|
#include "program.hpp"
|
||||||
#include "object.hpp"
|
#include "object.hpp"
|
||||||
#include "transformation.hpp"
|
#include "camera.hpp"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ static GLuint texture_uniform;
|
||||||
|
|
||||||
static bool keys[GLFW_KEY_LAST];
|
static bool keys[GLFW_KEY_LAST];
|
||||||
|
|
||||||
static Transformation camera;
|
static Camera camera;
|
||||||
|
|
||||||
static Model *suzanne;
|
static Model *suzanne;
|
||||||
static Model *teapot;
|
static Model *teapot;
|
||||||
|
@ -65,6 +65,7 @@ int main()
|
||||||
texture_uniform = program.get_uniform_location("texture");
|
texture_uniform = program.get_uniform_location("texture");
|
||||||
glUniform1i(texture_uniform, 0);
|
glUniform1i(texture_uniform, 0);
|
||||||
|
|
||||||
|
camera.projection = glm::perspective(45.0f, (float)640 / (float)480, 0.1f, 10.0f);
|
||||||
camera.position.z = 4;
|
camera.position.z = 4;
|
||||||
camera.position.y = 2;
|
camera.position.y = 2;
|
||||||
|
|
||||||
|
@ -145,9 +146,7 @@ void iterate()
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
const glm::mat4 projection = glm::perspective(45.0f, (float)640 / (float)480, 0.1f, 10.0f);
|
const glm::mat4 mvp = camera.transformation();
|
||||||
|
|
||||||
const glm::mat4 mvp = projection * glm::inverse(camera.transformation());
|
|
||||||
|
|
||||||
suzanne1->draw(mvp);
|
suzanne1->draw(mvp);
|
||||||
teapot1->draw(mvp);
|
teapot1->draw(mvp);
|
||||||
|
|
Reference in New Issue