Logo Search packages:      
Sourcecode: k3dsurf version File versions  Download package

******************************************************************************void Model3D::SpecialMorph_2 ( GLfloat *  NormVertexTabPt,
GLuint *  IndexPolyTabPt,
GLuint *  NbPolygnNbVertexPt,
int  NbStep 
)

We should not use this but...

End if(two_system == -1)...

Last Case : Two parametric Systems : ================ Begin treatement of two systemes ============

+++++++++++++++++++++++++++++++++++++++++++++++++++/// +++++++++ Now We have to calculate Normals ++++++++/// +++++++++++++++++++++++++++++++++++++++++++++++++++///

End of for(n=0; n<...)

++++++++++++++++++++++++++++++++++++++++++++++++++++/// ++++++++++++++++++++++++++++++++++++++++++++++++++++///

On va inclure cet objet dans un cube de langueur maximum egale a "hauteur_fenetre"

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/// +++++++++ Now we save all theses Arrays for further use +++++/// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++///

1) Save Vertex :

2) Save Index Polygones:

3) Nb Poly & Vertex :

Definition at line 3817 of file Model3D.cpp.

References parse_expression().

                                                                                                                      {
    double vals[] = {0,0,0,0,0,0};
    double vals2[] = {0,0,0,0,0,0};
    double iprime, jprime, valeur_de_fct_implicite, step_local;
    double spherical_val, cylindrical_val;
    int i, j, k, l=0, n, MorphDecalage;

parse_expression();

NbVertex = (nb_ligne)*(nb_colone);

morph_param = 0.0; // The starting point of the morph effect.
step_local = 1.0/(double)NbStep;
for(n=0; n<NbStep; n++) {

MorphDecalage = n*6*NbVertex;

// this is for the morph effect...
if(morph_param >= 0.0) {
 vals[2] = vals2[2] = morph_param ;
}
else {
 vals[2] = vals2[2] = -morph_param ;
}
morph_param += step_local;
if( morph_param == 1) morph_param = 0; /// We should not use this but...

//if( morph_param == 1) {step *=-1; morph_param += step;}
//if( morph_param  < 0) {step *=-1; morph_param += step;}
if ( supershape == 1){
double r1, r2;
  // Begin First case : n = 1, 3, 5.....
//  if(coefficent_fct_implicite_parity == 1)
    l=0;
    for(j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 );
    jprime = jprime * dif_u  + u_inf;
     for (i=0; i < nb_colone   ; i++)
       {
   iprime = (double)i/(double)(nb_colone -1 );
   iprime = iprime * dif_v + v_inf;
   r1 = pow(
        pow(fabs(cos(m1*jprime/4)/a_1), n2_1) +
        pow(fabs(sin(m1*jprime/4)/b_1), n3_1)
        , -1/n1_1);


   r2 = pow(
        pow(fabs(cos(m2*iprime/4)/a_2), n2_2) +
        pow(fabs(sin(m2*iprime/4)/b_2), n3_2)
        , -1/n1_2);


   NormVertexTab[l+3+MorphDecalage] = r1 * cos(jprime) * r2 * cos(iprime);
   NormVertexTab[l+4+MorphDecalage] = r1 * sin(jprime) * r2 * cos(iprime);
   NormVertexTab[l+5+MorphDecalage] = r2 * sin(iprime);
   l+=6;
  }       }
  // End of first case : n = 1, 3, 5.....
}
 else if (cylindricaldef == 1){
//  if(coefficent_fct_implicite_parity == 1)
    l =0;
    for(j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
  for (i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;

   vals[0]=jprime; vals[1]=iprime;   // u = jprime ; v = iprime;

   vals[3] = cos(jprime) ; // because  X = cos(u)
   vals[4] = sin(jprime);  // because  Y = sin(u)
   vals[5] = iprime  ;     // because  Z = v
   cylindrical_val = myParser_cylindrical.Eval(vals) ;

   (cylindrical_val  >= 0 ) ?
   cylindrical_val  =  pow(cylindrical_val, 1/coefficent_fct_implicite) :
   cylindrical_val  = -pow(-cylindrical_val, 1/coefficent_fct_implicite);

   NormVertexTab[l+3+MorphDecalage] = vals[3] * cylindrical_val;
   NormVertexTab[l+4+MorphDecalage] = vals[4] * cylindrical_val;
   NormVertexTab[l+5+MorphDecalage] = vals[5] ;
   l+=6;
  }      }
}
else if (sphericaldef == 1){
//  if(coefficent_fct_implicite_parity == 1)
    l=0;
    for(j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
     for (i=0; i < nb_colone   ; i++)
    {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;

   vals[0]=jprime; vals[1]=iprime;   // u = jprime ; v = iprime;

   vals[3] = cos(iprime)*cos(jprime) ; // because  X = cos(v)*cos(u)
   vals[4] = sin(iprime)*cos(jprime);  // because  Y = sin(v)*cos(u)
   vals[5] = sin(jprime)  ;            // because  Z = sin(u)
   spherical_val = myParser_spherical.Eval(vals) ;

   (spherical_val  >= 0 ) ?
   spherical_val  =  pow(spherical_val, 1/coefficent_fct_implicite) :
   spherical_val  = -pow(-spherical_val, 1/coefficent_fct_implicite);

   NormVertexTab[l+3+MorphDecalage] = vals[3] * spherical_val;
   NormVertexTab[l+4+MorphDecalage] = vals[4] * spherical_val;
   NormVertexTab[l+5+MorphDecalage] = vals[5] * spherical_val;
   l+=6;
  }
}
}
else
if(fourdimshapes == 1){
  l=0;
  for(j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
  for (i=0; i < nb_colone   ; i++)
  {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;

   vals[0]=jprime; vals[1]=iprime;

   vals[3] = NormVertexTab[l+3+MorphDecalage] = myParserX.Eval(vals);
   vals[4] = NormVertexTab[l+4+MorphDecalage] = myParserY.Eval(vals);
   NormVertexTab[l+5+MorphDecalage] = myParserZ.Eval(vals);
   l+=6;
  }     }
                  }
else
if(two_system == -1) {
 if(  implicitdef != 1 )    {
 // in this case we have a simple equation system...
  l=0;
  for(j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;

  for (i=0; i < nb_colone   ; i++)
  {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   vals[0]=jprime; vals[1]=iprime;

   vals[3] = NormVertexTab[l+3+MorphDecalage] = myParserX.Eval(vals);
   vals[4] = NormVertexTab[l+4+MorphDecalage] = myParserY.Eval(vals);
             NormVertexTab[l+5+MorphDecalage] = myParserZ.Eval(vals);
   l+=6;
  }
   } // End of if(there_is_condition == -1)
} // End  if(  implicitdef != 1 )
// here we are going to work with implicit equation...
 else
   {
  l=0;
  for(j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
  for (i=0; i < nb_colone   ; i++)
   {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   vals[0]=jprime; vals[1]=iprime;
   vals[3] = NormVertexTab[l+3+MorphDecalage] = jprime; // because  X = u
   vals[4] = NormVertexTab[l+4+MorphDecalage] = iprime; // because  Y = v

   valeur_de_fct_implicite = myParserZ.Eval(vals) ;
   (valeur_de_fct_implicite  >= 0 ) ?
   NormVertexTab[l+5+MorphDecalage] = pow(valeur_de_fct_implicite, 1/coefficent_fct_implicite) :
   NormVertexTab[l+5+MorphDecalage] = -pow(-valeur_de_fct_implicite, 1/coefficent_fct_implicite);
   l+=6;
  }
}
}
}/// End if(two_system == -1)...

/// Last Case : Two parametric Systems :
///================ Begin treatement of two systemes ============
 else {
 
 
  l=0;
  for(j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;

  for (i=0; i < nb_colone   ; i++)
  {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   vals[0]=jprime; vals[1]=iprime;

   vals[3] = NormVertexTab[l+3+MorphDecalage] = myParserX.Eval(vals);
   vals[4] = NormVertexTab[l+4+MorphDecalage] = myParserY.Eval(vals);
             NormVertexTab[l+5+MorphDecalage] = myParserZ.Eval(vals);
   l+=6;
  }
   }
 
 /*
moitie_colone = nb_colone/2;
   l=0;
// We begin with half of the grid...be careful...
  for(j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
  for (i=0; i < moitie_colone   ; i++)
{
   iprime = (double)i/(double)(moitie_colone -1 ) ;
   iprime = iprime * dif_v + v_inf;
   vals[0]=jprime; vals[1]=iprime;
   vals[3] = NormVertexTab[l+3+MorphDecalage] = myParserX.Eval(vals);
   vals[4] = NormVertexTab[l+4+MorphDecalage] = myParserY.Eval(vals);
   vals[5] = NormVertexTab[l+5+MorphDecalage] = myParserZ.Eval(vals);
   l+=6;
 }
}
/// we finish the remaining of the grid...
  for(j=0; j < nb_ligne; j++) {
    jprime = (double)j/(double)(nb_ligne -1);
    jprime = jprime * dif_u_2  + u_inf_2;
  for (i=moitie_colone; i < nb_colone; i++){
   iprime = (double)(i - moitie_colone)/(double)(nb_colone -1 -moitie_colone);
   iprime = iprime * dif_v_2 + v_inf_2;

   vals2[0]=jprime; vals2[1]=iprime;

   vals2[3] = NormVertexTab[l+3+MorphDecalage] = myParserX_2.Eval(vals2);
   vals2[4] = NormVertexTab[l+4+MorphDecalage] = myParserY_2.Eval(vals2);
   vals2[5] = NormVertexTab[l+5+MorphDecalage] = myParserZ_2.Eval(vals2);
   l+=6;
  }
}
*/
}

///+++++++++++++++++++++++++++++++++++++++++++++++++++///
///+++++++++ Now We have to calculate Normals ++++++++///
///+++++++++++++++++++++++++++++++++++++++++++++++++++///
int deplacement = 6*nb_colone;

  for (i=0; i < nb_ligne -1  ; i++)
   for (j=0; j < nb_colone -1  ; j++) {

caa = NormVertexTab[(i+1)*deplacement+j*6+4+MorphDecalage] - NormVertexTab[i*deplacement +j*6+4+MorphDecalage];
bab = NormVertexTab[i*deplacement+(j+1)*6+5+MorphDecalage] - NormVertexTab[i*deplacement +j*6+5+MorphDecalage];
cab = NormVertexTab[(i+1)*deplacement+j*6+5+MorphDecalage] - NormVertexTab[i*deplacement +j*6+5+MorphDecalage];
baa = NormVertexTab[i*deplacement+(j+1)*6+4+MorphDecalage] - NormVertexTab[i*deplacement +j*6+4+MorphDecalage];
ba  = NormVertexTab[i*deplacement+(j+1)*6+3+MorphDecalage] - NormVertexTab[i*deplacement +j*6+3+MorphDecalage];
ca  = NormVertexTab[(i+1)*deplacement+j*6+3+MorphDecalage] - NormVertexTab[i*deplacement +j*6+3+MorphDecalage];

NormVertexTab[i*deplacement +j*6   +MorphDecalage] = caa*bab - cab*baa;
NormVertexTab[i*deplacement +j*6 +1+MorphDecalage] = cab*ba  - ca*bab;
NormVertexTab[i*deplacement +j*6 +2+MorphDecalage] = ca*baa  - caa*ba;

double b4 = (double)sqrt(
       (NormVertexTab[i*deplacement +j*6  +MorphDecalage]*NormVertexTab[i*deplacement +j*6  +MorphDecalage+MorphDecalage]) +
       (NormVertexTab[i*deplacement +j*6+1+MorphDecalage]*NormVertexTab[i*deplacement +j*6+1+MorphDecalage+MorphDecalage]) +
       (NormVertexTab[i*deplacement +j*6+2+MorphDecalage]*NormVertexTab[i*deplacement +j*6+2+MorphDecalage+MorphDecalage]));

// This must be changed...
if(b4 > 0.00000001) {
 NormVertexTab[i*deplacement +j*6  +MorphDecalage]/=b4;
 NormVertexTab[i*deplacement +j*6+1+MorphDecalage]/=b4;
 NormVertexTab[i*deplacement +j*6+2+MorphDecalage]/=b4;
}
}

i = nb_ligne -1;
 for (j=0; j < nb_colone -1   ; j++) {
 NormVertexTab[i*deplacement +j*6  +MorphDecalage] = NormVertexTab[(i-1)*deplacement +j*6  +MorphDecalage];
 NormVertexTab[i*deplacement +j*6+1+MorphDecalage] = NormVertexTab[(i-1)*deplacement +j*6+1+MorphDecalage];
 NormVertexTab[i*deplacement +j*6+2+MorphDecalage] = NormVertexTab[(i-1)*deplacement +j*6+2+MorphDecalage];
 }

j =nb_colone -1;
 for (i=0; i < nb_ligne -1  ; i++) {
 NormVertexTab[i*deplacement +j*6  +MorphDecalage] = NormVertexTab[i*deplacement +(j-1)*6  +MorphDecalage];
 NormVertexTab[i*deplacement +j*6+1+MorphDecalage] = NormVertexTab[i*deplacement +(j-1)*6+1+MorphDecalage];
 NormVertexTab[i*deplacement +j*6+2+MorphDecalage] = NormVertexTab[i*deplacement +(j-1)*6+2+MorphDecalage];
 }

 i = nb_ligne -1; j =nb_colone -1;
 NormVertexTab[i*deplacement +j*6  +MorphDecalage]  = NormVertexTab[(i-1)*deplacement +(j-1)*6  +MorphDecalage];
 NormVertexTab[i*deplacement +j*6+1+MorphDecalage]  = NormVertexTab[(i-1)*deplacement +(j-1)*6+1+MorphDecalage];
 NormVertexTab[i*deplacement +j*6+2+MorphDecalage]  = NormVertexTab[(i-1)*deplacement +(j-1)*6+2+MorphDecalage];

} /// End of for(n=0; n<...)




