TexGen
MatrixUtils.h
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#pragma once
21
22#include "mymath.h"
23#include "Matrix.h"
24
25namespace TexGen
26{
27 using namespace std;
28
29 // Maths from http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
31 {
32 CMatrix Mat;
33 Mat.InitialiseIdentity(3);
34 // Diagonal
35 Mat(0, 0) = Q.w*Q.w + Q.x*Q.x - Q.y*Q.y - Q.z*Q.z;
36 Mat(1, 1) = Q.w*Q.w - Q.x*Q.x + Q.y*Q.y - Q.z*Q.z;
37 Mat(2, 2) = Q.w*Q.w - Q.x*Q.x - Q.y*Q.y + Q.z*Q.z;
38 // Upper right
39 Mat(0, 1) = 2*Q.x*Q.y - 2*Q.w*Q.z;
40 Mat(0, 2) = 2*Q.w*Q.y + 2*Q.x*Q.z;
41 Mat(1, 2) = 2*Q.y*Q.z - 2*Q.w*Q.x;
42 // Lower left
43 Mat(1, 0) = 2*Q.w*Q.z + 2*Q.x*Q.y;
44 Mat(2, 0) = 2*Q.x*Q.z - 2*Q.w*Q.y;
45 Mat(2, 1) = 2*Q.w*Q.x + 2*Q.y*Q.z;
46 return Mat;
47 }
48
49 inline XYZ operator * (const CMatrix &Transform, const XYZ &Vector)
50 {
51 CMatrix VecMat;
52 VecMat.Initialise(3, 1);
53 VecMat(0, 0) = Vector.x;
54 VecMat(1, 0) = Vector.y;
55 VecMat(2, 0) = Vector.z;
56 VecMat = Transform * VecMat;
57 return XYZ(VecMat(0, 0), VecMat(1, 0), VecMat(2, 0));
58 }
59
60}; // namespace TexGen
61
62
63
64
65
66
67
68
69
70
Class to represent a matrix and perform various operations on it.
Definition: Matrix.h:33
void Initialise(int iHeight, int iWidth)
Definition: Matrix.h:144
void InitialiseIdentity(int iSize)
Definition: Matrix.h:155
Namespace containing a series of customised math operations not found in the standard c++ library.
XYZ operator*(const CMatrix &Transform, const XYZ &Vector)
Definition: MatrixUtils.h:49
CMatrix ConvertRotation(WXYZ Q)
Definition: MatrixUtils.h:30
Struct for representing a quaternion.
Definition: mymath.h:38
double z
Definition: mymath.h:39
double w
Definition: mymath.h:39
double y
Definition: mymath.h:39
double x
Definition: mymath.h:39
Struct for representing points in 3D space.
Definition: mymath.h:56
double z
Definition: mymath.h:57
double x
Definition: mymath.h:57
double y
Definition: mymath.h:57