Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

glutBuiltInModel.H

Go to the documentation of this file.
00001 
00015 #ifndef _GLUTBUILTINMODEL_H
00016 #define _GLUTBUILTINMODEL_H
00017 
00018 #include <GL/glut.h>
00019 #include <wrapGL.H>
00020 #include <Model.H>
00021 #include <Vector.H>
00022 
00023 namespace xchen
00024 {
00025   class glutBuiltInModel : public Model
00026   {
00027       enum { glutBuiltInSphere, glutBuiltInCube, glutBuiltInTorus, glutBuiltInCone, glutBuiltInTeapot };
00028       static int str2enum(const string& str);
00029   public:
00030       static glutBuiltInModel* NewModel(const string& file);
00031       static void GetAllglutBuiltInNames(vector<string>& filenames);
00032   };
00033   
00034 
00038   class Cone : public glutBuiltInModel
00039   {
00040       double base, height, at_z;
00041   public:
00042       Cone(double bs=.5, double h=1.0, double atZ = 0) : base(bs), height(h), at_z(atZ) { }
00043       void Draw() const                                              { wglCone(base, height, at_z, PosZDir); }
00044   };
00045   class Cube : public glutBuiltInModel
00046   {
00047       double size;
00048   public:
00049       Cube(double sz=1.0) : size(sz)  { }
00050       void Draw() const                                              { glutSolidCube(size); } 
00051   };
00052   class Sphere : public glutBuiltInModel
00053   {
00054       double r;
00055       E3 c;      // center
00056   public:
00057       Sphere(double rd = 1.0, E3 const& C=E3(0.0)) : r(rd), c(C)  { }
00058       void Draw() const                                              { wglTranslate(c); glutSolidSphere(r, 100, 100); } 
00059   };
00060   class Teapot : public glutBuiltInModel
00061   {
00062       double size;
00063   public:
00064       Teapot(double sz = 0.5) : size(sz)  { }
00065       void Draw() const                                              { glutSolidTeapot(size); }
00066   };
00067   class Torus : public glutBuiltInModel
00068   {
00069       double inner_r, outer_r;
00070   public:
00071       Torus(double i_r = .2, double o_r = .5) : inner_r(i_r), outer_r(o_r) { }
00072       void Draw() const                                              { glutSolidTorus(inner_r, outer_r, 100, 100); } 
00073   };
00074 
00075 
00076 
00077 
00078   
00079   inline int glutBuiltInModel :: str2enum(const string& str)
00080   {
00081     if( ! str.compare("glutBuiltInSphere") ) return glutBuiltInSphere;
00082     if( ! str.compare("glutBuiltInCube") ) return glutBuiltInCube;
00083     if( ! str.compare("glutBuiltInTorus") ) return glutBuiltInTorus;
00084     if( ! str.compare("glutBuiltInCone") ) return glutBuiltInCone;
00085     if( ! str.compare("glutBuiltInTeapot") ) return glutBuiltInTeapot;
00086     return -1;
00087   }
00088 
00089   inline glutBuiltInModel* glutBuiltInModel :: NewModel(const string& file)
00090   {
00091     switch( str2enum(file) ) 
00092     {
00093       case glutBuiltInSphere: return new Sphere();
00094       case glutBuiltInCube: return new Cube();
00095       case glutBuiltInTorus: return new Torus();
00096       case glutBuiltInCone: return new Cone();
00097       case glutBuiltInTeapot: return new Teapot();
00098     }
00099     return 0;
00100   }
00101 
00102   inline void glutBuiltInModel :: GetAllglutBuiltInNames( vector<string>& filenames ) 
00103   {
00104     filenames.push_back("glutBuiltInSphere");
00105     filenames.push_back("glutBuiltInCube");
00106     filenames.push_back("glutBuiltInTorus");
00107     filenames.push_back("glutBuiltInCone");
00108     filenames.push_back("glutBuiltInTeapot");
00109   }
00110 
00111 }
00112 #endif

Generated on Wed Apr 7 21:40:49 2004 by doxygen1.2.18