# Outerra forum

## User mods, screenshots & videos => Railway vehicles => Topic started by: planetsim on June 08, 2014, 01:04:31 am

Title: Miles of track
Post by: planetsim on June 08, 2014, 01:04:31 am
I have been working on implementing trains with Bullet physics before and I am going to try to bring a similar implementation in OT. Since OT already provides a beautiful world so running trains through it will be just awesome.

Basically I represented a track as a list of curves, curves were always either straight lines or circular sections. This may not be true in the real world, but should do as a low overhead start for miles and miles of tracks :)

For more realistic railroad modelling I decided to take a cube and make it float above a point on a plane first. For this I simply use a spring force with the force increasing linearly as the cube gets closer to the surface. So this is good enough to make it float. Since the railroad car has also got to be more or less parallel to the underlying track, I actually apply 2 "up" forces, one each at the center of the axle of the front and rear wheels to keep the bottom surface parallel to the track.

Then there is the rotation of the cars around the y-axis(the "UP" axis). The cars again remain parallel and facing forward through the use of a counter torque, if the car "swings" away from the tracks. This is based on the angle of deviation from the current direction of the track, with a torque applied to try and make this angle 0 always. It was easy to get this angle for straight segments of tracks. For curved segments, the radial vector connecting the center of the curve(curved tracks are always circular) with the center of the car is useful.

I experimented with tracks which gradually curve from 0 curvature(straight segment) to maximum curvature to get around sharp bends. The gradual curvature of track is whats used in real railroad tracks to prevent sudden changes in directions at high speed which would cause the cars to bang hard against the rails. However its not straight forward to get the radial vector at any point along a curve which is not circular. So I thought a gradual bending curve can also be approximated by a series of circular segments whose normals match at the ends. Thats the plan as of now. An automatic track layer would be great to do this matching !

The cars are kept on the track using a simple spring-like force on them of the form kx where x is the deviation of the center point of the axle for the front wheels. These forces try to push the wheels towards the center of the track from outside simulating the track's restraints on the wheels. k is considerably high.

Its easy to get the nearest point on a straight track , to the center point of the axles, and then apply a force towards the track to keep the cars on the rail trajectory. For curving tracks its even easier as a fixed radial distance has to be maintained from the center of the curve. So this is a kind of 'trajectory' constraint.

I really hardened the spring constants using values like 100000 to ensure the force was really great in case any of the cars deviated from the rails.

Now for the engine, the basic engine force is just a force applied on the center of the front most car. The toughest part to fix was the link forces between the cars which pull the car or slow them down.

The link forces are applied based on the distance between 2 cars. Every car apart from the engine, applies a force on itself proportional to its distance from the car ahead of it. This force is also applied on the car ahead as a pull, so the engine has to really pull hard to get a long line of cars moving.

The last thing to add was rail infrastructure in the form of junctions to allow track changes. Basically the train is diverted to a circular section thats touching a straight segment, when the junction is active but there are multiple cases. For example the junction must also work for cars rolling backwards etc, overlapping active junctions must not confuse the cars !!

With that out of the way, I added signals and a basic cab controller. The controller looks at the signal ahead of it on the same track and reaches a certain speed setpoint based on yellow or green. It applies brakes on red which is applied on all the cars.

The system is stable at high speeds and for curves there are speed limits. Sharp curves taken at high speeds cause the link force to ramp up suddenly to unmanageable levels so currently I have clamped the maximum link forces, that helped.

The curves segments currently are along the ground plane but can be adapted to follow any kind of terrain, the math needs to be figured out to keep the train constrained, thats all.
Then adding multiple cabs to the train and ensuring the entire thing moves properly.
Simulating static and rolling friction that requires the loco to correctly apply larger forces to get things rolling.
Applying up forces on all 4 ends of a cab to simulate the suspension.

Title: Re: Miles of track
Post by: planetsim on June 08, 2014, 02:02:41 am
Are tunnels through the terrain possible ?

Is it possible to add a rigid body to a mesh from inside a plugin and then add forces to it ?
I would like add a cube for each of the cabs in the train and then add forces to it from a plugin.
Also I would need a way to visualize the frames of references and a wireframe drawing mode for the physics bodies like in any other physics debug viewer.

-----------------

Has any attempt been already made to make a larger scale railway simulation in Outerra ?

What was the approach followed there for representing tracks, motion of the cabs, forces used etc ?
Title: Re: Miles of track
Post by: cameni on June 09, 2014, 11:09:08 am
Only in a theoretical plane, when discussing the possibilities with a developer interested in making a railway simulator on OT.

Railroads will be rendered using a similar system as roads - spline interpolated waypoint system. Actually built on top of the road system, as the tracks will have to adjust the surrounding terrain as well. On top of it a geometry rails/sleepers generator.

