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);
00041
00042
00043 UI& GetUI() { return *ui; }
00044 void Draw() const;
00045
00046 dVector3D GetOrthographicVisualRay() const;
00047
00048 private:
00049 Model* model;
00050 static int cur_id;
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 };
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