Ignore:
Timestamp:
01/08/19 14:45:15 (5 years ago)
Author:
Sanahuja Guillaume
Message:

added earth frame axis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.