This is my callback
This function returns the first body the raycast hits... however I would like to add a mask to the raycast
so it behaves like filter masks ie
uint16 rayMask = levelCat | playerCat | enemyCat;
... only test ray against level, player and enemy categories as I might have bodies doing other tasks i dont want to test against
Any suggestions are gratefully recieved as my tinkering here seems to only make things worse.
Code:
// This class captures the closest hit shape.
class RayCastCallback : public b2RayCastCallback
{
public:
RayCastCallback()
{
m_fixture = NULL;
}
float32 ReportFixture( b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction)
{
m_fixture = fixture;
m_point = point;
m_normal = normal;
return fraction;
}
b2Fixture* m_fixture;
b2Vec2 m_point;
b2Vec2 m_normal;
};
class RayCastCallback : public b2RayCastCallback
{
public:
RayCastCallback()
{
m_fixture = NULL;
}
float32 ReportFixture( b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction)
{
m_fixture = fixture;
m_point = point;
m_normal = normal;
return fraction;
}
b2Fixture* m_fixture;
b2Vec2 m_point;
b2Vec2 m_normal;
};
This function returns the first body the raycast hits... however I would like to add a mask to the raycast
so it behaves like filter masks ie
uint16 rayMask = levelCat | playerCat | enemyCat;
... only test ray against level, player and enemy categories as I might have bodies doing other tasks i dont want to test against
Code:
b2Body* RayCast(float x1, float y1 , float x2, float y2)
{
// Ray points
b2Vec2 p1(x1/UNIT, y1/UNIT);
b2Vec2 p2(x2/UNIT, y2/UNIT);
// Get callback
RayCastCallback callback;
world->RayCast(&callback, p1, p2);
// Gets first shape only
b2Fixture *fixture = callback.m_fixture;
if (fixture != NULL)
{
return fixture->GetBody();
}
return NULL;
}
{
// Ray points
b2Vec2 p1(x1/UNIT, y1/UNIT);
b2Vec2 p2(x2/UNIT, y2/UNIT);
// Get callback
RayCastCallback callback;
world->RayCast(&callback, p1, p2);
// Gets first shape only
b2Fixture *fixture = callback.m_fixture;
if (fixture != NULL)
{
return fixture->GetBody();
}
return NULL;
}
Any suggestions are gratefully recieved as my tinkering here seems to only make things worse.