-
Simulating cable physics
Hello,
I'm working on a project where I would like the user to be able to drag virtual audio cables onto some hardware in a flash application and position each end in a virtual socket.
The action I'm looking for is close to the cable/pipe physics here yahoo pipes
Basically 2 moveable ends and a "bendy" cable :)
I dont have the first clue about physics in actionscript, is anyone aware of any tutorials along this line ?
TIA
-
1 Attachment(s)
The physics you're asking about is called inverse-kinematics (or IK-chains)...but that is overkill for what you're describing.
The easy way is best shown in a diagram...see the attached. You're trying to get from point A to point C...what you need to do is calculate points ab and bc and use those as your control-points for two bezier curves. eg:
PHP Code:
moveTo(A.x, A.y);
curveTo(ab.x, ab.y, B.x, B.y);
curveTo(bc.x, bc.y, C.x, C.y);
-
You don't actually need physics for that effect. What you do need is an understanding of Bezier curves.
Bezier curves are a mathematical way of describing a curve with 3 points. The start, end, and a control point. There's another class of curves with four points (start, end, and two control points) which allows a bit more flexibility, but they're a bit harder to work with in flash because they're not built in.
Conceptually, the control point is the point in space where lines tangent to the curve and going through the endpoints intersect. Read that again, it's a bit confusing.
Check out wikipedia:
http://en.wikipedia.org/wiki/B%C3%A9zier_curve
I couldn't tell in my brief exploration of that site whether their cables use one or two control points. If it's just one, then you can use the built in curveTo method in the Graphics class to draw such curves once you've calculated the 3 points necessary.