Loading...
Searching...
No Matches
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>
18
19namespace CubbyFlow
20{
21template <size_t N>
23{
24 // Do nothing
25};
26
27template <>
29{
30 public:
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
51template <>
53{
54 public:
56
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
81template <size_t N>
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
106 const Vector<double, N>& pointInWorld) const;
107
110 const Vector<double, N>& dirInWorld) const;
111
113 [[nodiscard]] Ray<double, N> ToLocal(
114 const Ray<double, N>& rayInWorld) const;
115
118 const BoundingBox<double, N>& bboxInWorld) const;
119
122 const Vector<double, N>& pointInLocal) const;
123
126 const Vector<double, N>& dirInLocal) const;
127
129 [[nodiscard]] Ray<double, N> ToWorld(
130 const Ray<double, N>& rayInLocal) const;
131
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
N-D axis-aligned bounding box class.
Definition BoundingBox.hpp:47
static std::enable_if_t< IsMatrixStaticSquare< Rows, Cols >(), D > MakeIdentity()
Makes a static identity matrix.
Definition MatrixDenseBase-Impl.hpp:169
Definition Matrix.hpp:30
Definition Transform.hpp:29
Vector2D ToWorld(const Vector2D &pointInLocal) const
Rotates a point in local space to the world coordinate.
void SetRotation(double angleInRadian)
Vector2D ToLocal(const Vector2D &pointInWorld) const
Rotates a point in world coordinate to the local frame.
Orientation(double angleInRadian)
Definition Transform.hpp:53
Vector3D ToWorld(const Vector3D &pointInLocal) const
Rotates a point in local space to the world coordinate.
Vector3D ToLocal(const Vector3D &pointInWorld) const
Rotates a point in world coordinate to the local frame.
Orientation(const QuaternionD &quat)
void SetRotation(const QuaternionD &quat)
const QuaternionD & GetRotation() const
Definition Transform.hpp:23
Class for N-D ray.
Definition Ray.hpp:26
Represents N-D rigid body transform.
Definition Transform.hpp:83
Vector< double, N > ToWorldDirection(const Vector< double, N > &dirInLocal) const
Transforms a direction in local space to the world coordinate.
Transform()=default
Constructs identity transform.
BoundingBox< double, N > ToLocal(const BoundingBox< double, N > &bboxInWorld) const
Transforms a bounding box in world coordinate to the local frame.
Ray< double, N > ToLocal(const Ray< double, N > &rayInWorld) const
Transforms a ray in world coordinate to the local frame.
void SetTranslation(const Vector< double, N > &translation)
Sets the translation.
void SetOrientation(const Orientation< N > &orientation)
Sets the orientation.
Vector< double, N > ToWorld(const Vector< double, N > &pointInLocal) const
Transforms a point in local space to the world coordinate.
const Orientation< N > & GetOrientation() const
Returns the orientation.
Transform(const Vector< double, N > &translation, const Orientation< N > &orientation)
Constructs a transform with translation and orientation.
Vector< double, N > ToLocalDirection(const Vector< double, N > &dirInWorld) const
Transforms a direction in world coordinate to the local frame.
const Vector< double, N > & GetTranslation() const
Returns the translation.
BoundingBox< double, N > ToWorld(const BoundingBox< double, N > &bboxInLocal) const
Transforms a bounding box in local space to the world coordinate.
Ray< double, N > ToWorld(const Ray< double, N > &rayInLocal) const
Transforms a ray in local space to the world coordinate.
Vector< double, N > ToLocal(const Vector< double, N > &pointInWorld) const
Transforms a point in world coordinate to the local frame.
Definition pybind11Utils.hpp:21