Bezier Curves in Corona ** SOURCE CODE

Finally !

Bezier segment manipulation using Corona SDK. This is a sample of how to manipulate a cubic bezier segment. Touch the screen to draw the four points (anchor1,handle1,handle2,anchor2) then manipulate the curve.

I cleaned up the code as much as I could. It is not optimized. Feel free to make changes, amplifications and updates and share with the rest of us.

You can download the code at Bezier Code

I tried it on iOS and Android devices.

Let me know what you think.

You can also find the code on the Code Exchange

Enjoy.

Carlos

Fixed a performance issue. Download the latest.

Carlos

hi im using the latest version of corona sdk, i have downloaded the code but im getting a blank black screen when i try to open,

of course you get a blank screen :D just tap the screen and play the red dot :D

This is excellent! (code and timing)
I've got a character in an animation flying a kite (with accelerometer) now I've got the kiteString too.
Now, if we can just talk Jonathan Beebe into making an OpenSource "Cut the Rope" clone :^)

Andy

well, that sounds great :D

Faster version uploaded !

c.

OK. Sorry but this is pretty mind blowing to me. Are you telling me that I can somehow manipulate your code to create curves with body and have say a ball slide down that awesome bezier curve?

Yes

Have you seen a video where I have a tank following the curve?

http://www.youtube.com/watch?v=722su8kVYW4&feature=related

c

Hi Carlos,

I'm really impressed by your bezier code, but I'd like to know how you got the tank to smoothly follow the curve. Obviously, you're not using the physics engine, but I'm having a little trouble getting the same effect.

Thanks,

Matt.

Pseudo code would be something like this

Set the tolerance to an acceptable level
Get the points to the curve
Walk the points and as you walk them get the angle between the points
move the object along the points and rotate it given the angle

C

Yep, I got that much, however the flip between, say, 5 degrees and 355 degrees causes the tank to spin a full circle on the spot. I was wondering how you got round this? I did myself, but was wondering about other approaches...

Matt

local angle = math.atan2(y-x)
angle = angle * 180 / PI (3.1415196)

object:rotate (angle-prevAngle)

prevAngle = angle;

Carlos

Thanks Carlos...

My bad - I think I assumed certain things. The problem I referred to comes from transition.to (which I used for smooth animation from one angle to the next) tweening between 355 and 5 degrees through the larger range around the circle's 360, not directly through the 360|0 border...

That, of course, is to simply check the difference and add/subtract 360 where appropriate.

m

xcellent

post video of such animation when you have it available.. would b great to see it

carlos

Not wishing to go off topic, but can you recommend something to take videos of the simulator screen?

matt

thats offtopic so no i won't go there..

;-)

I use screenflow http://www.telestream.net/screen-flow/overview.htm

there is a thread somewhere in the forum for other alternatives..... but i like screenflow a lot but that is my preference ;-)

c.

Why isn't this encapsulated into a useful module?

views:2619 update:2011/9/19 13:40:57
corona forums © 2003-2011