extract orbital camera into separate file
This commit is contained in:
@ -1,57 +1,24 @@
|
||||
#ifndef __RENDERER_HPP_
|
||||
#define __RENDERER_HPP_
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "camera.hpp"
|
||||
#include "config.hpp"
|
||||
#include "puzzle.hpp"
|
||||
#include "physics.hpp"
|
||||
|
||||
class OrbitCamera3D {
|
||||
friend class Renderer;
|
||||
|
||||
private:
|
||||
Camera camera;
|
||||
Vector3 target;
|
||||
float distance;
|
||||
float angle_x;
|
||||
float angle_y;
|
||||
Vector2 last_mouse;
|
||||
bool dragging;
|
||||
bool panning;
|
||||
bool target_lock;
|
||||
|
||||
public:
|
||||
OrbitCamera3D(Vector3 target, float distance)
|
||||
: camera({0}), target(target), distance(distance), angle_x(0.0),
|
||||
angle_y(0.0), last_mouse(Vector2Zero()), dragging(false),
|
||||
panning(false), target_lock(true) {
|
||||
camera.position = Vector3(0, 0, -1.0 * distance);
|
||||
camera.target = target;
|
||||
camera.up = Vector3(0, 1.0, 0);
|
||||
camera.fovy = CAMERA_FOV;
|
||||
camera.projection = CAMERA_PERSPECTIVE;
|
||||
}
|
||||
|
||||
~OrbitCamera3D() {}
|
||||
|
||||
public:
|
||||
auto Update(const Mass ¤t_mass) -> void;
|
||||
};
|
||||
#include "puzzle.hpp"
|
||||
|
||||
class Renderer {
|
||||
private:
|
||||
OrbitCamera3D camera;
|
||||
const OrbitCamera3D &camera;
|
||||
RenderTexture render_target;
|
||||
RenderTexture klotski_target;
|
||||
RenderTexture menu_target;
|
||||
|
||||
Material vertex_mat;
|
||||
|
||||
// Instancing
|
||||
Material vertex_mat;
|
||||
int transforms_size;
|
||||
Matrix *transforms;
|
||||
Mesh cube_instance;
|
||||
@ -62,18 +29,14 @@ public:
|
||||
bool connect_solutions;
|
||||
|
||||
public:
|
||||
Renderer()
|
||||
: camera(OrbitCamera3D(Vector3(0, 0, 0), CAMERA_DISTANCE)),
|
||||
mark_solutions(false), connect_solutions(false), transforms_size(0),
|
||||
transforms(nullptr) {
|
||||
Renderer(const OrbitCamera3D &camera)
|
||||
: camera(camera), mark_solutions(false), connect_solutions(false),
|
||||
transforms_size(0), transforms(nullptr) {
|
||||
render_target = LoadRenderTexture(GetScreenWidth() / 2.0,
|
||||
GetScreenHeight() - MENU_HEIGHT);
|
||||
klotski_target = LoadRenderTexture(GetScreenWidth() / 2.0,
|
||||
GetScreenHeight() - MENU_HEIGHT);
|
||||
menu_target = LoadRenderTexture(GetScreenWidth(), MENU_HEIGHT);
|
||||
|
||||
vertex_mat = LoadMaterialDefault();
|
||||
vertex_mat.maps[MATERIAL_MAP_DIFFUSE].color = VERTEX_COLOR;
|
||||
}
|
||||
|
||||
Renderer(const Renderer ©) = delete;
|
||||
@ -86,10 +49,9 @@ public:
|
||||
UnloadRenderTexture(klotski_target);
|
||||
UnloadRenderTexture(menu_target);
|
||||
|
||||
UnloadMaterial(vertex_mat);
|
||||
|
||||
// Instancing
|
||||
if (transforms != nullptr) {
|
||||
UnloadMaterial(vertex_mat);
|
||||
MemFree(transforms);
|
||||
UnloadMesh(cube_instance);
|
||||
|
||||
@ -106,9 +68,6 @@ private:
|
||||
-> void;
|
||||
|
||||
public:
|
||||
auto UpdateCamera(const MassSpringSystem &mass_springs,
|
||||
const State ¤t_state) -> void;
|
||||
|
||||
auto UpdateTextureSizes() -> void;
|
||||
|
||||
auto DrawMassSprings(const MassSpringSystem &mass_springs,
|
||||
|
||||
Reference in New Issue
Block a user