Author Topic: DAME spline pathing implementation suggestions  (Read 691 times)

jcothran

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Really like using DAME and able to see the spline/bezier pathing code snippets like below when exporting paths using the flixelComplex.lua exporter like below:

Code: [Select]
var pathobj:PathData;

pathobj = new PathData( [ { pos:new FlxPoint(264.000, 302.000), tan1:new FlxPoint(-59.000, 15.000), tan2:new FlxPoint(-(29.075), -(-7.392)) },
{ pos:new FlxPoint(157.000, 327.000), tan1:new FlxPoint(-29.698, -4.243), tan2:new FlxPoint(-(29.698), -(4.243)) },
{ pos:new FlxPoint(115.000, 293.000), tan1:new FlxPoint(23.202, -19.018), tan2:new FlxPoint(-(-23.202), -(19.018)) },
{ pos:new FlxPoint(159.000, 185.000), tan1:new FlxPoint(27.854, -11.142), tan2:new FlxPoint(-(-50.000), -(20.000)) },
{ pos:new FlxPoint(231.000, 185.000), tan1:new FlxPoint(21.000, -9.000), tan2:new FlxPoint(-(-27.574), -(11.818)) },
{ pos:new FlxPoint(266.000, 200.000), tan1:new FlxPoint(36.991, -33.774), tan2:new FlxPoint(-(-23.000), -(21.000)) },
{ pos:new FlxPoint(351.000, 195.000), tan1:new FlxPoint(29.818, -3.302), tan2:new FlxPoint(-(-29.818), -(3.302)) },
{ pos:new FlxPoint(409.000, 158.000), tan1:new FlxPoint(19.339, -22.935), tan2:new FlxPoint(-(-19.339), -(22.935)) },
{ pos:new FlxPoint(407.000, 281.000), tan1:new FlxPoint(-4.341, 29.684), tan2:new FlxPoint(-(4.341), -(-29.684)) },
{ pos:new FlxPoint(357.000, 351.000), tan1:new FlxPoint(-22.488, 19.856), tan2:new FlxPoint(-(22.488), -(-19.856)) }
], true, false, PlayState._Paths );
PlayState.paths.push(pathobj);

Anyone have working example functions or suggestions on how to go from the list of spline center points(pos) and tangent points(tan1,tan2) to moving a sprite along the suggested path as seen in the DAME editor?  The pathing functions with flixel are straight line(not spline) oriented, so guessing if still using those would have to create an approximation to a curve using straight segments substitution with a given resolution - only other alternatives I could think of besides approximating curves with lines would be a velocity altering function to approximate the curved motion, but more complexity/math than I want to consider at the moment.

http://www.paultondeur.com/2008/03/09/drawing-a-cubic-bezier-curve-using-actionscript-3/

http://www.senocular.com/flash/source/?entry=577

http://www.farmcode.org/post/2009/07/06/Fast-2D-Bezier-Library-for-ActionScript-3.aspx

Thanks


jcothran

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: DAME spline pathing implementation suggestions
« Reply #1 on: Wed, Jul 13, 2011 »
The DAME author responded to implement the function from the first link, so will try that


http://www.paultondeur.com/2008/03/09/drawing-a-cubic-bezier-curve-using-actionscript-3/

Quote
In the above link, just write a function that gets the position on a spline given a u value. Note that the author of that site really did not optimise his code well, e.g. calling Math.pow many times in a loop when it could have been unrolled and just calculated once at the start!