Reputation: 6207
I recently upgraded the version of box2d to v2.2.1 in a long-running project, and it caused a number of backward-compatibility issues with existing project code. Most were resolved, except for this one
b2Fixture *f = body->GetFixtureList();
b2RayCastOutput output;
b2RayCastInput input;
f->RayCast(&output, input) // broken call
is now broken, expecting a 3rd argument. I see in the box2d source code that the function signature is
inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const;
but I can't find any examples of what childIndex
is supposed to be. Can someone provide an example of how to use this updated RayCast function?
EDIT: I notice that setting childIndex
to 0 seems to work, but I don't know why.
Upvotes: 1
Views: 799
Reputation: 8272
This parameter is only relevant for b2ChainShape fixtures. For other shape types it's just there to conform to the virtual function signature.
The functionality of chain shapes is actually done by multiple b2EdgeShapes, and the chain shape itself could be thought of as a helper to organize these edge shape 'children'. It allocates memory, sets up ghost vertices for you, and delegates things like collsion checks to the edge shapes.
If you're not casting rays against chain shapes you can leave this as zero. If you are, you can use these functions of b2ChainShape to cast the ray against each child edge:
int32 GetChildCount() const;
void GetChildEdge(b2EdgeShape* edge, int32 index) const;
The second of those is used like:
b2EdgeShape edgeShape;
chainShape->GetChildEdge(&edgeShape, 123);
You'll need to cast the shape to a b2ChainShape* first:
if ( e_chain == fixture->GetType() ) {
b2ChainShape* chainShape = (b2ChainShape*)fixture->GetShape();
....
}
... it would be easier and more efficient to use the RayCast function of b2World :)
Upvotes: 3