00001
00007
00015 #ifdef WIN32
00016 #include <windows.h>
00017 #endif
00018 #ifdef __APPLE__
00019 #include <OpenGL/gl.h>
00020 #include <GLUT/glut.h>
00021 #else
00022 #include <GL/gl.h>
00023 #endif
00024
00025 #include <math.h>
00026
00027 #include "RenderRoutines.h"
00028
00032 bool RenderRoutines::isBounded() const {
00033 return true;
00034 }
00035
00036
00043 void RenderRoutines::draw( M3dView& view,
00044 const MDagPath& DGpath,
00045 M3dView::DisplayStyle style,
00046 M3dView::DisplayStatus status )
00047 {
00048
00049 view.beginGL();
00050
00051
00052 glPushAttrib( GL_CURRENT_BIT );
00053
00054 OnDraw(style,status);
00055
00056 glPopAttrib();
00057 view.endGL();
00058 }
00059
00060 void RenderRoutines::DrawSphere(const float r) {
00061 DrawCircleXY(r,30);
00062 DrawCircleXZ(r,30);
00063 DrawCircleYZ(r,30);
00064 }
00065
00066
00067
00068
00069
00070
00071 void RenderRoutines::DrawCrossXY(const float w,const float h) {
00072 glBegin(GL_LINES);
00073 glVertex3f( -0.5f*w, 0, 0 );
00074 glVertex3f( 0.5f*w, 0, 0 );
00075 glVertex3f( 0, 0.5f*h, 0 );
00076 glVertex3f( 0, -0.5f*h, 0 );
00077 glEnd();
00078 }
00079 void RenderRoutines::DrawCrossXZ(const float w,const float h) {
00080 glBegin(GL_LINES);
00081 glVertex3f( -0.5f*w, 0, 0 );
00082 glVertex3f( 0.5f*w, 0, 0 );
00083 glVertex3f( 0,0, 0.5f*h );
00084 glVertex3f( 0,0, -0.5f*h );
00085 glEnd();
00086 }
00087 void RenderRoutines::DrawCrossYZ(const float w,const float h) {
00088 glBegin(GL_LINES);
00089 glVertex3f( 0, -0.5f*w, 0 );
00090 glVertex3f( 0, 0.5f*w, 0 );
00091 glVertex3f( 0, 0, 0.5f*h );
00092 glVertex3f( 0, 0, -0.5f*h );
00093 glEnd();
00094 }
00095
00096
00097
00098
00099
00100 void RenderRoutines::DrawQuadXY(const float w,const float h) {
00101 glBegin(GL_LINE_LOOP);
00102 glVertex3f( -0.5f*w, -0.5f*h, 0 );
00103 glVertex3f( 0.5f*w, -0.5f*h, 0 );
00104 glVertex3f( 0.5f*w, 0.5f*h, 0 );
00105 glVertex3f( -0.5f*w, 0.5f*h, 0 );
00106 glEnd();
00107 }
00108 void RenderRoutines::DrawQuadXZ(const float w,const float h) {
00109 glBegin(GL_LINE_LOOP);
00110 glVertex3f( -0.5f*w, 0, -0.5f*h );
00111 glVertex3f( 0.5f*w, 0, -0.5f*h );
00112 glVertex3f( 0.5f*w, 0, 0.5f*h );
00113 glVertex3f( -0.5f*w, 0, 0.5f*h );
00114 glEnd();
00115 }
00116 void RenderRoutines::DrawQuadYZ(const float w,const float h) {
00117 glBegin(GL_LINE_LOOP);
00118 glVertex3f( 0, -0.5f*w, -0.5f*h );
00119 glVertex3f( 0, 0.5f*w, -0.5f*h );
00120 glVertex3f( 0, 0.5f*w, 0.5f*h );
00121 glVertex3f( 0, -0.5f*w, 0.5f*h );
00122 glEnd();
00123 }
00124
00125 void RenderRoutines::DrawFilledQuadXY(const float w,const float h) {
00126 glBegin(GL_QUADS);
00127 glVertex3f( -0.5f*w, -0.5f*h, 0 );
00128 glVertex3f( 0.5f*w, -0.5f*h, 0 );
00129 glVertex3f( 0.5f*w, 0.5f*h, 0 );
00130 glVertex3f( -0.5f*w, 0.5f*h, 0 );
00131 glEnd();
00132 }
00133 void RenderRoutines::DrawFilledQuadXZ(const float w,const float h) {
00134 glBegin(GL_QUADS);
00135 glVertex3f( -0.5f*w, 0, -0.5f*h );
00136 glVertex3f( 0.5f*w, 0, -0.5f*h );
00137 glVertex3f( 0.5f*w, 0, 0.5f*h );
00138 glVertex3f( -0.5f*w, 0, 0.5f*h );
00139 glEnd();
00140 }
00141 void RenderRoutines::DrawFilledQuadYZ(const float w,const float h) {
00142 glBegin(GL_QUADS);
00143 glVertex3f( 0, -0.5f*w, -0.5f*h );
00144 glVertex3f( 0, 0.5f*w, -0.5f*h );
00145 glVertex3f( 0, 0.5f*w, 0.5f*h );
00146 glVertex3f( 0, -0.5f*w, 0.5f*h );
00147 glEnd();
00148 }
00149
00150 void RenderRoutines::DrawCube(const float w,const float h,const float d) {
00151 glPushMatrix();
00152 glTranslatef(0,0,d/2);
00153 DrawQuadXY(w,h);
00154 glPopMatrix();
00155 glPushMatrix();
00156 glTranslatef(0,0,-d/2);
00157 DrawQuadXY(w,h);
00158 glPopMatrix();
00159
00160 glPushMatrix();
00161 glTranslatef(0,h/2,0);
00162 DrawQuadXZ(w,d);
00163 glPopMatrix();
00164 glPushMatrix();
00165 glTranslatef(0,-h/2,0);
00166 DrawQuadXZ(w,d);
00167 glPopMatrix();
00168
00169 glPushMatrix();
00170 glTranslatef(w/2,0,0);
00171 DrawQuadYZ(h,d);
00172 glPopMatrix();
00173 glPushMatrix();
00174 glTranslatef(-w/2,0,0);
00175 DrawQuadYZ(h,d);
00176 glPopMatrix();
00177 }
00178
00179 void RenderRoutines::DrawFilledCube(const float w,const float h,const float d) {
00180 glPushMatrix();
00181 glTranslatef(0,0,d/2);
00182 DrawFilledQuadXY(w,h);
00183 glPopMatrix();
00184 glPushMatrix();
00185 glTranslatef(0,0,-d/2);
00186 DrawFilledQuadXY(w,h);
00187 glPopMatrix();
00188
00189 glPushMatrix();
00190 glTranslatef(0,h/2,0);
00191 DrawFilledQuadXZ(w,d);
00192 glPopMatrix();
00193 glPushMatrix();
00194 glTranslatef(0,-h/2,0);
00195 DrawFilledQuadXZ(w,d);
00196 glPopMatrix();
00197
00198 glPushMatrix();
00199 glTranslatef(w/2,0,0);
00200 DrawFilledQuadYZ(h,d);
00201 glPopMatrix();
00202 glPushMatrix();
00203 glTranslatef(-w/2,0,0);
00204 DrawFilledQuadYZ(h,d);
00205 glPopMatrix();
00206 }
00207
00208
00209
00210
00211
00212 void RenderRoutines::DrawCylinderXY(const float r,const float h)
00213 {
00214 glPushMatrix();
00215 glTranslatef(0,0,h/2);
00216 DrawCircleXY(r,30);
00217 glPopMatrix();
00218 glPushMatrix();
00219 glTranslatef(0,0,-h/2);
00220 DrawCircleXY(r,30);
00221 glPopMatrix();
00222
00223 glBegin(GL_LINES);
00224 glVertex3f(r,0,-h/2);
00225 glVertex3f(r,0,h/2);
00226
00227 glVertex3f(-r,0,-h/2);
00228 glVertex3f(-r,0,h/2);
00229
00230 glVertex3f(0,r,-h/2);
00231 glVertex3f(0,r,h/2);
00232
00233 glVertex3f(0,-r,-h/2);
00234 glVertex3f(0,-r,h/2);
00235 glEnd();
00236 }
00237 void RenderRoutines::DrawCone(const float r,const float h)
00238 {
00239 glPushMatrix();
00240 glTranslatef(0,-h/2,0);
00241 DrawCircleXZ(r,30);
00242 glPopMatrix();
00243
00244 glBegin(GL_LINES);
00245 glVertex3f(r,-h/2,0);
00246 glVertex3f(0,h/2,0);
00247
00248 glVertex3f(-r,-h/2,0);
00249 glVertex3f(0,h/2,0);
00250
00251 glVertex3f(0,-h/2,r);
00252 glVertex3f(0,h/2,0);
00253
00254 glVertex3f(0,-h/2,-r);
00255 glVertex3f(0,h/2,0);
00256 glEnd();
00257 }
00258 void RenderRoutines::DrawCylinderXZ(const float r,const float h)
00259 {
00260 glPushMatrix();
00261 glTranslatef(0,h/2,0);
00262 DrawCircleXZ(r,30);
00263 glPopMatrix();
00264 glPushMatrix();
00265 glTranslatef(0,-h/2,0);
00266 DrawCircleXZ(r,30);
00267 glPopMatrix();
00268
00269 glBegin(GL_LINES);
00270 glVertex3f(r,-h/2,0);
00271 glVertex3f(r,h/2,0);
00272
00273 glVertex3f(-r,-h/2,0);
00274 glVertex3f(-r,h/2,0);
00275
00276 glVertex3f(0,-h/2,r);
00277 glVertex3f(0,h/2,r);
00278
00279 glVertex3f(0,-h/2,-r);
00280 glVertex3f(0,h/2,-r);
00281 glEnd();
00282 }
00283 void RenderRoutines::DrawCylinderYZ(const float r,const float h)
00284 {
00285 glPushMatrix();
00286 glTranslatef(h/2,0,0);
00287 DrawCircleYZ(r,30);
00288 glPopMatrix();
00289 glPushMatrix();
00290 glTranslatef(-h/2,0,0);
00291 DrawCircleYZ(r,30);
00292 glPopMatrix();
00293
00294 glBegin(GL_LINES);
00295 glVertex3f(-h/2,r,0);
00296 glVertex3f(h/2,r,0);
00297
00298 glVertex3f(-h/2,-r,0);
00299 glVertex3f(h/2,-r,0);
00300
00301 glVertex3f(-h/2,0,r);
00302 glVertex3f(h/2,0,r);
00303
00304 glVertex3f(-h/2,0,-r);
00305 glVertex3f(h/2,0,-r);
00306 glEnd();
00307 }
00308
00309
00310
00311
00312
00313 void RenderRoutines::DrawCircleXY(const float r,const int divs) {
00314 glBegin(GL_LINE_LOOP);
00315 for(int i=0;i!=divs;++i)
00316 {
00317 float angle = (i*360.0f/divs) * 3.1415926535898f/180.0f;
00318 float ca = cos(angle);
00319 float sa = sin(angle);
00320 glVertex3f(ca*r,sa*r,0.0f);
00321 }
00322 glEnd();
00323 }
00324 void RenderRoutines::DrawCircleXZ(const float r,const int divs) {
00325 glBegin(GL_LINE_LOOP);
00326 for(int i=0;i!=divs;++i)
00327 {
00328 float angle = (i*360.0f/divs) * 3.1415926535898f/180.0f;
00329 float ca = cos(angle);
00330 float sa = sin(angle);
00331 glVertex3f(ca*r,0.0f,sa*r);
00332 }
00333 glEnd();
00334 }
00335 void RenderRoutines::DrawCircleYZ(const float r,const int divs) {
00336 glBegin(GL_LINE_LOOP);
00337 for(int i=0;i!=divs;++i)
00338 {
00339 float angle = (i*360.0f/divs) * (3.1415926535898f/180.0f);
00340 float ca = cos(angle);
00341 float sa = sin(angle);
00342 glVertex3f(0.0f,ca*r,sa*r);
00343 }
00344 glEnd();
00345 }
00346 void RenderRoutines::DrawFilledCircleXY(const float r,const int divs) {
00347 glBegin(GL_POLYGON);
00348 for(int i=0;i!=divs;++i)
00349 {
00350 float angle = (i*360.0f/divs) * 3.1415926535898f/180.0f;
00351 float ca = cos(angle);
00352 float sa = sin(angle);
00353 glVertex3f(ca*r,sa*r,0.0f);
00354 }
00355 glEnd();
00356 }
00357 void RenderRoutines::DrawFilledCircleXZ(const float r,const int divs) {
00358 glBegin(GL_POLYGON);
00359 for(int i=0;i!=divs;++i)
00360 {
00361 float angle = (i*360.0f/divs) * 3.1415926535898f/180.0f;
00362 float ca = cos(angle);
00363 float sa = sin(angle);
00364 glVertex3f(ca*r,0.0f,sa*r);
00365 }
00366 glEnd();
00367 }
00368 void RenderRoutines::DrawFilledCircleYZ(const float r,const int divs) {
00369 glBegin(GL_POLYGON);
00370 for(int i=0;i!=divs;++i)
00371 {
00372 float angle = (i*360.0f/divs) * (3.1415926535898f/180.0f);
00373 float ca = cos(angle);
00374 float sa = sin(angle);
00375 glVertex3f(0.0f,ca*r,sa*r);
00376 }
00377 glEnd();
00378 }
00379
00380
00381
00382
00383
00384
00385
00386 void RenderRoutines::DrawArcXY(const float r,const float sa,const float ea,const int divs){
00387
00388 }
00389 void RenderRoutines::DrawArcXZ(const float r,const float sa,const float ea,const int divs){
00390
00391 }
00392 void RenderRoutines::DrawArcYZ(const float r,const float sa,const float ea,const int divs){
00393
00394 }
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 void RenderRoutines::DrawSpiralXY(const float sr,const float er,const float sa,const float ea,const float h,const int divs){
00405
00406 glPushMatrix();
00407 glTranslatef(0,0,-h/2);
00408 DrawCircleXY(sr,30);
00409 glPopMatrix();
00410 glPushMatrix();
00411 glTranslatef(0,0,h/2);
00412 DrawCircleXY(er,30);
00413 glPopMatrix();
00414
00415 glBegin(GL_LINE_STRIP);
00416 for(int i=0;i!=divs;++i)
00417 {
00418 float t = (float) i / (divs-1);
00419 float r = (1-t)*sr + t*er;
00420 float angle = (i*(ea-sa)/divs) * 3.1415926535898f/180.0f;
00421 float ca = cos(angle);
00422 float sa = sin(angle);
00423 glVertex3f(ca*r,sa*r,t*h -h/2);
00424 }
00425 glEnd();
00426 }
00427 void RenderRoutines::DrawSpiralXZ(const float sr,const float er,const float sa,const float ea,const float h,const int divs){
00428
00429 glPushMatrix();
00430 glTranslatef(0,-h/2,0);
00431 DrawCircleXZ(sr,30);
00432 glPopMatrix();
00433 glPushMatrix();
00434 glTranslatef(0,h/2,0);
00435 DrawCircleXZ(er,30);
00436 glPopMatrix();
00437
00438 glBegin(GL_LINE_STRIP);
00439 for(int i=0;i!=divs;++i)
00440 {
00441 float t = (float) i / (divs-1);
00442 float r = (1-t)*sr + t*er;
00443 float angle = (i*(ea-sa)/divs) * 3.1415926535898f/180.0f;
00444 float ca = cos(angle);
00445 float sa = sin(angle);
00446 glVertex3f(ca*r,t*h -h/2,sa*r);
00447 }
00448 glEnd();
00449 }
00450 void RenderRoutines::DrawSpiralYZ(const float sr,const float er,const float sa,const float ea,const float h,const int divs){
00451
00452 glPushMatrix();
00453 glTranslatef(-h/2,0,0);
00454 DrawCircleXZ(sr,30);
00455 glPopMatrix();
00456 glPushMatrix();
00457 glTranslatef(h/2,0,0);
00458 DrawCircleXZ(er,30);
00459 glPopMatrix();
00460
00461 glBegin(GL_LINE_STRIP);
00462 for(int i=0;i!=divs;++i)
00463 {
00464 float t = (float) i / (divs-1);
00465 float r = (1-t)*sr + t*er;
00466 float angle = (i*(ea-sa)/divs) * 3.1415926535898f/180.0f;
00467 float ca = cos(angle);
00468 float sa = sin(angle);
00469 glVertex3f(t*h -h/2,ca*r,sa*r);
00470 }
00471 glEnd();
00472 }