[SOLVED] Verts and ordering

Official forum for the Chipmunk2D Physics Library.
Post Reply
JonRambo
Posts: 23
Joined: Mon Sep 19, 2011 12:49 pm
Contact:

[SOLVED] Verts and ordering

Post by JonRambo »

Hi,

Thank you for taking the time to read my post.

I have read several posts about the ordering of verts, it is stated in these postes and the documentation that verts should be listed in clockwise order and must be convex. I am making a shape from two rectangles, the simulation does not work when I provide the verts array with element 0 as top left then element 1 as top right and element 2 as bot right and element 3 as bot left. So I am posting to ask assistance to solve my problem. I am running Chipmunk-6.0.1.

Firtsly I would like to ask if it is okay to start my rectangle at 0, 0 for top left like so:

Code: Select all

cpVect shapeVerts[ 4 ];
shapeVerts[ 0 ] = cpv( 0, 0 );
shapeVerts[ 1 ] = cpv( shapeWidth, 0 );
shapeVerts[ 2 ] = cpv( shapeWidth, shapeHeight );
shapeVerts[ 3 ] = cpv( 0, shapeHeight );

cpSpaceAddShape( theSpace, cpPolyShapeNew( theBody, 4, shapeVerts, cpv( -30, 0 ) ) );
Secondly I would like to ask if setting up my space with a postive gravity is okay?

Thirdly, is there a coarse of logic I can follow to try and resolve my unshapley shapes, we currently have a working simulation with co-ordinates cerntered over the center of gravity then offset into place starting from top left to bot left, bot right and then to top right which I assume is counter clockwise, now I know this is wrong and I worry that it may cause problems in the future and hiding something that is wrong with existing code. Since we are only dealing in combinations of rectangles I am assuming I am not falling prey to concave issues.

Image
Last edited by JonRambo on Sat Feb 04, 2012 11:23 am, edited 1 time in total.
JonRambo
Posts: 23
Joined: Mon Sep 19, 2011 12:49 pm
Contact:

[SOLVED] Re: Verts and ordering

Post by JonRambo »

Okay guys all of you who read my post and have a similar problem here is the explanation that was missing from the other posts that explains the reason why you might have this problem.

Chipmunk is a physics engine and as such it works in a mathmatics oriented enviroment i.e. to quote the tutorial that gave me my answer "Chipmunks coordinates' values increase when moving from the bottom-left corner of the screen to the top-right corner". As a programmer/hacker you might have been thinking in the co-ordinate set we've all become used to where 0,0 is at the top left of the screen and going down and left is to be increasing in quantity. This fix is unconfirmed however I'm fairly confident I know how to fix my code and that this was my problem.

Friendly Regards
JonRambo
gnasen
Posts: 24
Joined: Wed Mar 16, 2011 12:17 pm
Contact:

Re: [SOLVED] Verts and ordering

Post by gnasen »

I wrote a procedure for myself to sort an array of points clockwise. Its pretty easy to do (if wanted, I could post it, but its not written in c) and I think it would fit perfectly into chipmunk ;) This is a list of procedures I wrote for myself and which could be in my opinion pretty useful for native use:
  • check if polygon is convex
  • check if polygon is clockwise
  • create convex hull of polygon
  • sort polygon clockwise (together with convex hull pretty good for level editors)
  • simplify polygon (remove linearly dependencies, double points)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: [SOLVED] Verts and ordering

Post by slembcke »

Hmm. That reminds me, I was going to move my QHull implementation that I made for the autogeometry feature into vanilla Chipmunk.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
JonRambo
Posts: 23
Joined: Mon Sep 19, 2011 12:49 pm
Contact:

Re: [SOLVED] Verts and ordering

Post by JonRambo »

Nice functions, I'll be doing simple things though, thanks for the offer!

Friendly Regards
JonRambo

p.s.
gnasen wrote: [*] check if polygon is clockwise
I think this one already exists
Last edited by JonRambo on Mon Feb 06, 2012 12:28 pm, edited 3 times in total.
JonRambo
Posts: 23
Joined: Mon Sep 19, 2011 12:49 pm
Contact:

Re: [SOLVED] Verts and ordering

Post by JonRambo »

slembcke wrote:QHull
I presume that’s short for quick hull and has hull related shortcuts, glad I could indirectly help :D

p.s. Personally don’t use a great deal of complex shapes with chipmunk, this post was by no means a plea for more functionality I appreciate the raw simplicity of existing code.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 25 guests