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#include "./raylib.hpp"
11
12namespace raylib {
16class Camera3D : public ::Camera3D {
17public:
18 Camera3D(const ::Camera3D& camera) : ::Camera3D(camera) { }
19
31 ::Vector3 position,
32 ::Vector3 target = ::Vector3{0.0f, 0.0f, -1.0f},
33 ::Vector3 up = ::Vector3{0.0f, 1.0f, 0.0f},
34 float fovy = 45.0f,
35 int projection = CAMERA_PERSPECTIVE)
36 : ::Camera3D{position, target, up, fovy, projection} {}
37
38 Camera3D() {}
39
40 GETTERSETTER(::Vector3, Position, position)
41 GETTERSETTER(::Vector3, Target, target)
42 GETTERSETTER(::Vector3, Up, up)
43 GETTERSETTER(float, Fovy, fovy)
44 GETTERSETTER(int, Projection, projection)
45
46 Camera3D& operator=(const ::Camera3D& camera) {
47 set(camera);
48 return *this;
49 }
50
55 ::BeginMode3D(*this);
56 return *this;
57 }
58
63 ::EndMode3D();
64 return *this;
65 }
66
70 Matrix GetMatrix() const { return ::GetCameraMatrix(*this); }
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 { return ::GetMouseRay(mousePosition, *this); }
93
97 Vector2 GetWorldToScreen(::Vector3 position) const { return ::GetWorldToScreen(position, *this); }
98
102 Ray GetScreenToWorldRay(::Vector2 position, int width, int height) {
103 return ::GetScreenToWorldRayEx(position, *this, width, height);
104 }
105
109 void
110 DrawBillboard(const ::Texture2D& texture, ::Vector3 center, float size, ::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 }
125protected:
126 void set(const ::Camera3D& camera) {
127 position = camera.position;
128 target = camera.target;
129 up = camera.up;
130 fovy = camera.fovy;
131 projection = camera.projection;
132 }
133};
134
135using Camera = Camera3D;
136
137} // namespace raylib
138
139using RCamera = raylib::Camera;
141
142#endif // RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
Camera type, defines a camera position/orientation in 3d space.
Definition: Camera3D.hpp:16
Camera3D(::Vector3 position, ::Vector3 target=::Vector3{0.0f, 0.0f, -1.0f}, ::Vector3 up=::Vector3{0.0f, 1.0f, 0.0f}, float fovy=45.0f, int projection=CAMERA_PERSPECTIVE)
Create a new Camera3D.
Definition: Camera3D.hpp:30
Matrix GetMatrix() const
Get camera transform matrix (view matrix)
Definition: Camera3D.hpp:70
Camera3D & BeginMode()
Initializes 3D mode with custom camera (3D)
Definition: Camera3D.hpp:54
Camera3D & EndMode()
Ends 3D mode and returns to default 2D orthographic mode.
Definition: Camera3D.hpp:62
Vector2 GetWorldToScreen(::Vector3 position) const
Returns the screen space position for a 3d world space position.
Definition: Camera3D.hpp:97
void DrawBillboard(const ::Texture2D &texture, ::Vector3 center, float size, ::Color tint={255, 255, 255, 255}) const
Draw a billboard texture.
Definition: Camera3D.hpp:110
Ray GetScreenToWorldRay(::Vector2 position, int width, int height)
Get a ray trace from screen position (i.e mouse) in a viewport.
Definition: Camera3D.hpp:102
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
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:20
Vector3 type.
Definition: Vector3.hpp:20
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8