00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "Matrix33.h"
00013
#include <OpenCAL/Vector3.h>
00014
using namespace OpenCAL::Utils;
00015
00016
#include <math.h>
00017
00018
using namespace std;
00019
00020
00021
00022
const Matrix33 Matrix33::zero(0,0,0,0,0,0,0,0,0);
00023
const Matrix33 Matrix33::unity;
00024
00025
00026
00027
00028
00029
00030 Matrix33::Matrix33()
00031 {
00032 identity();
00033 }
00034
00035 Matrix33::Matrix33(
const Matrix33 &source)
00036 {
00037 memcpy(m_values, source.
m_values, 9 *
sizeof(
float));
00038 }
00039
00040 Matrix33::Matrix33(
float m11,
float m12,
float m13,
float m21,
float m22,
float m23,
float m31,
float m32,
float m33)
00041 {
00042 m_values[0] = m11; m_values[1] = m12; m_values[2] = m13;
00043 m_values[3] = m21; m_values[4] = m22; m_values[5] = m23;
00044 m_values[6] = m31; m_values[7] = m32; m_values[8] = m33;
00045 }
00046
00047 Matrix33::~Matrix33()
00048 {
00049 }
00050
00051
00052
00053
00054
00055
00056
void Matrix33::set(
float *values)
00057 {
00058 memcpy(m_values, values, 9 *
sizeof(
float));
00059 }
00060
00061
00062
00063
00064
00065
void Matrix33::operator=(
const Matrix33 &m)
00066 {
00067 memcpy(m_values, m.
m_values, 9 *
sizeof(
float));
00068 }
00069
00070
Matrix33 Matrix33::operator*(
const Matrix33 &m)
const
00071
{
00072
Matrix33 result;
00073
00074
for(
int i = 0; i < 3; ++i)
00075
for(
int j = 0; j < 3; ++j)
00076 result.
m_values[i * 3 + j] = m_values[i * 3] * m.
m_values[j] +
00077 m_values[i * 3 + 1] * m.
m_values[3 + j] +
00078 m_values[i * 3 + 2] * m.
m_values[6 + j] +
00079 m_values[i * 3 + 3] * m.
m_values[9 + j];
00080
00081
return result;
00082 }
00083
00084
Matrix33 Matrix33::operator*(
float factor)
const
00085
{
00086
Matrix33 result;
00087
00088
for(
int i = 0; i < 9; ++i)
00089 result.
m_values[i] = m_values[i] * factor;
00090
00091
return result;
00092 }
00093
00094 Vector3 Matrix33::operator*(
const Vector3 &v)
const
00095
{
00096 Vector3 result;
00097
00098 result.setX(m_values[0] * v.getX() + m_values[1] * v.getY() + m_values[2] * v.getZ());
00099 result.setY(m_values[3] * v.getX() + m_values[4] * v.getY() + m_values[5] * v.getZ());
00100 result.setZ(m_values[6] * v.getX() + m_values[7] * v.getY() + m_values[8] * v.getZ());
00101
00102
return result;
00103 }
00104
00105
Matrix33 Matrix33::operator+(
const Matrix33 &m)
const
00106
{
00107
Matrix33 result;
00108
00109
for(
int i = 0; i < 9; i++)
00110 result.
m_values[i] = m_values[i] + m.
m_values[i];
00111
00112
return result;
00113 }
00114
00115
Matrix33 Matrix33::operator-()
const
00116
{
00117
Matrix33 result;
00118
00119
for(
int i = 0; i < 9; i++)
00120 result.
m_values[i] = -m_values[i];
00121
00122
return result;
00123 }
00124
00125
void Matrix33::operator*=(
float factor)
00126 {
00127
for(
int i = 0; i < 9; ++i)
00128 m_values[i] *= factor;
00129 }
00130
00131
bool Matrix33::operator==(
const Matrix33 &m)
const
00132
{
00133
for(
int i = 0; i < 9; i++)
00134
if(m_values[i] != m.
m_values[i])
00135
return false;
00136
00137
return true;
00138 }
00139
00140
00141
00142
Matrix33 OpenCAL::Utils::operator*(
float factor,
const Matrix33 &m)
00143 {
00144
Matrix33 result;
00145
00146
for(
int i = 0; i < 9; i++)
00147 result.
m_values[i] = factor * m.
m_values[i];
00148
00149
return result;
00150 }
00151
00152
Matrix33 OpenCAL::Utils::operator/(
float factor,
const Matrix33 &m)
00153 {
00154
Matrix33 result;
00155
00156
for(
int i = 0; i < 9; i++)
00157 result.
m_values[i] = factor / m.
m_values[i];
00158
00159
return result;
00160 }
00161
00162
00163
00164
00165
00166
00167
void Matrix33::rotateX(
float angle)
00168 {
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 }
00190
00191
void Matrix33::rotateY(
float angle)
00192 {
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 }
00214
00215
void Matrix33::rotateZ(
float angle)
00216 {
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 }
00238
00239
00240
00241
00242
00243
00244
void Matrix33::identity()
00245 {
00246
00247 memset(m_values, 0, 8 *
sizeof(
float));
00248
00249
00250 m_values[0] = m_values[4] = m_values[8] = 1.0f;
00251 }
00252
00253
void Matrix33::clear()
00254 {
00255 memset(m_values, 0, 9 *
sizeof(
float));
00256 }
00257
00258
void Matrix33::transpose()
00259 {
00260 *
this = transposed();
00261 }
00262
00263
Matrix33 Matrix33::transposed()
00264 {
00265
Matrix33 result;
00266
00267
for(
int i = 0; i < 3; i++)
00268
for(
int j = 0; j < 3; j++)
00269 result.
m_values[i * 3 + j] = m_values[j * 3 + i];
00270
00271
return result;
00272 }
00273
00274
void Matrix33::fill(
float value)
00275 {
00276
for(
int i = 0; i < 9; ++i)
00277 m_values[i] = value;
00278 }
00279
00280
void Matrix33::print()
00281 {
00282
for(
int i = 0; i < 9; i++)
00283 {
00284 cout << m_values[i] <<
" ";
00285
if((i + 1) % 3 == 0)
00286 cout << endl;
00287 }
00288 cout << endl;
00289 }