/
mat4.h
195 lines (166 loc) · 4.89 KB
/
mat4.h
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
Copyright (c) 2009, Luke Benstead, Carsten Haubold
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _KAZMATHXX_MAT4_H
#define _KAZMATHXX_MAT4_H
#include <kazmath/mat4.h>
#include <kazmath/utility.h>
#include "vec3.h"
namespace km
{
class mat4 : public kmMat4
{
public:
/// Constructors
mat4()
{
kmMat4Identity(this);
}
mat4(const kmScalar* pIn)
{
kmMat4Fill(this,pIn);
}
void identity()
{
kmMat4Identity(this);
}
const mat4 inverse() const
{
mat4 result = *this;
kmMat4Inverse(&result, &result);
return result;
}
const bool isIdentity() const
{
return kmMat4IsIdentity(this);
}
const mat4 transpose() const
{
mat4 result = *this;
kmMat4Transpose(&result, &result);
return result;
}
static const mat4 rotationAxis(const kmVec3& axis, const kmScalar radians)
{
mat4 result;
kmMat4RotationAxisAngle(&result, &axis, radians);
return result;
}
static const mat4 rotationAxis(const kmScalar degrees, const kmScalar axis_x, const kmScalar axis_y, const kmScalar axis_z)
{
mat4 result;
vec3 axis(axis_x, axis_y, axis_z);
kmMat4RotationAxisAngle(&result, &axis, kmDegreesToRadians(degrees));
return result;
}
static const mat4 rotationX(const kmScalar radians)
{
mat4 result;
kmMat4RotationX(&result, radians);
return result;
}
static const mat4 rotationY(const kmScalar radians)
{
mat4 result;
kmMat4RotationY(&result, radians);
return result;
}
static const mat4 rotationZ(const kmScalar radians)
{
mat4 result;
kmMat4RotationZ(&result, radians);
return result;
}
static const mat4 rotationPitchYawRoll(const kmScalar pitch, const kmScalar yaw, const kmScalar roll)
{
mat4 result;
kmMat4RotationPitchYawRoll(&result, pitch, yaw, roll);
return result;
}
static const mat4 rotationQuaternion(const kmQuaternion& pQ)
{
mat4 result;
kmMat4RotationQuaternion(&result, &pQ);
return result;
}
static const mat4 scaling(const kmScalar x, const kmScalar y, const kmScalar z)
{
mat4 result;
kmMat4Scaling(&result, x,y,z);
return result;
}
static const mat4 translation(const kmScalar x, const kmScalar y, const kmScalar z)
{
mat4 result;
kmMat4Translation(&result, x,y,z);
return result;
}
const vec3 getUpVec3() const
{
vec3 result;
kmMat4GetUpVec3(&result, this);
return result;
}
const vec3 getRightVec3() const
{
vec3 result;
kmMat4GetRightVec3(&result, this);
return result;
}
const vec3 getForwardVec3() const
{
vec3 result;
kmMat4GetForwardVec3(&result, this);
return result;
}
static const mat4 perspectiveProjection(const kmScalar fovY, const kmScalar aspect, const kmScalar zNear, const kmScalar zFar)
{
mat4 result;
kmMat4PerspectiveProjection(&result, fovY, aspect, zNear, zFar);
return result;
}
static const mat4 orthographicProjection(const kmScalar left, const kmScalar right, const kmScalar bottom, const kmScalar top, const kmScalar nearVal, const kmScalar farVal)
{
mat4 result;
kmMat4OrthographicProjection(&result, left, right, bottom, top, nearVal, farVal);
return result;
}
static const mat4 lookAt(const kmVec3& pEye, const kmVec3& pCenter, const kmVec3& pUp)
{
mat4 result;
kmMat4LookAt(&result, &pEye, &pCenter, &pUp);
return result;
}
};
///< Matrix multiplication
inline const mat4 operator*(const mat4& lhs, const mat4& rhs)
{
mat4 result;
kmMat4Multiply(&result, &lhs, &rhs);
return result;
};
///< Checks for equality (with a small threshold epsilon)
inline const bool operator==(const mat4& lhs, const mat4& rhs)
{
return kmMat4AreEqual(&lhs,&rhs);
};
}
#endif