SuperDex Physics C++ API
Loading...
Searching...
No Matches
matrix_transform_rt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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
27
28namespace superdex {
29
30/************************************************************************************
31 Rotation and translation in Matrix form
32*/
34 public:
35 MatrixTransformRT() = default;
36 explicit MatrixTransformRT(Matrix3x3r const& rotation, Real3 const& translation);
37 explicit MatrixTransformRT(VMatrix3x3r const& rotation, Vec4r translation);
38
39 // clang-format off
40 [[nodiscard]] MOCHI_FORCE_INLINE VMatrix3x3r const& VGetRotation() const { return _rotation; }
41 [[nodiscard]] MOCHI_FORCE_INLINE Vec4r VGetTranslation() const { return _translation; }
42 [[nodiscard]] MOCHI_FORCE_INLINE Matrix3x3r GetRotation() const { return ToNdArray3x3(_rotation); }
43 [[nodiscard]] MOCHI_FORCE_INLINE Real3 GetTranslation() const { return ToReal3(_translation); }
44 // clang-format on
45
46 // Multiplication with a 3-component vector must specify point or direction
47 [[nodiscard]] Vec4r TransformPoint(Vec4r pt) const;
48 [[nodiscard]] Vec4r TransformDirection(Vec4r pt) const;
49 [[nodiscard]] Vec4r InverseTransformPoint(Vec4r pt) const;
50 [[nodiscard]] Vec4r InverseTransformDirection(Vec4r pt) const;
51 [[nodiscard]] Real3 TransformPoint(Real3 const& pt) const;
52 [[nodiscard]] Real3 TransformDirection(Real3 const& dir) const;
53 [[nodiscard]] Real3 InverseTransformPoint(Real3 const& pt) const;
54 [[nodiscard]] Real3 InverseTransformDirection(Real3 const& dir) const;
55
56 // Multiplication with another TransformRT concatenates transforms
57 [[nodiscard]] MatrixTransformRT operator*(MatrixTransformRT const& rhs) const;
58
59 private:
60 VMatrix3x3r _rotation = VEye<3>(); // 4th SIMD column is always 0
61 Vec4r _translation{0_r, 0_r, 0_r, 1_r}; // 4th SIMD components is always 1
62
63 public:
65 MOCHI_FIELD_NAME(_rotation, "rotation")
66 MOCHI_FIELD_NAME(_translation, "translation")
68};
69
70/************************************************************************************
71 Utilities
72*/
73
74// Converting representations
75[[nodiscard]] MOCHI_FORCE_INLINE MatrixTransformRT ToMatrixTransformRT(TransformRT const& a);
77ToMatrixTransformRT(Quaternion const& rot, Real3 const& trans);
78[[nodiscard]] MOCHI_FORCE_INLINE TransformRT ToTransformRT(MatrixTransformRT const& a);
81
82// Compute the inverse transform
84
85// NearEqual: (abs(a-b) <= epsilon)
86[[nodiscard]] MOCHI_FORCE_INLINE bool NearEqual(
87 MatrixTransformRT const& a,
88 MatrixTransformRT const& b,
90
91} // namespace superdex
92
93#include "matrix_transform_rt_inl.h"
Vec4r InverseTransformDirection(Vec4r pt) const
Vec4r TransformDirection(Vec4r pt) const
MatrixTransformRT operator*(MatrixTransformRT const &rhs) const
Vec4r InverseTransformPoint(Vec4r pt) const
VMatrix3x3r const & VGetRotation() const
#define MOCHI_FORCE_INLINE
constexpr T kDefaultNearEqualEpsilon
NdArray< Simd< real, 4 >, 3 > VMatrix3x3r
Definition vmatrix.h:52
NdArray< T, 3, 3 > ToNdArray3x3(NdArray< Simd< T, 4 >, 3 > m)
Definition vmatrix.h:375
Real3 ToReal3(Simd< T, 4 > v)
Definition vmatrix.h:354
Simd< real, 4 > Vec4r
Definition simd.h:206
NdArray< Simd< real, 4 >, 4 > VMatrix4x4r
Definition vmatrix.h:55
TransformRT Invert(TransformRT const &a)
VMatrix4x4r ToVMatrix4x4(TransformRT const &a)
NdArray< real, 3 > Real3
Definition nd_array.h:106
MatrixTransformRT ToMatrixTransformRT(TransformRT const &a)
NdArray< real, 3, 3 > Matrix3x3r
Definition nd_array.h:125
VMatrix4x4r ToVMatrix4x4Transpose(TransformRT const &a)
NdArray< Simd< T, 4 >, N > VEye()
bool NearEqual(TransformRT const &a, TransformRT const &b, real epsilon=kDefaultNearEqualEpsilon< real >)
TransformRT ToTransformRT(MatrixTransformRT const &a)
#define MOCHI_FIELD_NAME(realName, customName)
Definition reflection.h:294
#define MOCHI_STRUCT_END()
Definition reflection.h:279
#define MOCHI_STRUCT_BEGIN(name)
Definition reflection.h:278