raylib-cpp
C++ object-oriented wrapper library for raylib.
Camera2D.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_CAMERA2D_HPP_
26 #define RAYLIB_CPP_INCLUDE_CAMERA2D_HPP_
27 
28 #include "./raylib.hpp"
29 #include "./Vector2.hpp"
30 #include "./raylib-cpp-utils.hpp"
31 
32 namespace raylib {
33 class Camera2D : public ::Camera2D {
34  public:
35  Camera2D() {}
36  Camera2D(const ::Camera2D& camera) {
37  set(camera);
38  }
39 
40  Camera2D(::Vector2 offsetValue, ::Vector2 targetValue, float rotationValue = 0,
41  float zoomValue = 1) {
42  offset = offsetValue;
43  target = targetValue;
44  rotation = rotationValue;
45  zoom = zoomValue;
46  }
47 
48  inline Camera2D& BeginMode() {
49  ::BeginMode2D(*this);
50  return *this;
51  }
52 
53  inline Camera2D& EndMode() {
54  ::EndMode2D();
55  return *this;
56  }
57 
58  GETTERSETTER(::Vector2, Offset, offset)
59  GETTERSETTER(::Vector2, Target, target)
60  GETTERSETTER(float, Rotation, rotation)
61  GETTERSETTER(float, Zoom, zoom)
62 
63  Camera2D& operator=(const ::Camera2D& camera) {
64  set(camera);
65  return *this;
66  }
67 
68  Camera2D& operator=(const Camera2D& camera) {
69  set(camera);
70  return *this;
71  }
72 
76  inline Matrix GetMatrix() const {
77  return ::GetCameraMatrix2D(*this);
78  }
79 
83  inline Vector2 GetWorldToScreen(::Vector2 position) const {
84  return ::GetWorldToScreen2D(position, *this);
85  }
86 
90  inline Vector2 GetScreenToWorld(::Vector2 position) const {
91  return ::GetScreenToWorld2D(position, *this);
92  }
93 
94  protected:
95  inline void set(const ::Camera2D& camera) {
96  offset = camera.offset;
97  target = camera.target;
98  rotation = camera.rotation;
99  zoom = camera.zoom;
100  }
101 
102  inline void set(const Camera2D& camera) {
103  offset = camera.offset;
104  target = camera.target;
105  rotation = camera.rotation;
106  zoom = camera.zoom;
107  }
108 };
109 } // namespace raylib
110 
111 #endif // RAYLIB_CPP_INCLUDE_CAMERA2D_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Matrix
Definition: Matrix.hpp:46
raylib::Camera2D::GetScreenToWorld
Vector2 GetScreenToWorld(::Vector2 position) const
Returns the world space position for a 2d camera screen space position.
Definition: Camera2D.hpp:90
raylib::Camera2D::GetMatrix
Matrix GetMatrix() const
Returns camera 2d transform matrix.
Definition: Camera2D.hpp:76
raylib::Camera2D::EndMode
Camera2D & EndMode()
Definition: Camera2D.hpp:53
raylib::Camera2D::set
void set(const ::Camera2D &camera)
Definition: Camera2D.hpp:95
raylib::Camera2D::operator=
Camera2D & operator=(const Camera2D &camera)
Definition: Camera2D.hpp:68
raylib::Camera2D
Definition: Camera2D.hpp:33
raylib::Vector2
Definition: Vector2.hpp:37
raylib::Camera2D::set
void set(const Camera2D &camera)
Definition: Camera2D.hpp:102
raylib::Camera2D::GetWorldToScreen
Vector2 GetWorldToScreen(::Vector2 position) const
Returns the screen space position for a 3d world space position.
Definition: Camera2D.hpp:83
raylib::Camera2D::Camera2D
Camera2D()
Definition: Camera2D.hpp:35
raylib::Camera2D::Camera2D
Camera2D(const ::Camera2D &camera)
Definition: Camera2D.hpp:36
raylib::Camera2D::Camera2D
Camera2D(::Vector2 offsetValue, ::Vector2 targetValue, float rotationValue=0, float zoomValue=1)
Definition: Camera2D.hpp:40
raylib::Camera2D::BeginMode
Camera2D & BeginMode()
Definition: Camera2D.hpp:48