///++++++++++++++++++++++++++++++++++++++++++++++++++++///
///++++++++++++++++++++++++++++++++++++++++++++++++++++///

// calcul des minimas et des maximas des coordonnees: X,Y et Z

MINX =999999999;//Tre2[0][0];
MINY =999999999;//Tre2[1][0];
MINZ =999999999;//Tre2[2][0];

MAXX =-999999999;//Tre2[0][0];
MAXY =-999999999;//Tre2[1][0];
MAXZ =-999999999;//Tre2[2][0];

 for (i=0; i < NbStep*NbVertex   ; i++) {
     if(MINX > NormVertexTab[i*6 + 3] ) MINX = NormVertexTab[i*6 + 3];

     if(MINY > NormVertexTab[i*6 + 4] ) MINY = NormVertexTab[i*6 + 4];

     if(MINZ > NormVertexTab[i*6 + 5] ) MINZ = NormVertexTab[i*6 + 5];

     if(MAXX < NormVertexTab[i*6 + 3] ) MAXX = NormVertexTab[i*6 + 3];

     if(MAXY < NormVertexTab[i*6 + 4] ) MAXY = NormVertexTab[i*6 + 4];

     if(MAXZ < NormVertexTab[i*6 + 5] ) MAXZ = NormVertexTab[i*6 + 5];
    }
