[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>
|
---|
[45] | 33 | #include "compile_info.h"
|
---|
[8] | 34 |
|
---|
[45] | 35 | //todo: put it on seprate file, but not possible with static lib?
|
---|
| 36 | static void constructor() __attribute__((constructor));
|
---|
| 37 |
|
---|
| 38 | void constructor() {
|
---|
| 39 | compile_info("FlairSensorActuator");
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[8] | 42 | using namespace irr;
|
---|
| 43 | using namespace irr::video;
|
---|
| 44 | using namespace irr::core;
|
---|
| 45 | using namespace irr::scene;
|
---|
| 46 | using namespace irr::gui;
|
---|
| 47 | using namespace flair::core;
|
---|
| 48 |
|
---|
| 49 | namespace {
|
---|
[15] | 50 | flair::simulator::Gui *gui_ = NULL;
|
---|
| 51 | std::vector<std::string> extensions;
|
---|
| 52 | bool getGlInfo();
|
---|
[8] | 53 | }
|
---|
| 54 |
|
---|
[15] | 55 | namespace flair {
|
---|
| 56 | namespace simulator {
|
---|
[8] | 57 |
|
---|
[15] | 58 | Gui *getGui(void) { return gui_; }
|
---|
[8] | 59 |
|
---|
| 60 | bool noGui(void) {
|
---|
[15] | 61 | if (gui_ == NULL) {
|
---|
| 62 | return true;
|
---|
| 63 | } else {
|
---|
| 64 | return false;
|
---|
| 65 | }
|
---|
[8] | 66 | }
|
---|
| 67 |
|
---|
[15] | 68 | // getGlinfo, code from Song Ho Ahn (song.ahn@gmail.com)
|
---|
[8] | 69 | bool getGlInfo() {
|
---|
[15] | 70 | char *str = 0;
|
---|
| 71 | char *tok = 0;
|
---|
[8] | 72 |
|
---|
[15] | 73 | // get all extensions as a string
|
---|
| 74 | str = (char *)glGetString(GL_EXTENSIONS);
|
---|
[8] | 75 |
|
---|
[15] | 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
|
---|
[8] | 82 | }
|
---|
[15] | 83 | } else {
|
---|
| 84 | printf("cannot get gl extensions\n");
|
---|
| 85 | }
|
---|
[8] | 86 |
|
---|
[15] | 87 | // sort extension by alphabetical order
|
---|
| 88 | std::sort(extensions.begin(), extensions.end());
|
---|
[8] | 89 | }
|
---|
| 90 |
|
---|
[15] | 91 | // isGlExtensionSupported, code from Song Ho Ahn (song.ahn@gmail.com)
|
---|
| 92 | bool isGlExtensionSupported(const std::string &ext) {
|
---|
| 93 | if (extensions.size() == 0)
|
---|
| 94 | getGlInfo();
|
---|
[8] | 95 |
|
---|
[15] | 96 | // search corresponding extension
|
---|
| 97 | std::vector<std::string>::const_iterator iter = extensions.begin();
|
---|
| 98 | std::vector<std::string>::const_iterator endIter = extensions.end();
|
---|
[8] | 99 |
|
---|
[15] | 100 | while (iter != endIter) {
|
---|
| 101 | if (ext == *iter)
|
---|
| 102 | return true;
|
---|
| 103 | else
|
---|
| 104 | ++iter;
|
---|
| 105 | }
|
---|
| 106 | return false;
|
---|
[8] | 107 | }
|
---|
| 108 |
|
---|
[15] | 109 | float ToIrrlichtScale(float value) { return value * 100.; }
|
---|
[8] | 110 |
|
---|
[15] | 111 | float ToSimulatorScale(float value) { return value / 100.; }
|
---|
[8] | 112 |
|
---|
| 113 | vector3df ToIrrlichtCoordinates(vector3df vect) {
|
---|
[15] | 114 | return ToIrrlichtScale(1) * vector3df(vect.X, vect.Y, -vect.Z);
|
---|
[8] | 115 | }
|
---|
| 116 |
|
---|
| 117 | vector3df ToIrrlichtCoordinates(Vector3D vect) {
|
---|
[15] | 118 | return ToIrrlichtScale(1) * vector3df(vect.x, vect.y, -vect.z);
|
---|
[8] | 119 | }
|
---|
| 120 |
|
---|
| 121 | Vector3D ToSimulatorCoordinates(vector3df vect) {
|
---|
[15] | 122 | return ToSimulatorScale(1) * Vector3D(vect.X, vect.Y, -vect.Z);
|
---|
[8] | 123 | }
|
---|
| 124 |
|
---|
| 125 | Quaternion ToIrrlichtOrientation(Quaternion quat) {
|
---|
[15] | 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);
|
---|
[8] | 139 | }
|
---|
| 140 |
|
---|
[15] | 141 | Gui::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;
|
---|
[8] | 150 | }
|
---|
| 151 |
|
---|
[15] | 152 | Gui::~Gui() { delete pimpl_; }
|
---|
[8] | 153 |
|
---|
| 154 | float Gui::getAspectRatio(void) const {
|
---|
[15] | 155 | return (float)pimpl_->scene_width / (float)pimpl_->scene_height;
|
---|
[8] | 156 | }
|
---|
| 157 |
|
---|
[15] | 158 | ISceneManager *Gui::getSceneManager(void) const { return pimpl_->smgr; }
|
---|
[8] | 159 |
|
---|
[15] | 160 | void Gui::setMesh(std::string file, vector3df position, vector3df rotation,
|
---|
| 161 | vector3df scale) {
|
---|
| 162 | pimpl_->setMesh(file, position, rotation, scale);
|
---|
[8] | 163 | }
|
---|
| 164 |
|
---|
[15] | 165 | vector3df Gui::getRotation(void) const { return pimpl_->node->getRotation(); }
|
---|
[8] | 166 |
|
---|
[15] | 167 | IrrlichtDevice *Gui::getDevice(void) const { return pimpl_->device; }
|
---|
[8] | 168 |
|
---|
[15] | 169 | ITexture *Gui::getTexture(std::string filename) const {
|
---|
| 170 | filename = pimpl_->media_path + "/" + filename;
|
---|
| 171 | return pimpl_->driver->getTexture(filename.c_str());
|
---|
[8] | 172 | }
|
---|
| 173 |
|
---|
[15] | 174 | IAnimatedMesh *Gui::getMesh(std::string filename) const {
|
---|
| 175 | filename = pimpl_->media_path + "/" + filename;
|
---|
| 176 | return pimpl_->smgr->getMesh(filename.c_str());
|
---|
[8] | 177 | }
|
---|
| 178 |
|
---|
| 179 | } // end namespace simulator
|
---|
| 180 | } // end namespace flair
|
---|
[15] | 181 | #endif // GL
|
---|