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(::Vector2 offsetValue, ::Vector2 targetValue, float rotationValue = 0,
36  float zoomValue = 1) {
37  offset = offsetValue;
38  target = targetValue;
39  rotation = rotationValue;
40  zoom = zoomValue;
41  }
42 
43  inline Camera2D& BeginMode2D() {
44  ::BeginMode2D(*this);
45  return *this;
46  }
47 
48  inline Camera2D& EndMode2D() {
49  ::EndMode2D();
50  return *this;
51  }
52 
53  GETTERSETTER(::Vector2, Offset, offset)
54  GETTERSETTER(::Vector2, Target, target)
55  GETTERSETTER(float, Rotation, rotation)
56  GETTERSETTER(float, Zoom, zoom)
57 
58  Camera2D& operator=(const ::Camera2D& camera) {
59  set(camera);
60  return *this;
61  }
62 
63  Camera2D& operator=(const Camera2D& camera) {
64  set(camera);
65  return *this;
66  }
67 
71  inline Matrix GetMatrix() const {
72  return ::GetCameraMatrix2D(*this);
73  }
74 
78  inline Vector2 GetWorldToScreen2D(Vector2 position) const {
79  return ::GetWorldToScreen2D(position, *this);
80  }
81 
85  inline Vector2 GetScreenToWorld2D(Vector2 position) const {
86  return ::GetScreenToWorld2D(position, *this);
87  }
88 
89  protected:
90  inline void set(const ::Camera2D& camera) {
91  offset = camera.offset;
92  target = camera.target;
93  rotation = camera.rotation;
94  zoom = camera.zoom;
95  }
96 
97  inline void set(const Camera2D& camera) {
98  offset = camera.offset;
99  target = camera.target;
100  rotation = camera.rotation;
101  zoom = camera.zoom;
102  }
103 };
104 } // namespace raylib
105 
106 #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::GetMatrix
Matrix GetMatrix() const
Returns camera 2d transform matrix.
Definition: Camera2D.hpp:71
raylib::Camera2D::GetScreenToWorld2D
Vector2 GetScreenToWorld2D(Vector2 position) const
Returns the world space position for a 2d camera screen space position.
Definition: Camera2D.hpp:85
raylib::Camera2D::BeginMode2D
Camera2D & BeginMode2D()
Definition: Camera2D.hpp:43
raylib::Camera2D::set
void set(const ::Camera2D &camera)
Definition: Camera2D.hpp:90
raylib::Camera2D::operator=
Camera2D & operator=(const Camera2D &camera)
Definition: Camera2D.hpp:63
raylib::Camera2D
Definition: Camera2D.hpp:33
raylib::Camera2D::EndMode2D
Camera2D & EndMode2D()
Definition: Camera2D.hpp:48
raylib::Vector2
Definition: Vector2.hpp:37
raylib::Camera2D::set
void set(const Camera2D &camera)
Definition: Camera2D.hpp:97
raylib::Camera2D::Camera2D
Camera2D(::Vector2 offsetValue, ::Vector2 targetValue, float rotationValue=0, float zoomValue=1)
Definition: Camera2D.hpp:35
raylib::Camera2D::GetWorldToScreen2D
Vector2 GetWorldToScreen2D(Vector2 position) const
Returns the screen space position for a 3d world space position.
Definition: Camera2D.hpp:78