[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 |
|
---|
| 111 | vector3df ToIrrlichtCoordinates(Vector3D vect) {
|
---|
[15] | 112 | return ToIrrlichtScale(1) * vector3df(vect.x, vect.y, -vect.z);
|
---|
[8] | 113 | }
|
---|
| 114 |
|
---|
| 115 | Vector3D ToSimulatorCoordinates(vector3df vect) {
|
---|
[15] | 116 | return ToSimulatorScale(1) * Vector3D(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 |
|
---|
[15] | 135 | Gui::Gui(const Simulator *parent, std::string name, int app_width,
|
---|
| 136 | int app_height, int scene_width, int scene_height,
|
---|
| 137 | std::string media_path, E_DRIVER_TYPE driver_type)
|
---|
| 138 | : Object(parent, name, "Gui") {
|
---|
| 139 | if (gui_ != NULL)
|
---|
| 140 | Err("Gui should be instanced only one time\n");
|
---|
| 141 | pimpl_ = new Gui_impl(this, app_width, app_height, scene_width, scene_height,
|
---|
| 142 | media_path, driver_type);
|
---|
| 143 | gui_ = this;
|
---|
[8] | 144 | }
|
---|
| 145 |
|
---|
[15] | 146 | Gui::~Gui() { delete pimpl_; }
|
---|
[8] | 147 |
|
---|
| 148 | float Gui::getAspectRatio(void) const {
|
---|
[15] | 149 | return (float)pimpl_->scene_width / (float)pimpl_->scene_height;
|
---|
[8] | 150 | }
|
---|
| 151 |
|
---|
[15] | 152 | ISceneManager *Gui::getSceneManager(void) const { return pimpl_->smgr; }
|
---|
[8] | 153 |
|
---|
[15] | 154 | void Gui::setMesh(std::string file, vector3df position, vector3df rotation,
|
---|
| 155 | vector3df scale) {
|
---|
| 156 | pimpl_->setMesh(file, position, rotation, scale);
|
---|
[8] | 157 | }
|
---|
| 158 |
|
---|
[15] | 159 | vector3df Gui::getRotation(void) const { return pimpl_->node->getRotation(); }
|
---|
[8] | 160 |
|
---|
[15] | 161 | IrrlichtDevice *Gui::getDevice(void) const { return pimpl_->device; }
|
---|
[8] | 162 |
|
---|
[15] | 163 | ITexture *Gui::getTexture(std::string filename) const {
|
---|
| 164 | filename = pimpl_->media_path + "/" + filename;
|
---|
| 165 | return pimpl_->driver->getTexture(filename.c_str());
|
---|
[8] | 166 | }
|
---|
| 167 |
|
---|
[15] | 168 | IAnimatedMesh *Gui::getMesh(std::string filename) const {
|
---|
| 169 | filename = pimpl_->media_path + "/" + filename;
|
---|
| 170 | return pimpl_->smgr->getMesh(filename.c_str());
|
---|
[8] | 171 | }
|
---|
| 172 |
|
---|
| 173 | } // end namespace simulator
|
---|
| 174 | } // end namespace flair
|
---|
[15] | 175 | #endif // GL
|
---|