TheAtlasEngine
 
Loading...
Searching...
No Matches
math_types.hpp
1#pragma once
2
3#include <drivers/jolt-cpp/jolt-imports.hpp>
4#include <glm/glm.hpp>
5
12namespace atlas::physics {
13
14 template<typename T>
15 struct vector3;
16
17 template<>
18 struct vector3<JPH::Vec3> {
19 vector3() = default;
20
21 vector3(const JPH::Vec3& v) {
22 m_value = { v.GetX(), v.GetY(), v.GetZ() };
23 }
24
25 operator glm::vec3() const { return m_value; }
26
27 glm::vec3 operator=(const JPH::Vec3& v) {
28 m_value = { v.GetX(), v.GetY(), v.GetZ() };
29 return m_value;
30 }
31
32 bool operator==(const glm::vec3& other) const {
33 return m_value == other;
34 }
35
36 private:
37 glm::vec3 m_value;
38 };
39
40 template<>
41 struct vector3<JPH::Float3> {
42 vector3() = default;
43
44 vector3(const JPH::Float3& v) { m_value = { v.x, v.y, v.z }; }
45
46 operator glm::vec3() const { return m_value; }
47
48 glm::vec3 operator=(const JPH::Float3& v) {
49 m_value = { v.x, v.y, v.z };
50 return m_value;
51 }
52
53 bool operator==(const glm::vec3& other) const {
54 return m_value == other;
55 }
56
57 private:
58 glm::vec3 m_value;
59 };
60
61 template<>
62 struct vector3<JPH::DVec3> {
63 vector3() = default;
64
65 vector3(const JPH::DVec3& v) {
66 m_value = { v.GetX(), v.GetY(), v.GetZ() };
67 }
68
69 operator glm::dvec3() const { return m_value; }
70
71 glm::dvec3 operator=(const JPH::DVec3& v) {
72 m_value = { v.GetX(), v.GetY(), v.GetZ() };
73 return m_value;
74 }
75
76 bool operator==(const glm::dvec3& other) const {
77 return m_value == other;
78 }
79
80 private:
81 glm::dvec3 m_value;
82 };
83
84 template<>
85 struct vector3<JPH::Double3> {
86 vector3() = default;
87
88 vector3(const JPH::Double3& v) { m_value = { v.x, v.y, v.z }; }
89
90 operator glm::dvec3() const { return m_value; }
91
92 glm::dvec3 operator=(const JPH::Double3& v) {
93 m_value = { v.x, v.y, v.z };
94 return m_value;
95 }
96
97 bool operator==(const glm::dvec3& other) const {
98 return m_value == other;
99 }
100
101 private:
102 glm::dvec3 m_value;
103 };
104
105 // === VECTOR4 ADAPTER ===
106 template<typename T>
107 struct vector4;
108
109 template<>
110 struct vector4<JPH::Vec4> {
111 vector4() = default;
112
113 vector4(const JPH::Vec4& v) {
114 m_value = { v.GetX(), v.GetY(), v.GetZ(), v.GetW() };
115 }
116
117 operator glm::vec4() const { return m_value; }
118
119 glm::vec4 operator=(const JPH::Vec4& v) {
120 m_value = { v.GetX(), v.GetY(), v.GetZ(), v.GetW() };
121 return m_value;
122 }
123
124 bool operator==(const glm::vec4& other) const {
125 return m_value == other;
126 }
127
128 private:
129 glm::vec4 m_value;
130 };
131
132 template<>
133 struct vector4<JPH::Float4> {
134 vector4() = default;
135
136 vector4(const JPH::Float4& v) { m_value = { v.x, v.y, v.z, v.w }; }
137
138 operator glm::vec4() const { return m_value; }
139
140 glm::vec4 operator=(const JPH::Float4& v) {
141 m_value = { v.x, v.y, v.z, v.w };
142 return m_value;
143 }
144
145 bool operator==(const glm::vec4& other) const {
146 return m_value == other;
147 }
148
149 private:
150 glm::vec4 m_value;
151 };
152
153 // === QUATERNION ADAPTER ===
154 template<typename T>
156
157 // === MATRIX4 ADAPTER ===
158 template<typename T>
159 struct matrix4;
160
161 template<>
162 struct matrix4<JPH::Mat44> {
163 matrix4() = default;
164
165 matrix4(const JPH::Mat44& m) {
166 for (int i = 0; i < 4; ++i) {
167 const auto col = m.GetColumn4(i);
168 m_value[i] =
169 glm::vec4(col.GetX(), col.GetY(), col.GetZ(), col.GetW());
170 }
171 }
172
173 operator glm::mat4() const { return m_value; }
174
175 glm::mat4 operator=(const JPH::Mat44& m) {
176 for (int i = 0; i < 4; ++i) {
177 const auto col = m.GetColumn4(i);
178 m_value[i] =
179 glm::vec4(col.GetX(), col.GetY(), col.GetZ(), col.GetW());
180 }
181 return m_value;
182 }
183
184 bool operator==(const glm::mat4& other) const {
185 return m_value == other;
186 }
187
188 private:
189 glm::mat4 m_value;
190 };
191};
Types are still be filled out. When this is completed to_jph() can be removed.
Definition jolt_broad_phase.hpp:5
Definition math_types.hpp:159
Definition math_types.hpp:155
Definition math_types.hpp:15
Definition math_types.hpp:107