// On recherche la plus grande "difference" de distance entre les points
// pour reduire la figure a un cube d'une longueur de 1.
// On utilisera apres cette figure pour l'agrandir et bien la placer dans
// la fenetre de vue:

  DIFX = MAXX - MINX ;
  DIFY = MAXY - MINY ;
  DIFZ = MAXZ - MINZ ;

// Recherche du maximum :
  DIFMAXIMUM = DIFX;

  if (DIFY > DIFMAXIMUM) {DIFMAXIMUM = DIFY;};
  if (DIFZ > DIFMAXIMUM) {DIFMAXIMUM = DIFZ;};

/// On va inclure cet objet dans un cube de langueur maximum
/// egale a "hauteur_fenetre"

double decalage_xo = -(MINX +MAXX)/2 ;
double decalage_yo = -(MINY +MAXY)/2 ;
double decalage_zo = -(MINZ +MAXZ)/2 ;
double rapport = hauteur_fenetre/DIFMAXIMUM;

 for (i=0; i < NbStep*NbVertex   ; i++) {
  NormVertexTab[i*6 + 3] = rapport * (NormVertexTab[i*6 + 3] + decalage_xo) ;
  NormVertexTab[i*6 + 4] = rapport * (NormVertexTab[i*6 + 4] + decalage_yo) ;
  NormVertexTab[i*6 + 5] = rapport * (NormVertexTab[i*6 + 5] + decalage_zo) ;
    }

