1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#ifndef TMATRIX_H
#define TMATRIX_H
// Copyright (c) 2000, 2001, 2002, 2003 by David Scherer and others.
// See the file license.txt for complete license terms.
// See the file authors.txt for a complete list of contributors.
// tmatrix - double-precision 3D transformation matrices
#include "vector.h"
#include "vertex.h"
namespace visual {
class tmatrix
{
public:
typedef double scalar;
scalar M[4][4];
tmatrix() throw() {}
tmatrix( const tmatrix& t ) throw()
{ memcpy(M, t.M, sizeof(M)); }
tmatrix( const tmatrix& A, const tmatrix& B ) throw()
{ concat( A, B); }
static tmatrix
identity() throw()
{ tmatrix t; t.ident(); return t; }
inline void ident( void) throw()
{
x_column();
y_column();
z_column();
w_column();
w_row();
}
inline void x_column( const vector& v) throw()
{
M[0][0] = v.x;
M[1][0] = v.y;
M[2][0] = v.z;
}
inline void y_column( const vector& v) throw()
{
M[0][1] = v.x;
M[1][1] = v.y;
M[2][1] = v.z;
}
inline void z_column( const vector& v) throw()
{
M[0][2] = v.x;
M[1][2] = v.y;
M[2][2] = v.z;
}
inline void w_column( const vector& v) throw()
{
M[0][3] = v.x;
M[1][3] = v.y;
M[2][3] = v.z;
}
inline void x_column( double x=1, double y=0, double z=0) throw()
{
M[0][0] = x;
M[1][0] = y;
M[2][0] = z;
}
inline void y_column( double x=0, double y=1, double z=0) throw()
{
M[0][1] = x;
M[1][1] = y;
M[2][1] = z;
}
inline void z_column( double x=0, double y=0, double z=1) throw()
{
M[0][2] = x;
M[1][2] = y;
M[2][2] = z;
}
inline void w_column(double x=0, double y=0, double z=0) throw()
{
M[0][3] = x;
M[1][3] = y;
M[2][3] = z;
}
inline void w_row(double x=0, double y=0, double z=0, double w=1) throw()
{
M[3][0]=x;
M[3][1]=y;
M[3][2]=z;
M[3][3]=w;
}
// Projects v to o using the current tmatrix values.
// May be called with a float[3] or double[3] for v (implicitly converted).
// We take a full copy just to be safe here.
void project(const vector v, vertex& o) const throw();
void concat(const tmatrix& A, const tmatrix& B) throw();
void invert_ortho(const tmatrix& A) throw();
inline const double*
operator[]( int n) const throw() { return M[n]; }
inline double*
operator[]( int n) throw() { return M[n]; }
// M^-1 * [x y z w]
vector times_inv( const vector& v, double w = 1.0) const throw();
// multiplication by a vector [x y z 0]
vector times_v( const vector& v) const throw();
// multiplication by a point [x y z 1]
vector operator*( const vector& v) const throw();
inline double
x( const vector& v) const throw()
{
return M[0][0]*v.x + M[0][1]*v.y + M[0][2]*v.z + M[0][3];
}
inline double
y( const vector& v) const throw()
{
return M[1][0]*v.x + M[1][1]*v.y + M[1][2]*v.z + M[1][3];
}
inline double
z( const vector& v) const throw()
{
return M[2][0]*v.x + M[2][1]*v.y + M[2][2]*v.z + M[2][3];
}
inline double
w(const vector& v) const throw()
{
return M[3][0]*v.x + M[3][1]*v.y + M[3][2]*v.z + M[3][3];
}
// Overwrites the currently active matrix in OpenGL.
void
gl_load(void);
};
void frustum( tmatrix& T, tmatrix& I, double l, double r, double b, double t, double n, double f ) throw();
void rotation( tmatrix& T, double angle, const vector& a) throw();
double norm_dot( const vector& a, const vector& b) throw();
void tmatrix_init_type();
// Set up a tmatrix to rotate a vector or object as specified by angle, axis and origin
void py_rotation( tmatrix& R, double angle, vector axis, vector origin) throw();
} // !namespace visual
#endif // !TMATRIX_H
|