Main Page | Alphabetical List | Class List | File List | Class Members | File Members

t3d.cpp

Go to the documentation of this file.
00001 /*
00002 ** ---------------------------------------------------------------
00003 ** t3d.cpp  -  3D matrix transformations class.
00004 **
00005 ** ---------------------------------------------------------------
00006 */
00007 
00050 /*
00051 ** ---------------------------------------------------------------
00052 ** Global variables and symbols:
00053 */
00054 #include <math.h>
00055 #include "t3d.h"
00056 
00057 /*
00058 ** ---------------------------------------------------------------
00059 ** Initialization of class variables:
00060 */
00063 double T3d::mt[4][4] =
00064  {
00065   { 1.0, 0.0, 0.0, 0.0 } ,
00066   { 0.0, 1.0, 0.0, 0.0 } ,
00067   { 0.0, 0.0, 1.0, 0.0 } ,
00068   { 0.0, 0.0, 0.0, 1.0 }
00069  };
00070 
00071 /*
00072 ** ---------------------------------------------------------------
00073 ** Private class functions:
00074 */
00075 
00076 /*=======================  T3d::Accumulate  ======================*/
00081 void T3d::Accumulate( double new_mt[4][4] )
00082 {
00083  double   t0, t1, t2;
00084 
00085  t0       =  mt[0][0]*new_mt[0][0] + mt[1][0]*new_mt[0][1] 
00086            + mt[2][0]*new_mt[0][2] + mt[3][0]*new_mt[0][3];
00087  t1       =  mt[0][0]*new_mt[1][0] + mt[1][0]*new_mt[1][1] 
00088            + mt[2][0]*new_mt[1][2] + mt[3][0]*new_mt[1][3];
00089  t2       =  mt[0][0]*new_mt[2][0] + mt[1][0]*new_mt[2][1] 
00090            + mt[2][0]*new_mt[2][2] + mt[3][0]*new_mt[2][3];
00091  mt[3][0] =  mt[0][0]*new_mt[3][0] + mt[1][0]*new_mt[3][1] 
00092            + mt[2][0]*new_mt[3][2] + mt[3][0]*new_mt[3][3];
00093  mt[2][0] =  t2;
00094  mt[1][0] =  t1;
00095  mt[0][0] =  t0;
00096 
00097  t0       =  mt[0][1]*new_mt[0][0] + mt[1][1]*new_mt[0][1] 
00098            + mt[2][1]*new_mt[0][2] + mt[3][1]*new_mt[0][3];
00099  t1       =  mt[0][1]*new_mt[1][0] + mt[1][1]*new_mt[1][1] 
00100            + mt[2][1]*new_mt[1][2] + mt[3][1]*new_mt[1][3];
00101  t2       =  mt[0][1]*new_mt[2][0] + mt[1][1]*new_mt[2][1] 
00102            + mt[2][1]*new_mt[2][2] + mt[3][1]*new_mt[2][3];
00103  mt[3][1] =  mt[0][1]*new_mt[3][0] + mt[1][1]*new_mt[3][1] 
00104            + mt[2][1]*new_mt[3][2] + mt[3][1]*new_mt[3][3];
00105  mt[2][1] =  t2;
00106  mt[1][1] =  t1;
00107  mt[0][1] =  t0;
00108 
00109  t0       =  mt[0][2]*new_mt[0][0] + mt[1][2]*new_mt[0][1] 
00110            + mt[2][2]*new_mt[0][2] + mt[3][2]*new_mt[0][3];
00111  t1       =  mt[0][2]*new_mt[1][0] + mt[1][2]*new_mt[1][1] 
00112            + mt[2][2]*new_mt[1][2] + mt[3][2]*new_mt[1][3];
00113  t2       =  mt[0][2]*new_mt[2][0] + mt[1][2]*new_mt[2][1] 
00114            + mt[2][2]*new_mt[2][2] + mt[3][2]*new_mt[2][3];
00115  mt[3][2] =  mt[0][2]*new_mt[3][0] + mt[1][2]*new_mt[3][1] 
00116            + mt[2][2]*new_mt[3][2] + mt[3][2]*new_mt[3][3];
00117  mt[2][2] =  t2;
00118  mt[1][2] =  t1;
00119  mt[0][2] =  t0;
00120 
00121  t0       =  mt[0][3]*new_mt[0][0] + mt[1][3]*new_mt[0][1] 
00122            + mt[2][3]*new_mt[0][2] + mt[3][3]*new_mt[0][3];
00123  t1       =  mt[0][3]*new_mt[1][0] + mt[1][3]*new_mt[1][1] 
00124            + mt[2][3]*new_mt[1][2] + mt[3][3]*new_mt[1][3];
00125  t2       =  mt[0][3]*new_mt[2][0] + mt[1][3]*new_mt[2][1] 
00126            + mt[2][3]*new_mt[2][2] + mt[3][3]*new_mt[2][3];
00127  mt[3][3] =  mt[0][3]*new_mt[3][0] + mt[1][3]*new_mt[3][1] 
00128            + mt[2][3]*new_mt[3][2] + mt[3][3]*new_mt[3][3];
00129  mt[2][3] =  t2;
00130  mt[1][3] =  t1;
00131  mt[0][3] =  t0;
00132 }
00133 
00134 /*
00135 ** ---------------------------------------------------------------
00136 ** Public class functions:
00137 */
00138 /*======================  T3d::Transform  ========================*/
00139 
00140 void T3d::Transform( double* x, double* y, double* z )
00141 {
00142  double r, s, t, h;
00143 
00144   r = mt[0][0]*(*x)+mt[0][1]*(*y)+mt[0][2]*(*z)+mt[0][3];
00145   s = mt[1][0]*(*x)+mt[1][1]*(*y)+mt[1][2]*(*z)+mt[1][3];
00146   t = mt[2][0]*(*x)+mt[2][1]*(*y)+mt[2][2]*(*z)+mt[2][3];
00147   h = mt[3][0]*(*x)+mt[3][1]*(*y)+mt[3][2]*(*z)+mt[3][3];
00148  *x = r/h;
00149  *y = s/h;
00150  *z = t/h;
00151 }
00152 
00153 /*======================  T3d::Identity  ========================= */
00154 
00155 void T3d::Identity( void )
00156 {
00157  mt[0][0] = 1.0; mt[0][1] = 0.0; mt[0][2] = 0.0; mt[0][3] = 0.0;
00158  mt[1][0] = 0.0; mt[1][1] = 1.0; mt[1][2] = 0.0; mt[1][3] = 0.0;
00159  mt[2][0] = 0.0; mt[2][1] = 0.0; mt[2][2] = 1.0; mt[2][3] = 0.0;
00160  mt[3][0] = 0.0; mt[3][1] = 0.0; mt[3][2] = 0.0; mt[3][3] = 1.0;
00161 }
00162 
00163 /*=========================  T3d::Scale  =========================*/
00164 
00165 void T3d::Scale( double sx, double sy, double sz )
00166 {
00167  double scale[4][4];
00168 
00169 /*** COMPLETE AQUI: T3D-01 ***/
00170 
00171 
00172 
00173 
00174 /*** COMPLETE AQUI: T3D-01 ***/
00175 
00176  Accumulate( scale );
00177 }
00178 
00179 /*=======================  T3d::Translate  =======================*/
00180 
00181 void T3d::Translate( double tx, double ty, double tz )
00182 {
00183  double trans[4][4];
00184 
00185 /*** COMPLETE AQUI: T3D-02 ***/
00186 
00187 
00188 
00189 
00190 /*** COMPLETE AQUI: T3D-02 ***/
00191 
00192  Accumulate( trans );
00193 }
00194 
00195 /*======================  T3d::RotateBasis  ======================*/
00196 
00197 void T3d::RotateBasis( double ux, double uy, double uz, 
00198                        double vx, double vy, double vz,
00199                        double wx, double wy, double wz )
00200 {
00201  double rot[4][4];
00202 
00203 /*** COMPLETE AQUI: T3D-03 ***/
00204 
00205 
00206 
00207 
00208 /*** COMPLETE AQUI: T3D-03 ***/
00209 
00210  Accumulate( rot );
00211 }
00212 
00213 /*=========================  T3d::Camera  ========================*/
00214 
00215 void T3d::Camera( double eyex, double eyey, double eyez, 
00216                   double refx, double refy, double refz,
00217                   double vupx, double vupy, double vupz )
00218 {
00219  Vec  view, upvec;   /* view vector and view upper vector */
00220  Vec  u, v, w;       /* eye system unit vectors           */
00221 
00222 /* Define view vector (from ref to eye) and view up vector.
00223  */
00224 /*** COMPLETE AQUI: T3D-04 ***/
00225 
00226 
00227 
00228 
00229 
00230 
00231 /*** COMPLETE AQUI: T3D-04 ***/
00232 
00233 /* Find the eye system unit vectors.
00234  */
00235 /*** COMPLETE AQUI: T3D-05 ***/
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 /*** COMPLETE AQUI: T3D-05 ***/
00244 
00245 /* Concatenate a translation of basis from origin to eye point.
00246  */
00247 /*** COMPLETE AQUI: T3D-06 ***/
00248 
00249 /*** COMPLETE AQUI: T3D-06 ***/
00250 
00251 /* Concatenate a rotation of basis from world to eye system.
00252  */
00253 /*** COMPLETE AQUI: T3D-07 ***/
00254 
00255 /*** COMPLETE AQUI: T3D-07 ***/
00256 }
00257 
00258 /*======================  T3d::Perspective  ======================*/
00259 
00260 void T3d::Perspective( double d, double front, double back )
00261 {
00262  double alpha, beta;        /* perspective parameters */
00263  double pers[4][4];
00264 
00265 /* Define alpha and beta parameters from the front and back
00266  * arguments.
00267  */
00268 /*** COMPLETE AQUI: T3D-08 ***/
00269 
00270 
00271 /*** COMPLETE AQUI: T3D-08 ***/
00272 
00273 /* Create Perspective matrix.
00274  */
00275 /*** COMPLETE AQUI: T3D-09 ***/
00276 
00277 
00278 
00279 
00280 /*** COMPLETE AQUI: T3D-09 ***/
00281 
00282  Accumulate( pers );
00283 }
00284 
00285 /*=====================  T3d::NormalizeView  =====================*/
00286 
00287 void T3d::NormalizeView( double left, double right, 
00288                          double bottom, double top, 
00289                          double front, double back )
00290 {
00291  double tx, ty, tz;           /* translation factors */
00292  double sx, sy, sz;           /* scaling factors     */
00293 
00294 /* Concatenate a translation of basis from origin to center
00295  * of view volume.
00296  */
00297 /*** COMPLETE AQUI: T3D-10 ***/
00298 
00299 
00300 
00301 
00302 /*** COMPLETE AQUI: T3D-10 ***/
00303 
00304 /* Concatenate a scaling transformation that scales the view 
00305  * volume to a cube ranging from -1 to +1 in the 3 directions, 
00306  * also reverting the z-axis direction.
00307  */
00308 /*** COMPLETE AQUI: T3D-11 ***/
00309 
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 
00318 
00319 
00320 
00321 
00322 /*** COMPLETE AQUI: T3D-11 ***/
00323 }
00324 

Generated on Mon Jun 20 18:09:52 2011 for Trab8 by  doxygen 1.4.2-20050421