Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

matrix.h File Reference

#include "vec.h"

Include dependency graph for matrix.h:

Include dependency graph

Go to the source code of this file.

Compounds

struct  DrawContext
class  Matrix

Defines

#define M(a, b)   (tmp.r[b*3+a])
#define M(A, B)   t.r[B*3+A]
#define M(A, B)   t.r[B*3+A]
#define a   (trans.r[0])
#define b   (trans.r[3])
#define c   (trans.r[6])
#define d   (trans.r[1])
#define e   (trans.r[4])
#define f   (trans.r[7])
#define g   (trans.r[2])
#define h   (trans.r[5])
#define i   (trans.r[8])
#define a   (trans.r[0])
#define b   (trans.r[3])
#define c   (trans.r[6])
#define d   (trans.r[1])
#define e   (trans.r[4])
#define f   (trans.r[7])
#define g   (trans.r[2])
#define h   (trans.r[5])
#define i   (trans.r[8])
#define M(a, b)   (tmp.r[b*3+a])

Functions

const Matrix identity_matrix (1, 0, 0, 0, 1, 0, 0, 0, 1, QVector(0, 0, 0))
void ScaleMatrix (Matrix &matrix, const Vector &scale)
void VectorAndPositionToMatrix (Matrix &matrix, const Vector &v1, const Vector &v2, const Vector &v3, const QVector &pos)
void Zero (Matrix &matrix)
void Identity (Matrix &matrix)
void RotateAxisAngle (Matrix &tmp, const Vector &axis, const float angle)
void Translate (Matrix &matrix, const QVector &v)
void MultMatrix (Matrix &dest, const Matrix &m1, const Matrix &m2)
void CopyMatrix (Matrix &dest, const Matrix &source)
QVector Transform (const Matrix &t, const QVector &v)
Vector Transform (const Matrix &t, const Vector &v)
Vector InvTransformNormal (const Matrix &t, const Vector &v)
QVector InvTransformNormal (const Matrix &t, const QVector &v)
QVector InvTransform (const Matrix &t, const QVector &v)
Vector InvTransform (const Matrix &t, const Vector &v)
Vector TransformNormal (const Matrix &t, const Vector &v)
QVector TransformNormal (const Matrix &t, const QVector &v)
int invert (float b[], float a[])
void MatrixToVectors (const Matrix &m, Vector &p, Vector &q, Vector &r, QVector &c)
QVector InvScaleTransform (const Matrix &trans, QVector pos)
void InvertMatrix (Matrix &o, const Matrix &trans)
void Rotate (Matrix &tmp, const Vector &axis, float angle)


Define Documentation

#define a   (trans.r[0])
 

#define a   (trans.r[0])
 

#define b   (trans.r[3])
 

#define b   (trans.r[3])
 

#define c   (trans.r[6])
 

#define c   (trans.r[6])
 

#define d   (trans.r[1])
 

#define d   (trans.r[1])
 

#define e   (trans.r[4])
 

#define e   (trans.r[4])
 

#define f   (trans.r[7])
 

#define f   (trans.r[7])
 

#define g   (trans.r[2])
 

#define g   (trans.r[2])
 

#define h   (trans.r[5])
 

#define h   (trans.r[5])
 

#define i   (trans.r[8])
 

#define i   (trans.r[8])
 

#define M a,
     (tmp.r[b*3+a])
 

#define M A,
     t.r[B*3+A]
 

#define M A,
     t.r[B*3+A]
 

#define M a,
     (tmp.r[b*3+a])
 


Function Documentation

void CopyMatrix Matrix   dest,
const Matrix   source
[inline]
 

Copies Matrix source into the destination Matrix

00205                                                            {
00206   dest = source;
00207 }

void Identity Matrix   matrix [inline]
 

Computes a 4x4 identity matrix

00124 {
00125     matrix.r[0] = 1;
00126     matrix.r[1] = 0;
00127     matrix.r[2] = 0;
00128     matrix.r[3] = 0;
00129     matrix.r[4] = 1;
00130     matrix.r[5] = 0;
00131     matrix.r[6] = 0;
00132     matrix.r[7] = 0;
00133     matrix.r[8] = 1;
00134     matrix.position.Set(0,0,0);
00135 }

const Matrix identity_matrix  ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
QVector(0, 0, 0)   
 

int invert float    b[],
float    a[]
 

