[10] | 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}
|
---|
[8] | 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 |
|
---|
| 31 | using namespace irr;
|
---|
| 32 | using namespace irr::scene;
|
---|
| 33 | using namespace irr::core;
|
---|
| 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 | SimuLaserGL::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 |
|
---|
| 50 | SimuLaserGL::~SimuLaserGL()
|
---|
| 51 | {
|
---|
| 52 |
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | void 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
|
---|