paths for enemies.

BlitzMax Forums/BlitzMax Beginners Area/paths for enemies.

Ryan Burnside(Posted 2007) [#1]
I've been trying for some time to get a working type to handle spline movement. Basically I have been trying to have a spline type object that will take a two dimensional array of x and y values. It should have a function that would return the x and y value given a float "t" value ranging from 0 to 1. My problem is understanding how to compute the x and y values given "t". I think the spline I need is a cubic spline because the path must go through all control points.

If anyone has a type for the job that takes a two dimensional array of x,y values and could return the x and y values for a given time I would be grateful. I'm not progressing as quickly as I should in math, I'm just a hobbyist programmer. I did manage to find a class for splines in the code section of the forum but it has many arrays that I don't know the function of. Basically I just need somthing that takes a 2d array of x and y values and spits out the x and y positions for a given time between 1 and 0.


ImaginaryHuman(Posted 2007) [#2]
I think the term `cubic` means that there are usually four control points per spline, rather than that it necessarily goes through the control point. You're probably more likely talking about a b-spline or a catmull-rom spline. Look in the code archives, there is code for catmull rom splines and also cubic bezier splines. You can probably define how many `points` the curve has and therefore can calculate any given point along the curve in that many steps, which is what you need.


Ryan Burnside(Posted 2007) [#3]
I tried to use the crappy search feature to find some information about a spline class. I found some odd image related posts and some things about camera movement but nothing really about B Splines. I just can't seem to grasp the concept mathematically. Really I'm looking for something I can just plug in rather than having to reinvent the wheel.


Pongo(Posted 2007) [#4]
http://www.blitzbasic.com/codearcs/codearcs.php?code=1489

this is in BB, not in max, but you should be able to find what you need in there.


tonyg(Posted 2007) [#5]
This?
and this? which has links to this and this .
Perhaps this?
I found these using the search function with keyword 'Spline'.


Ryan Burnside(Posted 2007) [#6]
Thanks tonyg. Got somthing up and running now. :)