void InvertMatrix Matrix   o,
const Matrix   trans
[inline]
 

00297                                                           {
00298 #define a (trans.r[0])
00299 #define b (trans.r[3])
00300 #define c (trans.r[6])
00301 #define d (trans.r[1])
00302 #define e (trans.r[4])
00303 #define f (trans.r[7])
00304 #define g (trans.r[2])
00305 #define h (trans.r[5])
00306 #define i (trans.r[8])
00307   float factor = 1.0F/(-c*e*g+ b*f*g + c*d*h - a*f*h - b*d*i + a*e*i);
00308   o.r[0]=factor*(e*i- f*h);
00309   o.r[3]=factor*(c*h-b*i);
00310   o.r[6]=factor*(b*f-c*e);
00311   o.r[1]=factor*(f*g-d*i);
00312   o.r[4]=factor*(a*i-c*g);
00313   o.r[7]=factor*(c*d-a*f);
00314   o.r[2]=factor*(d*h-e*g);
00315   o.r[5]=factor*(b*g-a*h);
00316   o.r[8]=factor*(a*e-b*d);
00317 #undef a
00318 #undef b
00319 #undef c
00320 #undef d
00321 #undef e
00322 #undef f
00323 #undef g
00324 #undef h
00325 #undef i
00326   o.position= TransformNormal (o,QVector (-trans.position));
00327 }

QVector InvScaleTransform const Matrix   trans,
QVector    pos
[inline]
 

00274                                                                     {
00275   pos = pos - trans.position;
00276 #define a (trans.r[0])
00277 #define b (trans.r[3])
00278 #define c (trans.r[6])
00279 #define d (trans.r[1])
00280 #define e (trans.r[4])
00281 #define f (trans.r[7])
00282 #define g (trans.r[2])
00283 #define h (trans.r[5])
00284 #define i (trans.r[8])
00285   double factor = 1.0F/(-c*e*g+ b*f*g + c*d*h - a*f*h - b*d*i + a*e*i);
00286   return (QVector(pos.Dot (QVector (e*i- f*h,c*h-b*i,b*f-c*e)),pos.Dot (QVector (f*g-d*i,a*i-c*g, c*d-a*f)),pos.Dot (QVector (d*h-e*g, b*g-a*h, a*e-b*d)))*factor);
00287 #undef a
00288 #undef b
00289 #undef c
00290 #undef d
00291 #undef e
00292 #undef f
00293 #undef g
00294 #undef h
00295 #undef i
00296 }

Vector InvTransform const Matrix   t,
const Vector   v
[inline]
 

00250                                                                {
00251   return InvTransformNormal (t,  QVector (v.i-t.position.i, v.j-t.position.j, v.k-t.position.k)).Cast();
00252 }

QVector InvTransform const Matrix   t,
const QVector   v
[inline]
 

00247                                                                  {
00248   return InvTransformNormal (t,  QVector (v.i-t.position.i, v.j-t.position.j, v.k-t.position.k));
00249 }

QVector InvTransformNormal const Matrix   t,
const QVector   v
[inline]
 

00238                                                                        {
00239 
00240 #define M(A,B) t.r[B*3+A]
00241   return QVector(v.i*M(0,0)+v.j*M(1,0)+v.k*M(2,0),
00242          v.i*M(0,1)+v.j*M(1,1)+v.k*M(2,1),
00243          v.i*M(0,2)+v.j*M(1,2)+v.k*M(2,2));
00244 #undef M
00245 }

Vector InvTransformNormal const Matrix   t,
const Vector   v
[inline]
 

00230                                                                      {
00231 
00232 #define M(A,B) t.r[B*3+A]
00233   return Vector(v.i*M(0,0)+v.j*M(1,0)+v.k*M(2,0),
00234         v.i*M(0,1)+v.j*M(1,1)+v.k*M(2,1),
00235         v.i*M(0,2)+v.j*M(1,2)+v.k*M(2,2));
00236 #undef M
00237 }

void MatrixToVectors const Matrix   m,
Vector   p,
Vector   q,
Vector   r,
QVector   c
[inline]
 

00267                                                                                       {
00268   p.Set (m.r[0],m.r[1],m.r[2]);
00269   q.Set (m.r[3],m.r[4],m.r[5]);
00270   r.Set (m.r[6],m.r[7],m.r[8]);
00271   c=m.position;
00272 }

