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 
18  Camera3D(::Vector3 positionValue, ::Vector3 targetValue, ::Vector3 upValue,
19  float fovyValue = 0, int projectionValue = 0) {
20  position = positionValue;
21  target = targetValue;
22  up = upValue;
23  fovy = fovyValue;
24  projection = projectionValue;
25  }
26 
27  Camera3D() {}
28 
29  GETTERSETTER(::Vector3, Position, position)
30  GETTERSETTER(::Vector3, Target, target)
31  GETTERSETTER(::Vector3, Up, up)
32  GETTERSETTER(float, Fovy, fovy)
33  GETTERSETTER(int, Projection, projection)
34 
35  Camera3D& operator=(const ::Camera3D& camera) {
36  set(camera);
37  return *this;
38  }
39 
44  ::BeginMode3D(*this);
45  return *this;
46  }
47 
52  ::EndMode3D();
53  return *this;
54  }
55 
59  inline Matrix GetMatrix() const {
60  return ::GetCameraMatrix(*this);
61  }
62 
66  inline Camera3D& SetMode(int mode) {
67  ::SetCameraMode(*this, mode);
68  return *this;
69  }
70 
74  inline Camera3D& SetAltControl(int altKey) {
75  ::SetCameraAltControl(altKey);
76  return *this;
77  }
78 
82  inline Camera3D& SetSmoothZoomControl(int szKey) {
83  ::SetCameraSmoothZoomControl(szKey);
84  return *this;
85  }
86 
91  int frontKey, int backKey,
92  int rightKey, int leftKey,
93  int upKey, int downKey) {
94  ::SetCameraMoveControls(frontKey, backKey, rightKey, leftKey, upKey, downKey);
95  return *this;
96  }
97 
101  inline Camera3D& Update() {
102  ::UpdateCamera(this);
103  return *this;
104  }
105 
109  inline Ray GetMouseRay(::Vector2 mousePosition) const {
110  return ::GetMouseRay(mousePosition, *this);
111  }
112 
116  inline Vector2 GetWorldToScreen(::Vector3 position) const {
117  return ::GetWorldToScreen(position, *this);
118  }
119 
124  const ::Texture2D& texture,
125  ::Vector3 center,
126  float size,
127  ::Color tint = {255, 255, 255, 255}) {
128  ::DrawBillboard(*this, texture, center, size, tint);
129  return *this;
130  }
131 
136  const ::Texture2D& texture,
137  ::Rectangle sourceRec,
138  ::Vector3 center,
139  float size,
140  ::Color tint = {255, 255, 255, 255}) {
141  ::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
142  return *this;
143  }
144 
145  private:
146  inline void set(const ::Camera3D& camera) {
147  position = camera.position;
148  target = camera.target;
149  up = camera.up;
150  fovy = camera.fovy;
151  projection = camera.projection;
152  }
153 };
154 
155 typedef Camera3D Camera;
156 } // namespace raylib
157 
158 #endif // RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
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:196
raylib::Camera3D::GetMouseRay
Ray GetMouseRay(::Vector2 mousePosition) const
Returns a ray trace from mouse position.
Definition: Camera3D.hpp:109
raylib::Camera3D::SetMode
Camera3D & SetMode(int mode)
Set camera mode (multiple camera modes available)
Definition: Camera3D.hpp:66
raylib::Camera3D::GetMatrix
Matrix GetMatrix() const
Get transform matrix for camera.
Definition: Camera3D.hpp:59
raylib::Camera3D::BeginMode
Camera3D & BeginMode()
Initializes 3D mode with custom camera (3D)
Definition: Camera3D.hpp:43
raylib::Camera3D::EndMode
Camera3D & EndMode()
Ends 3D mode and returns to default 2D orthographic mode.
Definition: Camera3D.hpp:51
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:101
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:90
raylib::Camera3D::SetAltControl
Camera3D & SetAltControl(int altKey)
Set camera alt key to combine with mouse movement (free camera)
Definition: Camera3D.hpp:74
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:123
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::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::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:135
raylib::Camera3D::SetSmoothZoomControl
Camera3D & SetSmoothZoomControl(int szKey)
Set camera smooth zoom key to combine with mouse (free camera)
Definition: Camera3D.hpp:82
raylib::Camera3D::GetWorldToScreen
Vector2 GetWorldToScreen(::Vector3 position) const
Returns the screen space position for a 3d world space position.
Definition: Camera3D.hpp:116