89 const std::string& type )
90 :
Model( world, parent, type ),
136 s.
Load( wf, entity );
147 size.
Load( wf, entity,
"size" );
148 range.
Load( wf, entity,
"range" );
149 col.
Load( wf, entity );
150 fov = wf->
ReadAngle( entity,
"fov", fov );
151 sample_count = wf->
ReadInt( entity,
"samples", sample_count );
171 if( (hit == finder->
Parent()) || (hit == finder) )
return false;
187 ranges.resize( sample_count );
188 intensities.resize( sample_count );
189 bearings.resize( sample_count );
193 double sample_incr( fov / std::max(sample_count-1, (
unsigned int)1) );
196 double start_angle = (sample_count > 1 ? -fov/2.0 : 0.0);
199 rayorg.
a += start_angle;
200 rayorg.
z += size.z/2.0;
209 for(
size_t t(0); t<sample_count; t++ )
213 intensities[t] = r.mod ? r.mod->vis.ranger_return : 0.0;
214 bearings[t] = start_angle + ((double)t) * sample_incr;
232 snprintf( buf, 256,
"[ samples %u, range [%.2f %.2f] ]",
233 sample_count, range.min, range.max );
234 return( std::string( buf ) );
239 size_t sample_count( this->sample_count );
244 GLfloat pts[2*(sample_count+1)];
245 glVertexPointer( 2, GL_FLOAT, 0, &pts[0] );
250 glDepthMask( GL_FALSE );
261 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
262 glRectf( -size.x/2.0, -size.y/2.0, size.x/2.0, size.y/2.0 );
269 glPolygonMode( GL_FRONT, GL_FILL );
273 if( sample_count == 1 )
276 const double sidelen = ranges[0];
277 const double da = fov/2.0;
281 pts[2] = sidelen*cos(-da );
282 pts[3] = sidelen*sin(-da );
284 pts[4] = sidelen*cos(+da );
285 pts[5] = sidelen*sin(+da );
289 for(
size_t s(0);
s<sample_count+1;
s++ )
291 double ray_angle = (
s * (fov / (sample_count-1))) - fov/2.0;
292 pts[2*
s+2] = (float)(ranges[
s] * cos(ray_angle) );
293 pts[2*
s+3] = (float)(ranges[
s] * sin(ray_angle) );
300 if( sample_count > 1 )
302 glDrawArrays( GL_POLYGON, 0, sample_count );
305 glDepthMask( GL_TRUE );
322 glDrawArrays( GL_POINTS, 0, sample_count+1 );
328 for(
size_t s(0);
s<sample_count;
s++ )
330 double ray_angle((
s * (fov / (sample_count-1))) - fov/2.0);
331 pts[2*
s+2] = (float)(range.max * cos(ray_angle) );
332 pts[2*
s+3] = (float)(range.max * sin(ray_angle) );
335 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
338 glDrawArrays( GL_POLYGON, 0, sample_count+1 );
353 for(
size_t s(0);
s<sample_count;
s++ )
357 double ray_angle( sample_count == 1 ? 0 : (
s * (fov / (sample_count-1))) - fov/2.0 );
358 glVertex2f( ranges[
s] * cos(ray_angle),
359 ranges[
s] * sin(ray_angle) );
375 printf(
"\tRanges " );
376 for(
size_t i(0); i<
sensors.size(); i++ )
379 for(
size_t j(0); j<
sensors[i].ranges.size(); j++ )
380 printf(
"%.2f ",
sensors[i].ranges[j] );
385 printf(
"\n\tIntensities " );
386 for(
size_t i(0); i<
sensors.size(); i++ )
389 for(
size_t j(0); j<
sensors[i].intensities.size(); j++ )
390 printf(
"%.2f ",
sensors[i].intensities[j] );
415 ModelRanger* ranger( dynamic_cast<ModelRanger*>(mod) );
420 it->Visualize(
this, ranger );
422 const size_t sensor_count =
sensors.size();
426 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
429 for(
size_t s(0);
s<sensor_count;
s++ )
434 glBegin( GL_POINTS );
439 snprintf( buf, 8,
"%d", (
int)s );
virtual void PushColor(Color col)
static const watts_t RANGER_WATTSPERSENSOR
static const Color RANGER_CONFIG_COLOR(0, 0, 0.5)
ModelRanger(World *world, Model *parent, const std::string &type)
The Stage library uses its own namespace.
Stg::ModelRanger::Vis vis
std::string String() const
void RegisterOption(Option *opt)
Register an Option for pickup by the GUI.
static const Stg::Size RANGER_SIZE(0.15, 0.15, 0.2)
#define PRINT_DEBUG2(m, a, b)
virtual void Visualize(Model *mod, Camera *cam)
Pose & Load(Worldfile *wf, int section, const char *keyword)
void Visualize(Vis *vis, ModelRanger *rgr) const
std::vector< Sensor > sensors
static bool ranger_match(Model *hit, Model *finder, const void *dummy)
meters_t z
location in 3 axes
bool IsRelated(const Model *testmod) const
virtual void Print(char *prefix) const
void LoadSensor(Worldfile *wf, int entity)
meters_t range
range to beam hit in meters
void Load(Worldfile *wf, int entity)
RaytraceResult Raytrace(const Ray &ray)
const std::vector< Sensor > & GetSensors() const
void pose_shift(const Pose &pose)
virtual void Print(char *prefix) const
void AddVisualizer(Visualizer *custom_visual, bool on_by_default)
void draw_string(float x, float y, float z, const char *string)
void Update(ModelRanger *rgr)
class Stg::Model::Visibility vis
static Option showTransducers
void SetWatts(watts_t watts)
int ReadInt(int entity, const char *name, int value)
void SetGeom(const Geom &src)
radians_t a
rotation about the z axis.
static Option showStrikes
double ReadAngle(int entity, const char *name, double value)
Pose LocalToGlobal(const Pose &pose) const