I've created a triangle for jbox2d...

public void createTri(){ 

    PolygonDef shape = new PolygonDef();

    shape.density = 2.0f;

    shape.friction = 0.8f;
    shape.restitution = 0.3f;
    shape.addVertex( new Vec2(35/RATE,35/RATE) );
    shape.addVertex( new Vec2(65/RATE,35/RATE) );
    shape.addVertex( new Vec2(45/RATE,55/RATE) );

    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(50/RATE, 50/RATE);
    bodyT= world.createBody(bodyDef);

... but when drawing it on canvas, how to I get position of all the vertexes?

with bodyT.getPosition().x and .y I can get only the center spot.



I don't know about JBox2D but in the actual Box2D lib there is PolygonShape.GetVertex()

  //Returns a Vec2 (the coordinates) of a vertex given its index
  const b2Vec2& GetVertex(int32 index) const;

So according to your code, I think calling shape.GetVertex(1) returns the second vertex you added.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.