source: flair-src/branches/sanscv/lib/FlairSimulator/src/VisualizationCamera.cpp@ 412

Last change on this file since 412 was 324, checked in by Sanahuja Guillaume, 5 years ago

removing opencv dependency

File size: 6.7 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2016/09/01
6// filename: VisualizationCamera.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: class for a visualization camera in the gui
14//
15/*********************************************************************/
16#ifdef GL
17
18#include "VisualizationCamera.h"
19#include "Simulator.h"
20#include "Model.h"
21#include "Model_impl.h"
22#include "Gui.h"
23#include "Gui_impl.h"
24#include <Euler.h>
25#include <ICursorControl.h>
26#include <ICameraSceneNode.h>
27#include <IrrlichtDevice.h>
28#include <ISceneManager.h>
29#include <IGUIEnvironment.h>
30#include <IGUIFont.h>
31
32using namespace irr;
33using namespace gui;
34using namespace core;
35using namespace scene;
36using namespace video;
37
38namespace flair {
39namespace 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};
83
84VisualizationCamera::VisualizationCamera(std::string inName) {
85 name=inName;
86 currentZoom = 0;
87 LMouseKey = false;
88
89 // camera for visualization
90 camera = getGui()->getSceneManager()->addCameraSceneNode();
91 camera->setAspectRatio(getGui()->getAspectRatio()); // on force a cause du view port
92 camera->setUpVector(vector3df(0, 0, 1));
93 camera->addAnimator(this);
94 camera->setFarValue(8000);
95
96 getGui()->pimpl_->AddVisualizationCamera(this);
97
98 // camera to draw axis, in a new dedicated scene manager
99 axis_scenemanager=getGui()->getSceneManager()->createNewSceneManager();
100 axis_camera= axis_scenemanager->addCameraSceneNode();
101 axis_camera->setUpVector(vector3df(0, 0, 1));
102 axis_camera->setFOV(PI / 2.5f);
103 axis_scenemanager->setActiveCamera(axis_camera);
104
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);
108}
109
110VisualizationCamera::~VisualizationCamera() {}
111
112
113void VisualizationCamera::renderAxisToTexture(ITexture* texture,IGUIFont *font,AxisType axisType) {
114 //put axis at a "normalized" distance
115 vector3df direction=camera->getTarget()-camera->getPosition();
116 direction.normalize();
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
138 axis_camera->setPosition(camera->getPosition());
139 axis_camera->setRotation(camera->getRotation());
140 axis_camera->setTarget(camera->getTarget());
141 axis_camera->setAspectRatio((float)(texture->getSize().Width)/(float)(texture->getSize().Height)); // same as texture ratio
142
143
144 axis_scenemanager->getVideoDriver()->setRenderTarget(texture, true, true, SColor(0,0,0,0));
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
155 axis_scenemanager->getVideoDriver()->setRenderTarget(0, true, true, 0);
156}
157
158std::string VisualizationCamera::getName(void) {
159 return name;
160}
161
162ICameraSceneNode *VisualizationCamera::getCameraSceneNode(void) {
163 return camera;
164}
165
166ISceneNodeAnimator *VisualizationCamera::createClone(ISceneNode *node,
167 ISceneManager *newManager) {
168 return NULL;
169}
170
171bool VisualizationCamera::OnEvent(const irr::SEvent& event) {
172 if (event.EventType != EET_MOUSE_INPUT_EVENT)
173 return false;
174
175 switch (event.MouseInput.Event) {
176
177 case EMIE_MOUSE_WHEEL:
178 currentZoom -= event.MouseInput.Wheel;
179 break;
180 case EMIE_LMOUSE_PRESSED_DOWN:
181 LMouseKey = true;
182 break;
183 case EMIE_LMOUSE_LEFT_UP:
184 LMouseKey = false;
185 break;
186 case EMIE_MOUSE_MOVED:
187 MousePos = getGui()->getDevice()->getCursorControl()->getRelativePosition();
188 break;
189 default:
190 return false;
191 break;
192 }
193
194 return true;
195}
196
197} // end namespace simulator
198} // end namespace flair
199
200#endif // GL
Note: See TracBrowser for help on using the repository browser.