4#include <glm/gtc/matrix_transform.hpp>
8template<
typename T, glm::precision P>
16template<
typename T, glm::precision P>
23template<
typename T, glm::precision P>
26 mT = glm::tvec3<T, P>(
static_cast<T
>(0));
27 mS = glm::tvec3<T, P>(
static_cast<T
>(1));
28 mR = glm::tmat3x3<T, P>(
static_cast<T
>(1));
33template<
typename T, glm::precision P>
41template<
typename T, glm::precision P>
49template<
typename T, glm::precision P>
57template<
typename T, glm::precision P>
60 mR = glm::tmat3x3<T, P>(glm::rotate(glm::tmat4x4<T, P>(mR), angle, v));
65template<
typename T, glm::precision P>
68 T C = std::cos(angle);
69 T S = std::sin(angle);
70 mR = glm::tmat3x3<T, P>(
71 mR[0][0], C * mR[0][1] - mR[0][2] * S, C * mR[0][2] + mR[0][1] * S,
72 mR[1][0], C * mR[1][1] - mR[1][2] * S, C * mR[1][2] + mR[1][1] * S,
73 mR[2][0], C * mR[2][1] - mR[2][2] * S, C * mR[2][2] + mR[2][1] * S);
78template<
typename T, glm::precision P>
81 T C = std::cos(angle);
82 T S = std::sin(angle);
83 mR = glm::tmat3x3<T, P>(
84 C * mR[0][0] + mR[0][2] * S, mR[0][1], C * mR[0][2] - mR[0][0] * S,
85 C * mR[1][0] + mR[1][2] * S, mR[1][1], C * mR[1][2] - mR[1][0] * S,
86 C * mR[2][0] + mR[2][2] * S, mR[2][1], C * mR[2][2] - mR[2][0] * S);
91template<
typename T, glm::precision P>
94 T C = std::cos(angle);
95 T S = std::sin(angle);
96 mR = glm::tmat3x3<T, P>(
97 C * mR[0][0] - mR[0][1] * S, C * mR[0][1] + mR[0][0] * S, mR[0][2],
98 C * mR[1][0] - mR[1][1] * S, C * mR[1][1] + mR[1][0] * S, mR[1][2],
99 C * mR[2][0] - mR[2][1] * S, C * mR[2][1] + mR[2][0] * S, mR[2][2]);
104template<
typename T, glm::precision P>
107 mR = glm::tmat3x3<T, P>::RotationMatrix(angle, v) * mR;
112template<
typename T, glm::precision P>
117 mR = glm::tmat3x3<T, P>(
118 mR[0][0], mR[0][1], mR[0][2],
119 C * mR[1][0] + mR[2][0] * S, C * mR[1][1] + mR[2][1] * S, C * mR[1][2] + mR[2][2] * S,
120 C * mR[2][0] - mR[1][0] * S, C * mR[2][1] - mR[1][1] * S, C * mR[2][2] - mR[1][2] * S);
125template<
typename T, glm::precision P>
130 mR = glm::tmat3x3<T, P>(
131 C * mR[0][0] - mR[2][0] * S, C * mR[0][1] - mR[2][1] * S, C * mR[0][2] - mR[2][2] * S,
132 mR[1][0], mR[1][1], mR[1][2],
133 C * mR[2][0] + mR[0][0] * S, C * mR[2][1] + mR[0][1] * S, C * mR[2][2] + mR[0][2] * S);
138template<
typename T, glm::precision P>
143 mR = glm::tmat3x3<T, P>(
144 C * mR[0][0] + mR[1][0] * S, C * mR[0][1] + mR[1][1] * S, C * mR[0][2] + mR[1][2] * S,
145 C * mR[1][0] - mR[0][0] * S, C * mR[1][1] - mR[0][1] * S, C * mR[1][2] - mR[0][2] * S,
146 mR[2][0], mR[2][1], mR[2][2]);
151template<
typename T, glm::precision P>
159template<
typename T, glm::precision P>
167template<
typename T, glm::precision P>
170 mS = glm::tvec3<T, P>(uniform);
175template<
typename T, glm::precision P>
178 mR = glm::tmat3x3<T, P>(glm::rotate(glm::tmat4x4<T, P>(T(1)), angle, v));
183template<
typename T, glm::precision P>
186 mR = glm::tmat3x3<T, P>(glm::rotate(glm::tmat4x4<T, P>(T(1)), angle, glm::tvec3<T, P>(1, 0, 0)));
191template<
typename T, glm::precision P>
194 mR = glm::tmat3x3<T, P>(glm::rotate(glm::tmat4x4<T, P>(T(1)), angle, glm::tvec3<T, P>(0, 1, 0)));
199template<
typename T, glm::precision P>
202 mR = glm::tmat3x3<T, P>(glm::rotate(glm::tmat4x4<T, P>(T(1)), angle, glm::tvec3<T, P>(0, 0, 1)));
207template<
typename T, glm::precision P>
210 front_vec = normalize(front_vec);
211 up_vec = normalize(up_vec);
213 if (std::abs(dot(up_vec, front_vec)) > 0.99999f)
216 glm::tvec3<T, P> prev_up = up_vec;
218 glm::tvec3<T, P> right = cross(front_vec, prev_up);
219 glm::tvec3<T, P> up = cross(right, front_vec);
221 right = normalize(right);
231template<
typename T, glm::precision P>
234 LookTowards(front_vec, glm::tvec3<T, P>(0, 1, 0));
239template<
typename T, glm::precision P>
242 LookTowards(point - mT, up_vec);
247template<
typename T, glm::precision P>
250 LookTowards(point - mT);
255template<
typename T, glm::precision P>
258 return glm::tmat4x4<T, P>(
262 mT.x, mT.y, mT.z, 1);
267template<
typename T, glm::precision P>
270 return glm::tmat4x4<T, P>(
271 mR[0][0], mR[0][1], mR[0][2], 0,
272 mR[1][0], mR[1][1], mR[1][2], 0,
273 mR[2][0], mR[2][1], mR[2][2], 0,
279template<
typename T, glm::precision P>
282 return glm::tmat4x4<T, P>(
291template<
typename T, glm::precision P>
294 return glm::tmat4x4<T, P>(
298 -mT.x, -mT.y, -mT.z, 1);
303template<
typename T, glm::precision P>
306 return glm::tmat4x4<T, P>(
307 mR[0][0], mR[1][0], mR[2][0], 0,
308 mR[0][1], mR[1][1], mR[2][1], 0,
309 mR[0][2], mR[1][2], mR[2][2], 0,
315template<
typename T, glm::precision P>
318 return glm::tmat4x4<T, P>(
327template<
typename T, glm::precision P>
330 return glm::tmat4x4<T, P>(
331 mR[0][0], mR[0][1], mR[0][2], 0,
332 mR[1][0], mR[1][1], mR[1][2], 0,
333 mR[2][0], mR[2][1], mR[2][2], 0,
334 mT.x, mT.y, mT.z, 1);
339template<
typename T, glm::precision P>
342 return glm::tmat4x4<T, P>(
343 mR[0][0]*mS.x, mR[0][1]*mS.x, mR[0][2]*mS.x, 0,
344 mR[1][0]*mS.y, mR[1][1]*mS.y, mR[1][2]*mS.y, 0,
345 mR[2][0]*mS.z, mR[2][1]*mS.z, mR[2][2]*mS.z, 0,
346 mT.x, mT.y, mT.z, 1);
351template<
typename T, glm::precision P>
354 glm::tvec3<T, P> X = glm::tvec3<T, P>(T(1) / mS.x, T(1) / mS.y, T(1) / mS.z);
356 T a = mR[0][0] * X.x;
357 T b = mR[1][0] * X.y;
358 T c = mR[2][0] * X.z;
359 T d = mR[0][1] * X.x;
360 T e = mR[1][1] * X.y;
361 T f = mR[2][1] * X.z;
362 T g = mR[0][2] * X.x;
363 T h = mR[1][2] * X.y;
364 T i = mR[2][2] * X.z;
366 return glm::tmat4x4<T, P>(
370 -(mT.x * a + mT.y * d + mT.z * g), -(mT.x * b + mT.y * e + mT.z * h), -(mT.x * c + mT.y * f + mT.z * i), 1);
375template<
typename T, glm::precision P>
383template<
typename T, glm::precision P>
391template<
typename T, glm::precision P>
399template<
typename T, glm::precision P>
402 return glm::tvec3<T, P>(mR[1][0]*mS.y, mR[1][1]*mS.y, mR[1][2]*mS.y);
405template<
typename T, glm::precision P>
411template<
typename T, glm::precision P>
417template<
typename T, glm::precision P>
420 return glm::tvec3<T, P>(mR[0][0]*mS.x, mR[0][1]*mS.x, mR[0][2]*mS.x);
423template<
typename T, glm::precision P>
429template<
typename T, glm::precision P>
432 return glm::tvec3<T, P>(mR[2][0]*mS.z, mR[2][1]*mS.z, mR[2][2]*mS.z);