[8] | 1 | // created: 2013/03/27
|
---|
| 2 | // filename: Gui.cpp
|
---|
| 3 | //
|
---|
| 4 | // author: Guillaume Sanahuja
|
---|
| 5 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 6 | //
|
---|
| 7 | // version: $Id: $
|
---|
| 8 | //
|
---|
| 9 | // purpose: classe definissant une Gui
|
---|
| 10 | //
|
---|
| 11 | /*********************************************************************/
|
---|
| 12 | #ifdef GL
|
---|
| 13 |
|
---|
| 14 | #include "Gui.h"
|
---|
| 15 | #include "Gui_impl.h"
|
---|
| 16 | #include "Simulator.h"
|
---|
| 17 | #include "Simulator_impl.h"
|
---|
| 18 | #include "Model.h"
|
---|
| 19 | #include "Model_impl.h"
|
---|
| 20 | #include "AnimPoursuite.h"
|
---|
| 21 | #include <Euler.h>
|
---|
| 22 | #include <Object.h>
|
---|
| 23 | #include <IMeshSceneNode.h>
|
---|
| 24 | #include <IVideoDriver.h>
|
---|
| 25 | #include <ISceneManager.h>
|
---|
| 26 | #include <unistd.h>
|
---|
| 27 | #include <algorithm>
|
---|
| 28 | #include <GL/gl.h>
|
---|
| 29 |
|
---|
| 30 | using namespace irr;
|
---|
| 31 | using namespace irr::video;
|
---|
| 32 | using namespace irr::core;
|
---|
| 33 | using namespace irr::scene;
|
---|
| 34 | using namespace irr::gui;
|
---|
| 35 | using namespace flair::core;
|
---|
| 36 |
|
---|
| 37 | namespace {
|
---|
| 38 | flair::simulator::Gui* gui_=NULL;
|
---|
| 39 | std::vector <std::string> extensions;
|
---|
| 40 | bool getGlInfo();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | namespace flair { namespace simulator {
|
---|
| 44 |
|
---|
| 45 | Gui* getGui(void) {
|
---|
| 46 | return gui_;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | bool noGui(void) {
|
---|
| 50 | if(gui_==NULL) {
|
---|
| 51 | return true;
|
---|
| 52 | } else {
|
---|
| 53 | return false;
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | //getGlinfo, code from Song Ho Ahn (song.ahn@gmail.com)
|
---|
| 58 | bool getGlInfo() {
|
---|
| 59 | char* str = 0;
|
---|
| 60 | char* tok = 0;
|
---|
| 61 |
|
---|
| 62 | // get all extensions as a string
|
---|
| 63 | str = (char*)glGetString(GL_EXTENSIONS);
|
---|
| 64 |
|
---|
| 65 | // split extensions
|
---|
| 66 | if(str) {
|
---|
| 67 | tok = strtok((char*)str, " ");
|
---|
| 68 | while(tok) {
|
---|
| 69 | extensions.push_back(tok); // put a extension into struct
|
---|
| 70 | tok = strtok(0, " "); // next token
|
---|
| 71 | }
|
---|
| 72 | } else {
|
---|
| 73 | printf("cannot get gl extensions\n");
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | // sort extension by alphabetical order
|
---|
| 77 | std::sort(extensions.begin(), extensions.end());
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | //isGlExtensionSupported, code from Song Ho Ahn (song.ahn@gmail.com)
|
---|
| 81 | bool isGlExtensionSupported(const std::string& ext) {
|
---|
| 82 | if(extensions.size()==0) getGlInfo();
|
---|
| 83 |
|
---|
| 84 | // search corresponding extension
|
---|
| 85 | std::vector<std::string>::const_iterator iter = extensions.begin();
|
---|
| 86 | std::vector<std::string>::const_iterator endIter = extensions.end();
|
---|
| 87 |
|
---|
| 88 | while(iter != endIter) {
|
---|
| 89 | if(ext == *iter)
|
---|
| 90 | return true;
|
---|
| 91 | else
|
---|
| 92 | ++iter;
|
---|
| 93 | }
|
---|
| 94 | return false;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | float ToIrrlichtScale(float value) {
|
---|
| 98 | return value*100.;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | float ToSimulatorScale(float value) {
|
---|
| 102 | return value/100.;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | vector3df ToIrrlichtCoordinates(vector3df vect) {
|
---|
| 106 | return ToIrrlichtScale(1)*vector3df(vect.X,vect.Y,-vect.Z);
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | vector3df ToIrrlichtCoordinates(Vector3D vect) {
|
---|
| 110 | return ToIrrlichtScale(1)*vector3df(vect.x,vect.y,-vect.z);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | Vector3D ToSimulatorCoordinates(vector3df vect) {
|
---|
| 114 | return ToSimulatorScale(1)*Vector3D(vect.X,vect.Y,-vect.Z);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | Quaternion ToIrrlichtOrientation(Quaternion quat) {
|
---|
| 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);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | 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") {
|
---|
| 134 | if(gui_!=NULL) Err("Gui should be instanced only one time\n");
|
---|
| 135 | pimpl_=new Gui_impl(this,app_width,app_height,scene_width,scene_height,media_path,driver_type);
|
---|
| 136 | gui_=this;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | Gui::~Gui() {
|
---|
| 140 | delete pimpl_;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | float Gui::getAspectRatio(void) const {
|
---|
| 144 | return (float)pimpl_->scene_width/(float)pimpl_->scene_height;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | ISceneManager* Gui::getSceneManager(void) const {
|
---|
| 148 | return pimpl_->smgr;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | void Gui::setMesh(std::string file,vector3df position,vector3df rotation,vector3df scale) {
|
---|
| 152 | pimpl_->setMesh(file,position,rotation,scale);
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | vector3df Gui::getRotation(void) const {
|
---|
| 156 | return pimpl_->node->getRotation();
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | IrrlichtDevice *Gui::getDevice(void) const {
|
---|
| 160 | return pimpl_->device;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | ITexture* Gui::getTexture(std::string filename) const {
|
---|
| 164 | filename=pimpl_->media_path+ "/" +filename;
|
---|
| 165 | return pimpl_->driver->getTexture(filename.c_str());
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | IAnimatedMesh* Gui::getMesh(std::string filename) const {
|
---|
| 169 | filename=pimpl_->media_path+ "/" +filename;
|
---|
| 170 | return pimpl_->smgr->getMesh(filename.c_str());
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | } // end namespace simulator
|
---|
| 174 | } // end namespace flair
|
---|
| 175 | #endif //GL
|
---|