Reputation: 11
I am trying to create a b2ChainShape object in Python to later use it in collision detection but I am having trouble creating the chain object in a loop.
from Box2D import b2Vec2, b2ChainShape
A = b2Vec2(1, 1) # vertices to test the loop creation
B = b2Vec2(2, 2)
C = b2Vec2(3, 3)
chain = b2ChainShape()
chain.CreateLoop([A,B,C], 3)
TypeError: Expected tuple or list of length 2, got length 3
How am I supposed to give the vertices as input? Tuple is also not working. I've already checked the Box2D.py but I did not find it helpful since it expects vertices to be b2Vec2 vertices but seemingly it doesn't iterate. I checked the C++ docs and found this quite analogue example in C++:
b2Vec2 vs[4];
vs[0].Set(1.7f, 0.0f);
vs[1].Set(1.0f, 0.25f);
vs[2].Set(0.0f, 0.0f);
vs[3].Set(-1.7f, 0.4f);
b2ChainShape chain;
chain.CreateLoop(vs, 4);
Further
chain.CreateChain(A, 2)
does work (even with only one vertex given) but I do need a chain with a lot of vertices.
Thank you in advance.
Upvotes: 1
Views: 34