2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 14.01.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_CAMERA_H
|
|
|
|
#define ENGINE_CAMERA_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include "Plane.h"
|
|
|
|
#include "Mesh.h"
|
2021-10-22 19:42:32 +03:00
|
|
|
#include <SFML/OpenGL.hpp>
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class Camera final : public Object{
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
2021-09-19 11:25:10 +03:00
|
|
|
Matrix4x4 _S; // screen space matrix
|
|
|
|
Matrix4x4 _P; // projections matrix
|
|
|
|
Matrix4x4 _V; // camera matrix
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
// To accelerate calculations we can use precalculated matrix that does not chance
|
2021-09-19 11:25:10 +03:00
|
|
|
Matrix4x4 _SP; // screen-space-projections matrix
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
std::vector<std::shared_ptr<Triangle>> _triangles{};
|
2021-10-02 20:36:07 +03:00
|
|
|
std::vector<Plane> _clipPlanes{};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-09-19 11:25:10 +03:00
|
|
|
bool _ready = false;
|
2021-10-02 20:36:07 +03:00
|
|
|
double _aspect = 0;
|
2021-10-22 19:42:32 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
public:
|
2021-10-28 16:58:02 +03:00
|
|
|
Camera() : Object(ObjectNameTag("Camera")) {};
|
2021-09-13 15:53:43 +03:00
|
|
|
Camera(const Camera& camera) = delete;
|
|
|
|
|
|
|
|
void init(int width, int height, double fov = 110.0, double ZNear = 0.1, double ZFar = 5000.0);
|
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
std::vector<std::shared_ptr<Triangle>> project(std::shared_ptr<Mesh> mesh);
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-09-19 11:25:10 +03:00
|
|
|
void clear();
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-09-19 11:25:10 +03:00
|
|
|
[[nodiscard]] int buffSize() const { return _triangles.size(); }
|
2021-10-12 17:12:47 +03:00
|
|
|
std::vector<std::shared_ptr<Triangle>> sorted();
|
2021-10-22 19:42:32 +03:00
|
|
|
|
|
|
|
// OpenGL function
|
|
|
|
[[nodiscard]] GLfloat* view() const;
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //INC_3DZAVR_CAMERA_H
|