Changeset 288 in flair-src for trunk/lib/FlairSimulator/src
- Timestamp:
- Jan 8, 2019, 2:45:15 PM (6 years ago)
- Location:
- trunk/lib/FlairSimulator/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSimulator/src/Gui_impl.cpp
r286 r288 180 180 ITexture* texture=0; 181 181 IGUIFont* font =0; 182 VisualizationCamera::AxisType axisType=VisualizationCamera::AxisType::vrpn; 182 183 183 184 if (!driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) { … … 216 217 217 218 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"); 218 223 219 224 while (device->run()) { … … 260 265 //render to texture for axis if possible 261 266 if (texture) { 262 cameras.at(cam_id)->renderAxisToTexture(texture );267 cameras.at(cam_id)->renderAxisToTexture(texture,font,axisType); 263 268 } 264 269 … … 278 283 279 284 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 285 device->getGUIEnvironment()->drawAll(); 288 286 driver->endScene(); … … 306 304 receiver->SetModel(getModelFromVisualizationCamera(models,cameras.at(cam_id))); 307 305 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 } 308 319 } 309 320 -
trunk/lib/FlairSimulator/src/VisualizationCamera.cpp
r287 r288 27 27 #include <IrrlichtDevice.h> 28 28 #include <ISceneManager.h> 29 #include <IGUIEnvironment.h> 30 #include <IGUIFont.h> 29 31 30 32 using namespace irr; … … 36 38 namespace flair { 37 39 namespace simulator { 40 41 class 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 }; 38 83 39 84 VisualizationCamera::VisualizationCamera(std::string inName) { … … 54 99 axis_scenemanager=getGui()->getSceneManager()->createNewSceneManager(); 55 100 axis_camera= axis_scenemanager->addCameraSceneNode(); 56 axis_camera->setAspectRatio(1); // same as texture ratio, TODO: get it from texture in renderAxisToTexture57 101 axis_camera->setUpVector(vector3df(0, 0, 1)); 58 102 axis_camera->setFOV(PI / 2.5f); 59 103 axis_scenemanager->setActiveCamera(axis_camera); 60 104 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); 79 108 } 80 109 81 110 VisualizationCamera::~VisualizationCamera() {} 82 111 83 void VisualizationCamera::renderAxisToTexture(ITexture* texture) { 112 113 void VisualizationCamera::renderAxisToTexture(ITexture* texture,IGUIFont *font,AxisType axisType) { 84 114 //put axis at a "normalized" distance 85 115 vector3df direction=camera->getTarget()-camera->getPosition(); 86 116 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 91 138 axis_camera->setPosition(camera->getPosition()); 92 139 axis_camera->setRotation(camera->getRotation()); 93 140 axis_camera->setTarget(camera->getTarget()); 141 axis_camera->setAspectRatio((float)(texture->getSize().Width)/(float)(texture->getSize().Height)); // same as texture ratio 142 94 143 95 144 axis_scenemanager->getVideoDriver()->setRenderTarget(texture, true, true, SColor(0,0,0,0)); 96 145 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 97 155 axis_scenemanager->getVideoDriver()->setRenderTarget(0, true, true, 0); 98 156 } -
trunk/lib/FlairSimulator/src/VisualizationCamera.h
r287 r288 30 30 class ITexture; 31 31 } 32 namespace gui { 33 class IGUIFont; 34 } 32 35 } 33 36 34 37 namespace flair { 35 38 namespace simulator { 39 class AxisSceneNode; 36 40 37 41 class VisualizationCamera : private irr::scene::ISceneNodeAnimator { … … 45 49 irr::scene::ICameraSceneNode *getCameraSceneNode(void); 46 50 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); 48 53 49 54 private: 50 55 virtual bool isEventReceiverEnabled(void) const { return true; } 51 irr::scene::ISceneNode *nodeX,*nodeY,*nodeZ;52 56 irr::scene::ISceneManager *axis_scenemanager; 57 AxisSceneNode *vrpnSceneNode; 58 AxisSceneNode *earthSceneNode; 53 59 54 60 protected:
Note:
See TracChangeset
for help on using the changeset viewer.