MINX = rapport * (MINX + decalage_xo);
MINY = rapport * (MINY + decalage_yo);
MINZ = rapport * (MINZ + decalage_zo);

MAXX = rapport * (MAXX + decalage_xo);
MAXY = rapport * (MAXY + decalage_yo);
MAXZ = rapport * (MAXZ + decalage_zo);

///+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++///
///+++++++++ Now we save all theses Arrays for further use +++++///
///+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++///

/// 1) Save Vertex :
memcpy(NormVertexTabPt, NormVertexTab, NbStep*6*NbVertex*sizeof(GLfloat));


/// 2) Save Index Polygones:

   k=0;
   for (i=0; i< nb_ligne - coupure_ligne -1; i++)
      for (j=0; j< nb_colone - coupure_col -1; j++) {
     IndexPolyTab[k  ] = i*nb_colone + j;
     IndexPolyTab[k+1] = (i+1)*nb_colone + j;
     IndexPolyTab[k+2] = (i+1)*nb_colone + (j+1);
     IndexPolyTab[k+3] = i*nb_colone + (j+1);
     k+=4;
    }
NbPolygn = 4*(nb_ligne  - coupure_ligne -1)*(nb_colone - coupure_col -1);

    // Generate the Indices Tables for all Morph Frames :
  for(j =1; j < NbStep; j++)
    for(i =0; i < (int)NbPolygn; i++){
    IndexPolyTab[j*NbPolygn + i] = IndexPolyTab[i] + j*nb_ligne*nb_colone;
    }
memcpy(IndexPolyTabPt, IndexPolyTab, NbStep*NbPolygn*sizeof(GLuint));


/// 3) Nb Poly & Vertex :
 for(i =0; i < NbStep; i++) {
   NbPolygnNbVertex[2*i  ] = NbPolygn;
   NbPolygnNbVertex[2*i+1] = i*NbPolygn;//nb_ligne*nb_colone;
   };
memcpy(NbPolygnNbVertexPt, NbPolygnNbVertex, 2*NbStep*sizeof(GLuint));

 }


Generated by  Doxygen 1.6.0   Back to index