00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef TRANSFORMATION_HPP
00044 #define TRANSFORMATION_HPP 1
00045
00046
00047 #include <string.h>
00048 #include "vec3d.hpp"
00049 #include "vec4d.hpp"
00050
00051
00059 class Transformation
00060 {
00061
00062 double x[16];
00063
00064
00065
00066
00067
00068
00069 public:
00070
00073 Transformation() {
00074 x[0] = x[5] = x[10] = x[15] = 1.0;
00075 x[1] = x[2] = x[3] = x[4] = x[6] = x[7]
00076 = x[8] = x[9] = x[11] = x[12] = x[13]
00077 = x[14] = 0.0;
00078 }
00079
00082 Transformation( double x11, double x12, double x13, double x14,
00083 double x21, double x22, double x23, double x24,
00084 double x31, double x32, double x33, double x34,
00085 double x41, double x42, double x43, double x44 ) {
00086 x[0] = x11;
00087 x[1] = x12;
00088 x[2] = x13;
00089 x[3] = x14;
00090 x[4] = x21;
00091 x[5] = x22;
00092 x[6] = x23;
00093 x[7] = x24;
00094 x[8] = x31;
00095 x[9] = x32;
00096 x[10] = x33;
00097 x[11] = x34;
00098 x[12] = x41;
00099 x[13] = x42;
00100 x[14] = x43;
00101 x[15] = x44;
00102 }
00103
00106 Transformation( const Transformation &m ) {
00107 memcpy( x, m.x, 16*sizeof(double) );
00108 }
00109
00112 ~Transformation() {}
00113
00114
00115
00116
00117
00120 double &operator[]( int i ) {
00121 return( x[i] );
00122 }
00123
00126 const double &operator[]( int i ) const {
00127 return( x[i] );
00128 }
00129
00132 double determinant( void ) const;
00133
00136 Transformation inverse( void ) const;
00137
00140 const Transformation &operator*=( double s );
00141
00150 Transformation operator*( const Transformation &m ) const;
00151
00156 Vec4D operator*( const Vec4D &v ) const;
00157
00163 Vec4D operator%( const Vec4D &v ) const;
00164
00165
00166
00167
00168
00171 Vec4D transform( const Vec4D &xin ) const;
00172
00173
00174
00175
00181 Vec3D transform_point( const Vec3D &xin ) const;
00182
00192 Vec3D inv_transform_point( const Vec3D &xin ) const;
00193
00194
00195
00196
00202 Vec3D transform_vector( const Vec3D &xin ) const;
00203
00213 Vec3D inv_transform_vector( const Vec3D &xin ) const;
00214
00215
00216
00217
00223 void translate( const Vec3D &d ) {
00224 Transformation t1 = translation( d );
00225 Transformation t2 = *this * t1;
00226 *this = t2;
00227 }
00228
00234 void scale( const Vec3D &s ) {
00235 Transformation t1 = scaling( s );
00236 Transformation t2 = *this * t1;
00237 *this = t2;
00238 }
00239
00245 void rotate_x( double a ) {
00246 Transformation t1 = rotation_x( a );
00247 Transformation t2 = *this * t1;
00248 *this = t2;
00249 }
00250
00256 void rotate_y( double a ) {
00257 Transformation t1 = rotation_y( a );
00258 Transformation t2 = *this * t1;
00259 *this = t2;
00260 }
00261
00267 void rotate_z( double a ) {
00268 Transformation t1 = rotation_z( a );
00269 Transformation t2 = *this * t1;
00270 *this = t2;
00271 }
00272
00273
00274
00277 static Transformation translation( const Vec3D &d ) {
00278 return( Transformation( 1, 0, 0, d[0],
00279 0, 1, 0, d[1],
00280 0, 0, 1, d[2],
00281 0, 0, 0, 1 ) );
00282 }
00283
00286 static Transformation scaling( const Vec3D &s ) {
00287 return( Transformation( s[0], 0, 0, 0,
00288 0, s[1], 0, 0,
00289 0, 0, s[2], 0,
00290 0, 0, 0, 1 ) );
00291 }
00292
00295 static Transformation rotation_x( double a ) {
00296 return( Transformation( 1, 0, 0, 0,
00297 0, cos(a), -sin(a), 0,
00298 0, sin(a), cos(a), 0,
00299 0, 0, 0, 1 ) );
00300 }
00301
00304 static Transformation rotation_y( double a ) {
00305 return( Transformation( cos(a), 0, sin(a), 0,
00306 0, 1, 0, 0,
00307 -sin(a), 0, cos(a), 0,
00308 0, 0, 0, 1 ) );
00309 }
00310
00313 static Transformation rotation_z( double a ) {
00314 return( Transformation( cos(a), -sin(a), 0, 0,
00315 sin(a), cos(a), 0, 0,
00316 0, 0, 1, 0,
00317 0, 0, 0, 1 ) );
00318 }
00319
00322 friend std::ostream &operator<<( std::ostream &os, const Transformation &t );
00323 };
00324
00325
00326
00327
00328 #endif
00329