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