Kale
Loading...
Searching...
No Matches
Transform.hpp
Go to the documentation of this file.
1/*
2 Copyright 2022 Rishi Challa
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
22#include <Kale/Math/Ray/Ray.hpp>
26
27#include <type_traits>
28
29#include <nlohmann/json.hpp>
30
31namespace Kale {
32
37 using JSON = nlohmann::json;
38
42 class Transform : public Matrix3f {
43 public:
44
48 Transform();
49
54 Transform(const Matrix3f& matrix);
55
60 Transform(Matrix3f&& matrix);
61
66 Transform(const std::array<float, 9>& arr);
67
72 Transform(std::array<float, 9>&& arr);
73
81 Transform(const Vector2f& translation, float rotation, const Vector2f& scaleFactor, AngleUnit unit);
82
92 Transform(float translateX, float translateY, float rotation, float scaleX, float scaleY, AngleUnit unit);
93
97 void setIdentity();
98
103 void scale(const Vector2f& vec);
104
110 void scale(float x, float y);
111
116 void scale(float factor);
117
123 void scale(float factor, const Vector2f& origin);
124
131 void scale(float x, float y, const Vector2f& origin);
132
137 void translate(const Vector2f& vec);
138
144 void translate(float x, float y);
145
151 void rotate(float angle, AngleUnit unit);
152
159 void rotate(float angle, AngleUnit unit, const Vector2f& origin);
160
166 void setTranslation(float x, float y);
167
172 void setTranslation(const Vector2f& vec);
173
178 Vector2f getTranslation() const;
179
185 void setRotation(float angle, AngleUnit unit);
186
192 float getRotation(AngleUnit unit) const;
193
199 void setScale(float scaleX, float scaleY);
200
205 void setScale(float scale);
206
211 Vector2f getScale() const;
212
218 Vector2f transform(const Vector2f& vec) const;
219
224 void transformInplace(Vector2f& vec) const;
225
232 Vector2f inverseTransform(const Vector2f& vec) const;
233
239 void inverseTransformInplace(Vector2f& vec) const;
240
246 RotatedRect transform(const RotatedRect& rect) const;
247
254 RotatedRect inverseTransform(const RotatedRect& rect) const;
255
261 RotatedRect transform(const Rect& rect) const;
262
269 RotatedRect inverseTransform(const Rect& rect) const;
270
276 Ray transform(const Ray& ray) const;
277
284 Ray inverseTransform(const Ray& ray) const;
285
291 Line transform(const Line& line) const;
292
299 Line inverseTransform(const Line& line) const;
300
306 Circle transform(const Circle& circle) const;
307
314 Circle inverseTransform(const Circle& circle) const;
315
322 template <typename T> typename std::enable_if<std::is_base_of<Geometry, T>::value, bool>::type
323 isInView(const T& geometry, const Rect& sceneBounds) {
324 return geometry.rectCollision(transform(sceneBounds));
325 }
326
327 };
328
333
337 inline void from_json(const JSON& j, Transform& p) {
338 from_json(j, dynamic_cast<Matrix3f&>(p));
339 }
340
344 inline void to_json(JSON& j, const Transform& p) {
345 to_json(j, dynamic_cast<const Matrix3f&>(p));
346 }
347
348}
float getRotation(AngleUnit unit) const
void scale(const Vector2f &vec)
void inverseTransformInplace(Vector2f &vec) const
void transformInplace(Vector2f &vec) const
void setRotation(float angle, AngleUnit unit)
void setScale(float scaleX, float scaleY)
std::enable_if< std::is_base_of< Geometry, T >::value, bool >::type isInView(const T &geometry, const Rect &sceneBounds)
void rotate(float angle, AngleUnit unit)
void setTranslation(float x, float y)
Vector2f getScale() const
void translate(const Vector2f &vec)
Vector2f inverseTransform(const Vector2f &vec) const
Vector2f getTranslation() const
Vector2f transform(const Vector2f &vec) const
Transform Camera
nlohmann::json JSON
Definition Scene.hpp:39
AngleUnit
Definition Utils.hpp:30
void to_json(JSON &j, const Matrix< w, h, T > &p)
Definition Matrix.hpp:547
void from_json(const JSON &j, Matrix< w, h, T > &p)
Definition Matrix.hpp:539