raylib-cpp
C++ object-oriented wrapper library for raylib.
Camera3D.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
2 #define RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
3 
4 #include "./raylib.hpp"
5 #include "./Vector3.hpp"
6 #include "./raylib-cpp-utils.hpp"
7 
8 namespace raylib {
12 class Camera3D : public ::Camera3D {
13  public:
14  Camera3D(const ::Camera3D& camera) {
15  set(camera);
16  }
17 
27  Camera3D(::Vector3 position,
28  ::Vector3 target = ::Vector3{0.0f, 0.0f, 0.0f},
29  ::Vector3 up = ::Vector3{0.0f, 1.0f, 0.0f},
30  float fovy = 0,
31  int projection = CAMERA_PERSPECTIVE) : ::Camera3D{position, target, up, fovy, projection} {}
32 
33  Camera3D() {}
34 
35  GETTERSETTER(::Vector3, Position, position)
36  GETTERSETTER(::Vector3, Target, target)
37  GETTERSETTER(::Vector3, Up, up)
38  GETTERSETTER(float, Fovy, fovy)
39  GETTERSETTER(int, Projection, projection)
40 
41  Camera3D& operator=(const ::Camera3D& camera) {
42  set(camera);
43  return *this;
44  }
45 
50  ::BeginMode3D(*this);
51  return *this;
52  }
53 
58  ::EndMode3D();
59  return *this;
60  }
61 
65  inline Matrix GetMatrix() const {
66  return ::GetCameraMatrix(*this);
67  }
68 
72  inline Camera3D& SetMode(int mode) {
73  ::SetCameraMode(*this, mode);
74  return *this;
75  }
76 
80  inline Camera3D& SetAltControl(int altKey) {
81  ::SetCameraAltControl(altKey);
82  return *this;
83  }
84 
88  inline Camera3D& SetSmoothZoomControl(int szKey) {
89  ::SetCameraSmoothZoomControl(szKey);
90  return *this;
91  }
92 
97  int frontKey, int backKey,
98  int rightKey, int leftKey,
99  int upKey, int downKey) {
100  ::SetCameraMoveControls(frontKey, backKey, rightKey, leftKey, upKey, downKey);
101  return *this;
102  }
103 
107  inline Camera3D& Update() {
108  ::UpdateCamera(this);
109  return *this;
110  }
111 
115  inline Ray GetMouseRay(::Vector2 mousePosition) const {
116  return ::GetMouseRay(mousePosition, *this);
117  }
118 
122  inline Vector2 GetWorldToScreen(::Vector3 position) const {
123  return ::GetWorldToScreen(position, *this);
124  }
125 
130  const ::Texture2D& texture,
131  ::Vector3 center,
132  float size,
133  ::Color tint = {255, 255, 255, 255}) {
134  ::DrawBillboard(*this, texture, center, size, tint);
135  return *this;
136  }
137 
142  const ::Texture2D& texture,
143  ::Rectangle sourceRec,
144  ::Vector3 center,
145  ::Vector2 size,
146  ::Color tint = {255, 255, 255, 255}) {
147  ::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
148  return *this;
149  }
150 
151  private:
152  inline void set(const ::Camera3D& camera) {
153  position = camera.position;
154  target = camera.target;
155  up = camera.up;
156  fovy = camera.fovy;
157  projection = camera.projection;
158  }
159 };
160 
161 typedef Camera3D Camera;
162 } // namespace raylib
163 
164 #endif // RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
raylib::Matrix
Matrix type (OpenGL style 4x4 - right handed, column major)
Definition: Matrix.hpp:16
raylib::UpdateCamera
static void UpdateCamera(const ::Camera &camera)
Update camera depending on selected mode.
Definition: Functions.hpp:202
raylib::Camera3D::GetMouseRay
Ray GetMouseRay(::Vector2 mousePosition) const
Returns a ray trace from mouse position.
Definition: Camera3D.hpp:115
raylib::Camera3D::SetMode
Camera3D & SetMode(int mode)
Set camera mode (multiple camera modes available)
Definition: Camera3D.hpp:72
raylib::Camera3D::GetMatrix
Matrix GetMatrix() const
Get transform matrix for camera.
Definition: Camera3D.hpp:65
raylib::Camera3D::BeginMode
Camera3D & BeginMode()
Initializes 3D mode with custom camera (3D)
Definition: Camera3D.hpp:49
raylib::Camera3D::EndMode
Camera3D & EndMode()
Ends 3D mode and returns to default 2D orthographic mode.
Definition: Camera3D.hpp:57
raylib::Ray
Ray type (useful for raycast)
Definition: Ray.hpp:12
raylib::Camera3D::Update
Camera3D & Update()
Update camera position for selected mode.
Definition: Camera3D.hpp:107
raylib::Camera3D::SetMoveControls
Camera3D & SetMoveControls(int frontKey, int backKey, int rightKey, int leftKey, int upKey, int downKey)
Set camera move controls (1st person and 3rd person cameras)
Definition: Camera3D.hpp:96
raylib::Camera3D::DrawBillboard
Camera3D & DrawBillboard(const ::Texture2D &texture, ::Rectangle sourceRec, ::Vector3 center, ::Vector2 size, ::Color tint={255, 255, 255, 255})
Draw a billboard texture defined by source.
Definition: Camera3D.hpp:141
raylib::Camera3D::SetAltControl
Camera3D & SetAltControl(int altKey)
Set camera alt key to combine with mouse movement (free camera)
Definition: Camera3D.hpp:80
raylib::Camera3D::DrawBillboard
Camera3D & DrawBillboard(const ::Texture2D &texture, ::Vector3 center, float size, ::Color tint={255, 255, 255, 255})
Draw a billboard texture.
Definition: Camera3D.hpp:129
raylib::Vector3
Vector3 type.
Definition: Vector3.hpp:16
raylib::Camera3D
Camera type, defines a camera position/orientation in 3d space.
Definition: Camera3D.hpp:12
raylib::Camera3D::Camera3D
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:27
raylib::Rectangle
Rectangle type.
Definition: Rectangle.hpp:12
raylib::Vector2
Vector2 type.
Definition: Vector2.hpp:16
raylib::Color
Color type, RGBA (32bit)
Definition: Color.hpp:14
raylib::Camera3D::SetSmoothZoomControl
Camera3D & SetSmoothZoomControl(int szKey)
Set camera smooth zoom key to combine with mouse (free camera)
Definition: Camera3D.hpp:88
raylib::Camera3D::GetWorldToScreen
Vector2 GetWorldToScreen(::Vector3 position) const
Returns the screen space position for a 3d world space position.
Definition: Camera3D.hpp:122