00001
00014 #ifndef _WRAPGL_H
00015 #define _WRAPGL_H
00016
00017 #include <GL/glut.h>
00018 #include <Rect.H>
00019 #include <Frenet.H>
00020 #include <RGB.H>
00021 #include <UserInterface.H>
00022
00023 namespace xchen
00024 {
00025 enum Axis { NegXDir, PosXDir, NegYDir, PosYDir, NegZDir, PosZDir };
00026
00027 void xglCylinder( GLUquadric* quad, GLdouble base=.5, GLdouble top=.5, GLdouble height=1.0,
00028 GLdouble base_at=0, GLint slices=200, GLint stacks=200, Axis dir=PosXDir );
00029 void xglDisk(GLUquadric* quad, GLdouble inner_r, GLdouble outer_r, GLdouble at=0, GLint slices=200, GLint rings=200, Axis dir=PosXDir );
00030 void wglCone(double bs=0.5, double h=1.0, double top = 0, Axis align = PosZDir, GLint slices=200, GLint stacks=200);
00031
00032 void wglArrow();
00033 void wglArrow(const dVector3D& dir, const RGBAS&);
00034
00035 void wglCircle(const dPoint3D& center, double r, const RGB& col=White, int segments = 100);
00036 void wgl2DStar(const dPoint2D& pnt);
00037 void wglXYZAxes(float scale=1.0);
00038 void wglFrame(const Frame& frm, float scale = 1.0);
00039 void wglFrenet(const Frenet& frt, float frmscale = 1.0);
00040 void wglFrames( vector<Frame> :: const_iterator iter, vector<Frame> :: const_iterator stop );
00041 void wglFrenets( vector<Frenet> :: const_iterator iter, vector<Frenet> :: const_iterator stop );
00042
00043 template<class T, int dim>
00044 void wglPolyLine( const vector< Point<T, dim> >& pnts )
00045 {
00046 glDisable(GL_LIGHTING);
00047 {
00048 if(cur_glmodel_ui->GetfloatControl("Line Width") == 0 )
00049 {
00050 glPointSize( cur_glmodel_ui->GetfloatControl("Point Size") );
00051 glBegin(GL_POINTS);
00052 }
00053 else
00054 glBegin(GL_LINE_STRIP);
00055
00056 for(typename vector< Point<T, dim> > :: const_iterator iter = pnts.begin(); iter != pnts.end(); iter++)
00057 wglVertex( *iter );
00058
00059 glEnd();
00060 }
00061 glEnable(GL_LIGHTING);
00062 }
00063
00064
00065 inline void wglViewport(const GLViewPort& gl_viewport)
00066 {
00067 glViewport(gl_viewport.StartX(),gl_viewport.StartY(),gl_viewport.Width(),gl_viewport.Height());
00068 }
00069
00070 void wglOrtho(const dPoint2D& min, const dPoint2D& max);
00071 void wglOrtho(const dPoint3D& min, const dPoint3D& max);
00072
00073
00074 inline void wglTranslate(const dVector3D& v) { glTranslated(v[0], v[1], v[2]); }
00075 inline void wglTranslate(const fVector3D& v) { glTranslatef(v[0], v[1], v[2]); }
00076 inline void wglTranslate(const iVector3D& v) { glTranslatef(v[0], v[1], v[2]); }
00077
00078 inline void wglScale(float s) { glScalef(s,s,s); }
00079 inline void wglScale(double s) { glScaled(s,s,s); }
00080 inline void wglScale(int s) { glScalef(s,s,s); }
00081
00082 inline void wglScale(const fVector3D& v) { glScalef(v[0],v[1],v[2]); }
00083 inline void wglScale(const dVector3D& v) { glScaled(v[0],v[1],v[2]); }
00084 inline void wglScale(const iVector3D& v) { glScalef(v[0],v[1],v[2]); }
00085
00086
00087 inline void wglRotate(const fVector3D& angles)
00088 {
00089 glRotatef(angles[0], 1,0,0);
00090 glRotatef(angles[1], 0,1,0);
00091 glRotatef(angles[2], 0,0,1);
00092 }
00093
00094 inline void wglRotate(const dVector3D& rot_dir, double rot_angle)
00095
00096 {
00097 glRotated(rot_angle, rot_dir[0], rot_dir[1], rot_dir[2]);
00098 }
00099 inline void wglRotate(double rot_angle, const dVector3D& rot_dir)
00100
00101 {
00102 glRotated(rot_angle, rot_dir[0], rot_dir[1], rot_dir[2]);
00103 }
00104
00105 inline void wglRotateTo(const dVector3D& from, const dVector3D& to)
00106
00107 {
00108 wglRotate(from^to, from.Angle(to));
00109 }
00110
00111
00112
00113 inline void wglClearColor (const RGBA& rgba)
00114 {
00115 glClearColor(rgba[0], rgba[1], rgba[2], rgba[2]);
00116 }
00117
00118 inline void wglColor(const fVector3D& col)
00119 {
00120 glColor3f(col[0], col[1], col[2]);
00121 }
00122
00123 inline void wglColorHSV(const HSV& hsv)
00124 {
00125 HSV col(hsv); HSV2RGB(col); wglColor(col);
00126 }
00127
00128 inline void wglNormal(const dPoint3D& v)
00129 {
00130 glNormal3d(v[0], v[1], v[2]);
00131 }
00132 inline void wglNormal(const dPoint3D* v)
00133 {
00134 wglNormal(*v);
00135 }
00136 inline void wglNormal(const fPoint3D& v)
00137 {
00138 glNormal3f(v[0], v[1], v[2]);
00139 }
00140 inline void wglNormal(const fPoint3D* v)
00141 {
00142 wglNormal(*v);
00143 }
00144 inline void wglNormal(const iPoint3D& v)
00145 {
00146 glNormal3i(v[0], v[1], v[2]);
00147 }
00148 inline void wglNormal(const iPoint3D* v)
00149 {
00150 wglNormal(*v);
00151 }
00152
00153
00154 inline void wglTexCoord(const dPoint2D& v)
00155 {
00156 glTexCoord2d(v[0], v[1]);
00157 }
00158 inline void wglTexCoord(const dPoint2D* v)
00159 {
00160 wglTexCoord(*v);
00161 }
00162 inline void wglTexCoord(const fPoint2D& v)
00163 {
00164 glTexCoord2f(v[0], v[1]);
00165 }
00166 inline void wglTexCoord(const fPoint2D* v)
00167 {
00168 wglTexCoord(*v);
00169 }
00170 inline void wglTexCoord(const iPoint2D& v)
00171 {
00172 glTexCoord2i(v[0], v[1]);
00173 }
00174 inline void wglTexCoord(const iPoint2D* v)
00175 {
00176 wglTexCoord(*v);
00177 }
00178
00179
00180 inline void wglTexCoord(const dPoint3D& v)
00181 {
00182 glTexCoord3d(v[0], v[1], v[2]);
00183 }
00184 inline void wglTexCoord(const dPoint3D* v)
00185 {
00186 wglTexCoord(*v);
00187 }
00188 inline void wglTexCoord(const fPoint3D& v)
00189 {
00190 glTexCoord3f(v[0], v[1], v[2]);
00191 }
00192 inline void wglTexCoord(const fPoint3D* v)
00193 {
00194 wglTexCoord(*v);
00195 }
00196 inline void wglTexCoord(const iPoint3D& v)
00197 {
00198 glTexCoord3i(v[0], v[1], v[2]);
00199 }
00200 inline void wglTexCoord(const iPoint3D* v)
00201 {
00202 wglTexCoord(*v);
00203 }
00204
00205
00206 inline void wglRect(const Rect<float>& r)
00207 {
00208 float sx = r.StartX(), sy = r.StartY();
00209 glRectf(sx, sy, sx + r.Width(), sy + r.Height());
00210 }
00211 inline void wglRect(const dRect& r)
00212 {
00213 double sx = r.StartX(), sy = r.StartY();
00214 glRectd(sx, sy, sx + r.Width(), sy + r.Height());
00215 }
00216 inline void wglRect(const iRect& r)
00217 {
00218 int sx = r.StartX(), sy = r.StartY();
00219 glRecti(sx, sy, sx + r.Width(), sy + r.Height());
00220 }
00221
00222
00223
00224 void wglText(bool fixed, const dPoint3D& pos, char* str, bool large_font = false, const RGB& col = White);
00225 void wglDrawMarkSquare(double u, double v, double z=-1, const RGB& col=Magenta, int sz=5);
00226
00227 inline void wglText(bool fixed, double x, double y, char* str, bool large_font = false, const RGB& col = White)
00228
00229 {
00230 wglText(fixed, dPoint3D(x,y,0), str, large_font, col);
00231 }
00232
00233 inline void wglFixedPositionText(const dPoint3D& pos, char* str, bool large_font = false, const RGB& col = White)
00234
00235 {
00236 wglText(true, pos, str, large_font, col);
00237 }
00238 inline void wglFixedPositionText(double x, double y, char* str, bool large_font = false, const RGB& col = White)
00239
00240 {
00241 wglFixedPositionText(dPoint3D(x,y,0), str, large_font, col);
00242 }
00243
00244
00245
00246 inline void wglNonFixedPositionText(const dPoint3D& pos, char* str, bool large_font = false, const RGB& col = White)
00247
00248 {
00249 wglText(false, pos, str, large_font, col);
00250 }
00251 inline void wglNonFixedPositionText(double x, double y, char* str, bool large_font = false, const RGB& col = White)
00252
00253 {
00254 wglNonFixedPositionText(dPoint3D(x,y,0), str, large_font, col);
00255 }
00256
00257
00258 inline void _wglVertex(const iPoint2D& v) { glVertex2iv(v.GetData()); }
00259 inline void _wglVertex(const iPoint2D* v) { glVertex2iv(v->GetData()); }
00260 inline void _wglVertex(const iPoint3D& v) { glVertex3iv(v.GetData()); }
00261 inline void _wglVertex(const iPoint3D* v) { glVertex3iv(v->GetData()); }
00262 inline void _wglVertex(const iPoint4D& v) { glVertex4iv(v.GetData()); }
00263 inline void _wglVertex(const iPoint4D* v) { glVertex4iv(v->GetData()); }
00264
00265 inline void _wglVertex(const fPoint2D& v) { glVertex2fv(v.GetData()); }
00266 inline void _wglVertex(const fPoint2D* v) { glVertex2fv(v->GetData()); }
00267 inline void _wglVertex(const fPoint3D& v) { glVertex3fv(v.GetData()); }
00268 inline void _wglVertex(const fPoint3D* v) { glVertex3fv(v->GetData()); }
00269 inline void _wglVertex(const fPoint4D& v) { glVertex4fv(v.GetData()); }
00270 inline void _wglVertex(const fPoint4D* v) { glVertex4fv(v->GetData()); }
00271
00272 inline void _wglVertex(const dPoint2D& v) { glVertex2dv(v.GetData()); }
00273 inline void _wglVertex(const dPoint2D* v) { glVertex2dv(v->GetData()); }
00274 inline void _wglVertex(const dPoint3D& v) { glVertex3dv(v.GetData()); }
00275 inline void _wglVertex(const dPoint3D* v) { glVertex3dv(v->GetData()); }
00276 inline void _wglVertex(const dPoint4D& v) { glVertex4dv(v.GetData()); }
00277 inline void _wglVertex(const dPoint4D* v) { glVertex4dv(v->GetData()); }
00278
00279 template<class T, int sz>
00280 void wglNormalizeVertex(const Point<T,sz>& p)
00281 {
00282 _wglVertex(p.GetNormalizedVector());
00283 }
00284
00285 template<class T, int sz>
00286 void wglVertex(const Point<T,sz>& p)
00287 {
00288 _wglVertex(p);
00289 }
00290
00291
00292 void wglShading(const RGBAS& rgbas, bool revert_color = false );
00293
00294 }
00295 #endif
00296