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 
65  ::BeginMode3D(*this);
66  return *this;
67  }
68 
73  ::EndMode3D();
74  return *this;
75  }
76 
80  inline Matrix GetMatrix() const {
81  return ::GetCameraMatrix(*this);
82  }
83 
87  inline Camera3D& SetMode(int mode) {
88  ::SetCameraMode(*this, mode);
89  return *this;
90  }
91 
95  inline Camera3D& SetAltControl(int altKey) {
96  ::SetCameraAltControl(altKey);
97  return *this;
98  }
99 
103  inline Camera3D& SetSmoothZoomControl(int szKey) {
104  ::SetCameraSmoothZoomControl(szKey);
105  return *this;
106  }
107 
112  int frontKey, int backKey,
113  int rightKey, int leftKey,
114  int upKey, int downKey) {
115  ::SetCameraMoveControls(frontKey, backKey, rightKey, leftKey, upKey, downKey);
116  return *this;
117  }
118 
122  inline Camera3D& Update() {
123  ::UpdateCamera(this);
124  return *this;
125  }
126 
131  ::UpdateVrTracking(this);
132  return *this;
133  }
134 
138  inline Ray GetMouseRay(::Vector2 mousePosition) const {
139  return ::GetMouseRay(mousePosition, *this);
140  }
141 
145  inline Vector2 GetWorldToScreen(::Vector3 position) const {
146  return ::GetWorldToScreen(position, *this);
147  }
148 
153  const ::Texture2D& texture,
154  ::Vector3 center,
155  float size,
156  ::Color tint = {255, 255, 255, 255}) {
157  ::DrawBillboard(*this, texture, center, size, tint);
158  return *this;
159  }
160 
165  const ::Texture2D& texture,
166  ::Rectangle sourceRec,
167  ::Vector3 center,
168  float size,
169  ::Color tint = {255, 255, 255, 255}) {
170  ::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
171  return *this;
172  }
173 
174  protected:
175  inline void set(const ::Camera3D& camera) {
176  position = camera.position;
177  target = camera.target;
178  up = camera.up;
179  fovy = camera.fovy;
180  type = camera.type;
181  }
182 };
183 
184 typedef Camera3D Camera;
185 } // namespace raylib
186 
187 #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::UpdateCamera
static void UpdateCamera(const ::Camera &camera)
Definition: Functions.hpp:211
raylib::Camera3D::GetMouseRay
Ray GetMouseRay(::Vector2 mousePosition) const
Returns a ray trace from mouse position.
Definition: Camera3D.hpp:138
raylib::Camera3D::SetMode
Camera3D & SetMode(int mode)
Set camera mode (multiple camera modes available)
Definition: Camera3D.hpp:87
raylib::Camera3D::GetMatrix
Matrix GetMatrix() const
Get transform matrix for camera.
Definition: Camera3D.hpp:80
raylib::Camera3D::BeginMode
Camera3D & BeginMode()
Initializes 3D mode with custom camera (3D)
Definition: Camera3D.hpp:64
raylib::Camera3D::EndMode
Camera3D & EndMode()
Ends 3D mode and returns to default 2D orthographic mode.
Definition: Camera3D.hpp:72
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:130
raylib::Camera3D::Camera3D
Camera3D()
Definition: Camera3D.hpp:48
raylib::Camera3D::Update
Camera3D & Update()
Update camera position for selected mode.
Definition: Camera3D.hpp:122
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:111
raylib::Camera3D::SetAltControl
Camera3D & SetAltControl(int altKey)
Set camera alt key to combine with mouse movement (free camera)
Definition: Camera3D.hpp:95
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:152
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:184
raylib::Camera3D::Camera3D
Camera3D(const ::Camera3D &camera)
Definition: Camera3D.hpp:35
raylib::Camera3D
Definition: Camera3D.hpp:33
raylib::Rectangle
Definition: Rectangle.hpp:33
raylib::Vector2
Definition: Vector2.hpp:37
raylib::Camera3D::set
void set(const ::Camera3D &camera)
Definition: Camera3D.hpp:175
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})
Draw a billboard texture defined by source.
Definition: Camera3D.hpp:164
raylib::Camera3D::SetSmoothZoomControl
Camera3D & SetSmoothZoomControl(int szKey)
Set camera smooth zoom key to combine with mouse (free camera)
Definition: Camera3D.hpp:103
raylib::Camera3D::GetWorldToScreen
Vector2 GetWorldToScreen(::Vector3 position) const
Returns the screen space position for a 3d world space position.
Definition: Camera3D.hpp:145