opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
transform.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <ostream>
7
8namespace osc
9{
10 // packaged-up SQT transform (scale -> rotate -> translate)
12
14 {
15 return Transform{.scale = scale, .rotation = rotation, .translation = new_translation};
16 }
17
19 {
20 return Transform{.scale = scale, .rotation = new_rotation, .translation = translation};
21 }
22
23 constexpr Transform with_scale(const Vector3& new_scale) const
24 {
25 return Transform{.scale = new_scale, .rotation = rotation, .translation = translation};
26 }
27
28 constexpr Transform with_scale(float new_scale) const
29 {
30 return Transform{.scale = Vector3{new_scale}, .rotation = rotation, .translation = translation};
31 }
32
33 friend bool operator==(const Transform&, const Transform&) = default;
34
38 };
39
40 // applies the transform to a point vector (equivalent to `transform_point`)
41 constexpr Vector3 operator*(const Transform& transform, Vector3 point)
42 {
43 point *= transform.scale;
44 point = transform.rotation * point;
45 point += transform.translation;
46 return point;
47 }
48
49 template<typename T>
50 constexpr T identity();
51
52 template<>
54 {
55 return Transform{};
56 }
57
58 inline std::ostream& operator<<(std::ostream& out, const Transform& transform)
59 {
60 return out << "Transform(translation = " << transform.translation << ", rotation = " << transform.rotation << ", scale = " << transform.scale << ')';
61 }
62}
Definition custom_decoration_generator.h:5
constexpr Transform identity< Transform >()
Definition transform.h:53
std::ostream & operator<<(std::ostream &, const Object &)
constexpr T identity()
constexpr U to(T &&value)
Definition conversion.h:56
Matrix< T, 3, 3 > operator*(const Matrix< T, 3, 3 > &m, T scalar)
Definition matrix3x3.h:273
Definition transform.h:11
constexpr Transform with_scale(const Vector3 &new_scale) const
Definition transform.h:23
Vector3 translation
Definition transform.h:37
constexpr Transform with_rotation(const Quaternion &new_rotation) const
Definition transform.h:18
friend bool operator==(const Transform &, const Transform &)=default
constexpr Transform with_scale(float new_scale) const
Definition transform.h:28
Quaternion rotation
Definition transform.h:36
constexpr Transform with_translation(const Vector3 &new_translation) const
Definition transform.h:13
Vector3 scale
Definition transform.h:35