source: flair-src/branches/mavlink/lib/FlairSimulator/src/Gui.cpp@ 98

Last change on this file since 98 was 15, checked in by Bayard Gildas, 8 years ago

sources reformatted with flair-format-dir script

File size: 4.4 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
34using namespace irr;
35using namespace irr::video;
36using namespace irr::core;
37using namespace irr::scene;
38using namespace irr::gui;
39using namespace flair::core;
40
41namespace {
42flair::simulator::Gui *gui_ = NULL;
43std::vector<std::string> extensions;
44bool getGlInfo();
45}
46
47namespace flair {
48namespace simulator {
49
50Gui *getGui(void) { return gui_; }
51
52bool noGui(void) {
53 if (gui_ == NULL) {
54 return true;
55 } else {
56 return false;
57 }
58}
59
60// getGlinfo, code from Song Ho Ahn (song.ahn@gmail.com)
61bool getGlInfo() {
62 char *str = 0;
63 char *tok = 0;
64
65 // get all extensions as a string
66 str = (char *)glGetString(GL_EXTENSIONS);
67
68 // split extensions
69 if (str) {
70 tok = strtok((char *)str, " ");
71 while (tok) {
72 extensions.push_back(tok); // put a extension into struct
73 tok = strtok(0, " "); // next token
74 }
75 } else {
76 printf("cannot get gl extensions\n");
77 }
78
79 // sort extension by alphabetical order
80 std::sort(extensions.begin(), extensions.end());
81}
82
83// isGlExtensionSupported, code from Song Ho Ahn (song.ahn@gmail.com)
84bool isGlExtensionSupported(const std::string &ext) {
85 if (extensions.size() == 0)
86 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
101float ToIrrlichtScale(float value) { return value * 100.; }
102
103float ToSimulatorScale(float value) { return value / 100.; }
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,
134 int app_height, int scene_width, int scene_height,
135 std::string media_path, E_DRIVER_TYPE driver_type)
136 : Object(parent, name, "Gui") {
137 if (gui_ != NULL)
138 Err("Gui should be instanced only one time\n");
139 pimpl_ = new Gui_impl(this, app_width, app_height, scene_width, scene_height,
140 media_path, driver_type);
141 gui_ = this;
142}
143
144Gui::~Gui() { delete pimpl_; }
145
146float Gui::getAspectRatio(void) const {
147 return (float)pimpl_->scene_width / (float)pimpl_->scene_height;
148}
149
150ISceneManager *Gui::getSceneManager(void) const { return pimpl_->smgr; }
151
152void Gui::setMesh(std::string file, vector3df position, vector3df rotation,
153 vector3df scale) {
154 pimpl_->setMesh(file, position, rotation, scale);
155}
156
157vector3df Gui::getRotation(void) const { return pimpl_->node->getRotation(); }
158
159IrrlichtDevice *Gui::getDevice(void) const { return pimpl_->device; }
160
161ITexture *Gui::getTexture(std::string filename) const {
162 filename = pimpl_->media_path + "/" + filename;
163 return pimpl_->driver->getTexture(filename.c_str());
164}
165
166IAnimatedMesh *Gui::getMesh(std::string filename) const {
167 filename = pimpl_->media_path + "/" + filename;
168 return pimpl_->smgr->getMesh(filename.c_str());
169}
170
171} // end namespace simulator
172} // end namespace flair
173#endif // GL
Note: See TracBrowser for help on using the repository browser.