Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Matrix4< T > Class Template Reference

#include <vecmath.h>

Inheritance diagram for Matrix4< T >:

Inheritance graph
List of all members.

Public Member Functions

Vector4< T > column (int) const
Matrix4< T > inverse () const
 Matrix4 (const Matrix4< T > &m)
 Matrix4 (const Vector4< T > &, const Vector4< T > &, const Vector4< T > &, const Vector4< T > &)
 Matrix4 ()
const Vector4< T > & operator[] (int) const
Vector4< T > row (int) const
void translate (const Point3< T > &)
Matrix4< T > transpose () const

Static Public Member Functions

static Matrix4< T > identity ()
static Matrix4< T > rotation (const Vector3< T > &, T)
static Matrix4< T > scaling (T)
static Matrix4< T > scaling (const Vector3< T > &)
static Matrix4< T > translation (const Vector3< T > &)
static Matrix4< T > translation (const Point3< T > &)
static Matrix4< T > xrotation (T)
static Matrix4< T > yrotation (T)
static Matrix4< T > zrotation (T)

Public Attributes

Vector4< T > r [4]

template<class T>
class Matrix4< T >


Constructor & Destructor Documentation

template<class T>
Matrix4< T >::Matrix4  ) 
 

Definition at line 794 of file vecmath.h.

References Matrix4< T >::r.

00795 {
00796     r[0] = Vector4<T>(0, 0, 0, 0);
00797     r[1] = Vector4<T>(0, 0, 0, 0);
00798     r[2] = Vector4<T>(0, 0, 0, 0);
00799     r[3] = Vector4<T>(0, 0, 0, 0);
00800 }

template<class T>
Matrix4< T >::Matrix4 const Vector4< T > &  ,
const Vector4< T > &  ,
const Vector4< T > &  ,
const Vector4< T > & 
 

Definition at line 803 of file vecmath.h.

References Matrix4< T >::r.

00807 {
00808     r[0] = v0;
00809     r[1] = v1;
00810     r[2] = v2;
00811     r[3] = v3;
00812 }

template<class T>
Matrix4< T >::Matrix4 const Matrix4< T > &  m  ) 
 

Definition at line 815 of file vecmath.h.

References Matrix3< T >::r, and Matrix4< T >::r.

00816 {
00817     r[0] = m.r[0];
00818     r[1] = m.r[1];
00819     r[2] = m.r[2];
00820     r[3] = m.r[3];
00821 }


Member Function Documentation

template<class T>
Vector4< T > Matrix4< T >::column int   )  const [inline]
 

Definition at line 835 of file vecmath.h.

References Matrix4< T >::r.

00836 {
00837     return Vector4<T>(r[0][n], r[1][n], r[2][n], r[3][n]);
00838 }

template<class T>
Matrix4< T > Matrix4< T >::identity  )  [static]
 

Definition at line 841 of file vecmath.h.

Referenced by Matrix4< T >::inverse().

00842 {
00843     return Matrix4<T>(Vector4<T>(1, 0, 0, 0),
00844                       Vector4<T>(0, 1, 0, 0),
00845                       Vector4<T>(0, 0, 1, 0),
00846                       Vector4<T>(0, 0, 0, 1));
00847 }

template<class T>
Matrix4< T > Matrix4< T >::inverse  )  const
 

Definition at line 1031 of file vecmath.h.

References Matrix4< T >::identity(), and Matrix4< T >::r.

01032 {
01033     Matrix4<T> a(*this);
01034     Matrix4<T> b(Matrix4<T>::identity());
01035     int i, j;
01036     int p;
01037 
01038     for (j = 0; j < 4; j++)
01039     {
01040         p = j;
01041         for (i = j + 1; i < 4; i++)
01042         {
01043             if (fabs(a.r[i][j]) > fabs(a.r[p][j]))
01044                 p = i;
01045         }
01046 
01047         // Swap rows p and j
01048         Vector4<T> t = a.r[p];
01049         a.r[p] = a.r[j];
01050         a.r[j] = t;
01051 
01052         t = b.r[p];
01053         b.r[p] = b.r[j];
01054         b.r[j] = t;
01055 
01056         T s = a.r[j][j];  // if s == 0, the matrix is singular
01057         a.r[j] *= (1.0f / s);
01058         b.r[j] *= (1.0f / s);
01059 
01060         // Eliminate off-diagonal elements
01061         for (i = 0; i < 4; i++)
01062         {
01063             if (i != j)
01064             {
01065                 b.r[i] -= a.r[i][j] * b.r[j];
01066                 a.r[i] -= a.r[i][j] * a.r[j];
01067             }
01068         }
01069     }
01070 
01071     return b;
01072 }

template<class T>
const Vector4< T > & Matrix4< T >::operator[] int   )  const [inline]
 

Definition at line 824 of file vecmath.h.

References Matrix4< T >::r.

00825 {
00826     return r[n];
00827     //    return const_cast<Vector4<T>&>(r[n]);
00828 }

template<class T>
Matrix4< T > Matrix4< T >::rotation const Vector3< T > &  ,
[static]
 

Definition at line 876 of file vecmath.h.

References cos(), and sin().

