P-E-R-R-Y
Utilitaires, contrats et vendors du moteur, en une seule doc
Loading...
Searching...
No Matches
RayCamera.hpp
Go to the documentation of this file.
1
10
11#ifndef RAYCAMERA_HPP_
12#define RAYCAMERA_HPP_
13
14//Raylib (without conflict)
15#include "RaylibAliases.hpp"
16
17//Interface
18#include "ICamera.hpp"
19
24
25 public:
26 RayCamera(Vector3f pos = {100.0f, 100.0f, 100.0f}, Vector3f target = {0.f, 0.f, 0.f}, float fov = 45.f) {
27 _camera = {0};
28 _camera.position = (raylib::Vector3){(float)pos.x, (float)pos.y, (float)pos.z};
29 _camera.target = (raylib::Vector3){(float)target.x, (float)target.y, (float)target.z};
30 _camera.up = (raylib::Vector3){0.f, 1.f, 0.0f};
31 _camera.fovy = fov;
32 _camera.projection = raylib::CAMERA_PERSPECTIVE;
33 _mode = raylib::CAMERA_CUSTOM;
34 }
35
36 ~RayCamera() = default;
37
38 float getFov() const override {
39 return _camera.fovy;
40 }
41
42 void setFov(float fov) override {
43 _camera.fovy = fov;
44 }
45
46 ICamera::Mode getMode() const override {
47 switch (_mode) {
48 case raylib::CameraMode::CAMERA_FREE: return ICamera::Mode::FREE;
49 case raylib::CameraMode::CAMERA_ORBITAL: return ICamera::Mode::ORBITAL;
50 case raylib::CameraMode::CAMERA_FIRST_PERSON: return ICamera::Mode::FIRST_PERSON;
51 case raylib::CameraMode::CAMERA_THIRD_PERSON: return ICamera::Mode::THIRD_PERSON;
52 default: return ICamera::Mode::CUSTOM;
53 }
54 }
55
56 void setMode(ICamera::Mode mode) override {
57 switch (mode) {
58 case ICamera::Mode::FREE: _mode = raylib::CameraMode::CAMERA_FREE; break;
59 case ICamera::Mode::ORBITAL: _mode = raylib::CameraMode::CAMERA_ORBITAL; break;
60 case ICamera::Mode::FIRST_PERSON: _mode = raylib::CameraMode::CAMERA_FIRST_PERSON; break;
61 case ICamera::Mode::THIRD_PERSON: _mode = raylib::CameraMode::CAMERA_THIRD_PERSON; break;
62 default: _mode = raylib::CameraMode::CAMERA_CUSTOM; break;
63 }
64 }
65
66 Vector3f getPosition() const override {
67 return {_camera.position.x, _camera.position.y, _camera.position.z};
68 }
69
70 void setPosition(Vector3f position) override {
71 _camera.position = {float(position.x), float(position.y), float(position.z)};
72 }
73
74 ICamera::Projection getProjection() const override {
75 return _camera.projection == raylib::CAMERA_ORTHOGRAPHIC ? ICamera::ORTHOGRAPHIC : ICamera::PERSPECTIVE;
76 }
77
78 void setProjection(ICamera::Projection projection) override {
79 _camera.projection = projection == ICamera::ORTHOGRAPHIC ? raylib::CAMERA_ORTHOGRAPHIC : raylib::CAMERA_PERSPECTIVE;
80 }
81
82 Vector3f getTarget() const override {
83 return {_camera.target.x, _camera.target.y, _camera.target.z};
84 }
85
86 void setTarget(Vector3f target) override {
87 _camera.target = {float(target.x), float(target.y), float(target.z)};
88 }
89
90 Vector3f getUp() const override {
91 return {_camera.up.x, _camera.up.y, _camera.up.z};
92 }
93
94 void setUp(Vector3f up) override {
95 _camera.up = {float(up.x), float(up.y), float(up.z)};
96 }
97
98 friend class RayWindow;
99
100 private:
101 raylib::Camera _camera;
102 raylib::CameraMode _mode;
103};
104
106
107#endif /* !RAYCAMERA_HPP_ */
void setPosition(Vector3f position) override
Set the position.
Definition RayCamera.hpp:70
void setProjection(ICamera::Projection projection) override
Definition RayCamera.hpp:78
float getFov() const override
Get the FOV.
Definition RayCamera.hpp:38
Vector3f getPosition() const override
Get the position.
Definition RayCamera.hpp:66
~RayCamera()=default
RayCamera(Vector3f pos={100.0f, 100.0f, 100.0f}, Vector3f target={0.f, 0.f, 0.f}, float fov=45.f)
Definition RayCamera.hpp:26
void setTarget(Vector3f target) override
Set the target.
Definition RayCamera.hpp:86
Vector3f getTarget() const override
Get the target.
Definition RayCamera.hpp:82
Vector3f getUp() const override
Get the up vector.
Definition RayCamera.hpp:90
friend class RayWindow
Definition RayCamera.hpp:98
ICamera::Projection getProjection() const override
Get the Projection.
Definition RayCamera.hpp:74
void setUp(Vector3f up) override
Set the up vector.
Definition RayCamera.hpp:94
void setFov(float fov) override
Set the FOV.
Definition RayCamera.hpp:42
void setMode(ICamera::Mode mode) override
Definition RayCamera.hpp:56
ICamera::Mode getMode() const override
Get the mode.
Definition RayCamera.hpp:46
Camera interface.
Definition ICamera.hpp:23
Vector3< double > Vector3f
Definition Vector3.hpp:121
T x
Definition Vector3.hpp:21
T y
Definition Vector3.hpp:21
T z
Definition Vector3.hpp:21