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

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

lic

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