VR-Vantage 3.1 API Documentation
Home
Modules
Namespaces
Classes
Files
Libraries
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
include
vrvMath
DtMatrix3.h
Go to the documentation of this file.
1
/******************************************************************************
2
** Copyright (c) 2017 MAK Technologies, Inc.
3
** All rights reserved.
4
******************************************************************************/
5
9
#pragma once
10
11
#include <
vrvMath/DtVector3.h
>
12
#include <
vrvMath/DtMath.h
>
13
#include <
vrvMath/DtAssert.h
>
14
15
namespace
makVrv {
16
19
template
<
class
T>
20
class
DtMatrix3
21
{
22
public
:
24
DtMatrix3
();
26
DtMatrix3
(
const
T rhs[3][3]);
28
DtMatrix3
(T m00, T m01, T m02
29
, T m10, T m11, T m12
30
, T m20, T m21, T m22);
32
DtMatrix3
(
const
T rhs[9]);
33
34
const
void
*
ptr
(
void
)
const
;
35
37
~DtMatrix3
();
38
40
DtMatrix3
operator*
(
const
DtMatrix3
& rhs)
const
;
41
43
DtVector3<T>
operator*
(
const
DtVector3<T>
& rhs)
const
;
44
46
void
setZero
(
void
);
47
49
void
setIdentity
(
void
);
50
52
DtMatrix3
getTranspose
(
void
)
const
;
53
55
bool
IsEqual
(
const
DtMatrix3
& rhs, T tolerance)
const
;
56
57
const
T*
operator []
(
size_t
iRow)
const
;
58
T*
operator []
(
size_t
iRow);
59
60
static
DtMatrix3
theIdentityMatrix
;
61
private
:
62
union
63
{
64
T
_m
[9];
65
T
m
[3][3];
66
};
67
};
68
69
template
<
class
T>
70
DtMatrix3<T> DtMatrix3<T>::theIdentityMatrix = DtMatrix3<T>(1,0,0
71
, 0,1,0
72
, 0,0,1);
73
74
template
<
class
T>
75
DtMatrix3<T>::DtMatrix3
()
76
{
77
78
}
79
80
template
<
class
T>
81
DtMatrix3<T>::DtMatrix3
(
const
T rhs[3][3])
82
{
83
memcpy(_m, rhs, 9*
sizeof
(T));
84
}
85
86
template
<
class
T>
87
DtMatrix3<T>::DtMatrix3
(T m00, T m01, T m02
88
, T m10, T m11, T m12
89
, T m20, T m21, T m22)
90
{
91
m
[0][0]=m00;
m
[0][1]=m01;
m
[0][2]=m02;
92
m
[1][0]=m10;
m
[1][1]=m11;
m
[1][2]=m12;
93
m
[2][0]=m20;
m
[2][1]=m21;
m
[2][2]=m22;
94
}
95
96
template
<
class
T>
97
DtMatrix3<T>::DtMatrix3
(
const
T rhs[9])
98
{
99
memcpy(_m, rhs, 9 *
sizeof
(T));
100
}
101
102
template
<
class
T>
103
DtMatrix3<T>::~DtMatrix3
()
104
{
105
106
}
107
template
<
class
T>
108
const
void
*
DtMatrix3<T>::ptr
(
void
)
const
109
{
110
return
_m;
111
}
112
113
template
<
class
T>
114
const
T*
DtMatrix3<T>::operator []
(
size_t
iRow)
const
115
{
116
ASSERT_PREDICATE_RETURN_ZERO
(iRow<3);
117
return
m
[iRow];
118
}
119
template
<
class
T>
120
T*
DtMatrix3<T>::operator []
(
size_t
iRow)
121
{
122
ASSERT_PREDICATE_RETURN_ZERO
(iRow<3);
123
return
m
[iRow];
124
}
125
126
typedef
DtMatrix3<float>
Matrix3_32
;
127
typedef
DtMatrix3<double>
Matrix3_64
;
128
129
template
<
class
T>
130
DtMatrix3<T>
DtMatrix3<T>::operator*
(
const
DtMatrix3<T>
& rhs)
const
131
{
132
/*
133
| lhs.00, lhs.01, lhs.02 | | rhs.00, rhs.01, rhs.02 |
134
| lhs.10, lhs.11, lhs.12 | | rhs.10, rhs.11, rhs.12 |
135
| lhs.20, lhs.21, lhs.22 | | rhs.20, rhs.21, rhs.22 |
136
*/
137
const
DtMatrix3
& lhs = *
this
;
138
139
DtMatrix3
result
;
140
141
result.
m
[0][0] = lhs.
m
[0][0]*rhs.
m
[0][0] + lhs.
m
[0][1]*rhs.
m
[1][0] + lhs.
m
[0][2]*rhs.
m
[2][0];
142
result.
m
[0][1] = lhs.
m
[0][0]*rhs.
m
[0][1] + lhs.
m
[0][1]*rhs.
m
[1][1] + lhs.
m
[0][2]*rhs.
m
[2][1];
143
result.
m
[0][2] = lhs.
m
[0][0]*rhs.
m
[0][2] + lhs.
m
[0][1]*rhs.
m
[1][2] + lhs.
m
[0][2]*rhs.
m
[2][2];
144
145
result.
m
[1][0] = lhs.
m
[1][0]*rhs.
m
[0][0] + lhs.
m
[1][1]*rhs.
m
[1][0] + lhs.
m
[1][2]*rhs.
m
[2][0];
146
result.
m
[1][1] = lhs.
m
[1][0]*rhs.
m
[0][1] + lhs.
m
[1][1]*rhs.
m
[1][1] + lhs.
m
[1][2]*rhs.
m
[2][1];
147
result.
m
[1][2] = lhs.
m
[1][0]*rhs.
m
[0][2] + lhs.
m
[1][1]*rhs.
m
[1][2] + lhs.
m
[1][2]*rhs.
m
[2][2];
148
149
result.
m
[2][0] = lhs.
m
[2][0]*rhs.
m
[0][0] + lhs.
m
[2][1]*rhs.
m
[1][0] + lhs.
m
[2][2]*rhs.
m
[2][0];
150
result.
m
[2][1] = lhs.
m
[2][0]*rhs.
m
[0][1] + lhs.
m
[2][1]*rhs.
m
[1][1] + lhs.
m
[2][2]*rhs.
m
[2][1];
151
result.
m
[2][2] = lhs.
m
[2][0]*rhs.
m
[0][2] + lhs.
m
[2][1]*rhs.
m
[1][2] + lhs.
m
[2][2]*rhs.
m
[2][2];
152
153
return
result
;
154
}
155
156
template
<
class
T>
157
DtVector3<T>
DtMatrix3<T>::operator*
(
const
DtVector3<T>
& rhs)
const
158
{
159
/*
160
| lhs.00, lhs.01, lhs.02 | | rhs.0 |
161
| lhs.10, lhs.11, lhs.12 | | rhs.1 |
162
| lhs.20, lhs.21, lhs.22 | | rhs.2 |
163
*/
164
DtVector3<T>
vResult;
165
166
const
DtMatrix3
& lhs = *
this
;
167
168
vResult.
x
= lhs.
m
[0][0]*rhs.
x
+ lhs.
m
[0][1]*rhs.
y
+ lhs.
m
[0][2]*rhs.
z
;
169
vResult.
y
= lhs.
m
[1][0]*rhs.
x
+ lhs.
m
[1][1]*rhs.
y
+ lhs.
m
[1][2]*rhs.
z
;
170
vResult.
z
= lhs.
m
[2][0]*rhs.
x
+ lhs.
m
[2][1]*rhs.
y
+ lhs.
m
[2][2]*rhs.
z
;
171
172
return
vResult;
173
}
174
175
template
<
class
T>
176
void
DtMatrix3<T>::setZero
(
void
)
177
{
178
memset(_m, 0, 9*
sizeof
(T));
179
}
180
181
template
<
class
T>
182
void
DtMatrix3<T>::setIdentity
(
void
)
183
{
184
setZero();
185
m
[0][0] =
m
[1][1] =
m
[2][2] = 1;
186
}
187
188
template
<
class
T>
189
DtMatrix3<T>
DtMatrix3<T>::getTranspose
(
void
)
const
190
{
191
return
DtMatrix3
(
192
m
[0][0],
m
[1][0],
m
[2][0]
193
,
m
[0][1],
m
[1][1],
m
[2][1]
194
,
m
[0][2],
m
[1][2],
m
[2][2]
195
);
196
}
197
198
template
<
class
T>
199
bool
DtMatrix3<T>::IsEqual
(
const
DtMatrix3<T>
& rhs, T tolerance)
const
200
{
201
const
DtMatrix3
& lhs = *
this
;
202
for
(
size_t
i = 0; i < 3; ++i)
203
{
204
for
(
size_t
j = 0; j < 3; ++j)
205
{
206
if
(!
DtMath::isEqual
(lhs[i][j], rhs[i][j], tolerance))
207
return
false
;
208
}
209
}
210
return
true
;
211
}
212
213
}
//namespace makVrv
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (
www.mak.com
)