close Warning: Can't use blame annotator:
svn blame failed on trunk/lib/FlairSimulator/src/Gui.cpp: 200029 - Couldn't perform atomic initialization

source: flair-src/trunk/lib/FlairSimulator/src/Gui.cpp@ 8

Last change on this file since 8 was 8, checked in by Sanahuja Guillaume, 8 years ago

simulator

File size: 4.3 KB
RevLine 
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
30using namespace irr;
31using namespace irr::video;
32using namespace irr::core;
33using namespace irr::scene;
34using namespace irr::gui;
35using namespace flair::core;
36
37namespace {
38 flair::simulator::Gui* gui_=NULL;
39 std::vector <std::string> extensions;
40 bool getGlInfo();
41}
42
43namespace flair { namespace simulator {
44
45Gui* getGui(void) {
46 return gui_;
47}
48
49bool 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)
58bool 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)
81bool 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
97float ToIrrlichtScale(float value) {
98 return value*100.;
99}
100
101float ToSimulatorScale(float value) {
102 return value/100.;
103}
104
105vector3df ToIrrlichtCoordinates(vector3df vect) {
106 return ToIrrlichtScale(1)*vector3df(vect.X,vect.Y,-vect.Z);
107}
108
109vector3df ToIrrlichtCoordinates(Vector3D vect) {
110 return ToIrrlichtScale(1)*vector3df(vect.x,vect.y,-vect.z);
111}
112
113Vector3D ToSimulatorCoordinates(vector3df vect) {
114 return ToSimulatorScale(1)*Vector3D(vect.X,vect.Y,-vect.Z);
115}
116
117Quaternion 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
133Gui::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
139Gui::~Gui() {
140 delete pimpl_;
141}
142
143float Gui::getAspectRatio(void) const {
144 return (float)pimpl_->scene_width/(float)pimpl_->scene_height;
145}
146
147ISceneManager* Gui::getSceneManager(void) const {
148 return pimpl_->smgr;
149}
150
151void Gui::setMesh(std::string file,vector3df position,vector3df rotation,vector3df scale) {
152 pimpl_->setMesh(file,position,rotation,scale);
153}
154
155vector3df Gui::getRotation(void) const {
156 return pimpl_->node->getRotation();
157}
158
159IrrlichtDevice *Gui::getDevice(void) const {
160 return pimpl_->device;
161}
162
163ITexture* Gui::getTexture(std::string filename) const {
164 filename=pimpl_->media_path+ "/" +filename;
165 return pimpl_->driver->getTexture(filename.c_str());
166}
167
168IAnimatedMesh* 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
Note: See TracBrowser for help on using the repository browser.