00001 00002 #ifndef Range_Sensor_h 00003 #define Range_Sensor_h 1 00004 00005 #include <iostream> 00006 using std::ostream ; 00007 00008 #include "streams\mystreams.h" 00009 #include "geometry\ObjectBase.h" 00010 #include "geometry\ObjectGroup.h" 00011 #include "geometry\mesh.h" 00012 #include "geometry\MPK_Cylinder.h" 00013 #include "geometry\MPK_Sphere.h" 00014 #include "geometry\MPK_Box.h" 00015 #include "math\math2.h" 00016 #include "universe\universe.h" 00017 #include "planners\output\O_Bitmap.h" 00018 #include "MgcFrustum.h" 00019 00020 //#include "stdafx.h" //for TRACE calls 00021 00022 00023 const int RAY_ARRAY_LIMIT = 256; //<-- don't change this, should be 256 to interface with octree code 00024 const double minrange = 0.000001; //constant should be close to 0 00025 00027 //note: going from double to float in the octree generation code saves us 12 megs! 00028 class ray_array_space 00029 { 00030 public: 00031 double values [RAY_ARRAY_LIMIT][RAY_ARRAY_LIMIT][3]; 00032 }; 00033 00034 class Range_Sensor : public ObjectBase 00035 { 00036 00037 public: 00038 00039 Range_Sensor (FrameManager* frameManager); 00040 00041 Range_Sensor (const Range_Sensor& right); 00042 00043 virtual ~Range_Sensor(); 00044 00045 virtual bool IsInterfering (const Entity* entity) const; 00046 00047 virtual bool CanCheckInterference (const Entity* entity) const; 00048 00049 virtual void Serialize (ostream& os) const; 00050 00051 virtual void Deserialize (istream& is); 00052 00053 void SetAngle (double angle); 00054 00055 void SetMaxRange (double maxrange); 00056 00057 void SetMaxError (double maxerror); 00058 00059 double GetAngle () const; 00060 00061 double GetMaxRange () const; 00062 00063 double GetMaxError () const; 00064 00065 void Range_Sensor::Take_Picture (const std::vector< Entity* > allEntities, bool display2DMap); 00066 00067 Entity* Range_Sensor::Clone () const; 00068 virtual bool Verify() const; 00069 00070 double ray_source[3]; 00071 double ray_coord_map[RAY_ARRAY_LIMIT][RAY_ARRAY_LIMIT][3]; //the output intersection coords 00072 double ray_depth_map[RAY_ARRAY_LIMIT][RAY_ARRAY_LIMIT]; 00073 00074 00075 protected: 00076 00077 bool DisplayingBitmapEnabled; 00078 bool amDisplayingBitmap; 00079 00080 O_Bitmap* bp; 00081 00082 void Range_Sensor::AddEntityToDepthMap (const Entity* entity); 00083 void Range_Sensor::AddMeshToDepthMap (const Mesh& mesh); 00084 void Range_Sensor::AddCylinderToDepthMap (const MPK_Cylinder& mpk_cylinder); 00085 void Range_Sensor::AddSphereToDepthMap (const MPK_Sphere& mpk_sphere); 00086 void Range_Sensor::AddBoxToDepthMap (const MPK_Box& mpk_box); 00087 void Range_Sensor::Generate_Ray_Array (); 00088 void Range_Sensor::Generate_Coord_Map (); 00089 00090 double angle; 00091 double maxrange; 00092 double maxerror; 00093 00094 double angleratio; //will be set to tan(angle/2) 00095 00096 MgcFrustum theFrustum; //shape of view frustum (automatically calculated for internal use) 00097 00098 Matrix4x4 absFrame; //postion of frame relative to (0,0,0) 00099 00100 ray_array_space* ray_array; // these will be the normalized ray direction vectors 00101 00102 int ray_half_limit; 00103 00104 int user_ray_range_y; 00105 int lower_ray_lim_y; 00106 int upper_ray_lim_y; 00107 00108 int user_ray_range_z; 00109 int lower_ray_lim_z; 00110 int upper_ray_lim_z; 00111 00112 private: 00113 00114 }; 00115 00116 00117 #endif