Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Object3D.cpp

Go to the documentation of this file.
00001 /* *************************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html
00017 ************************************************************************************* */
00018 
00019 #include "3d.h"
00020 #include "material.h"
00021 #include "object3d.h"
00022 
00023 #include "controlEngine.h"
00024 extern ControlEngine ce;
00025 
00026 /* ****************************************************************************
00027 **************************************************************************** */
00028 
00029 BOOL Object3D::DrawVectorMinMax(double x,double y,double minIntensity,double maxIntensity)
00030 {
00031         double intensity = sqrt(x*x+y*y);
00032         //MyDebug::SendEvent("draw vector","x:%lf y:%lf i:%lf",x,y,intensity);
00033         
00034         if (intensity<minIntensity) return FALSE;
00035         if (intensity>maxIntensity) 
00036         {
00037                 double angle=atan2(y,-x);
00038                 x=cos(angle)*maxIntensity;
00039                 y=sin(angle)*maxIntensity;
00040         }
00041         DrawVector(x,y);
00042         return TRUE;
00043 }
00044 
00049 void Object3D::DrawVector(double x,double y)
00050 {
00051         glDisable(GL_TEXTURE_2D);
00052         //glEnable(GL_BLEND);
00053         //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00054         double angle=atan2(y,-x)*(180.0/PI);
00055         double intensity = sqrt(x*x+y*y)/25.0;
00056 
00057         Point3D<double> rotate(0,0,angle);
00058 
00059         Material material;
00060         material.SetNull();
00061         //material.SetDS(0,0,1,0.5);
00062         material.emission.Set(0,0,1);
00063         material.Use();
00064 
00065         glPushMatrix();
00066         rotate.glRotated();
00067         glBegin(GL_POLYGON);
00068         glVertex2d(0,0);
00069         glVertex2d(intensity,0);
00070         glVertex2d(intensity-0.05,-0.05);
00071         glVertex2d(intensity-0.05,0.05);
00072         glVertex2d(intensity,0);
00073         glEnd();
00074         glPopMatrix();
00075         //glDisable(GL_BLEND);
00076 }
00077 
00078 void Object3D::DrawArrow(Color color)
00079 {
00080         glDisable(GL_BLEND);
00081         glDisable(GL_TEXTURE_2D);
00082         Material material;
00083 
00084         material.SetNull();
00085         material.emission = color;
00086         material.Use();
00087 
00088         // tracement des regions
00089         glBegin(GL_POLYGON);
00090         glVertex2d(0,0);
00091         glVertex2d(0,-0.2);
00092         glVertex2d(0.05,-0.15);
00093         glVertex2d(0.12,-0.3);
00094         glVertex2d(0.20,-0.22);
00095         glVertex2d(0.10,-0.10);
00096         glVertex2d(0.15,-0.06);
00097         glVertex2d(0,0);
00098         glEnd();
00099 
00100         // les contours
00101         material.emission.SetNull();
00102         material.Use();
00103         glBegin(GL_LINE_LOOP);
00104         glVertex2d(0,0);
00105         glVertex2d(0,-0.2);
00106         glVertex2d(0.05,-0.15);
00107         glVertex2d(0.12,-0.3);
00108         glVertex2d(0.2,-0.22);
00109         glVertex2d(0.10,-0.10);
00110         glVertex2d(0.15,-0.06);
00111         glEnd();
00112 }
00113 
00114 // ********************************************************************************
00115 
00116 void Object3D::DrawRepere()
00117 {
00118         glDisable(GL_BLEND);
00119         glDisable(GL_TEXTURE_2D);
00120 
00121         Material material;
00122         material.SetNull();
00123         
00124         GLUquadric *newQuadric = gluNewQuadric();
00125         gluQuadricNormals(newQuadric,GLU_NONE); // sinon influ de maniere misterieuse les autre normales
00126         double size=0.03;
00127         double baseSize=0.8;
00128         double arrowSize=0.3;
00129         double baseArrowSize=0.15;
00130 
00131         glPushMatrix(); // les Z
00132                 material.emission.Set(1,0,0);
00133                 material.Use();
00134                 gluCylinder(newQuadric,size,size,baseSize,3,3);
00135                 glTranslated(0,0,baseSize);
00136                 gluCylinder(newQuadric,baseArrowSize,0,arrowSize,3,3);
00137                 //glTranslated(0,0,0.5);
00138                 //DrawText("Z");
00139         glPopMatrix();
00140 
00141         glPushMatrix(); // les Y
00142                 material.emission.Set(0,1,0);
00143                 material.Use();
00144                 glRotated(-90,1,0,0);
00145                 gluCylinder(newQuadric,size,size,baseSize,3,3);
00146                 glTranslated(0,0,baseSize);
00147                 gluCylinder(newQuadric,baseArrowSize,0,arrowSize,3,3);
00148                 //glTranslated(0,0,0.5);
00149                 //DrawText("Y");
00150         glPopMatrix();
00151         
00152         glPushMatrix(); // les X
00153                 material.emission.Set(0,0,1);
00154                 material.Use();
00155                 glRotated(90,0,1,0);
00156                 gluCylinder(newQuadric,size,size,baseSize,3,3); 
00157                 glTranslated(0,0,baseSize);
00158                 gluCylinder(newQuadric,baseArrowSize,0,arrowSize,3,3);
00159                 //glTranslated(0,0,0.5);
00160                 //DrawText("X");
00161         glPopMatrix();
00162 
00163         gluDeleteQuadric(newQuadric);
00164         
00165         material.emission.SetNull();
00166         material.Use();
00167 }
00168 
00169 // ********************************************************************************
00170 
00171 void Object3D::DrawText(char *text)
00172 {
00173         //ce.fontTexture->Render(text);
00174 
00175         wglUseFontBitmaps (hDC, 0, 256, 1000); 
00176         glListBase (1000); 
00177         glRasterPos3d(0,0,0);
00178         glCallLists ((int)strlen(text),GL_BYTE,text); 
00179         glDeleteLists(1000,1);
00180 }

Generated on Fri Aug 20 19:19:48 2004 for 3d Controls by doxygen 1.3.6