void MultMatrix Matrix   dest,
const Matrix   m1,
const Matrix   m2
[inline]
 

Multiplies m1 and m2 and pops the result into dest; dest != m1, dest !=m2

00176 {
00177   dest.r[0] = m1.r[0]*m2.r[0] + m1.r[3]*m2.r[1] + m1.r[6]*m2.r[2];
00178   dest.r[1] = m1.r[1]*m2.r[0] + m1.r[4]*m2.r[1] + m1.r[7]*m2.r[2];
00179   dest.r[2] = m1.r[2]*m2.r[0] + m1.r[5]*m2.r[1] + m1.r[8]*m2.r[2];
00180 
00181   dest.r[3] = m1.r[0]*m2.r[3] + m1.r[3]*m2.r[4] + m1.r[6]*m2.r[5];
00182   dest.r[4] = m1.r[1]*m2.r[3] + m1.r[4]*m2.r[4] + m1.r[7]*m2.r[5];
00183   dest.r[5] = m1.r[2]*m2.r[3] + m1.r[5]*m2.r[4] + m1.r[8]*m2.r[5];
00184 
00185 
00186   dest.r[6] = m1.r[0]*m2.r[6] + m1.r[3]*m2.r[7] + m1.r[6]*m2.r[8];
00187   dest.r[7] = m1.r[1]*m2.r[6] + m1.r[4]*m2.r[7] + m1.r[7]*m2.r[8];
00188   dest.r[8] = m1.r[2]*m2.r[6] + m1.r[5]*m2.r[7] + m1.r[8]*m2.r[8];
00189 
00190   dest.position.i = m1.r[0]*m2.position.i + m1.r[3]*m2.position.j + m1.r[6]*m2.position.k + m1.position.i;
00191   dest.position.j = m1.r[1]*m2.position.i + m1.r[4]*m2.position.j + m1.r[7]*m2.position.k + m1.position.j;
00192   dest.position.k = m1.r[2]*m2.position.i + m1.r[5]*m2.position.j + m1.r[8]*m2.position.k + m1.position.k;
00193 
00194 }

void Rotate Matrix   tmp,
const Vector   axis,
float    angle
[inline]
 

00329                                                                   {
00330                 double c = cos (angle);
00331                 double s = sin (angle);
00332 //Row, COl
00333 #define M(a,b) (tmp.r[b*3+a])
00334                 M(0,0)=axis.i*axis.i*(1-c)+c;
00335                 M(0,1)=axis.i*axis.j*(1-c)-axis.k*s;
00336                 M(0,2)=axis.i*axis.k*(1-c)+axis.j*s;
00337         //          M(0,3)=0;
00338                 M(1,0)=axis.j*axis.i*(1-c)+axis.k*s;
00339                 M(1,1)=axis.j*axis.j*(1-c)+c;
00340                 M(1,2)=axis.j*axis.k*(1-c)-axis.i*s;
00341         //                M(1,3)=0;
00342                 M(2,0)=axis.i*axis.k*(1-c)-axis.j*s;
00343                 M(2,1)=axis.j*axis.k*(1-c)+axis.i*s;
00344                 M(2,2)=axis.k*axis.k*(1-c)+c;
00345         //                M(2,3)=0;
00346 #undef M
00347         tmp.position.Set(0,0,0);
00348 }

void RotateAxisAngle Matrix   tmp,
const Vector   axis,
const float    angle
[inline]
 

Computes a Translation matrix based on x,y,z translation

00139                                                                                  {
00140   float c = cosf (angle);
00141   float s = sinf (angle);
00142 #define M(a,b) (tmp.r[b*3+a])
00143                 M(0,0)=axis.i*axis.i*(1-c)+c;
00144                 M(0,1)=axis.i*axis.j*(1-c)-axis.k*s;
00145                 M(0,2)=axis.i*axis.k*(1-c)+axis.j*s;
00146         //                M(0,3)=0;
00147                 M(1,0)=axis.j*axis.i*(1-c)+axis.k*s;
00148                 M(1,1)=axis.j*axis.j*(1-c)+c;
00149                 M(1,2)=axis.j*axis.k*(1-c)-axis.i*s;
00150         //                M(1,3)=0;
00151                 M(2,0)=axis.i*axis.k*(1-c)-axis.j*s;
00152                 M(2,1)=axis.j*axis.k*(1-c)+axis.i*s;
00153                 M(2,2)=axis.k*axis.k*(1-c)+c;
00154         //                M(2,3)=0;
00155 #undef M
00156         tmp.position.Set (0,0,0);
00157 }

