private int getSensorIndex(IAgent agent, int offset, int pos)
{
double sensorWidth = 180.0 / (double)SENSORS_PER_OBJECT_TYPE;
double dtheta = pos - agent.Orientation;
if (Math.Abs(pos - agent.Orientation) > Math.Abs(pos - (agent.Orientation + 360)))
dtheta = pos - (agent.Orientation + 360);
// If the plant's behind us
if(dtheta < -90 || dtheta > 90)
return -1;
int idx = 0;
for (double degrees = -90 + sensorWidth; degrees <= 90 + double.Epsilon; degrees += sensorWidth, idx++)
if (degrees > dtheta)
return idx + offset;
return -1;
}
#endregion