00878 {
00879     T c = (T) cos(angle);
00880     T s = (T) sin(angle);
00881     T t = 1 - c;
00882 
00883     return Matrix4<T>(Vector4<T>(t * axis.x * axis.x + c,
00884                                  t * axis.x * axis.y - s * axis.z,
00885                                  t * axis.x * axis.z + s * axis.y,
00886                                  0),
00887                       Vector4<T>(t * axis.x * axis.y + s * axis.z,
00888                                  t * axis.y * axis.y + c,
00889                                  t * axis.y * axis.z - s * axis.x,
00890                                  0),
00891                       Vector4<T>(t * axis.x * axis.z - s * axis.y,
00892                                  t * axis.y * axis.z + s * axis.x,
00893                                  t * axis.z * axis.z + c,
00894                                  0),
00895                       Vector4<T>(0, 0, 0, 1));
00896 }

template<class T>
Vector4< T > Matrix4< T >::row int   )  const [inline]
 

Definition at line 830 of file vecmath.h.

References Matrix4< T >::r.

00831 {
00832     return r[n];
00833 }

template<class T>
Matrix4< T > Matrix4< T >::scaling  )  [static]
 

Definition at line 944 of file vecmath.h.

References Matrix4< T >::scaling().

00945 {
00946     return scaling(Vector3<T>(scale, scale, scale));
00947 }

template<class T>
Matrix4< T > Matrix4< T >::scaling const Vector3< T > &   )  [static]
 

Definition at line 935 of file vecmath.h.

Referenced by Matrix4< T >::scaling().

00936 {
00937     return Matrix4<T>(Vector4<T>(scale.x, 0, 0, 0),
00938                       Vector4<T>(0, scale.y, 0, 0),
00939                       Vector4<T>(0, 0, scale.z, 0),
00940                       Vector4<T>(0, 0, 0, 1));
00941 }

template<class T>
void Matrix4< T >::translate const Point3< T > &   ) 
 

Definition at line 868 of file vecmath.h.

References Matrix4< T >::r.

00869 {
00870     r[3].x += p.x;
00871     r[3].y += p.y;
00872     r[3].z += p.z;
00873 }

template<class T>
Matrix4< T > Matrix4< T >::translation const Vector3< T > &   )  [static]
 

Definition at line 859 of file vecmath.h.

00860 {
00861     return Matrix4<T>(Vector4<T>(1, 0, 0, 0),
00862                       Vector4<T>(0, 1, 0, 0),
00863                       Vector4<T>(0, 0, 1, 0),
00864                       Vector4<T>(v.x, v.y, v.z, 1));
00865 }

template<class T>
Matrix4< T > Matrix4< T >::translation const Point3< T > &   )  [static]
 

Definition at line 850 of file vecmath.h.

Referenced by Body::getLocalToHeliocentric().

00851 {
00852     return Matrix4<T>(Vector4<T>(1, 0, 0, 0),
00853                       Vector4<T>(0, 1, 0, 0),
00854                       Vector4<T>(0, 0, 1, 0),
00855                       Vector4<T>(p.x, p.y, p.z, 1));
00856 }

template<class T>
Matrix4< T > Matrix4< T >::transpose  )  const
 

Definition at line 1002 of file vecmath.h.

References Matrix4< T >::r.

01003 {
01004     return Matrix4<T>(Vector4<T>(r[0].x, r[1].x, r[2].x, r[3].x),
01005                       Vector4<T>(r[0].y, r[1].y, r[2].y, r[3].y),
01006                       Vector4<T>(r[0].z, r[1].z, r[2].z, r[3].z),
01007                       Vector4<T>(r[0].w, r[1].w, r[2].w, r[3].w));
01008 }

template<class T>
Matrix4< T > Matrix4< T >::xrotation  )  [static]
 

Definition at line 899 of file vecmath.h.

References cos(), and sin().

Referenced by Body::getLocalToHeliocentric().

00900 {
00901     T c = (T) cos(angle);
00902     T s = (T) sin(angle);
00903 
00904     return Matrix4<T>(Vector4<T>(1, 0, 0, 0),
00905                       Vector4<T>(0, c, -s, 0),
00906                       Vector4<T>(0, s, c, 0),
00907                       Vector4<T>(0, 0, 0, 1));
00908 }

template<class T>
Matrix4< T > Matrix4< T >::yrotation  )  [static]
 

Definition at line 911 of file vecmath.h.

References cos(), and sin().

Referenced by Body::getLocalToHeliocentric().

00912 {
00913     T c = (T) cos(angle);
00914     T s = (T) sin(angle);
00915 
00916     return Matrix4<T>(Vector4<T>(c, 0, s, 0),
00917                       Vector4<T>(0, 1, 0, 0),
00918                       Vector4<T>(-s, 0, c, 0),
00919                       Vector4<T>(0, 0, 0, 1));
00920 }

template<class T>
Matrix4< T > Matrix4< T >::zrotation  )  [static]
 

Definition at line 923 of file vecmath.h.

References cos(), and sin().

00924 {
00925     T c = (T) cos(angle);
00926     T s = (T) sin(angle);
00927 
00928     return Matrix4<T>(Vector4<T>(c, -s, 0, 0),
00929                       Vector4<T>(s, c, 0, 0),
00930                       Vector4<T>(0, 0, 1, 0),
00931                       Vector4<T>(0, 0, 0, 1));
00932 }


Member Data Documentation

template<class T>
Vector4<T> Matrix4< T >::r[4]
 

Definition at line 132 of file vecmath.h.

Referenced by Matrix4< T >::column(), Matrix4< T >::inverse(), Matrix4< T >::Matrix4(), Matrix4< T >::operator[](), Matrix4< T >::row(), Matrix4< T >::translate(), and Matrix4< T >::transpose().


The documentation for this class was generated from the following file:
Generated on Sat Jan 14 22:33:27 2006 for Celestia by  doxygen 1.4.1