Changeset 15 in flair-src for trunk/lib/FlairSimulator/src/Gui.cpp
- Timestamp:
- 04/08/16 15:40:57 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSimulator/src/Gui.cpp
r10 r15 40 40 41 41 namespace { 42 flair::simulator::Gui* gui_=NULL;43 std::vector<std::string> extensions;44 42 flair::simulator::Gui *gui_ = NULL; 43 std::vector<std::string> extensions; 44 bool getGlInfo(); 45 45 } 46 46 47 namespace flair { namespace simulator { 47 namespace flair { 48 namespace simulator { 48 49 49 Gui* getGui(void) { 50 return gui_; 50 Gui *getGui(void) { return gui_; } 51 52 bool noGui(void) { 53 if (gui_ == NULL) { 54 return true; 55 } else { 56 return false; 57 } 51 58 } 52 59 53 bool noGui(void) { 54 if(gui_==NULL) { 55 return true; 56 } else { 57 return false; 60 // getGlinfo, code from Song Ho Ahn (song.ahn@gmail.com) 61 bool getGlInfo() { 62 char *str = 0; 63 char *tok = 0; 64 65 // get all extensions as a string 66 str = (char *)glGetString(GL_EXTENSIONS); 67 68 // split extensions 69 if (str) { 70 tok = strtok((char *)str, " "); 71 while (tok) { 72 extensions.push_back(tok); // put a extension into struct 73 tok = strtok(0, " "); // next token 58 74 } 75 } else { 76 printf("cannot get gl extensions\n"); 77 } 78 79 // sort extension by alphabetical order 80 std::sort(extensions.begin(), extensions.end()); 59 81 } 60 82 61 // getGlinfo, code from Song Ho Ahn (song.ahn@gmail.com)62 bool getGlInfo() {63 char* str = 0;64 char* tok = 0;83 // isGlExtensionSupported, code from Song Ho Ahn (song.ahn@gmail.com) 84 bool isGlExtensionSupported(const std::string &ext) { 85 if (extensions.size() == 0) 86 getGlInfo(); 65 87 66 // get all extensions as a string 67 str = (char*)glGetString(GL_EXTENSIONS); 88 // search corresponding extension 89 std::vector<std::string>::const_iterator iter = extensions.begin(); 90 std::vector<std::string>::const_iterator endIter = extensions.end(); 68 91 69 // split extensions 70 if(str) { 71 tok = strtok((char*)str, " "); 72 while(tok) { 73 extensions.push_back(tok); // put a extension into struct 74 tok = strtok(0, " "); // next token 75 } 76 } else { 77 printf("cannot get gl extensions\n"); 78 } 79 80 // sort extension by alphabetical order 81 std::sort(extensions.begin(), extensions.end()); 92 while (iter != endIter) { 93 if (ext == *iter) 94 return true; 95 else 96 ++iter; 97 } 98 return false; 82 99 } 83 100 84 //isGlExtensionSupported, code from Song Ho Ahn (song.ahn@gmail.com) 85 bool isGlExtensionSupported(const std::string& ext) { 86 if(extensions.size()==0) getGlInfo(); 101 float ToIrrlichtScale(float value) { return value * 100.; } 87 102 88 // search corresponding extension 89 std::vector<std::string>::const_iterator iter = extensions.begin(); 90 std::vector<std::string>::const_iterator endIter = extensions.end(); 91 92 while(iter != endIter) { 93 if(ext == *iter) 94 return true; 95 else 96 ++iter; 97 } 98 return false; 99 } 100 101 float ToIrrlichtScale(float value) { 102 return value*100.; 103 } 104 105 float ToSimulatorScale(float value) { 106 return value/100.; 107 } 103 float ToSimulatorScale(float value) { return value / 100.; } 108 104 109 105 vector3df ToIrrlichtCoordinates(vector3df vect) { 110 return ToIrrlichtScale(1)*vector3df(vect.X,vect.Y,-vect.Z);106 return ToIrrlichtScale(1) * vector3df(vect.X, vect.Y, -vect.Z); 111 107 } 112 108 113 109 vector3df ToIrrlichtCoordinates(Vector3D vect) { 114 return ToIrrlichtScale(1)*vector3df(vect.x,vect.y,-vect.z);110 return ToIrrlichtScale(1) * vector3df(vect.x, vect.y, -vect.z); 115 111 } 116 112 117 113 Vector3D ToSimulatorCoordinates(vector3df vect) { 118 return ToSimulatorScale(1)*Vector3D(vect.X,vect.Y,-vect.Z);114 return ToSimulatorScale(1) * Vector3D(vect.X, vect.Y, -vect.Z); 119 115 } 120 116 121 117 Quaternion ToIrrlichtOrientation(Quaternion quat) { 122 123 124 125 126 127 128 129 130 131 132 133 //seems to be equivalent to:134 return Quaternion(quat.q0,-quat.q1,-quat.q2,quat.q3);118 /* original code 119 Euler euler; 120 quat.ToEuler(euler); 121 matrix4 m; 122 m.setRotationRadians(vector3df(0, 0, euler.yaw)); 123 matrix4 n; 124 n.setRotationRadians(vector3df(0, -euler.pitch,0)); 125 m *= n; 126 n.setRotationRadians(vector3df(-euler.roll, 0, 0)); 127 m *= n; 128 */ 129 // seems to be equivalent to: 130 return Quaternion(quat.q0, -quat.q1, -quat.q2, quat.q3); 135 131 } 136 132 137 Gui::Gui(const Simulator* parent,std::string name,int app_width, int app_height,int scene_width, int scene_height,std::string media_path,E_DRIVER_TYPE driver_type): Object(parent,name,"Gui") { 138 if(gui_!=NULL) Err("Gui should be instanced only one time\n"); 139 pimpl_=new Gui_impl(this,app_width,app_height,scene_width,scene_height,media_path,driver_type); 140 gui_=this; 133 Gui::Gui(const Simulator *parent, std::string name, int app_width, 134 int app_height, int scene_width, int scene_height, 135 std::string media_path, E_DRIVER_TYPE driver_type) 136 : Object(parent, name, "Gui") { 137 if (gui_ != NULL) 138 Err("Gui should be instanced only one time\n"); 139 pimpl_ = new Gui_impl(this, app_width, app_height, scene_width, scene_height, 140 media_path, driver_type); 141 gui_ = this; 141 142 } 142 143 143 Gui::~Gui() { 144 delete pimpl_; 144 Gui::~Gui() { delete pimpl_; } 145 146 float Gui::getAspectRatio(void) const { 147 return (float)pimpl_->scene_width / (float)pimpl_->scene_height; 145 148 } 146 149 147 float Gui::getAspectRatio(void) const { 148 return (float)pimpl_->scene_width/(float)pimpl_->scene_height; 150 ISceneManager *Gui::getSceneManager(void) const { return pimpl_->smgr; } 151 152 void Gui::setMesh(std::string file, vector3df position, vector3df rotation, 153 vector3df scale) { 154 pimpl_->setMesh(file, position, rotation, scale); 149 155 } 150 156 151 ISceneManager* Gui::getSceneManager(void) const { 152 return pimpl_->smgr; 157 vector3df Gui::getRotation(void) const { return pimpl_->node->getRotation(); } 158 159 IrrlichtDevice *Gui::getDevice(void) const { return pimpl_->device; } 160 161 ITexture *Gui::getTexture(std::string filename) const { 162 filename = pimpl_->media_path + "/" + filename; 163 return pimpl_->driver->getTexture(filename.c_str()); 153 164 } 154 165 155 void Gui::setMesh(std::string file,vector3df position,vector3df rotation,vector3df scale) { 156 pimpl_->setMesh(file,position,rotation,scale); 157 } 158 159 vector3df Gui::getRotation(void) const { 160 return pimpl_->node->getRotation(); 161 } 162 163 IrrlichtDevice *Gui::getDevice(void) const { 164 return pimpl_->device; 165 } 166 167 ITexture* Gui::getTexture(std::string filename) const { 168 filename=pimpl_->media_path+ "/" +filename; 169 return pimpl_->driver->getTexture(filename.c_str()); 170 } 171 172 IAnimatedMesh* Gui::getMesh(std::string filename) const { 173 filename=pimpl_->media_path+ "/" +filename; 174 return pimpl_->smgr->getMesh(filename.c_str()); 166 IAnimatedMesh *Gui::getMesh(std::string filename) const { 167 filename = pimpl_->media_path + "/" + filename; 168 return pimpl_->smgr->getMesh(filename.c_str()); 175 169 } 176 170 177 171 } // end namespace simulator 178 172 } // end namespace flair 179 #endif // GL173 #endif // GL
Note:
See TracChangeset
for help on using the changeset viewer.