-
Notifications
You must be signed in to change notification settings - Fork 1
/
lin_alg.cpp
80 lines (73 loc) · 2.65 KB
/
lin_alg.cpp
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
#include "lin_alg.h"
void TestLinAlg()
{
// Instantiate templates, check sizes, make sure operators compile etc.
static_assert(sizeof(Vec2f) == 8 , "Vec2f size test failed" );
static_assert(sizeof(Vec3f) == 12 , "Vec3f size test failed" );
static_assert(sizeof(Vec4f) == 16 , "Vec4f size test failed" );
static_assert(sizeof(Vec2d) == 16 , "Vec2d size test failed" );
static_assert(sizeof(Vec3d) == 24 , "Vec3d size test failed" );
static_assert(sizeof(Vec4d) == 32 , "Vec4d size test failed" );
static_assert(sizeof(Vec2i) == 8 , "Vec2i size test failed" );
static_assert(sizeof(Vec3i) == 12 , "Vec3i size test failed" );
static_assert(sizeof(Vec4i) == 16 , "Vec4i size test failed" );
static_assert(sizeof(Vec2ui) == 8 , "Vec2ui size test failed" );
static_assert(sizeof(Vec3ui) == 12 , "Vec3ui size test failed" );
static_assert(sizeof(Vec4ui) == 16 , "Vec4ui size test failed" );
static_assert(sizeof(Matrix44f) == 64 , "Matrix44f size test failed");
static_assert(sizeof(Matrix44d) == 128, "Matrix44d size test failed");
Vec2f vec2f(0.0f, 0.0f);
Vec3f vec3f(0.0f, 0.0f, 0.0f);
Vec4f vec4f(0.0f, 0.0f, 0.0f, 0.0f);
Vec2d vec2d(0.0, 0.0);
Vec3d vec3d(0.0, 0.0, 0.0);
Vec4d vec4d(0.0, 0.0, 0.0, 0.0);
Vec2i vec2i(-1, -1);
Vec3i vec3i(-1, -1, -1);
Vec4i vec4i(-1, -1, -1, -1);
Vec2ui vec2ui(0, 0);
Vec3ui vec3ui(0, 0, 0);
Vec4ui vec4ui(0, 0, 0, 0);
float f = 0.0f;
bool b = false;
b = (vec3f == vec3f);
b = (vec3f != vec3f);
vec3f = Vec3f(1.0f) + Vec3f(2.0f);
vec3f = Vec3f(1.0f) - Vec3f(2.0f);
vec3f = Vec3f(1.0f) * Vec3f(2.0f);
vec3f = Vec3f(1.0f) / Vec3f(2.0f);
vec3f = Vec3f(1.0f) * f;
vec3f = f * Vec3f(1.0f);
vec3f = Vec3f(1.0f) / f;
vec3f = -Vec3f(1.0f);
vec3f += Vec3f(1.0f);
vec3f -= Vec3f(1.0f);
vec3f *= Vec3f(1.0f);
vec3f /= Vec3f(1.0f);
vec3f *= f;
vec3f /= f;
f = vec3f[0];
vec3f[0] = f;
f = Length(vec3f);
f = LengthSquared(vec3f);
vec3f = Normalize(vec3f);
f = Dot(Vec3f(1.0f), Vec3f(2.0f));
vec3f = Vec3f(1.0f) ^ Vec3f(2.0f);
Matrix44f matf;
matf.Identity();
Matrix44d matd;
matf.RotationX(1);
matf.RotationY(1);
matf.RotationZ(1);
matf.Scaling(1);
b = matf == matf;
matf = matf * matf;
matf.BuildLookAtMatrix(Vec3f(0.0f, 10.0f, 10.0f), Vec3f(0.0f));
matf.BuildProjection(90.0f, 4.0f / 3.0f, 1.0f, 1000.0f);
Vec3f out;
matf.Transf3x3(vec3f, out);
matf.Transf4x4(vec3f, out);
matf.Transpose3x3();
matf.Transpose4x4();
matf.Invert();
}