5#pragma warning(disable: 4244)
7#define PI 3.14159265359
8#define ONEDIV180 0.00555555555
10inline float DegToRad(
float degree) {
11 return degree * PI * ONEDIV180;
14inline float RadToDeg(
float rad) {
15 return 180.0 * rad / PI;
27 Vector2(T x = 0.0f, T y = 0.0f);
33 Vector2 Rotate(
float const& angle);
36 Vector2 operator + (T
const& num);
38 Vector2 operator - (T
const& num);
40 Vector2 operator * (T1
const& num);
42 bool operator == (
Vector2 const& vec1);
43 bool operator != (
Vector2 const& vec1);
48 T* operator [] (
int index);
54 float magnitude = pow(x * x + y * y, 0.5);
62 return pow(x * x + y * y, 0.5);
67 return x * vec1.x + y * vec1.y;
73 return Dot(vec1) * vec1;
78 float angle0 = DegToRad(angle);
135 return (x ==
vec1.x) && (y ==
vec1.y);
140 return (x !=
vec1.x) && (y !=
vec1.y);
145 return index == 0 ? &x : &y;
152 if (
number < 0)
return -1;
158 return x <= y ? x : y;
163 return x >= y ? x : y;
207 float magnitude =
pow(x * x + y * y + z * z, 0.5);
208 return Vector3<float>(x / magnitude, y / magnitude, z / magnitude);
212 return pow(x * x + y * y + z * z,0.5);
292 Vector4(
T x = 0.0f,
T y = 0.0f,
T z = 0.0f,
T w = 0.0f);
305template<u
int8_t n, u
int8_t m,
typename T>
323template<u
int8_t n, u
int8_t m,
typename T>
327 int size =
sizeof(
T) *
n *
m;
330 for (
int i = 0;
i <
n *
m;
i++) {
337template<u
int8_t n, u
int8_t m,
typename T>
346template<u
int8_t n, u
int8_t m,
typename T>
353template<u
int8_t n, u
int8_t m,
typename T>
362template<u
int8_t n, u
int8_t m,
typename T>
369template<u
int8_t n, u
int8_t m,
typename T>
378template<u
int8_t n, u
int8_t m,
typename T>
385template<u
int8_t n, u
int8_t m,
typename T>
418 values[0] =
diag; values[1] = 0;
419 values[2] = 0 ; values[3] =
diag:
430 result.values[0] = this->values[0] *
other.values[0] + this->values[1] *
other.values[2];
431 result.values[1] = this->values[0] *
other.values[1] + this->values[1] *
other.values[3];
432 result.values[2] = this->values[2] *
other.values[0] + this->values[3] *
other.values[2];
433 result.values[3] = this->values[2] *
other.values[1] + this->values[3] *
other.values[3];
440 result.values[0] =
other.values[0] * values[0] +
other.values[1] * values[2];
441 result.values[1] =
other.values[0] * values[1] +
other.values[1] * values[3];
442 result.values[2] =
other.values[2] * values[0] +
other.values[3] * values[2];
443 result.values[3] =
other.values[2] * values[1] +
other.values[3] * values[3];
444 this->values =
memcpy(this->values,
result.values, 4 *
sizeof(
T))
465 values[0] =
diag; values[1] = 0 ; values[2] = 0;
466 values[3] = 0 ; values[4] =
diag; values[5] = 0;
467 values[6] = 0 ; values[7] = 0 ; values[8] =
diag;
479 result.values[0] =
other.values[0] * values[0] +
other.values[1] * values[3] +
other.values[2] * values[6];
480 result.values[1] =
other.values[0] * values[1] +
other.values[1] * values[4] +
other.values[2] * values[7];
481 result.values[2] =
other.values[0] * values[2] +
other.values[1] * values[5] +
other.values[2] * values[8];
482 result.values[3] =
other.values[3] * values[0] +
other.values[4] * values[3] +
other.values[5] * values[6];
483 result.values[4] =
other.values[3] * values[1] +
other.values[4] * values[4] +
other.values[5] * values[7];
484 result.values[5] =
other.values[3] * values[2] +
other.values[4] * values[5] +
other.values[5] * values[8];
485 result.values[6] =
other.values[6] * values[0] +
other.values[7] * values[3] +
other.values[8] * values[6];
486 result.values[7] =
other.values[6] * values[1] +
other.values[7] * values[4] +
other.values[8] * values[7];
487 result.values[8] =
other.values[6] * values[2] +
other.values[7] * values[5] +
other.values[8] * values[8];
494 result.values[0] =
other.values[0] * values[0] +
other.values[1] * values[3] +
other.values[2] * values[6];
495 result.values[1] =
other.values[0] * values[1] +
other.values[1] * values[4] +
other.values[2] * values[7];
496 result.values[2] =
other.values[0] * values[2] +
other.values[1] * values[5] +
other.values[2] * values[8];
497 result.values[3] =
other.values[3] * values[0] +
other.values[4] * values[3] +
other.values[5] * values[6];
498 result.values[4] =
other.values[3] * values[1] +
other.values[4] * values[4] +
other.values[5] * values[7];
499 result.values[5] =
other.values[3] * values[2] +
other.values[4] * values[5] +
other.values[5] * values[8];
500 result.values[6] =
other.values[6] * values[0] +
other.values[7] * values[3] +
other.values[8] * values[6];
501 result.values[7] =
other.values[6] * values[1] +
other.values[7] * values[4] +
other.values[8] * values[7];
502 result.values[8] =
other.values[6] * values[2] +
other.values[7] * values[5] +
other.values[8] * values[8];
503 this->values =
memcpy(this->values,
result.values, 4 *
sizeof(
T))
527 values[0] =
diag; values[1] = 0; values[2] = 0; values[3] = 0;
528 values[4] = 0; values[5] =
diag; values[6] = 0; values[7] = 0;
529 values[8] = 0; values[9] = 0; values[10] =
diag; values[11] = 0;
530 values[12] = 0; values[13] = 0; values[14] = 0; values[15] =
diag;
541#define TMP_MAT_4x4_MUL \
542 result.values[0] = other.values[0] * values[0] + other.values[1] * values[4] + other.values[2] * values[8] + other.values[3] * values[12]; \
543 result.values[1] = other.values[0] * values[1] + other.values[1] * values[5] + other.values[2] * values[9] + other.values[3] * values[13]; \
544 result.values[2] = other.values[0] * values[2] + other.values[1] * values[6] + other.values[2] * values[10] + other.values[3] * values[14]; \
545 result.values[3] = other.values[0] * values[3] + other.values[1] * values[7] + other.values[2] * values[11] + other.values[3] * values[15]; \
546 result.values[4] = other.values[4] * values[0] + other.values[5] * values[4] + other.values[6] * values[8] + other.values[7] * values[12]; \
547 result.values[5] = other.values[4] * values[1] + other.values[5] * values[5] + other.values[6] * values[9] + other.values[7] * values[13]; \
548 result.values[6] = other.values[4] * values[2] + other.values[5] * values[6] + other.values[6] * values[10] + other.values[7] * values[14]; \
549 result.values[7] = other.values[4] * values[3] + other.values[5] * values[7] + other.values[6] * values[11] + other.values[7] * values[15]; \
550 result.values[8] = other.values[8] * values[0] + other.values[9] * values[4] + other.values[10] * values[8] + other.values[11] * values[12]; \
551 result.values[9] = other.values[8] * values[1] + other.values[9] * values[5] + other.values[10] * values[9] + other.values[11] * values[13]; \
552 result.values[10] = other.values[8] * values[2] + other.values[9] * values[6] + other.values[10] * values[10] + other.values[11] * values[14]; \
553 result.values[11] = other.values[8] * values[3] + other.values[9] * values[7] + other.values[10] * values[11] + other.values[11] * values[15]; \
554 result.values[12] = other.values[12] * values[0] + other.values[13] * values[4] + other.values[14] * values[8] + other.values[15] * values[12]; \
555 result.values[13] = other.values[12] * values[1] + other.values[13] * values[5] + other.values[14] * values[9] + other.values[15] * values[13]; \
556 result.values[14] = other.values[12] * values[2] + other.values[13] * values[6] + other.values[14] * values[10] + other.values[15] * values[14]; \
557 result.values[15] = other.values[12] * values[3] + other.values[13] * values[7] + other.values[14] * values[11] + other.values[15] * values[15];
567 this->values =
memcpy(this->values,
result.values, 4 *
sizeof(
T))
569#undef TMP_MAT_4x4_MUL
590 float rml = 1.0f / (right - left);
597 matrix.values[12] = (-right - left) *
rml;
604 matrix.values[12] += coeff.x;
605 matrix.values[13] += coeff.y;
606 matrix.values[14] += coeff.z;
611 matrix.values[0] *= coeff.x ;
612 matrix.values[5] *= coeff.y;
613 matrix.values[10] *= coeff.z;
622 float cmpC = 1.0f -
c;
653template<
typename T,
typename T1>
656 return source + (target - source) *
percent;
659template<
typename T,
typename T1>
664template<
typename T,
typename T1>
667 lerp(source.z, target.z,
percent.z));
670template<
typename T,
typename T1>
680template<
typename T,
typename T1>
687template<
typename T,
typename T1>
695template<
typename T,
typename T1>
707template<
typename T,
typename T1>
714template<
typename T,
typename T1>
726 return a.x * b.y - a.y * b.x;