ChirpSim
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
irsensor.h
Go to the documentation of this file.
1 #ifndef IRSENSOR_H
2 #define IRSENSOR_H
3 
4 #include <QGraphicsItem>
5 #include <QVector>
6 #include <QJsonObject>
7 #include <QPointF>
8 #include <Box2D/Box2D.h>
9 
10 #include "sensor.h"
11 #include "world.h"
12 #include "robot.h"
14 
15 
21 class IrSensorRayCastCallback : public b2RayCastCallback
22 {
23 public:
24  IrSensorRayCastCallback() : b2RayCastCallback(), _fraction(1) {}
25  float32 ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float32 fraction);
26 
30  void reset();
31 
35  float fraction() const;
36 
40  b2Body *objectHit() const;
41 private:
42  float _fraction;
43  b2Body *_object;
44 };
45 
52 class ChirpIrSensor : public Sensor
53 {
54 public:
55  explicit ChirpIrSensor(PhysicalObject *robot, QPointF position,
56  float rotationAngle, float reach, float maxValue, float sensorWidth, uint rays);
57 
62  unsigned value();
63 
69 
73  void update();
74 
75 private:
77 
78  QPointF _position;
79  float _maxDistance;
80  float _maxValue;
81  QVector<float> _fractions;
82  float _baseAngle;
83 
84  float _sensorWidth;
85  uint _rays;
86 
88 };
89 
90 
91 #endif // IRSENSOR_H