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