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(::Vector3 positionValue, ::Vector3 targetValue, ::Vector3 upValue,
36  float fovyValue = 0, int typeValue = 0) {
37  position = positionValue;
38  target = targetValue;
39  up = upValue;
40  fovy = fovyValue;
41  type = typeValue;
42  }
43 
44  Camera3D() {}
45 
46  GETTERSETTER(::Vector3, Position, position)
47  GETTERSETTER(::Vector3, Target, target)
48  GETTERSETTER(::Vector3, Up, up)
49  GETTERSETTER(float, Fovy, fovy)
50  GETTERSETTER(int, Type, type)
51 
52  Camera3D& operator=(const ::Camera3D& camera) {
53  set(camera);
54  return *this;
55  }
56 
57  Camera3D& operator=(const Camera3D& camera) {
58  set(camera);
59  return *this;
60  }
61 
63  ::BeginMode3D(*this);
64  return *this;
65  }
67  ::EndMode3D();
68  return *this;
69  }
70 
74  inline Matrix GetMatrix() const {
75  return ::GetCameraMatrix(*this);
76  }
77 
81  inline Camera3D& SetMode(int mode) {
82  ::SetCameraMode(*this, mode);
83  return *this;
84  }
85 
89  inline Camera3D& SetAltControl(int altKey) {
90  ::SetCameraAltControl(altKey);
91  return *this;
92  }
93 
97  inline Camera3D& SetSmoothZoomControl(int szKey) {
98  ::SetCameraSmoothZoomControl(szKey);
99  return *this;
100  }
101 
105  inline Camera3D& SetMoveControls(int frontKey, int backKey, int rightKey, int leftKey,
106  int upKey, int downKey) {
107  ::SetCameraMoveControls(frontKey, backKey, rightKey, leftKey, upKey, downKey);
108  return *this;
109  }
110 
114  inline Camera3D& Update() {
115  ::UpdateCamera(this);
116  return *this;
117  }
118 
123  ::UpdateVrTracking(this);
124  return *this;
125  }
126 
130  inline Ray GetMouseRay(::Vector2 mousePosition) const {
131  return ::GetMouseRay(mousePosition, *this);
132  }
133 
137  inline Vector2 GetWorldToScreen(::Vector3 position) const {
138  return ::GetWorldToScreen(position, *this);
139  }
140 
141  inline Camera3D& DrawBillboard(::Texture2D texture, ::Vector3 center, float size,
142  ::Color tint = WHITE) {
143  ::DrawBillboard(*this, texture, center, size, tint);
144  return *this;
145  }
146 
147  inline Camera3D& DrawBillboard(::Texture2D texture, ::Rectangle sourceRec, ::Vector3 center,
148  float size, ::Color tint = WHITE) {
149  ::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
150  return *this;
151  }
152 
153  protected:
154  inline void set(const ::Camera3D& camera) {
155  position = camera.position;
156  target = camera.target;
157  up = camera.up;
158  fovy = camera.fovy;
159  type = camera.type;
160  }
161 
162  inline void set(const Camera3D& camera) {
163  position = camera.position;
164  target = camera.target;
165  up = camera.up;
166  fovy = camera.fovy;
167  type = camera.type;
168  }
169 };
170 
171 typedef Camera3D Camera;
172 } // namespace raylib
173 
174 #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:130
raylib::Camera3D::SetMode
Camera3D & SetMode(int mode)
Set camera mode (multiple camera modes available)
Definition: Camera3D.hpp:81
raylib::Camera3D::DrawBillboard
Camera3D & DrawBillboard(::Texture2D texture, ::Vector3 center, float size, ::Color tint=WHITE)
Definition: Camera3D.hpp:141
raylib::Camera3D::GetMatrix
Matrix GetMatrix() const
Get transform matrix for camera.
Definition: Camera3D.hpp:74
raylib::Camera3D::DrawBillboard
Camera3D & DrawBillboard(::Texture2D texture, ::Rectangle sourceRec, ::Vector3 center, float size, ::Color tint=WHITE)
Definition: Camera3D.hpp:147
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:122
raylib::Camera3D::Camera3D
Camera3D()
Definition: Camera3D.hpp:44
raylib::Camera3D::Update
Camera3D & Update()
Update camera position for selected mode.
Definition: Camera3D.hpp:114
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:105
raylib::Camera3D::SetAltControl
Camera3D & SetAltControl(int altKey)
Set camera alt key to combine with mouse movement (free camera)
Definition: Camera3D.hpp:89
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:35
raylib::Camera
Camera3D Camera
Definition: Camera3D.hpp:171
raylib::Camera3D
Definition: Camera3D.hpp:33
raylib::Camera3D::BeginMode3D
Camera3D & BeginMode3D()
Definition: Camera3D.hpp:62
raylib::Camera3D::operator=
Camera3D & operator=(const Camera3D &camera)
Definition: Camera3D.hpp:57
raylib::Camera3D::EndMode3D
Camera3D & EndMode3D()
Definition: Camera3D.hpp:66
raylib::Rectangle
Definition: Rectangle.hpp:33
raylib::Vector2
Definition: Vector2.hpp:37
raylib::Camera3D::set
void set(const ::Camera3D &camera)
Definition: Camera3D.hpp:154
raylib::Color
Definition: Color.hpp:35
raylib::Camera3D::SetSmoothZoomControl
Camera3D & SetSmoothZoomControl(int szKey)
Set camera smooth zoom key to combine with mouse (free camera)
Definition: Camera3D.hpp:97
raylib::Camera3D::set
void set(const Camera3D &camera)
Definition: Camera3D.hpp:162
raylib::Texture
Definition: Texture.hpp:36
raylib::Camera3D::GetWorldToScreen
Vector2 GetWorldToScreen(::Vector3 position) const
Returns the screen space position for a 3d world space position.
Definition: Camera3D.hpp:137