Sounds like a lot of work to achieve something that can be done just as well in a more simple way.
I think you'll probably get neater results either -
a) just making the train follow the rails and then add extra code to check for excess speed, then convert to ODE objects only once the train has come off the tracks and is crashing. This is the same approach as with non-physics driven animated characters that convert to a physics ragdoll when killed).
or
b) use ODE all the time but only effectively in 1 dimension (ie. Z, down the track ) - ignore the X and Y directions (the across-the-rails sideways direction and vertical). Make the train objects follow the track spline in the 3d world with only their forward and backward position and movement linked to ODE, and set their 3d position so they always stay on the curve of the track spline. This prevents your physics simulation having to somehow follow the track spline or rails which is going to be tricky and fairly prone to going wrong, especially as you say at the track junctions. Then switch over to full 3d physics only once the train is derailed and crashing (ie. when it corners too fast or hits another object with too much force). If you keep all your physics trains along the same static axis then they should automatically deal with shunting and impacts, you just need to decide when the impacts are too great and the simulation needs to switch to a full 3d simulation for the crash.
You should easily be able to use the spline curve to calculate if the train has exceeded the maximum cornering speed, very easy to do if your track spline is made from a series of points.
|