Changeset 15 in flair-src for trunk/lib/FlairSimulator/src/Gui.cpp


Ignore:
Timestamp:
04/08/16 15:40:57 (8 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSimulator/src/Gui.cpp

    r10 r15  
    4040
    4141namespace {
    42     flair::simulator::Gui* gui_=NULL;
    43     std::vector <std::string> extensions;
    44     bool getGlInfo();
     42flair::simulator::Gui *gui_ = NULL;
     43std::vector<std::string> extensions;
     44bool getGlInfo();
    4545}
    4646
    47 namespace flair { namespace simulator {
     47namespace flair {
     48namespace simulator {
    4849
    49 Gui* getGui(void) {
    50     return gui_;
     50Gui *getGui(void) { return gui_; }
     51
     52bool noGui(void) {
     53  if (gui_ == NULL) {
     54    return true;
     55  } else {
     56    return false;
     57  }
    5158}
    5259
    53 bool noGui(void) {
    54     if(gui_==NULL) {
    55         return true;
    56     } else {
    57         return false;
     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
    5874    }
     75  } else {
     76    printf("cannot get gl extensions\n");
     77  }
     78
     79  // sort extension by alphabetical order
     80  std::sort(extensions.begin(), extensions.end());
    5981}
    6082
    61 //getGlinfo, code from Song Ho Ahn (song.ahn@gmail.com)
    62 bool getGlInfo() {
    63     char* str = 0;
    64     char* tok = 0;
     83// isGlExtensionSupported, code from Song Ho Ahn (song.ahn@gmail.com)
     84bool isGlExtensionSupported(const std::string &ext) {
     85  if (extensions.size() == 0)
     86    getGlInfo();
    6587
    66     // get all extensions as a string
    67     str = (char*)glGetString(GL_EXTENSIONS);
     88  // search corresponding extension
     89  std::vector<std::string>::const_iterator iter = extensions.begin();
     90  std::vector<std::string>::const_iterator endIter = extensions.end();
    6891
    69     // split extensions
    70     if(str) {
    71         tok = strtok((char*)str, " ");
    72         while(tok) {
    73             extensions.push_back(tok);    // put a extension into struct
    74             tok = strtok(0, " ");               // next token
    75         }
    76     } else {
    77         printf("cannot get gl extensions\n");
    78     }
    79 
    80     // sort extension by alphabetical order
    81     std::sort(extensions.begin(), extensions.end());
     92  while (iter != endIter) {
     93    if (ext == *iter)
     94      return true;
     95    else
     96      ++iter;
     97  }
     98  return false;
    8299}
    83100
    84 //isGlExtensionSupported, code from Song Ho Ahn (song.ahn@gmail.com)
    85 bool isGlExtensionSupported(const std::string& ext) {
    86     if(extensions.size()==0) getGlInfo();
     101float ToIrrlichtScale(float value) { return value * 100.; }
    87102
    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 
    101 float ToIrrlichtScale(float value) {
    102     return value*100.;
    103 }
    104 
    105 float ToSimulatorScale(float value) {
    106     return value/100.;
    107 }
     103float ToSimulatorScale(float value) { return value / 100.; }
    108104
    109105vector3df ToIrrlichtCoordinates(vector3df vect) {
    110     return ToIrrlichtScale(1)*vector3df(vect.X,vect.Y,-vect.Z);
     106  return ToIrrlichtScale(1) * vector3df(vect.X, vect.Y, -vect.Z);
    111107}
    112108
    113109vector3df ToIrrlichtCoordinates(Vector3D vect) {
    114     return ToIrrlichtScale(1)*vector3df(vect.x,vect.y,-vect.z);
     110  return ToIrrlichtScale(1) * vector3df(vect.x, vect.y, -vect.z);
    115111}
    116112
    117113Vector3D ToSimulatorCoordinates(vector3df vect) {
    118     return ToSimulatorScale(1)*Vector3D(vect.X,vect.Y,-vect.Z);
     114  return ToSimulatorScale(1) * Vector3D(vect.X, vect.Y, -vect.Z);
    119115}
    120116
    121117Quaternion ToIrrlichtOrientation(Quaternion quat) {
    122     /* original code
    123     Euler euler;
    124     quat.ToEuler(euler);
    125     matrix4 m;
    126     m.setRotationRadians(vector3df(0, 0, euler.yaw));
    127     matrix4 n;
    128     n.setRotationRadians(vector3df(0, -euler.pitch,0));
    129     m *= n;
    130     n.setRotationRadians(vector3df(-euler.roll, 0, 0));
    131     m *= n;
    132     */
    133     //seems to be equivalent to:
    134     return Quaternion(quat.q0,-quat.q1,-quat.q2,quat.q3);
     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);
    135131}
    136132
    137 Gui::Gui(const Simulator* parent,std::string name,int app_width, int app_height,int scene_width, int scene_height,std::string media_path,E_DRIVER_TYPE driver_type): Object(parent,name,"Gui") {
    138     if(gui_!=NULL) Err("Gui should be instanced only one time\n");
    139     pimpl_=new Gui_impl(this,app_width,app_height,scene_width,scene_height,media_path,driver_type);
    140     gui_=this;
     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;
    141142}
    142143
    143 Gui::~Gui() {
    144     delete pimpl_;
     144Gui::~Gui() { delete pimpl_; }
     145
     146float Gui::getAspectRatio(void) const {
     147  return (float)pimpl_->scene_width / (float)pimpl_->scene_height;
    145148}
    146149
    147 float Gui::getAspectRatio(void) const {
    148     return (float)pimpl_->scene_width/(float)pimpl_->scene_height;
     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);
    149155}
    150156
    151 ISceneManager* Gui::getSceneManager(void) const {
    152     return pimpl_->smgr;
     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());
    153164}
    154165
    155 void Gui::setMesh(std::string file,vector3df position,vector3df rotation,vector3df scale) {
    156     pimpl_->setMesh(file,position,rotation,scale);
    157 }
    158 
    159 vector3df Gui::getRotation(void) const {
    160     return pimpl_->node->getRotation();
    161 }
    162 
    163 IrrlichtDevice *Gui::getDevice(void) const {
    164     return pimpl_->device;
    165 }
    166 
    167 ITexture* Gui::getTexture(std::string filename) const {
    168     filename=pimpl_->media_path+ "/" +filename;
    169     return pimpl_->driver->getTexture(filename.c_str());
    170 }
    171 
    172 IAnimatedMesh* Gui::getMesh(std::string filename) const {
    173     filename=pimpl_->media_path+ "/" +filename;
    174     return pimpl_->smgr->getMesh(filename.c_str());
     166IAnimatedMesh *Gui::getMesh(std::string filename) const {
     167  filename = pimpl_->media_path + "/" + filename;
     168  return pimpl_->smgr->getMesh(filename.c_str());
    175169}
    176170
    177171} // end namespace simulator
    178172} // end namespace flair
    179 #endif //GL
     173#endif // GL
Note: See TracChangeset for help on using the changeset viewer.