Game Development Community

2D spline path class

by Phil Carlisle · in Torque Game Builder · 10/21/2005 (4:56 pm) · 9 replies

I'm working on a 2D spline path class and wondered if anyone had some feedback on what to derive it from.

I'm thinking 2dsceneobject (cant remember the exact class, but the one everything in T2d is derived from).

But I also need to be able to have this object contain a list of connected objects (kind of like a simset). So maybe I should just embed the simset into this class.

Anyway, anyone have some feedback on how best to create a containment object that draws itself? Does the base class have any notion of containment?


Ah well, no worries.

#2
10/24/2005 (12:09 pm)
Phil,

I guess the answer to your question depends on how far this containment e.g. ownership goes. If you want to have a scene-object that renders some kind of path and maybe waypoints/anchors but have the ability to attach other scene-objects then I'd go down the route of just creating a class that inherits from t2dSceneObject (old one of fxSceneObject2D) and just incorporates a SimSet. You can then just add the script-interface to add/remove objects and define your path. If you don't bother creating a special config-datablock for it then this code would be tiny.

If you want the other way where you want to add scene-objects but you want to explicitly control the rendering for these objects then you want to go down the route that I took with the tile-map/layers. T2D has the notion of child objects which are excluded from certain operations automatically. For instance, they cannot be deleted using "safeDelete()" as they are owned by the parent. This code takes a little more effort but gives you total control.

If you want to post a little more info on the functionality then I could perhaps help a little more.

Failing that, you know the email address. ;)

- Melv.
#3
10/29/2005 (8:24 pm)
In case you're interested, I currently have a working spline class. Here's how I layed things out: The spline class is actually a standard Torque console object and is not capable of rendering itself. The spline class contains positional data for exactly one scene object and needs to be updated each frame. In other words, one scene object essentially owns one spline.

I added an optional "update(elapsedTime)" script callback to the sceneobject update() method so that I can do things like update my spline class every frame without changing the C++ internals of t2dSceneObject too much. I may at some later time resort to pure C++ pointers in the interest of speed.

I only want to render the spline when I am debugging and this is the reason I chose not to make the spline a scene object. When I want to render the spline, I use a t2dLineStrip which is essentially just a bunch of line segments. Unfortunately the t2dLineStrip is not currently in my primitive addon pack, so I admit to holding out on the T2D community a bit. I'm actually hoping that the new T2D version will be released soon and this will presumably make life a lot easier for me to release source code.

In any event, if you wait a while longer, I should be releasing my spline class and you're more than welcome to look at it. I'm not entirely sure that what I'm working on is what you want but it never hurts to have some additional code to look at. I'm also happy to discuss splines in e-mail or otherwise if you're interested.

Spline Shot
#4
11/04/2005 (3:44 pm)
Hello, I am in the middle of writing the same thing. My plan is to use the splines as paths for enemies in a shooter game. I derived from fxSceneObject2D. I rigged up some script callbacks to draw the curves in an editor, and I can save and load them to a file. I'm sort of an amateur so one problem I am having is that when I draw a lot of points the game slows down alot because I am recomputing all curves every frame and querying the mouse pos to highlight points etc. I think now I need to just daw them into a buffer and only recompute the curves for points that have moved since the last frame.

If you want you can have my code up to this point for a reference. Maybe you can even give me some tips.
if so, email me at joes@capcom.com

I am using hermite interpolation
www.joespataro.com/images/splines.jpg
#5
12/28/2005 (9:54 pm)
I was just thinking about this the other day...

If *I* were doing a spline class, I'd be interested in using it for paths for units to follow generated at runtime. I'd want a function for addKnot( t2dVector, percentAlongPath ), which would add the point at the coord, and the spline would interpolate through it. This way, you could add as many points as you needed to get the shape you want.

Then, I'd make a getPointPosition( percentAlong Path ) that would return a coord as a t2dVector at the specified percentage along the path. Would also want a getPointAngle( percentAlongPath ) to return the tangent to the spline at that location.

Other functions that might be useful would be moveKnot( index? ), getNumKnots().

Thate would be the basics i think. Then you could do stuff like
%mySprite.setPostition (%myPath.getPointPosition( 0.5 ); 
%mySprite.setRotation (%myPath.getPointAngle( 0.5 );

You could do a lot with something like this. One weird thing though would be that the locations of the points at percent X would change as you moved the splines knots around. They kind of have to though, so I don't know what to do about that.

A more advanced feature would be to add linkPoints that could move automatically along the path at set speeds.

Drawing slpines is another issue. I'd like to see some robust vector functionality also. I guess I'm just throwing in my vote for these other types of features also, if anyone's working on them.
#6
02/28/2006 (8:26 am)
Hey. I was just about to start working on a spline editor for my game and noticed this thread. I don't suppose anyone has released any code that I could have a look at to save me a load of time. It would be greatly appreciated!
#7
03/07/2006 (8:39 am)
I would glad to see what advance is in this area.
Are someone thinking in post this as a resource?

Regards.
#8
03/07/2006 (8:54 am)
I'd like spline support in TGB as well.
#9
06/16/2006 (1:06 am)
Well, there is t2dPath, and it's quite cool, but one feature that would make it cooler is being able to modify tangents in the editor (a la 3D Max) for bezier paths :)