As for the physics, we'll probably generate forces that normally keep cars on the rails, when they follow a track. That should be automatic for railway module.
Title: Re: Miles of track
Post by: planetsim on June 09, 2014, 11:15:12 am
Wow, I never thought of splines. Yes of course that makes sense now. You just pick a few waypoints and a track is generated through these waypoints for you :). How do you generally find out the force to be applied on the wheels for such a curve ? The force will be inwards for both wheels and in opposite directions(for wheels on the left and the right of the cab).  I think you will need to get the tangent at any point and then the normal  ?
Title: Re: Miles of track
Post by: cameni on June 09, 2014, 11:22:15 am
Yes, you need to get the tangent. But that's already done for roads, so no problem there.
Title: Re: Miles of track
Post by: planetsim on June 09, 2014, 11:24:27 am
Ok, is it possible to add rigid bodies to the physics world in OT currently from plugins ? As in can I get started on it with the currently exposed public functionality to plugins :)
Title: Re: Miles of track
Post by: HiFlyer on June 09, 2014, 12:22:39 pm
So how does Outerra intend to handle bridges, both for Train tracks and for Roads?
Title: Re: Miles of track
Post by: cameni on June 10, 2014, 03:17:09 am
Ok, is it possible to add rigid bodies to the physics world in OT currently from plugins ? As in can I get started on it with the currently exposed public functionality to plugins :)
All would have to be separate vehicles. It's not clear if there will be only the Bullet engine inside, so we'd like to keep an abstraction layer.

So how does Outerra intend to handle bridges, both for Train tracks and for Roads?
Likely as separate models with some geometry generator that can repeat pieces of geometry over a spline, same thing as used for the rails and other stuff. That's also going to be used for tunnel insides etc.
Title: Re: Miles of track
Post by: planetsim on June 10, 2014, 05:04:57 am
ok, is it possible to add custom physics to vehicles currently ? As in if I decided to add a vehicle on a rail then I would need to add custom forces, adjust wheel positions etc. Is it possible to do this via a plugin currently ?
Title: Re: Miles of track
Post by: cameni on June 10, 2014, 07:34:27 am
The only custom physics you can do is generating those extra forces in vehicle script. Wheel positions can be controlled by physics scripts as well, as joints.
Plugin can't do it now, we'll have to open a way for vehicles to use dll modules first.
Title: Re: Miles of track
Post by: HiFlyer on June 10, 2014, 08:50:44 am
Ok, is it possible to add rigid bodies to the physics world in OT currently from plugins ? As in can I get started on it with the currently exposed public functionality to plugins :)
All would have to be separate vehicles. It's not clear if there will be only the Bullet engine inside, so we'd like to keep an abstraction layer.

So how does Outerra intend to handle bridges, both for Train tracks and for Roads?
Likely as separate models with some geometry generator that can repeat pieces of geometry over a spline, same thing as used for the rails and other stuff. That's also going to be used for tunnel insides etc.

