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

glModel.H

Go to the documentation of this file.
00001 
00015 #ifndef _GLMODEL_H
00016 #define _GLMODEL_H
00017 
00018 #include <Menu.H>
00019 #include <wrapGL.H>
00020 #include <Model.H>
00021 #include <UserInterface.H>
00022 #include <Picking.H>
00023 #include <string>
00024 #include <vector>
00025 
00026 namespace xchen
00027 {
00028   class View;
00029 
00030   class glModel
00031   {
00032       enum { MAX_GL_MODELS = 1000 };
00033       static glModel* glModels[MAX_GL_MODELS];
00034   public:
00035       static glModel* Get_glModel(int id)                    { return glModels[id]; }
00036   public:
00037       glModel(View* v, Model* m = 0);
00038       ~glModel();
00039 
00040       int ReadModel(const string& file);                       // return 1 if error, 0 otherwise.
00041       //      void SetModel(Model* m)                                  { delete model; model = m; generateUI(); }
00042 
00043       UI& GetUI()                        { return  *ui; }
00044       void Draw() const;                                       // draw model, and related entity if its ctrl-bvar is on.
00045 
00046       dVector3D GetOrthographicVisualRay() const;              // may differ from that got from View, due to model transform.
00047 
00048   private:
00049       Model* model;
00050       static int cur_id;                                       // for open GL selection mode. starts with 1.
00051       int id;
00052       bool isSelected() const                                  { return UI::GetSelectedModel() == id; }
00053 
00054       View* view;
00055       UI* ui;
00056 
00057   private:
00058       int assign_glModel_id();
00059       void generateUI();
00060       void transform();
00061 
00062       static void del_selected_cb(ConvertedKeyValue, int, int)   { delete  Get_glModel( UI::GetSelectedModel() ); }
00063   
00064   private:
00065       enum PrimitiveModel { _Sphere, _Cube, _Torus, _Cone, _Teapot }; // The same user interface as open file.
00066       static const int num_primitives = 5;
00067       static string primitive2str[num_primitives];
00068 
00069       static void RegisterPrimitives( vector<string>& filenames ) 
00070       {
00071         for(int i=0; i<num_primitives; i++) 
00072           filenames.push_back( primitive2str[i] );
00073       }
00074 
00075       friend ostream& operator<<(ostream& os, const glModel& m);
00076       friend ostream& operator<<(ostream& os, const glModel* m) { return os << (*m); }
00077   };
00078 
00079 
00080 
00081   inline void glModel :: transform()
00082   {
00083     wglTranslate(ui->GetTranslate());
00084     glMultMatrixd(ui->GetRotateTransform().GetGLMatrix());
00085   }
00086  
00087 }
00088 
00089 #endif

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