Need a scan cone ideas

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
monchito
Posts: 59
Joined: Thu Mar 08, 2007 9:38 pm

Need a scan cone ideas

Post by monchito »

I nee some sight in front of the entities more or less like real. Like a limited vision angle and directed by the angle of rotation. I tried a triangle 'scan cone'

Code: Select all

bool ScanCone( const core::vector3df origin, const float cone_angle, const float direction, const float lenght )
  {
    core::triangle3df hcone;
    // get 3 points for a horizontal triangle 'cone'
    hcone.pointA = origin;
    hcone.pointA.X += lenght * cos((direction + cone_angle) * core::DEGTORAD);
    hcone.pointA.Z -= lenght * sin((direction + cone_angle) * core::DEGTORAD);

    hcone.pointB = origin;
    hcone.pointB.X += lenght * cos((direction - cone_angle) * core::DEGTORAD);
    hcone.pointB.Z -= lenght * sin((direction - cone_angle) * core::DEGTORAD);

    hcone.pointC = origin;

    core::triangle3df vcone;
    // get 3 points for a vertical triangle 'cone'
    core::line3df line( hcone.pointA, hcone.pointB );
    vcone.pointA = line.getMiddle();
    vcone.pointA.Y += line.getLength()/2;

    vcone.pointB = line.getMiddle();
    vcone.pointB.Y -= line.getLength()/2;

    vcone.pointC = origin;

    For each node in the node list
    {
      get one node position
      core::vector3df point = node->getPosition();

      if ( hcone.isPointInsideFast( point ) )
        if ( vcone.isPointInsideFast( point ) )
        {
          if ( Trace( origin,  node position ) );
             std::cout << "Is inside cone" << std::endl;
        }
    }
    
    return false;
  }
an angle based one

Code: Select all

int IsInsideVisionCone( core::vector3df v1, core::vector3df v2, core::vector3df vision )
{
  float vision_angle = vision.X;
  float vision_rangeSQ = vision.Z * vision.Z;
  float vision_rotation = vision.Y;

  // out of range?.... can't see
  float DistanceSQ = v1.getDistanceFromSQ( v2 );
  if ( DistanceSQ > vision_rangeSQ )
    return 0;

  // get angles
  core::vector3df  angles = (v2 - v1).getHorizontalAngle();

  float angleH = angles.Y - 90;
  // angle between 0-360
  angleH = fmod( angleH,360 );
  angleH -= vision_rotation;
  while(angleH < 0)   angleH += 360;
  while(angleH > 360) angleH -= 360;

  // outside vision angle?.... can't see
  if ( ( angleH > vision_angle ) && ( angleH < ( 360 - vision_angle ) ) )
    return 0;

  float angleV = angles.X;
  angleV = fmod( angleV,360 ); 
  angleV -= vision_rotation;
  while(angleV < 0) angleV += 360;
  while(angleV > 360) angleV -= 360;

  if ( ( angleV > vision_angle ) && ( angleV < ( 360 - vision_angle ) ) )
    return 0;

  return 1;
}
don't know if can be near to a scan cone. Do I need another approach?
Post Reply