Thanks!
Title: Re: Miles of track
Post by: John514 on July 20, 2014, 05:11:08 pm
The Trainz Simulator series of train simulators is based entirely on splines.
The placement system is very semilar to outerra`s roads, although much more flexible, since the track don`t deform the terrain until the user specifies.
I personaly like that concept and I`d love to see it here.
Title: Re: Miles of track
Post by: planetsim on August 10, 2014, 10:33:01 am
I guess only scripts can be used currently to define railway vehicles ? No C++ code ?

I was looking at adapting a vehicle as a railway engine:

http://xtrac.outerraworld.com/trac.fcgi/wiki/vehicle (http://xtrac.outerraworld.com/trac.fcgi/wiki/vehicle)

So if I want to add a new type of vehicle called railway engine, so that it appears inside outerra, then what are the initial setup steps for this ? Also where is the vehicle script inside Outerra ?

Also, is it possible to create railway tracks based on splines through scripting alone ? Someplace would be needed to store the spline information I guess.

Anyone has any info on how splines can be used to create tracks or keep a vehicle moving on it ?

http://www.learn-cocos2d.com/2012/07/starting-point-train-game-freeform-tracks/ (http://www.learn-cocos2d.com/2012/07/starting-point-train-game-freeform-tracks/)

Looking at some info here : http://gamedev.stackexchange.com/questions/504/what-are-some-methods-to-represent-train-tracks (http://gamedev.stackexchange.com/questions/504/what-are-some-methods-to-represent-train-tracks)

Apparently if F(t) is the spline curve then the distance travelled in equal intervals of t is not the same. hmmm

http://www.redblobgames.com/articles/curved-paths/ (http://www.redblobgames.com/articles/curved-paths/)

Circular arcs with a variable radius seems to be easier to deal with. The constant curvature makes the distance calculation easier.

So the railway track would basically be a list of functions for each segment, straight line information followed by circular arc information for curved segments. Increasing curvature of a curved segment would mean a new circular arc with smaller radius matching the tangents at the transition.
Title: Re: Miles of track
Post by: planetsim on August 10, 2014, 01:20:23 pm
We really do need a way to draw the tracks first based on a specified list of curves.
Title: Re: Miles of track
Post by: cameni on August 10, 2014, 04:07:09 pm
C++ API isn't open yet, but it's not really needed for vehicles at this point - you would only need it for performance reasons, but otherwise the API is the same as the script version.

For railways we want to use the same spline based system as for the roads, and a railway engine vehicle type would automatically produce the necessary forces on wheels on rails, just as car tires do now. You can't really add rails support yourself - as soon as their rendering is implemented, there will be also a railway physics vehicle type available. Vehicle models and their scripts definitely won't be dealing with rails physics themselves.
Title: Re: Miles of track
Post by: planetsim on August 11, 2014, 12:01:33 am
ok ...so is there anything I can do to help with the rail physics implementation right now ?
Title: Re: Miles of track
Post by: planetsim on August 24, 2014, 08:47:29 am
Hallo :)

Any luck with adding rails support and rendering or  a railway physics vehicle type?
Title: Re: Miles of track
Post by: cameni on August 24, 2014, 11:23:55 am
Unfortunately it's not a matter of luck, and while the railway tracks are in the plan for a long time, we have lots of open stuff that needs completing before we open new tasks.
Title: Re: Miles of track
Post by: planetsim on August 24, 2014, 12:40:56 pm
ok, we will wait :)

By the way what are you guys working on at the moment ?
Title: Re: Miles of track
Post by: cameni on August 24, 2014, 01:51:07 pm
Apart from secret contracted stuff - terrain self-shadowing, tree shadows, lights, SSAO, Rift DK2 support ...
Title: Re: Miles of track
Post by: ZeosPantera on August 24, 2014, 03:39:13 pm
>  secret contracted stuff

Damn you!

Waterboarding for all!
Title: Re: Miles of track
Post by: planetsim on November 20, 2014, 09:44:22 am
Whats been happening in Outerra over the last few weeks :)

Here is what I wants in Outerra :D

Title: Re: Miles of track
Post by: HiFlyer on November 20, 2014, 09:47:08 am
Whats been happening in Outerra over the last few weeks :)

Here is what I wants in Outerra :D

Granted, the game in your picture has good graphics and a high frame rate...... but there's no way to save your progress, and you only get one life!!
Title: Re: Miles of track
Post by: PytonPago on November 20, 2014, 02:41:53 pm
Whats been happening in Outerra over the last few weeks :)

Here is what I wants in Outerra :D

Granted, the game in your picture has good graphics and a high frame rate...... but there's no way to save your progress, and you only get one life!!

And the tracks editing takes so much time ! :D :D
Title: Re: Miles of track
Post by: HiFlyer on May 30, 2015, 05:52:03 pm
Hmmmmmmm....... I wonder.........

Since they are redoing the road system anyway, and I assume adding support of some sort for waterways, it seems a shame to not throw track support in there while they are at it.........

A lot of people would be ecstatic........
Title: Re: Miles of track
Post by: cameni on May 31, 2015, 11:56:50 am
Tracks alone won't be enough, you'll need also a physics module.

Tracks require two things, a modification to the road system (for track foundation), and a spline-based geometry generator (repeater, for cross ties and rails).
Repeater requires a modification of the material system to support small instanced geometry rendering without a full blown object pipeline. It's going to be used also for other road and railroad related things like poles, guard rails, but also highway connections, bridges and tunnels.
Material system update depends on shader system update (which is now mostly ready, so it's waiting on a free time slot).
Title: Re: Miles of track
Post by: HiFlyer on May 31, 2015, 03:40:45 pm
Cool! Sounds very promising!
Title: Re: Miles of track
Post by: Cormac21 on June 03, 2015, 11:21:35 pm
Wow its really awesome.
I personaly like that concept and I`d love to see it here.
Well done..
Title: Re: Miles of track
Post by: John514 on September 09, 2015, 01:49:26 am
Tracks alone won't be enough, you'll need also a physics module.

Tracks require two things, a modification to the road system (for track foundation), and a spline-based geometry generator (repeater, for cross ties and rails).
Repeater requires a modification of the material system to support small instanced geometry rendering without a full blown object pipeline. It's going to be used also for other road and railroad related things like poles, guard rails, but also highway connections, bridges and tunnels.
Material system update depends on shader system update (which is now mostly ready, so it's waiting on a free time slot).
It also needs a procedural rail system to automatically create cuts and blades in junctions.