raylib-cpp
C++ object-oriented wrapper library for raylib.
Camera3D.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
26 #define RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
27 
28 #include "./raylib.hpp"
29 #include "./Vector3.hpp"
30 #include "./raylib-cpp-utils.hpp"
31 
32 namespace raylib {
33 class Camera3D : public ::Camera3D {
34  public:
35  Camera3D(const ::Camera3D& camera) {
36  set(camera);
37  }
38 
39  Camera3D(::Vector3 positionValue, ::Vector3 targetValue, ::Vector3 upValue,
40  float fovyValue = 0, int typeValue = 0) {
41  position = positionValue;
42  target = targetValue;
43  up = upValue;
44  fovy = fovyValue;
45  type = typeValue;
46  }
47 
48  Camera3D() {}
49 
50  GETTERSETTER(::Vector3, Position, position)
51  GETTERSETTER(::Vector3, Target, target)
52  GETTERSETTER(::Vector3, Up, up)
53  GETTERSETTER(float, Fovy, fovy)
54  GETTERSETTER(int, Type, type)
55 
56  Camera3D& operator=(const ::Camera3D& camera) {
57  set(camera);
58  return *this;
59  }
60 
61  Camera3D& operator=(const Camera3D& camera) {
62  set(camera);
63  return *this;
64  }
65 
70  ::BeginMode3D(*this);
71  return *this;
72  }
73 
78  ::EndMode3D();
79  return *this;
80  }
81 
85  inline Matrix GetMatrix() const {
86  return ::GetCameraMatrix(*this);
87  }
88 
92  inline Camera3D& SetMode(int mode) {
93  ::SetCameraMode(*this, mode);
94  return *this;
95  }
96 
100  inline Camera3D& SetAltControl(int altKey) {
101  ::SetCameraAltControl(altKey);
102  return *this;
103  }
104 
108  inline Camera3D& SetSmoothZoomControl(int szKey) {
109  ::SetCameraSmoothZoomControl(szKey);
110  return *this;
111  }
112 
117  int frontKey, int backKey,
118  int rightKey, int leftKey,
119  int upKey, int downKey) {
120  ::SetCameraMoveControls(frontKey, backKey, rightKey, leftKey, upKey, downKey);
121  return *this;
122  }
123 
127  inline Camera3D& Update() {
128  ::UpdateCamera(this);
129  return *this;
130  }
131 
136  ::UpdateVrTracking(this);
137  return *this;
138  }
139 
143  inline Ray GetMouseRay(::Vector2 mousePosition) const {
144  return ::GetMouseRay(mousePosition, *this);
145  }
146 
150  inline Vector2 GetWorldToScreen(::Vector3 position) const {
151  return ::GetWorldToScreen(position, *this);
152  }
153 
155  const ::Texture2D& texture,
156  ::Vector3 center,
157  float size,
158  ::Color tint = {255, 255, 255, 255}) {
159  ::DrawBillboard(*this, texture, center, size, tint);
160  return *this;
161  }
162 
164  const ::Texture2D& texture,
165  ::Rectangle sourceRec,
166  ::Vector3 center,
167  float size,
168  ::Color tint = {255, 255, 255, 255}) {
169  ::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
170  return *this;
171  }
172 
173  protected:
174  inline void set(const ::Camera3D& camera) {
175  position = camera.position;
176  target = camera.target;
177  up = camera.up;
178  fovy = camera.fovy;
179  type = camera.type;
180  }
181 
182  inline void set(const Camera3D& camera) {
183  position = camera.position;
184  target = camera.target;
185  up = camera.up;
186  fovy = camera.fovy;
187  type = camera.type;
188  }
189 };
190 
191 typedef Camera3D Camera;
192 } // namespace raylib
193 
194 #endif // RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Matrix
Definition: Matrix.hpp:46
raylib::Camera3D::GetMouseRay
Ray GetMouseRay(::Vector2 mousePosition) const
Returns a ray trace from mouse position.
Definition: Camera3D.hpp:143
raylib::Camera3D::SetMode
Camera3D & SetMode(int mode)
Set camera mode (multiple camera modes available)
Definition: Camera3D.hpp:92
raylib::Camera3D::GetMatrix
Matrix GetMatrix() const
Get transform matrix for camera.
Definition: Camera3D.hpp:85
raylib::Camera3D::BeginMode
Camera3D & BeginMode()
Initializes 3D mode with custom camera (3D)
Definition: Camera3D.hpp:69
raylib::Camera3D::EndMode
Camera3D & EndMode()
Ends 3D mode and returns to default 2D orthographic mode.
Definition: Camera3D.hpp:77
raylib::Ray
Ray type (useful for raycast)
Definition: Ray.hpp:38
raylib::Camera3D::UpdateVrTracking
Camera3D & UpdateVrTracking()
Update VR tracking (position and orientation) and camera.
Definition: Camera3D.hpp:135
raylib::Camera3D::Camera3D
Camera3D()
Definition: Camera3D.hpp:48
raylib::Camera3D::Update
Camera3D & Update()
Update camera position for selected mode.
Definition: Camera3D.hpp:127
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:116
raylib::Camera3D::SetAltControl
Camera3D & SetAltControl(int altKey)
Set camera alt key to combine with mouse movement (free camera)
Definition: Camera3D.hpp:100
raylib::Camera3D::DrawBillboard
Camera3D & DrawBillboard(const ::Texture2D &texture, ::Vector3 center, float size, ::Color tint={255, 255, 255, 255})
Definition: Camera3D.hpp:154
raylib::Vector3
Definition: Vector3.hpp:37
raylib::Camera3D::Camera3D
Camera3D(::Vector3 positionValue, ::Vector3 targetValue, ::Vector3 upValue, float fovyValue=0, int typeValue=0)
Definition: Camera3D.hpp:39
raylib::Camera
Camera3D Camera
Definition: Camera3D.hpp:191
raylib::Camera3D::Camera3D
Camera3D(const ::Camera3D &camera)
Definition: Camera3D.hpp:35
raylib::Camera3D
Definition: Camera3D.hpp:33
raylib::Camera3D::operator=
Camera3D & operator=(const Camera3D &camera)
Definition: Camera3D.hpp:61
raylib::Rectangle
Definition: Rectangle.hpp:33
raylib::Vector2
Definition: Vector2.hpp:37
raylib::Camera3D::set
void set(const ::Camera3D &camera)
Definition: Camera3D.hpp:174
raylib::Color
Definition: Color.hpp:35
raylib::Camera3D::DrawBillboard
Camera3D & DrawBillboard(const ::Texture2D &texture, ::Rectangle sourceRec, ::Vector3 center, float size, ::Color tint={255, 255, 255, 255})
Definition: Camera3D.hpp:163
raylib::Camera3D::SetSmoothZoomControl
Camera3D & SetSmoothZoomControl(int szKey)
Set camera smooth zoom key to combine with mouse (free camera)
Definition: Camera3D.hpp:108
raylib::Camera3D::set
void set(const Camera3D &camera)
Definition: Camera3D.hpp:182
raylib::Camera3D::GetWorldToScreen
Vector2 GetWorldToScreen(::Vector3 position) const
Returns the screen space position for a 3d world space position.
Definition: Camera3D.hpp:150