Get mesh points from shape

Posts that don't fit into other categories.
assofohdz
Posts: 25
Joined: Mon Apr 17, 2017 10:46 am

Get mesh points from shape

Postby assofohdz » Mon Aug 07, 2017 1:33 pm

Hi

Is there any way to get the mesh point (x,y) from a shape in Dyn4j?

William
Site Admin
Posts: 345
Joined: Sat Feb 06, 2010 10:23 pm

Re: Get mesh points from shape

Postby William » Mon Aug 07, 2017 6:17 pm

It will depend on the shape:

Shapes that implement Wound will have getVertices() and getNormals() methods: Link, Segment, Polygon, Rectangle, Triangle.

The other shapes; Circle, Ellipse, HalfEllipse, and Slice have curved features so technically have an infinite number of vertices. Each one is stored differently. For example, a circle is represented as a center point and a radius, an ellipse is represented by it's width/height and local axis, and so on.

If you are using the Shape or Convex interfaces you'll need to do some type checking:
Code: [Select all] [Expand/Collapse] [Download] (Untitled.java)
  1. Convex c = // whatever;
  2. if (c instanceof Wound) {
  3.   Wound w = (Wound)c;
  4.   Vector2[] points = w.getVertices();
  5. }

If you need all your shapes to have vertices, look into the Geometry.createPolygonalX methods to create polygonal approximations of the curved shapes.

William

assofohdz
Posts: 25
Joined: Mon Apr 17, 2017 10:46 am

Re: Get mesh points from shape

Postby assofohdz » Tue Aug 08, 2017 3:42 am

Thanks. I found the JavaDoc after I posted and also found the method you mentioned. I converted my circles to polygonals. I guess some of my shapes will have to have circle-shape (due to game logic I want projectiles to bounce correctly off surfaces for example, but it doesn't matter that much for impact on enemies if the enemy is circular or polygonal).

Thanks for the quick response


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest