added cameras

This commit is contained in:
Lauchmelder 2021-12-21 18:14:01 +01:00
parent 19cae22aba
commit c1b96fc14e
7 changed files with 119 additions and 12 deletions

View file

@ -0,0 +1,52 @@
#pragma once
#include <memory>
#include "Transformable.hpp"
#include "Drawable.hpp"
// TODO: Find better name
class CameraBase : public Transformable
{
public:
// "Scaling" doesn't really makes sense for a camera
void GetScale() = delete;
void SetScale(const glm::vec3&) = delete;
void Scale(const glm::vec3&) = delete;
inline const glm::mat4& GetView() const
{
return transformation;
}
inline const glm::mat4& GetProjection() const
{
return projection;
}
inline void Draw(const Drawable& drawable) const
{
drawable.Draw(*this);
}
protected:
glm::mat4 projection;
};
class Camera : public CameraBase
{
public:
Camera(float fov = 90.0f, float aspect = 1.0f, float zNear = 0.01f, float zFar = 100.0f)
{
projection = glm::perspective(glm::radians(fov), aspect, zNear, zFar);
}
};
class OrthogonalCamera : public CameraBase
{
public:
OrthogonalCamera(float left = -1.0f, float right = 1.0f, float bottom = -1.0f, float top = 1.0f, float zNear = -100.0f, float zFar = 100.0f)
{
projection = glm::ortho(left, right, bottom, top, zNear, zFar);
}
};

View file

@ -4,6 +4,8 @@
#include "VertexArrayObject.hpp"
#include "Shader.hpp"
class CameraBase;
enum class PrimitiveType
{
Lines = GL_LINES,
@ -21,8 +23,8 @@ public:
Drawable(const Drawable& other) = delete;
void operator=(const Drawable& other) = delete;
virtual void InitializeShader() = 0;
void Render();
virtual void InitializeShader(const CameraBase& camera) const = 0;
void Draw(const CameraBase& camera) const;
void SetPrimitiveType(PrimitiveType type);
protected: