-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMathConversionUtils.h
113 lines (89 loc) · 2.66 KB
/
MathConversionUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#pragma once
#include <filament/Box.h>
#include <math/mat2.h>
#include <math/mat3.h>
#include <math/mat4.h>
#include <math/vec2.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <spatial/common/AxisAlignedBoundingBox.h>
#include <spatial/common/Math.h>
namespace spatial
{
/** ---- Vector 2 ---- **/
template <typename T>
inline filament::math::vec2<T> toFilament(const math::vec<2, T>& vec)
{
return {vec.x, vec.y};
}
template <typename T>
inline math::vec<2, T> fromFilament(const filament::math::vec2<T>& vec)
{
return {vec.x, vec.y};
}
/** ---- Vector 3 ---- **/
template <typename T>
inline filament::math::vec3<T> toFilament(const math::vec<3, T>& vec)
{
return {vec.x, vec.y, vec.z};
}
template <typename T>
inline math::vec<3, T> fromFilament(const filament::math::vec3<T>& vec)
{
return {vec.x, vec.y, vec.z};
}
/** ---- Vector 4 ---- **/
template <typename T>
inline filament::math::vec4<T> toFilament(const math::vec<4, T>& vec)
{
return {vec.x, vec.y, vec.z, vec.w};
}
template <typename T>
inline math::vec<4, T> fromFilament(const filament::math::vec4<T>& vec)
{
return {vec.x, vec.y, vec.z, vec.w};
}
/** ---- Matrix 2x2 ---- **/
template <typename T>
inline filament::math::details::TMat22<T> toFilament(const math::mat<2, 2, T>& mat)
{
return {toFilament(mat[0]), toFilament(mat[1])};
}
template <typename T>
inline math::mat<2, 2, T> fromFilament(const filament::math::details::TMat22<T>& mat)
{
return {fromFilament(mat[0]), fromFilament(mat[1])};
}
/** ---- Matrix 3x3 ---- **/
template <typename T>
inline filament::math::details::TMat33<T> toFilament(const math::mat<3, 3, T>& mat)
{
return {toFilament(mat[0]), toFilament(mat[1]), toFilament(mat[2])};
}
template <typename T>
inline math::mat<3, 3, T> fromFilament(const filament::math::details::TMat33<T>& mat)
{
return {fromFilament(mat[0]), fromFilament(mat[1]), fromFilament(mat[2])};
}
/** ---- Matrix 4x4 ---- **/
template <typename T>
inline filament::math::details::TMat44<T> toFilament(const math::mat<4, 4, T>& mat)
{
return {toFilament(mat[0]), toFilament(mat[1]), toFilament(mat[2]), toFilament(mat[3])};
}
template <typename T>
inline math::mat<4, 4, T> fromFilament(const filament::math::details::TMat44<T>& mat)
{
return {fromFilament(mat[0]), fromFilament(mat[1]), fromFilament(mat[2]), fromFilament(mat[3])};
}
/** ---- Bounding Box ---- **/
template <typename T>
inline filament::Box toFilament(const math::BaseAxisAlignedBoundingBox<T>& aabb)
{
return {toFilament(aabb.getCenter()), toFilament(aabb.getExtent())};
}
inline math::AxisAlignedBoundingBox fromFilament(const filament::Box& box)
{
return {fromFilament(box.getMin()), fromFilament(box.getMax())};
}
} // namespace spatial