Raycast doesn't see any bodies

Discuss issues specific to miscellaneous ports of Box2D
chelneru
Posts: 5
Joined: Fri Nov 08, 2013 11:33 am

Raycast doesn't see any bodies

Postby chelneru » Wed Feb 05, 2014 1:15 pm

Hi !

I am using the iforce's raycast example but my raycast doesn't detect any collision with the bodies
This is the raycast function (copy/pasted)

Code: Select all


void drawRay( b2Vec2 p1, b2Vec2 p2 )
  {
 
      //set up input
      b2RayCastInput input;
      input.p1 = p1;
      input.p2 = p2;
      input.maxFraction = 1;
 
   
      float closestFraction = 1;
      b2Vec2 intersectionNormal(0,0);
      for (b2Body* b = world->GetBodyList(); b; b = b->GetNext()) {
          for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) {
 
              b2RayCastOutput output;
              if ( ! f->RayCast( &output, input,0 ) )
                  continue;
              if ( output.fraction < closestFraction ) {
                  closestFraction = output.fraction;
                  intersectionNormal = output.normal;
              }           
          }
      }
 
      b2Vec2 intersectionPoint = p1 + closestFraction * (p2 - p1);
 
      //draw a line
     al_draw_line(p1.x,p1.y,intersectionPoint.x,intersectionPoint.y,al_map_rgb(255,0,0),1);
     
  }




I call this function right after 'world->Step(timeStep, velocityIterations, positionIterations); '

I see the line moving counter-clockwise but without modifying it's length when intersects a body

Could you tell me what's to be fixed ?

Return to “Miscellaneous”



Who is online

Users browsing this forum: No registered users and 1 guest