Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Pages: [1] 2

Author Topic: Miles of track  (Read 50045 times)

planetsim

  • Jr. Member
  • *
  • Posts: 38
  • newbie
Miles of track
« 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.

My physics implementation in Bullet was here :

Code: https://code.google.com/p/surface-physics/source/browse/#svn%2Ftrunk%2FTestRig%2FTrain

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.

Interesting times up ahead.

« Last Edit: June 08, 2014, 01:23:19 am by planetsim »
Logged

planetsim

  • Jr. Member
  • *
  • Posts: 38
  • newbie
Re: Miles of track
« Reply #1 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 ?
« Last Edit: June 08, 2014, 05:05:22 am by planetsim »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Miles of track
« Reply #2 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.
Logged

planetsim

  • Jr. Member
  • *
  • Posts: 38
  • newbie
Re: Miles of track
« Reply #3 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  ?
« Last Edit: June 09, 2014, 11:17:21 am by planetsim »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Miles of track
« Reply #4 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.
Logged

planetsim

  • Jr. Member
  • *
  • Posts: 38
  • newbie
Re: Miles of track
« Reply #5 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 :)
Logged

HiFlyer

  • Hero Member
  • *****
  • Posts: 1788
  • newbie
Re: Miles of track
« Reply #6 on: June 09, 2014, 12:22:39 pm »

So how does Outerra intend to handle bridges, both for Train tracks and for Roads?
Logged
Spex: Intel Core i7 6700K @ 4.6GHz / 32.0GB G.SKILL TridentZ Series Dual-Channel Ram / ASUS STRIX GeForce GTX 1080 / Sound Blaster Z / Oculus Rift VR Headset / Klipsch® Promedia 2.1 Computer Speakers / ASUS ROG SWIFT PG279Q ‑ 27" IPS LED Monitor ‑ QHD / 2x Samsung SSD 850 EVO 500GB / Windows 10 Pro

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Miles of track
« Reply #7 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.
Logged

planetsim

  • Jr. Member
  • *
  • Posts: 38
  • newbie
Re: Miles of track
« Reply #8 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 ?
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Miles of track
« Reply #9 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.
Logged

HiFlyer

  • Hero Member
  • *****
  • Posts: 1788
  • newbie
Re: Miles of track
« Reply #10 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!
Logged
Spex: Intel Core i7 6700K @ 4.6GHz / 32.0GB G.SKILL TridentZ Series Dual-Channel Ram / ASUS STRIX GeForce GTX 1080 / Sound Blaster Z / Oculus Rift VR Headset / Klipsch® Promedia 2.1 Computer Speakers / ASUS ROG SWIFT PG279Q ‑ 27" IPS LED Monitor ‑ QHD / 2x Samsung SSD 850 EVO 500GB / Windows 10 Pro

John514

  • Hero Member
  • *****
  • Posts: 543
  • Certified TARDIS driver.
Re: Miles of track
« Reply #11 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.
Logged
You mustn't be afraid to dream a little bigger, darling

Note: I do not claim to know everything.
I just like to help people around the forum.

planetsim

  • Jr. Member
  • *
  • Posts: 38
  • newbie
Re: Miles of track
« Reply #12 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

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/

Looking at some info here : 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/

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

http://theory.stanford.edu/~amitp/_test/demo_roads.swf

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.
« Last Edit: August 10, 2014, 02:27:17 pm by planetsim »
Logged

planetsim

  • Jr. Member
  • *
  • Posts: 38
  • newbie
Re: Miles of track
« Reply #13 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.
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Miles of track
« Reply #14 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.
Logged
Pages: [1] 2