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

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

added compile info

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