Changeset 286 in flair-src for trunk/lib/FlairSimulator


Ignore:
Timestamp:
01/08/19 10:13:03 (5 years ago)
Author:
Sanahuja Guillaume
Message:

draw vrpn axis in simulator

Location:
trunk/lib/FlairSimulator/src
Files:
4 added
19 edited

Legend:

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

    r15 r286  
    6464}
    6565
     66Blade::Blade(ISceneNode *parent, const vector3df &position, bool inverted, s32 id)
     67    : ISceneNode(parent, getGui()->getSceneManager(), id,
     68                 position) {
     69  ISceneManager *mgr = getGui()->getSceneManager();
     70
     71  const IGeometryCreator *geo;
     72  geo = mgr->getGeometryCreator();
     73  pale = geo->createCubeMesh(vector3df(63.5, 0.5, 5));
     74
     75  float angle;
     76  if (inverted == false) {
     77    angle = 20;
     78  } else {
     79    angle = -20;
     80  }
     81
     82  ITexture *texture = getGui()->getTexture("carbone.jpg");
     83  pale_1 = new MeshSceneNode(parent, pale, vector3df(-30, 0, 0),
     84                             vector3df(-angle + 90, 0, 0), texture);
     85  pale_1->setParent(this);
     86  pale_2 = new MeshSceneNode(parent, pale, vector3df(30, 0, 0),
     87                             vector3df(angle + 90, 0, 0), texture);
     88  pale_2->setParent(this);
     89
     90  anim = mgr->createRotationAnimator(vector3df(0.f, 0.f, 0.f));
     91  addAnimator(anim);
     92}
     93
    6694void Blade::OnRegisterSceneNode() {
    6795  if (IsVisible)
  • trunk/lib/FlairSimulator/src/Blade.h

    r15 r286  
    3636        const irr::core::vector3df &position = irr::core::vector3df(0, 0, 0),
    3737        bool inverted = false, irr::s32 id = -1);
     38
     39  Blade(irr::scene::ISceneNode *parent,
     40        const irr::core::vector3df &position = irr::core::vector3df(0, 0, 0),
     41        bool inverted = false, irr::s32 id = -1);
     42 
    3843  virtual void OnRegisterSceneNode(void);
    3944  virtual void render(void);
  • trunk/lib/FlairSimulator/src/FixedCamera.cpp

    r167 r286  
    2727#include <Euler.h>
    2828
     29
    2930using namespace irr;
    3031using namespace gui;
     
    5152void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) {
    5253  ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
    53 
     54 
    5455  if (LMouseKey == true) {
    5556    if (!Rotating) {
  • trunk/lib/FlairSimulator/src/FollowMeCamera.cpp

    r70 r286  
    6363
    6464void FollowMeCamera::animateNode(ISceneNode *node, u32 timeMs) {
    65 
    6665  float nRotY = RotY;
    6766  float nRotZ = RotZ;
  • trunk/lib/FlairSimulator/src/GenericObject.cpp

    r158 r286  
    4040{
    4141        meshSceneNode=getGui()->getSceneManager()->addMeshSceneNode(mesh);
    42        
     42        /*
    4343  selector = getGui()->getSceneManager()->createTriangleSelector(mesh, meshSceneNode);
    4444  meshSceneNode->setTriangleSelector(selector);
    45        
     45        */
    4646  meshSceneNode->setMaterialFlag(EMF_LIGHTING, false);
    4747
     
    5353ITriangleSelector *GenericObject::TriangleSelector(void) { return selector; }
    5454
     55void GenericObject::setVisible(bool isVisible) {
     56  meshSceneNode->setVisible(isVisible);
     57}
    5558void GenericObject::setScale(float value) {
    5659  meshSceneNode->setScale(vector3df(value, value, value));
  • trunk/lib/FlairSimulator/src/Gui_impl.cpp

    r166 r286  
    9494  device->setResizable(false);
    9595
    96   // font = device->getGUIEnvironment()->getBuiltInFont();
    9796  driver = device->getVideoDriver();
    9897  smgr = device->getSceneManager();
     
    179178  int lastFPS = -1;
    180179  int cam_id = 0;
     180  ITexture* texture=0;
     181  IGUIFont* font =0;
     182 
     183  if (!driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) {
     184    self->Warn("rendering to texture is not possible, axis will not be displayed\n");
     185  } else {
     186    texture= getGui()->getSceneManager()->getVideoDriver()->addRenderTargetTexture(dimension2d<u32>(128,128));
     187    device->getGUIEnvironment()->addImage(texture,position2d<s32>(0,scene_height-texture->getSize().Height));
     188    font = getGui()->getDevice()->getGUIEnvironment()->getFont((media_path+"/font/simu_axis_font.xml").c_str());
     189  }
    181190
    182191  receiver->SetModel(models.at(0));
     
    242251    driver->setViewPort(core::rect<s32>(0, 0, scene_width, scene_height));
    243252    smgr->drawAll(); // commente voir plus bas
    244                      /*
    245                  env->drawAll();
    246                  if (font)
    247                  {
    248                                      font->draw(L"This demo shows that Irrlicht is also capable
    249                  of drawing 2D graphics.",
    250                                              core::rect<s32>(130,10,300,50),
    251                                              video::SColor(255,255,255,255));
    252                  }
    253                  else
    254                  {
    255                  printf("err\n");
    256                  }
    257                  device->setWindowCaption(L"toto");*/
    258 
     253                   
    259254    if (dbtFile_r == NULL) {// mode normal
    260255      for (size_t i = 0; i < models.size(); i++) {
     
    263258    }
    264259
     260    //render to texture for axis if possible
     261    if (texture) {
     262      cameras.at(cam_id)->renderAxisToTexture(texture);
     263    }
     264   
     265    //process update for sensors (cam, us...)
     266    //also draws embedded cameras (see SimuCameraGL::UpdateFrom)
    265267    for (size_t i = 0; i < models.size(); i++) {
    266268      models.at(i)->ProcessUpdate(NULL);
    267269    }
    268 
     270   
    269271    // on fait ca ici, devrait etre un peu plus haut
    270272    // mais a priori souci avec models.at(i)->pimpl_->CheckCollision();
     
    274276    driver->setViewPort(core::rect<s32>(0, 0, scene_width, scene_height));
    275277    smgr->drawAll();
    276 
     278   
     279    driver->setViewPort(core::rect<s32>(0, 0, smgr->getVideoDriver()->getScreenSize().Width, smgr->getVideoDriver()->getScreenSize().Height));
     280    if(font) {
     281      font->draw(L"VRPN:",rect<s32>(10,scene_height-30,100,50),SColor(128,255,255,255));
     282      font->draw(L"X",rect<s32>(60,scene_height-30,100,50),SColor(255,255,0,0));
     283      font->draw(L"Y",rect<s32>(70,scene_height-30,100,50),SColor(255,0,255,0));
     284      font->draw(L"Z",rect<s32>(80,scene_height-30,100,50),SColor(255,0,0,255));
     285     
     286    }
     287    device->getGUIEnvironment()->drawAll();
    277288    driver->endScene();
    278 
     289   
    279290    int fps = driver->getFPS();
    280291
  • trunk/lib/FlairSimulator/src/MeshSceneNode.cpp

    r15 r286  
    4949}
    5050
     51MeshSceneNode::MeshSceneNode(ISceneNode *parent, IMesh *mesh,
     52                             const vector3df &position,
     53                             const vector3df &rotation, ITexture *texture,
     54                             s32 id)
     55    : IMeshSceneNode(parent, getGui()->getSceneManager(), id,
     56                     position, rotation) {
     57  Material.Wireframe = false;
     58  Material.Lighting = false;
     59
     60  setMesh(mesh);
     61
     62  if (texture != NULL) {
     63    setMaterialTexture(0, texture);
     64  }
     65
     66  //parent->getBoundingBox().addInternalBox(getTransformedBoundingBox());
     67}
     68
    5169void MeshSceneNode::OnRegisterSceneNode(void) {
    5270  if (IsVisible)
  • trunk/lib/FlairSimulator/src/MeshSceneNode.h

    r15 r286  
    3131      const irr::core::vector3df &rotation = irr::core::vector3df(0, 0, 0),
    3232      irr::video::ITexture *texture = NULL, irr::s32 id = -1);
     33 
     34  MeshSceneNode(
     35      irr::scene::ISceneNode *parent, irr::scene::IMesh *mesh,
     36      const irr::core::vector3df &position = irr::core::vector3df(0, 0, 0),
     37      const irr::core::vector3df &rotation = irr::core::vector3df(0, 0, 0),
     38      irr::video::ITexture *texture = NULL, irr::s32 id = -1);
    3339
    3440  virtual void OnRegisterSceneNode(void);
  • trunk/lib/FlairSimulator/src/SimuBldc.cpp

    r224 r286  
    7373}
    7474
    75 } // end namespace sensor
     75} // end namespace actuator
    7676} // end namespace flair
  • trunk/lib/FlairSimulator/src/Simulator.cpp

    r167 r286  
    3636Simulator *getSimulator(void) { return simu; }
    3737
    38 Simulator::Simulator(string name, int optitrack_mstime, float yaw_deg)
     38Simulator::Simulator(string name, int optitrack_mstime, float yaw_deg, int port)
    3939    : FrameworkManager(name) {
    4040  if (simu != NULL)
    4141    Err("Simulator should be instanced only one time\n");
    4242
    43   pimpl_ = new Simulator_impl(this, optitrack_mstime, yaw_deg);
     43  pimpl_ = new Simulator_impl(this, optitrack_mstime, yaw_deg,port);
    4444  simu = this;
    4545}
  • trunk/lib/FlairSimulator/src/Simulator.h

    r167 r286  
    4444  // yaw_deg: rotation of the vrpn coordinate with respect to the earth
    4545  // coordinate, around z axis
    46   Simulator(std::string name, int optitrack_mstime = 10, float yaw_deg = 30);
     46  Simulator(std::string name, int optitrack_mstime = 10, float yaw_deg = 30, int port=3883);
    4747  ~Simulator();
    4848  void RunSimu(void);
  • trunk/lib/FlairSimulator/src/Simulator_impl.cpp

    r218 r286  
    3131
    3232Simulator_impl::Simulator_impl(Simulator *self, int optitrack_mstime,
    33                                float yaw_deg)
    34     : vrpn_Connection_IP(), Thread(self, "simulator", 1) {
     33                               float yaw_deg,int port)
     34    : vrpn_Connection_IP(port), Thread(self, "simulator", 1) {
    3535  this->self = self;
    3636  this->optitrack_mstime = optitrack_mstime;
  • trunk/lib/FlairSimulator/src/VisualizationCamera.cpp

    r70 r286  
    3131using namespace core;
    3232using namespace scene;
     33using namespace video;
    3334
    3435namespace flair {
     
    4041  LMouseKey = false;
    4142
    42    // camera
     43  // camera for visualization
    4344  camera = getGui()->getSceneManager()->addCameraSceneNode();
    4445  camera->setAspectRatio(getGui()->getAspectRatio()); // on force a cause du view port
     
    4849
    4950  getGui()->pimpl_->AddVisualizationCamera(this);
     51 
     52  // camera to draw axis, in a new dedicated scene manager
     53  axis_scenemanager=getGui()->getSceneManager()->createNewSceneManager();
     54  axis_camera = axis_scenemanager->addCameraSceneNode();
     55  axis_camera->setAspectRatio(1);  // same as texture ratio, TODO: get it from texture in renderAxisToTexture
     56  axis_camera->setUpVector(vector3df(0, 0, 1));
     57  axis_camera->setFOV(PI / 2.5f);
     58  axis_scenemanager->setActiveCamera(axis_camera);
     59  prendre en compte le yaw monde/optitrack (rotation de axis_scenemanager?)
     60  IAnimatedMesh* arrowMeshRed = axis_scenemanager->addArrowMesh( "x_axisArrow",video::SColor(255, 255, 0, 0),video::SColor(255, 255, 0, 0));
     61  nodeX = axis_scenemanager->addMeshSceneNode(arrowMeshRed);
     62  nodeX->setMaterialFlag(video::EMF_LIGHTING, false);
     63  nodeX->setRotation(vector3df(0,0,-90));
     64  nodeX->setScale(vector3df(1,3,1));
     65 
     66  IAnimatedMesh* arrowMeshGreen = axis_scenemanager->addArrowMesh( "y_axisArrow",video::SColor(255, 0, 255, 0),video::SColor(255, 0, 255, 0));
     67  nodeY = axis_scenemanager->addMeshSceneNode(arrowMeshGreen);
     68  nodeY->setMaterialFlag(video::EMF_LIGHTING, false);
     69  nodeY->setScale(vector3df(1,3,1));
     70 
     71  IAnimatedMesh* arrowMeshBlue = axis_scenemanager->addArrowMesh( "z_axisArrow",video::SColor(255, 0, 0, 255),video::SColor(255, 0, 0, 255));
     72  nodeZ = axis_scenemanager->addMeshSceneNode(arrowMeshBlue);
     73  nodeZ->setMaterialFlag(video::EMF_LIGHTING, false);
     74  nodeZ->setRotation(vector3df(-90,0,0));//irrlicht is left handed, draw a right handed axis
     75  nodeZ->setScale(vector3df(1,3,1));
    5076}
    5177
    5278VisualizationCamera::~VisualizationCamera() {}
     79
     80void VisualizationCamera::renderAxisToTexture(ITexture* texture) {
     81  //put axis at a "normalized" distance
     82  vector3df direction=camera->getTarget()-camera->getPosition();
     83  direction.normalize();
     84  nodeX->setPosition(camera->getPosition()+direction*6);
     85  nodeY->setPosition(camera->getPosition()+direction*6);
     86  nodeZ->setPosition(camera->getPosition()+direction*6);
     87
     88  axis_camera->setPosition(camera->getPosition());
     89  axis_camera->setRotation(camera->getRotation());
     90  axis_camera->setTarget(camera->getTarget());
     91 
     92  axis_scenemanager->getVideoDriver()->setRenderTarget(texture, true, true, SColor(0,0,0,0));
     93  axis_scenemanager->drawAll();
     94  axis_scenemanager->getVideoDriver()->setRenderTarget(0, true, true, 0);
     95}
    5396
    5497std::string VisualizationCamera::getName(void) {
  • trunk/lib/FlairSimulator/src/VisualizationCamera.h

    r70 r286  
    2727    class ICameraSceneNode;
    2828  }
     29  namespace video {
     30    class ITexture;
     31  }
    2932}
    3033
     
    4245  irr::scene::ICameraSceneNode *getCameraSceneNode(void);
    4346  std::string getName(void);
     47  void renderAxisToTexture(irr::video::ITexture* texture);
    4448
    4549private:
    4650  virtual bool isEventReceiverEnabled(void) const { return true; }
    47 
     51  irr::scene::ISceneNode *nodeX,*nodeY,*nodeZ;
     52  irr::scene::ISceneManager *axis_scenemanager;
     53 
    4854protected:
    4955  bool LMouseKey;
    5056  irr::scene::ICameraSceneNode *camera;
     57  irr::scene::ICameraSceneNode *axis_camera;
    5158  irr::core::position2df MousePos;
    5259  float currentZoom;
  • trunk/lib/FlairSimulator/src/X4.h

    r214 r286  
    4343#ifdef GL
    4444  virtual void Draw(void);
    45   virtual void ExtraDraw(void){};
     45  virtual void ExtraDraw(void){};
     46#endif
    4647
    47 protected:
    48   Blade *fl_blade, *fr_blade, *rl_blade, *rr_blade;
    49   core::Mutex *motor_speed_mutex;
    50 #endif
    5148private:
    5249  void CalcModel(void);
     
    5653  void WritedbtBuf(char *dbtbuf);
    5754  void ReaddbtBuf(char *dbtbuf);
     55  Blade *fl_blade, *fr_blade, *rl_blade, *rr_blade;
     56  core::Mutex *motor_speed_mutex;
    5857#endif
    5958
  • trunk/lib/FlairSimulator/src/X8.h

    r214 r286  
    4545
    4646protected:
    47 #ifdef GL
    48   Blade *tfl_blade, *tfr_blade, *trl_blade, *trr_blade;
    49   Blade *bfl_blade, *bfr_blade, *brl_blade, *brr_blade;
    50 #endif
     47
    5148private:
    5249  void CalcModel(void);
     
    5754  void ReaddbtBuf(char *dbtbuf);
    5855  core::Mutex *motor_speed_mutex;
     56  Blade *tfl_blade, *tfr_blade, *trl_blade, *trr_blade;
     57  Blade *bfl_blade, *bfr_blade, *brl_blade, *brr_blade;
    5958#endif
    6059
  • trunk/lib/FlairSimulator/src/unexported/GenericObject.h

    r158 r286  
    4747        void setPosition(const irr::core::vector3df& position);
    4848  void setRotation(const irr::core::vector3df& rotation);
     49  void setVisible(bool isVisible);//visible by default at construction
    4950 
    5051private:
  • trunk/lib/FlairSimulator/src/unexported/Model_impl.h

    r218 r286  
    7272  void OnRegisterSceneNode(void);
    7373  void render(void);
    74   void Draw(void) {
    75     printf("CA MARCHE PAS PUNAISE\r\n");
    76     ExtraDraw();
    77   };
    78   void ExtraDraw(void) { printf("nope\r\n"); };
    7974
    8075  const irr::core::aabbox3d<irr::f32> &getBoundingBox(void) const {
  • trunk/lib/FlairSimulator/src/unexported/Simulator_impl.h

    r158 r286  
    3737public:
    3838  Simulator_impl(flair::simulator::Simulator *self, int optitrack_mstime = 10,
    39                  float yaw_deg = 30);
     39                 float yaw_deg = 30, int port=3883);
    4040  ~Simulator_impl();
    4141
Note: See TracChangeset for help on using the changeset viewer.