Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Bezier Curves Physics and Ghost Vertices
Started by Fernker Mar 05 2015 08:22 AM

11 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Fernker

[GLOBAL: userInfoPane.html]
Fernker
  • Enthusiast

  • 44 posts
  • Corona SDK

I've been done plenty of testing and research with Level Director and bezier curves.

 

I have some bezier curves (nothing extreme, just some nice hills up and down).

 

I have a rectangle that slides up and down the hills.

 

 

The problem is that occasionally the corner of the rectangle gets stuck and flips the rectangle (not desired effect).  

 

Digging into the function in the Level Editor helper file I can see that the curve is split into segments and little overlapping long-triangles are created (sort of like a sawtooth).  This is still causing flipping at certain points and it's also horrible because the object can't go backwards over the curve.

 

Doing some more research I've learned that this is a common issue/question with Box2d and with ghost vertices.

 

http://www.iforce2d.net/b2dtut/ghost-vertices

 

The thing that's cool is that the chain shape in Box2d removes this issue:  http://www.box2d.org/manual.html

In section 4.6 it says this:   "Chain shapes automatically eliminate ghost collisions and provide two sided collision."

 

Is this the same as the 

Edge Shape (Chain) Body

 

Listed here in Corona docs:  http://docs.coronalabs.com/guide/physics/physicsBodies/index.html

 

Is there anyway that Level Director's algorithm could be upgraded to use this for bezier curved physics?  I think it would improve the overall result of physics applied to bezier curves.

 

 



[TOPIC: post.html]
#2

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 318 posts
  • Corona SDK

Yes it was quite a challenge getting the Bezier curves working and even more difficult when you add physics to the equation.

It has actually been on my list for a while to revisit the Bezier curve creation as I always felt there was a better way to implement it but back then (approx. 2 years ago) my Lua skills were limited and this was also prior to Graphics 2.0.

 

I'll try and find some time to take a look at this.



[TOPIC: post.html]
#3

Fernker

[GLOBAL: userInfoPane.html]
Fernker
  • Enthusiast

  • 44 posts
  • Corona SDK

Great!

 

I'll do more digging and research as well.  



[TOPIC: post.html]
#4

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 318 posts
  • Corona SDK

I had a play today and think I may have a solution.

 

The revised code is actually 50% faster and uses chain edge physics.

 

I'll send you the new file to test.

 

 



[TOPIC: post.html]
#5

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 318 posts
  • Corona SDK

FYI - if you set the physics shape on your object to be a circle or a shape similar to a rounded rectangle this also helps eliminate the problem.

 

Hopefully the new changes I sent will work but I'm a little concerned about the 32 vertices limit on chain edges as it appears to work with more than 32 in the simulator.



[TOPIC: post.html]
#6

Fernker

[GLOBAL: userInfoPane.html]
Fernker
  • Enthusiast

  • 44 posts
  • Corona SDK

Yeah I tried rounding the corners of the shape but it would still snag.

 

I looking into using a circle but that doesn't work because I can't offset the circle shape on the object (a long rectangle) so it would be in the center which won't work for what I'm trying to achieve.

 

I'm also curious about the 32 vertices limit and wonder if it's a Corona limit (I couldn't find any mention of a 32 vertices limit in box2d documentation). 



[TOPIC: post.html]
#7

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 318 posts
  • Corona SDK

Yes fingers crossed as it seems to work really well in my initial tests.



[TOPIC: post.html]
#8

Fernker

[GLOBAL: userInfoPane.html]
Fernker
  • Enthusiast

  • 44 posts
  • Corona SDK

I've only tested it on one device (a 3 year old Android phone) and it seems to work fine.  

 

In my test I had 4 bezier curves to create a longer level and it had no problems.  Thanks for the quick turn-around on this.  I'll let you know if I have any issues. 



[TOPIC: post.html]
#9

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 318 posts
  • Corona SDK

Sounds good, glad to help.

 

If any other Level Director users would like to try out the new Bezier code then let me know. 



[TOPIC: post.html]
#10

virtunox

[GLOBAL: userInfoPane.html]
virtunox
  • Observer

  • 22 posts
  • Corona SDK

Hi everybody

 

Yes I would be very interested about your code.
I am struggling to do the following (please open the attachment):
 

Please have a look at the pic.

For a bouncing ball on a bezier curver I would like to dynamically calculate the absolute distance between the anchor point of the ball and the corresponding coordinate on the bezier curve at any given x while the result is the distance in pixels of y.

 

The requirement would be that at any given x one could calculate the corresponding coordinates on the bezier curve.

 

Do you think that it is possible and does anyone have an idea how to do it?

 

Thanks for any reply

Matteo

Attached Files



[TOPIC: post.html]
#11

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 318 posts
  • Corona SDK

Hi, sorry for the delay.

 

You can get the latest helper file from here : http://bit.ly/1OLni8F

 

By default this will use Chain physics for Bezier curves.

 

Let me know how you get on.



[TOPIC: post.html]
#12

virtunox

[GLOBAL: userInfoPane.html]
virtunox
  • Observer

  • 22 posts
  • Corona SDK

Hi, sorry for the delay.

 

You can get the latest helper file from here : http://bit.ly/1OLni8F

 

By default this will use Chain physics for Bezier curves.

 

Let me know how you get on.

 

Hi how can I get the distance betwen the bouncing ball and the corresponding point on the bezier curve with same x-coordinate?




[topic_controls]
[/topic_controls]