Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Beta/3D/Object3d.cpp

Go to the documentation of this file.
00001 // Classes des objets 3D et derivées.
00002 
00003 #include "objet3d.hpp"
00004 #include <math.h>
00005 
00006 ///////////////////////////////////////////////////////////////////////////////
00007 // La classe des fenêtres de projection.
00008 // La classe des boites limites.
00009 // La classe des sphères limites.
00010 // La classe de base des objets 3D.
00011 // La classe des capteurs visuels.
00012 ///////////////////////////////////////////////////////////////////////////////
00013 
00014 void CapteurVisuel3D::CalculPerspective ()
00015    {
00016    // on prend pour le calcul, le vecteur inverse.
00017    Vector3DH direction( _direction.b, _direction.a );
00018 
00019    // Calcul de la distance D du point de visée à l'observateur.
00020    realtype D = _direction.norme();
00021 
00022    // theta: angle entre le vecteur direction et sa projection sur le plan XOY.
00023    // Calcul des sin et cos.
00024    realtype costheta = 0.0f,
00025          sintheta = 0.0f;
00026 
00027    direction.cos_sinangle_ver(costheta, sintheta);
00028 
00029    // phi : angle entre la projection du vecteur direction sur le plans XOY et
00030    // l'axe des abscisses.
00031    // Calcul des sin et cos.
00032    // Nb - le cas particulier où la visée est verticale rend la projection sur
00033    //      le plans XOY égale à un point. Dans ce cas, il n'y à pas de calcul
00034    //      d'angle possible. On suppose donc phi=0;
00035 
00036    realtype cosphi= 0.0f,
00037          sinphi= 0.0f;
00038 
00039    direction.cos_sinangle_hor(cosphi, sinphi);
00040 
00041    // on intialise la matrice perspective
00042    _perspective.setIdentity();
00043 
00044    // On initialise la matrice de changement de repère.
00045    Matrice44 mat;
00046    mat.setIdentity();
00047 
00048    // Etape 1. On effectue la première translation de changement de repère.
00049    mat.setTranslateX(-direction.compox());
00050    mat.setTranslateY(-direction.compoy());
00051    mat.setTranslateZ(-direction.compoz());
00052 
00053    _perspective.multiplyByMatrix(mat);
00054 
00055    // Etape 2. Rotation négative autour de l'axe Z0 de PI/2-phi.
00056    // nous avons cos PI/2-phi = sin phi
00057    //            sin PI/2-phi = -cos phi
00058    // or nous effectuons un changement de repère ce qui implique la matrice
00059    // inverse d'ou phi devient -phi
00060    // nous avons cos -phi = cos phi
00061    //            sin -phi = -sin phi
00062    //     |sinphi  cosphi 0 0|
00063    //     |-cosphi sinphi 0 0|
00064    // B = |  0       0    1 0|
00065    //     |  0       0    0 1|
00066    //
00067    mat.setIdentity();
00068    mat.setRotateZ(sinphi,
00069                     cosphi);
00070    _perspective.multiplyByMatrix(mat);
00071 
00072    // Etape 3. Rotation positive autour de l'axe X1 de PI/2+theta
00073    // nous avons cos PI/2+theta = -sin theta
00074    //            sin PI/2+theta = cos theta
00075    // or nous effectuons un changement de repère ce qui implique la matrice
00076    // inverse d'ou phi devient -theta
00077    // nous avons cos -theta = cos theta
00078    //            sin -theta = -sin theta
00079    //     |  1       0         0       0|
00080    //     |  0  -sintheta  -costheta   0|
00081    // B = |  0   costheta  -sintheta   0|
00082    //     |  0       0         0       1|
00083    //
00084    mat.setIdentity();
00085    mat.setRotateX(-sintheta,
00086                     -costheta );
00087    _perspective.multiplyByMatrix(mat);
00088 
00089    // Etape 4. Changement de sens d'axe X. repère direct.
00090    mat.setIdentity();
00091    mat.xx = -1.0f;
00092 
00093    _perspective.multiplyByMatrix(mat);
00094 
00095    // Etape 5. Rotation du spin.
00096    realtype spin    = ((realtype)(M_PI) / 180.0f)* _spin,
00097             cosspin = (realtype)cos( spin ),
00098             sinspin = (realtype)sin( spin );
00099 
00100    mat.setIdentity();
00101    mat.setRotateZ(cosspin, -sinspin);
00102 
00103    _perspective.multiplyByMatrix(mat);
00104 
00105    // Etape 6. Normalisation et projection perspective à un point de fuite.
00106    mat.setIdentity();
00107    realtype ouverture     = (realtype)(M_PI / 180.0f)* _ouverture,
00108             halfsizeprojy = (realtype)tan(ouverture)* D,
00109             halfsizeprojx = halfsizeprojy*( _fenetre._halfsize.x/
00110                                                 _fenetre._halfsize.y);
00111 
00112    // 6a - Normalisation xy
00113    mat.xx = 1.0f/halfsizeprojx;
00114    mat.yy = 1.0f/halfsizeprojy;
00115 
00116    // 6b - perspective Z.
00117    mat.zw = 1.0f / D;
00118 
00119    _perspective.multiplyByMatrix(mat);
00120    }
00121 
00122 void CapteurVisuel3D::VisualisationFilaireObjet( HDC dc, RObjet3D obj )
00123    {
00124    int        cardsommet = obj.data.cardsommets;
00125    PPixel     pixels     = new Pixel[ cardsommet ];
00126    Sommet3DH  transform;
00127 
00128    // transformation des sommets.
00129    for ( int i = 0; i < cardsommet; i ++ )
00130      {
00131      Sommet3DH& sommet = obj.data.sommets[i];
00132      transform.x = sommet.x;
00133      transform.y = sommet.y;
00134      transform.z = sommet.z;
00135      transform.w = sommet.w;
00136 
00137      transform.multiplyByMatrix(_perspective);
00138 
00139      // on initialise les coordonées écran.
00140      pixels[i].x = (int)((transform.x/transform.w)*
00141                                 _fenetre._halfsize.x );
00142      pixels[i].y = (int)((transform.y/transform.w)*
00143                                 _fenetre._halfsize.y );
00144      }
00145 
00146    int    cardarc = obj.data.cardarcs;
00147 
00148    // affichage des arcs.
00149    for ( int i = 0; i < cardarc; i ++ )
00150      {
00151      RArcD arc = obj.data.arcs[i];
00152      Pixel& pixelini = pixels[arc.sini-1],//la numérotation commence à 1
00153             pixelfin = pixels[arc.sfin-1];//la table à 0. D'où - 1.
00154 
00155      MoveToEx(dc, pixelini.x, pixelini.y, NULL);
00156      LineTo(dc, pixelfin.x, pixelfin.y);
00157      }
00158 
00159    if ( pixels ) delete [] pixels;
00160    }
00161 
00162 void CapteurVisuel3D::VisualisationFilaireScene( HDC dc)
00163  {
00164  if (!_dans ) return;
00165  _dans->VisualisationFilaire( dc, (RCapteurVisuel3D)*this );
00166  }
00167 
00168 ///////////////////////////////////////////////////////////////////////////////
00169 // La classe des scènes 3D.
00170 ///////////////////////////////////////////////////////////////////////////////
00171 void Scene3D::VisualisationFilaire( HDC hdc, RCapteurVisuel3D obs )
00172  {
00173  if (!_obj ) return;
00174 
00175  obs.VisualisationFilaireObjet( hdc, (RObjet3D)(*_obj) );
00176  }
00177 
00178 

Generated on Sun Oct 14 18:46:08 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001