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


Ignore:
Timestamp:
Jan 8, 2019, 2:45:15 PM (6 years ago)
Author:
Sanahuja Guillaume
Message:

added earth frame axis

Location:
trunk/lib/FlairSimulator/src
Files:
3 edited

Legend:

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

    r286 r288  
    180180  ITexture* texture=0;
    181181  IGUIFont* font =0;
     182  VisualizationCamera::AxisType axisType=VisualizationCamera::AxisType::vrpn;
    182183 
    183184  if (!driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) {
     
    216217
    217218  setWindowCaption(0, 0);
     219 
     220  Printf("\nUsefull keys:\n");
     221  Printf(" page up/down: circle between cameras\n");
     222  Printf(" a: change axis display (VRPN, earth or none)\n");
    218223
    219224  while (device->run()) {
     
    260265    //render to texture for axis if possible
    261266    if (texture) {
    262       cameras.at(cam_id)->renderAxisToTexture(texture);
     267      cameras.at(cam_id)->renderAxisToTexture(texture,font,axisType);
    263268    }
    264269   
     
    278283   
    279284    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     }
    287285    device->getGUIEnvironment()->drawAll();
    288286    driver->endScene();
     
    306304      receiver->SetModel(getModelFromVisualizationCamera(models,cameras.at(cam_id)));
    307305      setWindowCaption(cam_id, fps);
     306    }
     307    if (receiver->IsKeyDown(KEY_KEY_A)) {
     308      switch(axisType) {
     309        case VisualizationCamera::AxisType::vrpn:
     310          axisType=VisualizationCamera::AxisType::earth;
     311          break;
     312        case VisualizationCamera::AxisType::earth:
     313          axisType=VisualizationCamera::AxisType::none;
     314          break;
     315        case VisualizationCamera::AxisType::none:
     316          axisType=VisualizationCamera::AxisType::vrpn;
     317          break;
     318      }
    308319    }
    309320
  • trunk/lib/FlairSimulator/src/VisualizationCamera.cpp

    r287 r288  
    2727#include <IrrlichtDevice.h>
    2828#include <ISceneManager.h>
     29#include <IGUIEnvironment.h>
     30#include <IGUIFont.h>
    2931
    3032using namespace irr;
     
    3638namespace flair {
    3739namespace simulator {
     40
     41class AxisSceneNode: public ISceneNode {
     42    public:
     43      AxisSceneNode(ISceneManager *axis_scenemanager):ISceneNode(axis_scenemanager->getRootSceneNode(), axis_scenemanager, -1) {
     44        //draw ned axis
     45        IAnimatedMesh* arrowMeshRed = axis_scenemanager->addArrowMesh( "x_axisArrow",video::SColor(255, 255, 0, 0),video::SColor(255, 255, 0, 0));
     46        nodeX = axis_scenemanager->addMeshSceneNode(arrowMeshRed,this);
     47        nodeX->setMaterialFlag(video::EMF_LIGHTING, false);
     48        nodeX->setRotation(vector3df(0,0,-90));//use vrpn yaw rotation from earth
     49        nodeX->setScale(vector3df(1,3,1));
     50       
     51        IAnimatedMesh* arrowMeshGreen = axis_scenemanager->addArrowMesh( "y_axisArrow",video::SColor(255, 0, 255, 0),video::SColor(255, 0, 255, 0));
     52        nodeY = axis_scenemanager->addMeshSceneNode(arrowMeshGreen,this);
     53        nodeY->setMaterialFlag(video::EMF_LIGHTING, false);
     54        nodeY->setScale(vector3df(1,3,1));
     55       
     56        IAnimatedMesh* arrowMeshBlue = axis_scenemanager->addArrowMesh( "z_axisArrow",video::SColor(255, 0, 0, 255),video::SColor(255, 0, 0, 255));
     57        nodeZ = axis_scenemanager->addMeshSceneNode(arrowMeshBlue,this);
     58        nodeZ->setMaterialFlag(video::EMF_LIGHTING, false);
     59        nodeZ->setRotation(vector3df(-90,0,0));//irrlicht is left handed, draw a right handed axis
     60        nodeZ->setScale(vector3df(1,3,1)); 
     61      }
     62     
     63      void render(void) {
     64        IVideoDriver *driver = SceneManager->getVideoDriver();
     65        driver->setTransform(ETS_WORLD, AbsoluteTransformation);
     66      }
     67
     68      void OnRegisterSceneNode(void) {
     69        if (IsVisible)
     70          SceneManager->registerNodeForRendering(this);
     71
     72        ISceneNode::OnRegisterSceneNode();
     73      }
     74     
     75      const aabbox3d<f32> &getBoundingBox(void) const {
     76        return box;
     77      }
     78     
     79    private:
     80      aabbox3d<f32> box;
     81      ISceneNode *nodeX,*nodeY,*nodeZ;
     82};
    3883
    3984VisualizationCamera::VisualizationCamera(std::string inName) {
     
    5499  axis_scenemanager=getGui()->getSceneManager()->createNewSceneManager();
    55100  axis_camera= axis_scenemanager->addCameraSceneNode();
    56   axis_camera->setAspectRatio(1);  // same as texture ratio, TODO: get it from texture in renderAxisToTexture
    57101  axis_camera->setUpVector(vector3df(0, 0, 1));
    58102  axis_camera->setFOV(PI / 2.5f);
    59103  axis_scenemanager->setActiveCamera(axis_camera);
    60104 
    61   //draw ned axis
    62   IAnimatedMesh* arrowMeshRed = axis_scenemanager->addArrowMesh( "x_axisArrow",video::SColor(255, 255, 0, 0),video::SColor(255, 255, 0, 0));
    63   nodeX = axis_scenemanager->addMeshSceneNode(arrowMeshRed);
    64   nodeX->setMaterialFlag(video::EMF_LIGHTING, false);
    65   nodeX->setRotation(vector3df(0,0,-90+core::Euler::ToDegree(getSimulator()->Yaw())));//use vrpn yaw rotation from earth
    66   nodeX->setScale(vector3df(1,3,1));
    67  
    68   IAnimatedMesh* arrowMeshGreen = axis_scenemanager->addArrowMesh( "y_axisArrow",video::SColor(255, 0, 255, 0),video::SColor(255, 0, 255, 0));
    69   nodeY = axis_scenemanager->addMeshSceneNode(arrowMeshGreen);
    70   nodeY->setMaterialFlag(video::EMF_LIGHTING, false);
    71   nodeY->setRotation(vector3df(0,0,core::Euler::ToDegree(getSimulator()->Yaw())));//use vrpn yaw rotation from earth
    72   nodeY->setScale(vector3df(1,3,1));
    73  
    74   IAnimatedMesh* arrowMeshBlue = axis_scenemanager->addArrowMesh( "z_axisArrow",video::SColor(255, 0, 0, 255),video::SColor(255, 0, 0, 255));
    75   nodeZ = axis_scenemanager->addMeshSceneNode(arrowMeshBlue);
    76   nodeZ->setMaterialFlag(video::EMF_LIGHTING, false);
    77   nodeZ->setRotation(vector3df(-90,0,0));//irrlicht is left handed, draw a right handed axis
    78   nodeZ->setScale(vector3df(1,3,1));
     105  vrpnSceneNode=new AxisSceneNode(axis_scenemanager);
     106  vrpnSceneNode->setRotation(vector3df(0,0,core::Euler::ToDegree(getSimulator()->Yaw())));//use vrpn yaw rotation from earth
     107  earthSceneNode=new AxisSceneNode(axis_scenemanager);
    79108}
    80109
    81110VisualizationCamera::~VisualizationCamera() {}
    82111
    83 void VisualizationCamera::renderAxisToTexture(ITexture* texture) {
     112
     113void VisualizationCamera::renderAxisToTexture(ITexture* texture,IGUIFont *font,AxisType axisType) {
    84114  //put axis at a "normalized" distance
    85115  vector3df direction=camera->getTarget()-camera->getPosition();
    86116  direction.normalize();
    87   nodeX->setPosition(camera->getPosition()+direction*6);
    88   nodeY->setPosition(camera->getPosition()+direction*6);
    89   nodeZ->setPosition(camera->getPosition()+direction*6);
    90 
     117  vrpnSceneNode->setPosition(camera->getPosition()+direction*6);
     118  earthSceneNode->setPosition(camera->getPosition()+direction*6);
     119 
     120  stringw axisText;
     121  switch(axisType) {
     122    case AxisType::vrpn:
     123      vrpnSceneNode->setVisible(true);
     124      earthSceneNode->setVisible(false);
     125      axisText="VRPN";
     126      break;
     127    case AxisType::earth:
     128      vrpnSceneNode->setVisible(false);
     129      earthSceneNode->setVisible(true);
     130      axisText="earth";
     131      break;
     132    case AxisType::none:
     133      vrpnSceneNode->setVisible(false);
     134      earthSceneNode->setVisible(false);
     135      break;
     136  }
     137 
    91138  axis_camera->setPosition(camera->getPosition());
    92139  axis_camera->setRotation(camera->getRotation());
    93140  axis_camera->setTarget(camera->getTarget());
     141  axis_camera->setAspectRatio((float)(texture->getSize().Width)/(float)(texture->getSize().Height));  // same as texture ratio
     142
    94143 
    95144  axis_scenemanager->getVideoDriver()->setRenderTarget(texture, true, true, SColor(0,0,0,0));
    96145  axis_scenemanager->drawAll();
     146 
     147  if(font && axisType!=AxisType::none) {
     148    font->draw(axisText,rect<s32>(10,texture->getSize().Height-25,texture->getSize().Width,texture->getSize().Height),SColor(255,255,255,255));
     149    font->draw("X",rect<s32>(60,texture->getSize().Height-25,texture->getSize().Width,texture->getSize().Height),SColor(255,255,0,0));
     150    font->draw("Y",rect<s32>(70,texture->getSize().Height-25,texture->getSize().Width,texture->getSize().Height),SColor(255,0,255,0));
     151    font->draw("Z",rect<s32>(80,texture->getSize().Height-25,texture->getSize().Width,texture->getSize().Height),SColor(255,0,0,255));
     152    getGui()->getDevice()->getGUIEnvironment()->drawAll();
     153  }
     154 
    97155  axis_scenemanager->getVideoDriver()->setRenderTarget(0, true, true, 0);
    98156}
  • trunk/lib/FlairSimulator/src/VisualizationCamera.h

    r287 r288  
    3030    class ITexture;
    3131  }
     32  namespace gui {
     33    class IGUIFont;
     34  }
    3235}
    3336
    3437namespace flair {
    3538namespace simulator {
     39class AxisSceneNode;
    3640
    3741class VisualizationCamera : private irr::scene::ISceneNodeAnimator {
     
    4549  irr::scene::ICameraSceneNode *getCameraSceneNode(void);
    4650  std::string getName(void);
    47   void renderAxisToTexture(irr::video::ITexture* texture);
     51  enum class AxisType { vrpn,earth,none};
     52  void renderAxisToTexture(irr::video::ITexture* texture,irr::gui::IGUIFont *font,AxisType axisType);
    4853
    4954private:
    5055  virtual bool isEventReceiverEnabled(void) const { return true; }
    51   irr::scene::ISceneNode *nodeX,*nodeY,*nodeZ;
    5256  irr::scene::ISceneManager *axis_scenemanager;
     57  AxisSceneNode *vrpnSceneNode;
     58  AxisSceneNode *earthSceneNode;
    5359
    5460protected:
Note: See TracChangeset for help on using the changeset viewer.