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 | #include "SimuUsGL.h"
|
---|
14 | #include "Model.h"
|
---|
15 | #include <cvmatrix.h>
|
---|
16 | #include <SharedMem.h>
|
---|
17 | #include <TabWidget.h>
|
---|
18 | #include <Tab.h>
|
---|
19 | #include <DoubleSpinBox.h>
|
---|
20 | #include <Vector3DSpinBox.h>
|
---|
21 |
|
---|
22 | #ifdef GL
|
---|
23 | #include "Gui.h"
|
---|
24 | #include <ISceneNode.h>
|
---|
25 | #include <ISceneCollisionManager.h>
|
---|
26 | using namespace irr;
|
---|
27 | using namespace irr::scene;
|
---|
28 | using namespace irr::core;
|
---|
29 | #endif
|
---|
30 | using namespace flair::core;
|
---|
31 | using namespace flair::gui;
|
---|
32 | using namespace flair::simulator;
|
---|
33 |
|
---|
34 | namespace flair
|
---|
35 | {
|
---|
36 | namespace sensor
|
---|
37 | {
|
---|
38 | SimuUsGL::SimuUsGL(const Model* parent,std::string name,int dev_id) :SimuUs(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,6,1);
|
---|
44 | }
|
---|
45 |
|
---|
46 | SimuUsGL::~SimuUsGL()
|
---|
47 | {
|
---|
48 |
|
---|
49 | }
|
---|
50 |
|
---|
51 | void SimuUsGL::UpdateFrom(const io_data *data)
|
---|
52 | {
|
---|
53 | float value;
|
---|
54 | #ifdef GL
|
---|
55 | if(noGui()==true)
|
---|
56 | {
|
---|
57 | #endif
|
---|
58 | //todo: utiliser le placement de l'us dans le drone et sa portée
|
---|
59 | cvmatrix *input=(cvmatrix*)data;
|
---|
60 | value=input->Value(9,0);
|
---|
61 | shmem->Write((char*)&value,sizeof(float));
|
---|
62 | #ifdef GL
|
---|
63 | }
|
---|
64 |
|
---|
65 | if(noGui()==false && data==NULL)
|
---|
66 | {
|
---|
67 | line3d<f32> ray_us;//rayon provenant de l'ultra son
|
---|
68 | vector3df intersection_us;//point intersection us avec le sol
|
---|
69 | triangle3df hitTriangle_us;//triangle intersection us avec le sol
|
---|
70 |
|
---|
71 | //get rotation matrix of node - Zeuss must be getRotation not getRelativeTransformation
|
---|
72 | matrix4 m;
|
---|
73 | m.setRotationDegrees(Node()->getRotation());
|
---|
74 |
|
---|
75 | // transform forward vector of us
|
---|
76 | vector3df frv =ToIrrlichtCoordinates(direction->Value());
|
---|
77 | m.transformVect(frv);
|
---|
78 | frv.normalize();
|
---|
79 |
|
---|
80 | // transform pos vector of us
|
---|
81 | vector3df pos =ToIrrlichtCoordinates(position->Value());
|
---|
82 | m.transformVect(pos);
|
---|
83 |
|
---|
84 | ray_us.start =Node()->getPosition() +pos;
|
---|
85 | ray_us.end = ray_us.start + ToIrrlichtScale(range->Value())*frv;
|
---|
86 |
|
---|
87 | scene::ISceneNode * selectedSceneNode =
|
---|
88 | CollMan()->getSceneNodeAndCollisionPointFromRay(ray_us,intersection_us,hitTriangle_us);
|
---|
89 |
|
---|
90 | if(selectedSceneNode)
|
---|
91 | {
|
---|
92 | float value=ToSimulatorScale(ray_us.start.getDistanceFrom(intersection_us));
|
---|
93 | shmem->Write((char*)&value,sizeof(float));
|
---|
94 | }
|
---|
95 | }
|
---|
96 | #endif
|
---|
97 | }
|
---|
98 |
|
---|
99 | } // end namespace sensor
|
---|
100 | } // end namespace flair
|
---|