[10] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[10] | 4 | // %flair:license}
|
---|
[8] | 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 {
|
---|
[15] | 42 | flair::simulator::Gui *gui_ = NULL;
|
---|
| 43 | std::vector<std::string> extensions;
|
---|
| 44 | bool getGlInfo();
|
---|
[8] | 45 | }
|
---|
| 46 |
|
---|
[15] | 47 | namespace flair {
|
---|
| 48 | namespace simulator {
|
---|
[8] | 49 |
|
---|
[15] | 50 | Gui *getGui(void) { return gui_; }
|
---|
[8] | 51 |
|
---|
| 52 | bool noGui(void) {
|
---|
[15] | 53 | if (gui_ == NULL) {
|
---|
| 54 | return true;
|
---|
| 55 | } else {
|
---|
| 56 | return false;
|
---|
| 57 | }
|
---|
[8] | 58 | }
|
---|
| 59 |
|
---|
[15] | 60 | // getGlinfo, code from Song Ho Ahn (song.ahn@gmail.com)
|
---|
[8] | 61 | bool getGlInfo() {
|
---|
[15] | 62 | char *str = 0;
|
---|
| 63 | char *tok = 0;
|
---|
[8] | 64 |
|
---|
[15] | 65 | // get all extensions as a string
|
---|
| 66 | str = (char *)glGetString(GL_EXTENSIONS);
|
---|
[8] | 67 |
|
---|
[15] | 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
|
---|
[8] | 74 | }
|
---|
[15] | 75 | } else {
|
---|
| 76 | printf("cannot get gl extensions\n");
|
---|
| 77 | }
|
---|
[8] | 78 |
|
---|
[15] | 79 | // sort extension by alphabetical order
|
---|
| 80 | std::sort(extensions.begin(), extensions.end());
|
---|
[8] | 81 | }
|
---|
| 82 |
|
---|
[15] | 83 | // isGlExtensionSupported, code from Song Ho Ahn (song.ahn@gmail.com)
|
---|
| 84 | bool isGlExtensionSupported(const std::string &ext) {
|
---|
| 85 | if (extensions.size() == 0)
|
---|
| 86 | getGlInfo();
|
---|
[8] | 87 |
|
---|
[15] | 88 | // search corresponding extension
|
---|
| 89 | std::vector<std::string>::const_iterator iter = extensions.begin();
|
---|
| 90 | std::vector<std::string>::const_iterator endIter = extensions.end();
|
---|
[8] | 91 |
|
---|
[15] | 92 | while (iter != endIter) {
|
---|
| 93 | if (ext == *iter)
|
---|
| 94 | return true;
|
---|
| 95 | else
|
---|
| 96 | ++iter;
|
---|
| 97 | }
|
---|
| 98 | return false;
|
---|
[8] | 99 | }
|
---|
| 100 |
|
---|
[15] | 101 | float ToIrrlichtScale(float value) { return value * 100.; }
|
---|
[8] | 102 |
|
---|
[15] | 103 | float ToSimulatorScale(float value) { return value / 100.; }
|
---|
[8] | 104 |
|
---|
| 105 | vector3df ToIrrlichtCoordinates(vector3df vect) {
|
---|
[15] | 106 | return ToIrrlichtScale(1) * vector3df(vect.X, vect.Y, -vect.Z);
|
---|
[8] | 107 | }
|
---|
| 108 |
|
---|
| 109 | vector3df ToIrrlichtCoordinates(Vector3D vect) {
|
---|
[15] | 110 | return ToIrrlichtScale(1) * vector3df(vect.x, vect.y, -vect.z);
|
---|
[8] | 111 | }
|
---|
| 112 |
|
---|
| 113 | Vector3D ToSimulatorCoordinates(vector3df vect) {
|
---|
[15] | 114 | return ToSimulatorScale(1) * Vector3D(vect.X, vect.Y, -vect.Z);
|
---|
[8] | 115 | }
|
---|
| 116 |
|
---|
| 117 | Quaternion ToIrrlichtOrientation(Quaternion quat) {
|
---|
[15] | 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);
|
---|
[8] | 131 | }
|
---|
| 132 |
|
---|
[15] | 133 | Gui::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;
|
---|
[8] | 142 | }
|
---|
| 143 |
|
---|
[15] | 144 | Gui::~Gui() { delete pimpl_; }
|
---|
[8] | 145 |
|
---|
| 146 | float Gui::getAspectRatio(void) const {
|
---|
[15] | 147 | return (float)pimpl_->scene_width / (float)pimpl_->scene_height;
|
---|
[8] | 148 | }
|
---|
| 149 |
|
---|
[15] | 150 | ISceneManager *Gui::getSceneManager(void) const { return pimpl_->smgr; }
|
---|
[8] | 151 |
|
---|
[15] | 152 | void Gui::setMesh(std::string file, vector3df position, vector3df rotation,
|
---|
| 153 | vector3df scale) {
|
---|
| 154 | pimpl_->setMesh(file, position, rotation, scale);
|
---|
[8] | 155 | }
|
---|
| 156 |
|
---|
[15] | 157 | vector3df Gui::getRotation(void) const { return pimpl_->node->getRotation(); }
|
---|
[8] | 158 |
|
---|
[15] | 159 | IrrlichtDevice *Gui::getDevice(void) const { return pimpl_->device; }
|
---|
[8] | 160 |
|
---|
[15] | 161 | ITexture *Gui::getTexture(std::string filename) const {
|
---|
| 162 | filename = pimpl_->media_path + "/" + filename;
|
---|
| 163 | return pimpl_->driver->getTexture(filename.c_str());
|
---|
[8] | 164 | }
|
---|
| 165 |
|
---|
[15] | 166 | IAnimatedMesh *Gui::getMesh(std::string filename) const {
|
---|
| 167 | filename = pimpl_->media_path + "/" + filename;
|
---|
| 168 | return pimpl_->smgr->getMesh(filename.c_str());
|
---|
[8] | 169 | }
|
---|
| 170 |
|
---|
| 171 | } // end namespace simulator
|
---|
| 172 | } // end namespace flair
|
---|
[15] | 173 | #endif // GL
|
---|