source: flair-src/trunk/lib/FlairSimulator/src/SimuLaserGL.cpp@ 8

Last change on this file since 8 was 8, checked in by Sanahuja Guillaume, 6 years ago

simulator

File size: 3.0 KB
Line 
1// created: 2014/02/07
2// filename: SimuUsGL.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: Class for a simulation us
10//
11//
12/*********************************************************************/
13#ifdef GL
14
15#include "SimuLaserGL.h"
16#include "Model.h"
17#include "Gui.h"
18#include <cvmatrix.h>
19#include <SharedMem.h>
20#include <TabWidget.h>
21#include <Tab.h>
22#include <DoubleSpinBox.h>
23#include <Vector3DSpinBox.h>
24#include <ISceneNode.h>
25#include <ISceneCollisionManager.h>
26
27using namespace irr;
28using namespace irr::scene;
29using namespace irr::core;
30using namespace flair::core;
31using namespace flair::gui;
32using namespace flair::simulator;
33
34namespace flair
35{
36namespace sensor
37{
38SimuLaserGL::SimuLaserGL(const Model* parent,std::string name,int dev_id) :SimuLaser(parent,name,dev_id),SensorGL(parent)
39{
40 Tab* setup_tab=new Tab(parent->GetTabWidget(),name);
41 position=new Vector3DSpinBox(setup_tab->NewRow(),"position",-2,2,.01);
42 direction=new Vector3DSpinBox(setup_tab->NewRow(),"direction",-2,2,.01);
43 range=new DoubleSpinBox(setup_tab->NewRow(),"range:",0,30,1);
44}
45
46SimuLaserGL::~SimuLaserGL()
47{
48
49}
50
51void SimuLaserGL::UpdateFrom(const io_data *data)
52{
53 float value[360];
54
55 if(noGui()==false && data==NULL)
56 {
57 for (int i=0; i<360; i++)
58 {
59 line3d<f32> ray_laser;//rayon provenant de l'ultra son
60 vector3df intersection_laser;//point intersection us avec le sol
61 triangle3df hitTriangle_laser;//triangle intersection us avec le sol
62
63 //get rotation matrix of node - Zeuss must be getRotation not getRelativeTransformation
64 matrix4 m;
65 matrix4 M;
66 m.setRotationDegrees(Node()->getRotation());
67
68 //Matrice de rotation pour balayage du laser, angle i
69 M.setRotationDegrees(vector3df(0,0,i));
70 // transform forward vector of us
71 vector3df frv =ToIrrlichtCoordinates(direction->Value());
72 M.transformVect(frv);
73 m.transformVect(frv);
74 frv.normalize();
75
76
77 // transform pos vector of us
78 vector3df pos =ToIrrlichtCoordinates(position->Value());
79 m.transformVect(pos);
80
81 ray_laser.start =Node()->getPosition() + pos;
82 ray_laser.end = ray_laser.start + ToIrrlichtScale(range->Value())*frv;
83
84 scene::ISceneNode * selectedSceneNode =
85 CollMan()->getSceneNodeAndCollisionPointFromRay(ray_laser,intersection_laser,hitTriangle_laser);
86 // //////////////////////////////////////////
87 if(selectedSceneNode) //
88 {
89 value[i]=ToSimulatorScale(ray_laser.start.getDistanceFrom(intersection_laser));
90 }
91 else
92 {
93 value[i]=-1;
94 }
95
96 }
97 shmem->Write((char*)value,360*sizeof(float));
98 }
99}
100
101} // end namespace sensor
102} // end namespace flair
103#endif
Note: See TracBrowser for help on using the repository browser.