I am trying to implement collisions using the separating axis theorem. However All I have ever used in terms of polygons is the Rectangle class included in XNA already. How can I make multi-sided polygons?
1 Answer
\$\begingroup\$
\$\endgroup\$
5
You can draw triangles directly using DrawUserIndexedPrimitives and other similar functions. Yes, it is much more work than simply drawing rectangles.
Example code: http://msdn.microsoft.com/en-us/library/bb196414(v=xnagamestudio.40).aspx
-
\$\begingroup\$ This is good but I am looking more for a function I can use to draw multi sided polygons, not just triangles \$\endgroup\$– RogerMay 23, 2013 at 15:52
-
\$\begingroup\$ @Roger There is no such thing built into the XNA framework. You could build something to do it for you, of course. But no matter what you do, a polygon would need to be defined in terms of its component triangles; that's the only format the GPU can process. \$\endgroup\$ May 23, 2013 at 16:49
-
\$\begingroup\$ I think the user's question is more to do with collision detection. Question for the user: Are you expecting your polygons to have concave sections? (so that if you're following along its boundary: Do you ever turn "left" instead of right?) This may affect what kinds of collision detection you can use . \$\endgroup\$ May 24, 2013 at 13:12
-
\$\begingroup\$ @Katana314 I thought the same thing, actually. But that (implicit) question is "how do I do SAT collision physics?", which is too broadly scoped to be answerable, so I ignored it on purpose. I also assumed that any half-hearted implementation of those collisions would have vertex data available. \$\endgroup\$ May 24, 2013 at 14:13
-
\$\begingroup\$ @Katana314 Yes I am trying to implement SAT collision following a tutorial if found but its written in AS3. This is the example I am following and trying to replicate on XNA metanetsoftware.com/technique/diagrams/tutA_demo.html. The problem is I'm still pretty new at this and I don't know how to make any other shapes other than rectangles \$\endgroup\$– RogerMay 25, 2013 at 17:26