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

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

modifs pour template vectors

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