00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __IRSENSOR_H
00033 #define __IRSENSOR_H
00034
00035 #include <enki/PhysicalEngine.h>
00036 #include <enki/Interaction.h>
00037
00038 #include <valarray>
00039
00044 namespace Enki
00045 {
00050
00051
00052 struct SensorResponseFunctor
00053 {
00055 virtual ~SensorResponseFunctor() {}
00057 virtual double operator()(double, const An::Color &) = 0;
00058 };
00059
00061
00062 class IRSensor : public LocalInteraction
00063 {
00064 protected:
00066 An::Vector absPos;
00068 double absOrientation;
00070 An::Vector pos;
00072 double height;
00074 double orientation;
00076 double range;
00078 double aperture;
00080 unsigned rayCount;
00082
00085 std::valarray<SensorResponseFunctor *> sensorResponseKernel;
00086
00088 double smartRadius;
00090 An::Point smartPos;
00092 An::Vector absSmartPos;
00094 std::valarray<double> rayValues;
00096 std::valarray<An::Color> rayColors;
00098 std::valarray<double> rayAngles;
00100 std::valarray<double> absRayAngles;
00101
00102 public:
00104 double finalValue;
00105
00106 public:
00110 IRSensor(Robot *owner, An::Vector pos, double height, double orientation, double range, double aperture, unsigned rayCount, SensorResponseFunctor **sensorResponseKernel);
00112 void init();
00114 void objectStep(double dt, PhysicalObject *po, World *w);
00116 void wallsStep(World *w);
00118 void finalize(double dt);
00119
00121 An::Point getAbsolutePosition(void) { return absPos; }
00123 double getAbsoluteOrientation(void) { return absOrientation; }
00125 unsigned getRayCount(void) { return rayCount; }
00127 double getAperture(void) { return aperture; }
00129 double getRange(void) { return range; }
00131 double getSmartRadius(void) { return smartRadius; }
00133 An::Point getAbsSmartPos(void) { return absSmartPos; }
00134
00135 private:
00138 double distanceToPolygon(double rayAngle, const An::Polygone &p) const;
00139 };
00140 }
00141
00142 #endif