Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
    bodyT.createShape(shape);
    bodyT.setMassFromShapes();
}

... 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.

Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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