raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
Camera3D.hpp
1#ifndef RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
2#define RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
3
4#include "./raylib.hpp"
5#include "./Vector2.hpp"
6#include "./Vector3.hpp"
7#include "./Matrix.hpp"
8#include "./Ray.hpp"
9#include "./raylib-cpp-utils.hpp"
10
11namespace raylib {
15class Camera3D : public ::Camera3D {
16 public:
17 Camera3D(const ::Camera3D& camera) {
18 set(camera);
19 }
20
30 Camera3D(::Vector3 position,
31 ::Vector3 target = ::Vector3{0.0f, 0.0f, 0.0f},
32 ::Vector3 up = ::Vector3{0.0f, 1.0f, 0.0f},
33 float fovy = 0,
34 int projection = CAMERA_PERSPECTIVE) : ::Camera3D{position, target, up, fovy, projection} {}
35
36 Camera3D() {}
37
38 GETTERSETTER(::Vector3, Position, position)
39 GETTERSETTER(::Vector3, Target, target)
40 GETTERSETTER(::Vector3, Up, up)
41 GETTERSETTER(float, Fovy, fovy)
42 GETTERSETTER(int, Projection, projection)
43
44 Camera3D& operator=(const ::Camera3D& camera) {
45 set(camera);
46 return *this;
47 }
48
53 ::BeginMode3D(*this);
54 return *this;
55 }
56
61 ::EndMode3D();
62 return *this;
63 }
64
68 Matrix GetMatrix() const {
69 return ::GetCameraMatrix(*this);
70 }
71
75 Camera3D& Update(int mode) {
76 ::UpdateCamera(this, mode);
77 return *this;
78 }
79
84 Camera3D& Update(::Vector3 movement, ::Vector3 rotation, float zoom = 1.0f) {
85 ::UpdateCameraPro(this, movement, rotation, zoom);
86 return *this;
87 }
88
92 Ray GetMouseRay(::Vector2 mousePosition) const {
93 return ::GetMouseRay(mousePosition, *this);
94 }
95
99 Vector2 GetWorldToScreen(::Vector3 position) const {
100 return ::GetWorldToScreen(position, *this);
101 }
102
107 const ::Texture2D& texture,
108 ::Vector3 center,
109 float size,
110 ::Color tint = {255, 255, 255, 255}) const {
111 ::DrawBillboard(*this, texture, center, size, tint);
112 }
113
118 const ::Texture2D& texture,
119 ::Rectangle sourceRec,
120 ::Vector3 center,
121 ::Vector2 size,
122 ::Color tint = {255, 255, 255, 255}) const {
123 ::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
124 }
125
126 protected:
127 void set(const ::Camera3D& camera) {
128 position = camera.position;
129 target = camera.target;
130 up = camera.up;
131 fovy = camera.fovy;
132 projection = camera.projection;
133 }
134};
135
136using Camera = Camera3D;
137
138} // namespace raylib
139
140using RCamera = raylib::Camera;
142
143#endif // RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
Camera type, defines a camera position/orientation in 3d space.
Definition: Camera3D.hpp:15
Matrix GetMatrix() const
Get camera transform matrix (view matrix)
Definition: Camera3D.hpp:68
Camera3D & BeginMode()
Initializes 3D mode with custom camera (3D)
Definition: Camera3D.hpp:52
Camera3D & EndMode()
Ends 3D mode and returns to default 2D orthographic mode.
Definition: Camera3D.hpp:60
Vector2 GetWorldToScreen(::Vector3 position) const
Returns the screen space position for a 3d world space position.
Definition: Camera3D.hpp:99
void DrawBillboard(const ::Texture2D &texture, ::Vector3 center, float size, ::Color tint={255, 255, 255, 255}) const
Draw a billboard texture.
Definition: Camera3D.hpp:106
Camera3D & Update(int mode)
Update camera position for selected mode.
Definition: Camera3D.hpp:75
Camera3D & Update(::Vector3 movement, ::Vector3 rotation, float zoom=1.0f)
Update camera movement/rotation.
Definition: Camera3D.hpp:84
Camera3D(::Vector3 position, ::Vector3 target=::Vector3{0.0f, 0.0f, 0.0f}, ::Vector3 up=::Vector3{0.0f, 1.0f, 0.0f}, float fovy=0, int projection=CAMERA_PERSPECTIVE)
Create a new Camera3D.
Definition: Camera3D.hpp:30
Ray GetMouseRay(::Vector2 mousePosition) const
Returns a ray trace from mouse position.
Definition: Camera3D.hpp:92
void DrawBillboard(const ::Texture2D &texture, ::Rectangle sourceRec, ::Vector3 center, ::Vector2 size, ::Color tint={255, 255, 255, 255}) const
Draw a billboard texture defined by source.
Definition: Camera3D.hpp:117
Matrix type (OpenGL style 4x4 - right handed, column major)
Definition: Matrix.hpp:18
Ray type (useful for raycast)
Definition: Ray.hpp:12
Vector2 type.
Definition: Vector2.hpp:19
Vector3 type.
Definition: Vector3.hpp:19