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