wolfganeLe 12/06/2005 à 20:39
Une petite optimisation :
/* ====================================================== */
/* = Function : Drawing Sphere = */
/* = Input : X,Y, ray, Phase & angleY, angleX = */
/* = Angles are used for projection formula = */
/* = Output : - = */
/* ====================================================== */
void DrawSphere(unsigned short x, unsigned short y, unsigned short r, float phase, float angleY, float angleX)
{
// real sphere coords
float xa = 0.0,
ya = 0.0,
za = 0.0;
// computation var.
float a = 0.0,
b = 0.0,
j = 0.0;
// counter for latitudes
short int latitude = 0,
longitude = 0,
delta = 0;
short int vertex = 180;
short tab[vertex][2];
//-----------------------------------------------------------
// computing sphericals points
for( a=-PI/2.0 ; a<=PI/2.0 ; a+=SPHERE_PRECISION,latitude++)
{
if(phase>PI)
{
b=phase-PI;
j=PI;
}
else
{
b=0.0;
j=phase;
}
// compute all the line
while(b<=j)
{
xa = (cos(a)*cos(b));
ya = (cos(a)*sin(b));
za = sin(a);
xa *= r;
ya *= r;
za *= r;
tab[longitude][0] = (unsigned short)Int_Float(xa*sin(angleX)+ya*-cos(angleX));
tab[longitude][1] = (unsigned short)Int_Float(za+ya*sin(angleY));
b+=SPHERE_PRECISION;
longitude++;
}
}
delta = (short)ceil((float)(longitude/latitude));
// drawing latitude lines with computed points
for(longitude=0,latitude=1;longitude<(vertex-delta);longitude++,latitude++)
{
if(latitude>=delta)
{
latitude=1;
longitude++;
}
DrawLine(tab[longitude][0]+x,tab[longitude][1]+y,tab[longitude+1][0]+x,tab[longitude+1][1]+y,A_NORMAL);
}
// drawing longitude lines with latitude's points computed before
for(longitude=0;longitude<(vertex-delta);longitude++)
DrawLine(tab[longitude][0]+x,tab[longitude][1]+y,tab[longitude+delta][0]+x,tab[longitude+delta][1]+y,A_NORMAL);
}