Página Principal | Lista Alfabética | Lista de Componentes | Lista de Arquivos | Componentes Membros | Arquivos Membros

t2d.c

Vá para a documentação deste arquivo.
00001 /*
00002 ** ---------------------------------------------------------------
00003 ** t2d.c  -  Module to manage 2D matrix transformations.
00004 **
00005 ** ---------------------------------------------------------------
00006 */
00007 
00038 /*
00039 ** ---------------------------------------------------------------
00040 ** Global variables and symbols:
00041 */
00042 #include <math.h>
00043 #include "t2d.h"
00044 
00045 /*
00046 ** ---------------------------------------------------------------
00047 ** Local variables and symbols:
00048 */
00049 #ifndef rad
00050 #define rad(a)  ((a)*(double)0.01745329252)
00051 #endif
00052 
00055 typedef double Matrix2d[2][3];
00056 
00059 static Matrix2d mt =
00060  {
00061   { 1.0, 0.0, 0.0 },
00062   { 0.0, 1.0, 0.0 }
00063  };
00064 
00065 /*
00066 ** ---------------------------------------------------------------
00067 ** Local functions:
00068 */
00069 
00070 /*=======================  t2dAccumulate  ======================*/
00077 static void t2dAccumulate( Matrix2d nmt )
00078 {
00079  double   t;
00080 
00081  t        =  mt[0][0]*nmt[0][0] + mt[1][0]*nmt[0][1];
00082  mt[1][0] =  mt[0][0]*nmt[1][0] + mt[1][0]*nmt[1][1];
00083  mt[0][0] =  t;
00084 
00085  t        =  mt[0][1]*nmt[0][0] + mt[1][1]*nmt[0][1];
00086  mt[1][1] =  mt[0][1]*nmt[1][0] + mt[1][1]*nmt[1][1];
00087  mt[0][1] =  t;
00088 
00089  t        =  mt[0][2]*nmt[0][0] + mt[1][2]*nmt[0][1] + nmt[0][2];
00090  mt[1][2] =  mt[0][2]*nmt[1][0] + mt[1][2]*nmt[1][1] + nmt[1][2];
00091  mt[0][2] =  t;
00092 }
00093 
00094 /*
00095 ** ---------------------------------------------------------------
00096 ** Public functions:
00097 */
00098 
00099 /*======================  t2dTransform  ========================*/
00107 void t2dTransform( double *x, double *y )
00108 {
00109  double t;
00110   t = (*x)*mt[0][0] + (*y)*mt[0][1] + mt[0][2];
00111  *y = (*x)*mt[1][0] + (*y)*mt[1][1] + mt[1][2];
00112  *x = t;
00113 }
00114 
00115 /*======================  t2dIdentity  =========================*/
00120 void t2dIdentity( void )
00121 {
00122  mt[0][0] = 1.0; mt[0][1] = 0.0; mt[0][2] = 0.0;
00123  mt[1][0] = 0.0; mt[1][1] = 1.0; mt[1][2] = 0.0;
00124 }
00125 
00126 /*=======================  t2dTranslate  =======================*/
00134 void t2dTranslate( double dx, double dy )
00135 {
00136  Matrix2d trl;
00137 
00138 /**** COMPLETE AQUI: 014 ****/
00139 
00140  t2dAccumulate( trl );
00141 }
00142 
00143 /*=========================  t2dScale  =========================*/
00152 void t2dScale( double sx, double sy )
00153 {
00154  Matrix2d scl;
00155 
00156 /**** COMPLETE AQUI: 015 ****/
00157 
00158  t2dAccumulate( scl );
00159 }
00160 
00161 /*=======================  t2dScaleAbout  ======================*/
00172 void t2dScaleAbout( double cx, double cy, double sx, double sy )
00173 {
00174  t2dTranslate( -cx, -cy );
00175  t2dScale( sx, sy );
00176  t2dTranslate( cx, cy );
00177 }
00178 
00179 /*=========================  t2dRotate  ========================*/
00188 void t2dRotate( double angle )
00189 {
00190  double cost = cos(rad(angle));
00191  double sint = sin(rad(angle));
00192  Matrix2d rot;
00193 
00194 /**** COMPLETE AQUI: 016 ****/
00195 
00196  t2dAccumulate( rot );
00197 }
00198 
00199 /*======================  t2dRotateAbout  ======================*/
00210 void t2dRotateAbout( double cx, double cy, double angle )
00211 {
00212  t2dTranslate( -cx, -cy );
00213  t2dRotate( angle );
00214  t2dTranslate( cx, cy );
00215 }
00216 

Gerado em Tue Oct 5 04:55:00 2004 para Trab3 por doxygen 1.3.4