1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2013/03/27
|
---|
6 | // filename: Gui.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: classe definissant une Gui
|
---|
14 | //
|
---|
15 | /*********************************************************************/
|
---|
16 | #ifdef GL
|
---|
17 |
|
---|
18 | #include "Gui.h"
|
---|
19 | #include "Gui_impl.h"
|
---|
20 | #include "Simulator.h"
|
---|
21 | #include "Simulator_impl.h"
|
---|
22 | #include "Model.h"
|
---|
23 | #include "Model_impl.h"
|
---|
24 | #include "AnimPoursuite.h"
|
---|
25 | #include <Euler.h>
|
---|
26 | #include <Object.h>
|
---|
27 | #include <IMeshSceneNode.h>
|
---|
28 | #include <IVideoDriver.h>
|
---|
29 | #include <ISceneManager.h>
|
---|
30 | #include <unistd.h>
|
---|
31 | #include <algorithm>
|
---|
32 | #include <GL/gl.h>
|
---|
33 |
|
---|
34 | using namespace irr;
|
---|
35 | using namespace irr::video;
|
---|
36 | using namespace irr::core;
|
---|
37 | using namespace irr::scene;
|
---|
38 | using namespace irr::gui;
|
---|
39 | using namespace flair::core;
|
---|
40 |
|
---|
41 | namespace {
|
---|
42 | flair::simulator::Gui* gui_=NULL;
|
---|
43 | std::vector <std::string> extensions;
|
---|
44 | bool getGlInfo();
|
---|
45 | }
|
---|
46 |
|
---|
47 | namespace flair { namespace simulator {
|
---|
48 |
|
---|
49 | Gui* getGui(void) {
|
---|
50 | return gui_;
|
---|
51 | }
|
---|
52 |
|
---|
53 | bool noGui(void) {
|
---|
54 | if(gui_==NULL) {
|
---|
55 | return true;
|
---|
56 | } else {
|
---|
57 | return false;
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | //getGlinfo, code from Song Ho Ahn (song.ahn@gmail.com)
|
---|
62 | bool getGlInfo() {
|
---|
63 | char* str = 0;
|
---|
64 | char* tok = 0;
|
---|
65 |
|
---|
66 | // get all extensions as a string
|
---|
67 | str = (char*)glGetString(GL_EXTENSIONS);
|
---|
68 |
|
---|
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());
|
---|
82 | }
|
---|
83 |
|
---|
84 | //isGlExtensionSupported, code from Song Ho Ahn (song.ahn@gmail.com)
|
---|
85 | bool isGlExtensionSupported(const std::string& ext) {
|
---|
86 | if(extensions.size()==0) getGlInfo();
|
---|
87 |
|
---|
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 | }
|
---|
108 |
|
---|
109 | vector3df ToIrrlichtCoordinates(vector3df vect) {
|
---|
110 | return ToIrrlichtScale(1)*vector3df(vect.X,vect.Y,-vect.Z);
|
---|
111 | }
|
---|
112 |
|
---|
113 | vector3df ToIrrlichtCoordinates(Vector3D vect) {
|
---|
114 | return ToIrrlichtScale(1)*vector3df(vect.x,vect.y,-vect.z);
|
---|
115 | }
|
---|
116 |
|
---|
117 | Vector3D ToSimulatorCoordinates(vector3df vect) {
|
---|
118 | return ToSimulatorScale(1)*Vector3D(vect.X,vect.Y,-vect.Z);
|
---|
119 | }
|
---|
120 |
|
---|
121 | Quaternion ToIrrlichtOrientation(Quaternion quat) {
|
---|
122 | /* original code
|
---|
123 | Euler euler;
|
---|
124 | quat.ToEuler(euler);
|
---|
125 | matrix4 m;
|
---|
126 | m.setRotationRadians(vector3df(0, 0, euler.yaw));
|
---|
127 | matrix4 n;
|
---|
128 | n.setRotationRadians(vector3df(0, -euler.pitch,0));
|
---|
129 | m *= n;
|
---|
130 | n.setRotationRadians(vector3df(-euler.roll, 0, 0));
|
---|
131 | m *= n;
|
---|
132 | */
|
---|
133 | //seems to be equivalent to:
|
---|
134 | return Quaternion(quat.q0,-quat.q1,-quat.q2,quat.q3);
|
---|
135 | }
|
---|
136 |
|
---|
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;
|
---|
141 | }
|
---|
142 |
|
---|
143 | Gui::~Gui() {
|
---|
144 | delete pimpl_;
|
---|
145 | }
|
---|
146 |
|
---|
147 | float Gui::getAspectRatio(void) const {
|
---|
148 | return (float)pimpl_->scene_width/(float)pimpl_->scene_height;
|
---|
149 | }
|
---|
150 |
|
---|
151 | ISceneManager* Gui::getSceneManager(void) const {
|
---|
152 | return pimpl_->smgr;
|
---|
153 | }
|
---|
154 |
|
---|
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());
|
---|
175 | }
|
---|
176 |
|
---|
177 | } // end namespace simulator
|
---|
178 | } // end namespace flair
|
---|
179 | #endif //GL
|
---|