/* -- Now the various shapes involving circles -- */
/*
* Compute lookup table of cos and sin values forming a circle
+ * (or half circle if halfCircle==TRUE)
*
* Notes:
* It is the responsibility of the caller to free these tables
* The last entry is exactly the same as the first
* The sign of n can be flipped to get the reverse loop
*/
-static void fghCircleTable(double **sint,double **cost,const int n)
+static void fghCircleTable(GLdouble **sint, GLdouble **cost, const int n, const GLboolean halfCircle)
{
int i;
-
+
/* Table size, the sign of n flips the circle direction */
-
const int size = abs(n);
/* Determine the angle between samples */
-
- const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
+ const GLdouble angle = (halfCircle?1:2)*M_PI/(GLdouble)( ( n == 0 ) ? 1 : n );
/* Allocate memory for n samples, plus duplicate of first entry at the end */
-
- *sint = (double *) calloc(sizeof(double), size+1);
- *cost = (double *) calloc(sizeof(double), size+1);
+ *sint = malloc(sizeof(GLdouble) * (size+1));
+ *cost = malloc(sizeof(GLdouble) * (size+1));
/* Bail out if memory allocation fails, fgError never returns */
-
if (!(*sint) || !(*cost))
{
free(*sint);
}
/* Compute cos and sin around the circle */
-
(*sint)[0] = 0.0;
(*cost)[0] = 1.0;
(*cost)[i] = cos(angle*i);
}
- /* Last sample is duplicate of the first */
-
- (*sint)[size] = (*sint)[0];
- (*cost)[size] = (*cost)[0];
+
+ if (halfCircle)
+ {
+ (*sint)[size] = 0.0; /* sin PI */
+ (*cost)[size] = -1.0; /* cos PI */
+ }
+ else
+ {
+ /* Last sample is duplicate of the first (sin or cos of 2 PI) */
+ (*sint)[size] = (*sint)[0];
+ (*cost)[size] = (*cost)[0];
+ }
}
vertices = cube_verts;
if (useWireMode)
- fghDrawGeometryWire (vertices ,cube_norms, CUBE_NUM_FACES,CUBE_NUM_EDGE_PER_FACE);
+ fghDrawGeometryWire (vertices,cube_norms, CUBE_NUM_FACES,CUBE_NUM_EDGE_PER_FACE);
else
- fghDrawGeometrySolid(vertices ,cube_norms,cube_vertIdxs,CUBE_VERT_PER_OBJ_TRI, CUBE_NUM_EDGE_PER_FACE);
+ fghDrawGeometrySolid(vertices,cube_norms,cube_vertIdxs,CUBE_VERT_PER_OBJ_TRI, CUBE_NUM_EDGE_PER_FACE);
if (dSize!=1.)
/* cleanup allocated memory */
/* Adjust z and radius as stacks are drawn. */
- double z0,z1;
- double r0,r1;
+ GLdouble z0,z1;
+ GLdouble r0,r1;
/* Pre-computed circle */
- double *sint1,*cost1;
- double *sint2,*cost2;
+ GLdouble *sint1,*cost1;
+ GLdouble *sint2,*cost2;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
- fghCircleTable(&sint1,&cost1,-slices);
- fghCircleTable(&sint2,&cost2,stacks*2);
+ fghCircleTable(&sint1,&cost1,-slices,FALSE);
+ fghCircleTable(&sint2,&cost2, stacks,TRUE);
/* The top stack is covered with a triangle fan */
/* Adjust z and radius as stacks and slices are drawn. */
- double r;
- double x,y,z;
+ GLdouble r;
+ GLdouble x,y,z;
/* Pre-computed circle */
- double *sint1,*cost1;
- double *sint2,*cost2;
+ GLdouble *sint1,*cost1;
+ GLdouble *sint2,*cost2;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
- fghCircleTable(&sint1,&cost1,-slices );
- fghCircleTable(&sint2,&cost2, stacks*2);
+ fghCircleTable(&sint1,&cost1,-slices,FALSE);
+ fghCircleTable(&sint2,&cost2, stacks,TRUE);
/* Draw a line loop for each stack */
x = cost1[i]*sint2[j];
y = sint1[i]*sint2[j];
z = cost2[j];
+ printf("j(%i):%1.3f\n",j,z);
glNormal3d(x,y,z);
glVertex3d(x*radius,y*radius,z*radius);
/* Step in z and radius as stacks are drawn. */
- double z0,z1;
- double r0,r1;
+ GLdouble z0,z1;
+ GLdouble r0,r1;
- const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
- const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
+ const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
+ const GLdouble rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
/* Scaling factors for vertex normals */
- const double cosn = ( height / sqrt ( height * height + base * base ));
- const double sinn = ( base / sqrt ( height * height + base * base ));
+ const GLdouble cosn = ( height / sqrt ( height * height + base * base ));
+ const GLdouble sinn = ( base / sqrt ( height * height + base * base ));
/* Pre-computed circle */
- double *sint,*cost;
+ GLdouble *sint,*cost;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
- fghCircleTable(&sint,&cost,-slices);
+ fghCircleTable(&sint,&cost,-slices,FALSE);
/* Cover the circular base with a triangle fan... */
/* Step in z and radius as stacks are drawn. */
- double z = 0.0;
- double r = base;
+ GLdouble z = 0.0;
+ GLdouble r = base;
- const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
- const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
+ const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
+ const GLdouble rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
/* Scaling factors for vertex normals */
- const double cosn = ( height / sqrt ( height * height + base * base ));
- const double sinn = ( base / sqrt ( height * height + base * base ));
+ const GLdouble cosn = ( height / sqrt ( height * height + base * base ));
+ const GLdouble sinn = ( base / sqrt ( height * height + base * base ));
/* Pre-computed circle */
- double *sint,*cost;
+ GLdouble *sint,*cost;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
- fghCircleTable(&sint,&cost,-slices);
+ fghCircleTable(&sint,&cost,-slices,FALSE);
/* Draw the stacks... */
/* Step in z and radius as stacks are drawn. */
- double z0,z1;
- const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
+ GLdouble z0,z1;
+ const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
/* Pre-computed circle */
- double *sint,*cost;
+ GLdouble *sint,*cost;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
- fghCircleTable(&sint,&cost,-slices);
+ fghCircleTable(&sint,&cost,-slices,FALSE);
/* Cover the base and top */
/* Step in z and radius as stacks are drawn. */
- double z = 0.0;
- const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
+ GLdouble z = 0.0;
+ const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
/* Pre-computed circle */
- double *sint,*cost;
+ GLdouble *sint,*cost;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
- fghCircleTable(&sint,&cost,-slices);
+ fghCircleTable(&sint,&cost,-slices,FALSE);
/* Draw the stacks... */
*/
void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
{
- double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
- double *vertex, *normal;
+ GLdouble iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
+ GLdouble *vertex, *normal;
int i, j;
- double spsi, cpsi, sphi, cphi ;
+ GLdouble spsi, cpsi, sphi, cphi ;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
if ( nRings < 1 ) nRings = 1;
/* Allocate the vertices array */
- vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
- normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
+ vertex = (GLdouble *)calloc( sizeof(GLdouble), 3 * nSides * nRings );
+ normal = (GLdouble *)calloc( sizeof(GLdouble), 3 * nSides * nRings );
glPushMatrix();
- dpsi = 2.0 * M_PI / (double)nRings ;
- dphi = -2.0 * M_PI / (double)nSides ;
+ dpsi = 2.0 * M_PI / (GLdouble)nRings ;
+ dphi = -2.0 * M_PI / (GLdouble)nSides ;
psi = 0.0;
for( j=0; j<nRings; j++ )
*/
void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
{
- double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
- double *vertex, *normal;
+ GLdouble iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
+ GLdouble *vertex, *normal;
int i, j;
- double spsi, cpsi, sphi, cphi ;
+ GLdouble spsi, cpsi, sphi, cphi ;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
nRings ++ ;
/* Allocate the vertices array */
- vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
- normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
+ vertex = (GLdouble *)calloc( sizeof(GLdouble), 3 * nSides * nRings );
+ normal = (GLdouble *)calloc( sizeof(GLdouble), 3 * nSides * nRings );
glPushMatrix();
- dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
- dphi = -2.0 * M_PI / (double)(nSides - 1) ;
+ dpsi = 2.0 * M_PI / (GLdouble)(nRings - 1) ;
+ dphi = -2.0 * M_PI / (GLdouble)(nSides - 1) ;
psi = 0.0;
for( j=0; j<nRings; j++ )