-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinalgaux.hpp
115 lines (78 loc) · 1.68 KB
/
linalgaux.hpp
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
114
115
// Author: Christian Vallentin <vallentin.source@gmail.com>
// Website: https://vallentin.dev
// Repository: https://github.com/vallentin/LinearAlgebra
// License: https://github.com/vallentin/LinearAlgebra/blob/master/LICENSE
//
// Date Created: October 01, 2013
// Last Modified: June 27, 2016
// Refrain from using any exposed macros, functions
// or structs prefixed with an underscore. As these
// are only intended for internal purposes. Which
// additionally means they can be removed, renamed
// or changed between minor updates without notice.
#ifndef LINEAR_ALGEBRA_AUXILIARY_HPP
#define LINEAR_ALGEBRA_AUXILIARY_HPP
#include <stack>
#include <cstddef>
#include "linalg.hpp"
template<typename T> class MatrixStackT;
typedef MatrixStackT<float> MatrixStack;
typedef MatrixStackT<double> MatrixStackD;
template<typename T>
class MatrixStackT
{
private:
typedef mat4_t<T> mat4;
private:
std::stack<mat4> stack;
public:
MatrixStackT()
{
}
~MatrixStackT()
{
clear();
}
mat4 getMatrix() const
{
if (this->stack.empty())
return mat4::identity;
return this->stack.top();
}
void pushMatrix()
{
this->stack.push(getMatrix());
}
void popMatrix()
{
if (!this->stack.empty())
this->stack.pop();
}
size_t size() const
{
return this->stack.size();
}
void clear()
{
while (!this->stack.empty())
this->stack.pop();
}
void loadMatrix(const mat4 &matrix)
{
if (this->stack.empty())
pushMatrix();
this->stack.pop();
this->stack.push(matrix);
}
void loadIdentity()
{
loadMatrix(mat4::identity);
}
void multMatrix(const mat4 &matrix)
{
if (this->stack.empty())
pushMatrix();
loadMatrix(this->stack.top() * matrix);
}
};
#endif