# Box2D create triangle coordinate system

This topic is 2688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I have been writing a Physics demo the last week using Box2D Net (Box2D wrapper and eseentially the same as Farseer) and XNA. I had no issues integrating a box, and sphere but than was wondering how the custom shape definition's work. So after some research on the web I found out you use the PolygonShape class and pass it a Vector2 array. So off I go defining my verticies in the space as my sprite by doing something such as this;

 PolygonShape triangle = new PolygonShape(); Vector2 position = base.image.Position; Vector2 origin = base.image.Origin; Vector2[] verts = new Vector2[] { Vector2.Subtract(position, origin), new Vector2(position.X, position.Y + origin.Y), new Vector2(position.X + origin.X, position.Y - origin.Y), }; triangle.Set(verts, verts.Length); ... 

To my shock I couldn't get this to work no matter what I tried, whether using clockwise or counter clockwise cordinates. So after much further investigation I found out that you have to define a triangle like this;

 PolygonShape triangle = new PolygonShape(); Vector2[] verts = new Vector2[] { new Vector2(-2f,-2f), new Vector2(-1f,-2f), new Vector2(0f,2f), }; triangle.Set(verts, verts.Length); ... 

After doing quite a few hours of researching I cannot seem to find something on google (including the Box2D manual about defining irregular shapes) coordinate system. So my question is, can someone tell me or point me to a resource that explains how to use Box2D's coordinate system.

Additional information; The base.image is my sprite and an example position is like Vector2(200f, 100f) and the Origin is 16f (direct middle of my sprite).

Any insight into the coordinate system of Box2D would be greatly appreciated.
Thank you.

**EDIT***
I have found a couple of documents explaining it, (I was searching Box2D Net but the real projcet is Box2D XNA). I have sense found some documentation on the coordinate system such as how you need to scale everything for the physics engine. I am stil having problems with custom verticies but I should be able to figure it out.

I can't find a way to delete this post otherwise I would. Admin: feel free to remove it. Edited by XXChester

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015431
×