00001
00002
00003
00004
00005
00006
00007
00038
00039
00040
00041
00042 #ifdef _WIN32
00043 #include <windows.h>
00044 #endif
00045 #include <stdlib.h>
00046 #include <stdio.h>
00047 #include <math.h>
00048 #include <GL/gl.h>
00049 #include <GL/glu.h>
00050
00051 #include "prm.h"
00052 #include "circ.h"
00053 #include "cd.h"
00054 #include "wd.h"
00055 #include "dsp.h"
00056
00057
00058
00059
00060
00061
00062 #define CIRC_SEGS 32
00063
00064 #ifndef M_PI
00065 #define M_PI 3.141592654
00066 #endif
00067
00070 struct _circ {
00072 Coord c;
00074 double r;
00075 };
00076
00077
00078
00079
00080
00081
00082
00083
00084 static void circGetLateralNormal( Circ *circ, Coord *p, Coord *normal );
00085
00086
00087
00088 static void circGetLateralNormal( Circ *circ, Coord *p, Coord *normal )
00089 {
00090 double len;
00091 normal->x = p->x - circ->c.x;
00092 normal->y = p->y - circ->c.y;
00093 len = sqrt( normal->x*normal->x + normal->y*normal->y );
00094 normal->x /= len;
00095 normal->y /= len;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105 Circ *circCreate( void )
00106 {
00107 Circ *circ;
00108
00109
00110
00111 circ = malloc( sizeof( Circ ) );
00112 if( circ == NULL )
00113 return( NULL );
00114
00115
00116
00117 circ->c.x = 0.0;
00118 circ->c.y = 0.0;
00119 circ->r = 1.0;
00120
00121 return( circ );
00122 }
00123
00124
00125
00126 void circDelete( Circ *circ )
00127 {
00128 free( circ );
00129 }
00130
00131
00132
00133 void circRead( Circ *circ, FILE *fd )
00134 {
00135
00136 }
00137
00138
00139
00140 void circWrite( Circ *circ, FILE *fd )
00141 {
00142
00143 }
00144
00145
00146
00147 int circGetNPts( Circ *circ )
00148 {
00149 return( 4 );
00150 }
00151
00152
00153
00154 void circSetCoords( Circ *circ, int id, double x, double y )
00155 {
00156
00157 }
00158
00159
00160
00161 void circGetCoords( Circ *circ, int id, double *x, double *y )
00162 {
00163
00164 }
00165
00166
00167
00168 void circSet1stPt( Circ *circ, double x, double y )
00169 {
00170
00171 }
00172
00173
00174
00175 void circSet2ndPt( Circ *circ, double x, double y )
00176 {
00177
00178 }
00179
00180
00181
00182 int circPickArea( Circ *circ, double x, double y )
00183 {
00184
00185
00186 return( 0 );
00187 }
00188
00189
00190
00191 int circPickVertex( Circ *circ, double x, double y, double tol,
00192 int *id )
00193 {
00194
00195
00196 return( 0 );
00197 }
00198
00199
00200
00201 int circPickSide( Circ *circ, double x, double y, double tol,
00202 int *id )
00203 {
00204 return( 0 );
00205 }
00206
00207
00208
00209 void circTranslate( Circ *circ, double dx, double dy )
00210 {
00211
00212 }
00213
00214
00215
00216 void circTranslateVertex( Circ *circ, int id, double dx, double dy )
00217 {
00218
00219 }
00220
00221
00222
00223 void circTranslateSide( Circ *circ, int id, double dx, double dy )
00224 {
00225 }
00226
00227
00228
00229 void circGetBox( Circ *circ, double *xmin, double *xmax,
00230 double *ymin, double *ymax )
00231 {
00232
00233 }
00234
00235
00236
00237 void circDisplayBoundary( Circ *circ )
00238 {
00239
00240 }
00241
00242
00243
00244 void circDisplayInterior( Circ *circ )
00245 {
00246
00247 }
00248
00249
00250
00251 void circDisplaySolid( Circ *circ, double height )
00252 {
00253
00254
00255
00256 }
00257
00258
00259
00260 void circHighltSolid( Circ *circ, double height )
00261 {
00262
00263
00264 }
00265
00266
00267
00268 void circDisplayZbuffer( Circ *circ, double height, long int color )
00269 {
00270 Coord p[32];
00271 Coord normal;
00272 double alpha;
00273 double delta = 2*M_PI/CIRC_SEGS;
00274 Coord midpt;
00275 int i;
00276
00277
00278
00279 alpha = 0.0;
00280 for( i = 0; i < CIRC_SEGS; i++ )
00281 {
00282 p[i].x = circ->c.x + circ->r * cos( alpha );
00283 p[i].y = circ->c.y + circ->r * sin( alpha );
00284 alpha += delta;
00285 }
00286
00287
00288
00289
00290 for( i = 0; i < CIRC_SEGS; i++ )
00291 {
00292 dspZbfBeginPoly( color, 0.0, 0.0, -1.0 );
00293 dspZbfVertex( circ->c.x, circ->c.y, 0.0 );
00294 dspZbfVertex( p[(i+1)%CIRC_SEGS].x, p[(i+1)%CIRC_SEGS].y, 0.0 );
00295 dspZbfVertex( p[i].x, p[i].y, 0.0 );
00296 dspZbfEndPoly( );
00297 }
00298
00299
00300
00301 if( height == 0.0 )
00302 {
00303 return;
00304 }
00305
00306
00307
00308 for( i = 0; i < CIRC_SEGS; i++ )
00309 {
00310 dspZbfBeginPoly( color, 0.0, 0.0, 1.0 );
00311 dspZbfVertex( circ->c.x, circ->c.y, height );
00312 dspZbfVertex( p[(i+1)%CIRC_SEGS].x, p[(i+1)%CIRC_SEGS].y, height );
00313 dspZbfVertex( p[i].x, p[i].y, height );
00314 dspZbfEndPoly( );
00315 }
00316
00317
00318
00319 for( i = 0; i < CIRC_SEGS; i++ )
00320 {
00321 midpt.x = (p[i].x + p[(i+1)%CIRC_SEGS].x) * 0.5;
00322 midpt.y = (p[i].y + p[(i+1)%CIRC_SEGS].y) * 0.5;
00323 circGetLateralNormal( circ, &midpt, &normal );
00324 dspZbfBeginPoly( color, normal.x, normal.y, 0.0 );
00325 dspZbfVertex( p[i].x, p[i].y, height );
00326 dspZbfVertex( p[i].x, p[i].y, 0.0 );
00327 dspZbfVertex( p[(i+1)%CIRC_SEGS].x, p[(i+1)%CIRC_SEGS].y, 0.0 );
00328 dspZbfVertex( p[(i+1)%CIRC_SEGS].x, p[(i+1)%CIRC_SEGS].y, height );
00329 dspZbfEndPoly( );
00330 }
00331 }
00332
00334 midpt, &normal );
00335 dspZbfBeginPoly( color, normal.x, normal.y, 0.0 );
00336 dspZbfVertex( p[i].x, p[i].y, height );
00337 dspZbfVertex( p[i].x, p[i].y, 0.0 );
00338 dspZbfVertex( p[(i+1)%CIRC_SEGS].x, p[(i+1)%CIRC_SEGS].y, 0.0 );
00339 dspZbfVertex( p[(i+1)%CIRC_SEGS].x, p[(i+1)%CIRC_SEGS].y, height );
00340 dspZbfEndPoly( );
00341 }
00342 }
00343