Transform.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_TRANSFORM_HPP
12 #define CUBBYFLOW_TRANSFORM_HPP
13 
15 #include <Core/Geometry/Ray.hpp>
16 #include <Core/Math/Quaternion.hpp>
17 #include <Core/Matrix/Matrix.hpp>
18 
19 namespace CubbyFlow
20 {
21 template <size_t N>
23 {
24  // Do nothing
25 };
26 
27 template <>
28 class Orientation<2>
29 {
30  public:
31  Orientation();
32 
33  Orientation(double angleInRadian);
34 
35  [[nodiscard]] double GetRotation() const;
36 
37  void SetRotation(double angleInRadian);
38 
40  [[nodiscard]] Vector2D ToLocal(const Vector2D& pointInWorld) const;
41 
43  [[nodiscard]] Vector2D ToWorld(const Vector2D& pointInLocal) const;
44 
45  private:
46  double m_angle = 0.0;
47  double m_cosAngle = 1.0;
48  double m_sinAngle = 0.0;
49 };
50 
51 template <>
52 class Orientation<3>
53 {
54  public:
55  Orientation();
56 
57  Orientation(const QuaternionD& quat);
58 
59  [[nodiscard]] const QuaternionD& GetRotation() const;
60 
61  void SetRotation(const QuaternionD& quat);
62 
64  [[nodiscard]] Vector3D ToLocal(const Vector3D& pointInWorld) const;
65 
67  [[nodiscard]] Vector3D ToWorld(const Vector3D& pointInLocal) const;
68 
69  private:
70  QuaternionD m_quat;
71  Matrix3x3D m_rotationMat3 = Matrix3x3D::MakeIdentity();
72  Matrix3x3D m_inverseRotationMat3 = Matrix3x3D::MakeIdentity();
73 };
74 
77 
81 template <size_t N>
82 class Transform
83 {
84  public:
86  Transform() = default;
87 
89  Transform(const Vector<double, N>& translation,
90  const Orientation<N>& orientation);
91 
93  [[nodiscard]] const Vector<double, N>& GetTranslation() const;
94 
96  void SetTranslation(const Vector<double, N>& translation);
97 
99  [[nodiscard]] const Orientation<N>& GetOrientation() const;
100 
102  void SetOrientation(const Orientation<N>& orientation);
103 
105  [[nodiscard]] Vector<double, N> ToLocal(
106  const Vector<double, N>& pointInWorld) const;
107 
109  [[nodiscard]] Vector<double, N> ToLocalDirection(
110  const Vector<double, N>& dirInWorld) const;
111 
113  [[nodiscard]] Ray<double, N> ToLocal(
114  const Ray<double, N>& rayInWorld) const;
115 
117  [[nodiscard]] BoundingBox<double, N> ToLocal(
118  const BoundingBox<double, N>& bboxInWorld) const;
119 
121  [[nodiscard]] Vector<double, N> ToWorld(
122  const Vector<double, N>& pointInLocal) const;
123 
125  [[nodiscard]] Vector<double, N> ToWorldDirection(
126  const Vector<double, N>& dirInLocal) const;
127 
129  [[nodiscard]] Ray<double, N> ToWorld(
130  const Ray<double, N>& rayInLocal) const;
131 
133  [[nodiscard]] BoundingBox<double, N> ToWorld(
134  const BoundingBox<double, N>& bboxInLocal) const;
135 
136  private:
137  Vector<double, N> m_translation;
138  Orientation<N> m_orientation;
139 };
140 
143 } // namespace CubbyFlow
144 
145 #endif
Class for N-D ray.
Definition: Ray.hpp:25
Represents N-D rigid body transform.
Definition: Transform.hpp:82
Definition: Matrix.hpp:27
static std::enable_if_t< IsMatrixStaticSquare< Rows, Cols >), D > MakeIdentity()
Makes a static identity matrix.
Definition: MatrixDenseBase-Impl.hpp:169
Definition: pybind11Utils.hpp:20
Definition: Transform.hpp:22
Definition: Transform.hpp:52
Definition: Transform.hpp:28