void ScaleMatrix Matrix   matrix,
const Vector   scale
[inline]
 

moves a vector struct to a matrix

00073                                                              {
00074   matrix.r[0]*=scale.i;
00075   matrix.r[1]*=scale.i;
00076   matrix.r[2]*=scale.i;
00077   matrix.r[3]*=scale.j;
00078   matrix.r[4]*=scale.j;
00079   matrix.r[5]*=scale.j;
00080   matrix.r[6]*=scale.k;
00081   matrix.r[7]*=scale.k;
00082   matrix.r[8]*=scale.k;
00083 }

Vector Transform const Matrix   t,
const Vector   v
[inline]
 

00216                                                             {
00217   return Vector (t.position.i+v.i*t.r[0]+v.j*t.r[3]+v.k*t.r[6],
00218           t.position.j+v.i*t.r[1]+v.j*t.r[4]+v.k*t.r[7],
00219           t.position.k+v.i*t.r[2]+v.j*t.r[5]+v.k*t.r[8]);
00220 }

QVector Transform const Matrix   t,
const QVector   v
[inline]
 

moves a vector in the localspace to world space through matrix t

00211                                                               {
00212   return QVector (t.position.i+v.i*t.r[0]+v.j*t.r[3]+v.k*t.r[6],
00213           t.position.j+v.i*t.r[1]+v.j*t.r[4]+v.k*t.r[7],
00214           t.position.k+v.i*t.r[2]+v.j*t.r[5]+v.k*t.r[8]);
00215 }

QVector TransformNormal const Matrix   t,
const QVector   v
[inline]
 

00259                                                                     {
00260   return QVector (v.i*t.r[0]+v.j*t.r[3]+v.k*t.r[6],
00261           v.i*t.r[1]+v.j*t.r[4]+v.k*t.r[7],
00262           v.i*t.r[2]+v.j*t.r[5]+v.k*t.r[8]);
00263 }

Vector TransformNormal const Matrix   t,
const Vector   v
[inline]
 

00254                                                                   {
00255   return Vector (v.i*t.r[0]+v.j*t.r[3]+v.k*t.r[6],
00256          v.i*t.r[1]+v.j*t.r[4]+v.k*t.r[7],
00257          v.i*t.r[2]+v.j*t.r[5]+v.k*t.r[8]);
00258 }

void Translate Matrix   matrix,
const QVector   v
[inline]
 

00159                                                         {
00160     matrix.r[0] = 1;
00161     matrix.r[1] = 0;
00162     matrix.r[2] = 0;
00163     matrix.r[3] = 0;
00164     matrix.r[4] = 1;
00165     matrix.r[5] = 0;
00166     matrix.r[6] = 0;
00167     matrix.r[7] = 0;
00168     matrix.r[8] = 1;
00169     matrix.position=v;
00170 }

void VectorAndPositionToMatrix Matrix   matrix,
const Vector   v1,
const Vector   v2,
const Vector   v3,
const QVector   pos
[inline]
 

00085                                                                                                                                 {
00086 
00087     matrix.r[0] = v1.i;
00088     matrix.r[1] = v1.j;
00089     matrix.r[2] = v1.k;
00090 
00091     matrix.r[3] = v2.i;
00092     matrix.r[4] = v2.j;
00093     matrix.r[5] = v2.k;
00094 
00095     matrix.r[6] = v3.i;
00096     matrix.r[7] = v3.j;
00097     matrix.r[8] = v3.k;
00098     matrix.position = pos;  
00099 }

void Zero Matrix   matrix [inline]
 

zeros out a 4x4 matrix quickly

00107 {
00108     matrix.r[0] = 0;
00109     matrix.r[1] = 0;
00110     matrix.r[2] = 0;
00111     matrix.r[3] = 0;
00112 
00113     matrix.r[4] = 0;
00114     matrix.r[5] = 0;
00115     matrix.r[6] = 0;
00116     matrix.r[7] = 0;
00117 
00118     matrix.r[8] = 0;
00119     matrix.position.Set(0,0,0);
00120 }


Generated on Mon Jul 7 21:13:48 2003 for Ethereal by doxygen1.2.15