Train simulator (renamed from Starter's questions)

Hello!

I'm new to JME. I have successfully read Starter'sGuide and reviewed all the examples and test classes in jmetest:)

And my desire is to write a train (subway/even maybe tram)…in few words, a rail transport simulator.



I understand that it is a great task and i should move from simple things to hard, so i will post questions concerning my railsim in this thread one by one…



The first one:)



As far as i understood, first of all i should create different gamestates, for example, GameLoadingScreen, MainMenu, InGame.

Lets leave all the gui, i add only text buttons in the menus…



So the question is: how to organize scenegraph? It should provide good performance (one route may vary to 200 miles square or even more, so it should be loaded as needed).

I think that there would be such groups of objects:



Terrain

RailSystem consisted of tracks pieces

RollingStock -> Trains consisted of locos and cars

StaticObjects such as trees, houses, etc.

DynamicObjects such as signals that should be always loaded. Not geometry, but as "context object" - i mean that sygnal should be initialized once at the time of route initializing, but not as it becomes visible to camera.



Also it would be a multiplayer game (i believe:)), so as far as understand, some machine acting as a server should keep all the logic and calculate physics and other participants should act only as "renderers".



Please clarify me these moments and give maybe some likns to read about all this questions.



Thank you!

In my opinion you should neither worry about scalability (e.g. "loading when it's needed") nor about game states when you start your first project with jME. Further on you should not start with making multiplayer things.



Start off by creating some dummy train (e.g. out of boxes) and let them follow some path…  you will get a feeling for the scenegraph stuff, quickly.  :slight_smile:



After you know what the scenegraph is all about I would suggest to think about your entities: Game data and logic should be modelled as own classes which are visualized by the scenegraph. Generally speaking, you should seperate things that would be saved in a savegame (or some kind of snapshot of the current game status) and those that are for visualization only.

(This will help you with the issues mentioned above, too)

Thanks a lot for your answers!

I didn't want to start with multiplayer, scalabilty and so on…i just wanted to "keep it always in mind" while buiding a game so i wouldn't have to re-create some wrong parts of it later.

I need just few abstract ideas about simulator game structure… "view at the distance".



The good thing this is that: "Generally speaking, you should seperate things that would be saved in a savegame (or some kind of snapshot of the current game status) and those that are for visualization only."

I thought in this way also, but was not sure.

So first of all i'll try to define some map format, define some track sections and make a simple path.

Then i will load model (i succeded to load a 3ds object of a loco:)), put it on tracks,

define input system and try to move it.


irrisor said:

In my opinion you should neither worry about scalability (e.g. "loading when it's needed") nor about game states when you start your first project with jME.

Actually, I think it's a great idea to -- even in the testing stage -- put your stuff in a gamestate; this way it'll be easy to put in menus and stuff later on.

So now it's time to ask about car moving.

What are the main principles of moving a car on the tracks?

I have defined a rail network structure - it is consisted of nodes and track sections, which can be straight (has length) or curved (has its radius and angle).

First i put my simple loco on somewhere on tracks. How to keep it moving on track? For example, if i want to move it at speed of 10km/h.

I suppose, i should somehow attract wheels (as children of loco model) to exact track location…

Please give me some ideas.

The realistic way would be to exactly define the tracks and car's wheels in the physics - system altough i dont know if this is possible yet.

Then apply gravity to Your world and accelerative and deccelerative forces to your car and physics should do the rest.



But i'd ask DP about this to be sure.

So how should i tell a car to move on a curved track. I'm not sure if current physics system supports this. I don't catch, who will rotate a car every step so it will follow the curve.

Or i should apply some "special" force that will make car rotating while passing a curve…rrrrrr:(

I guess you don't want to simulate speeding trains that are thrown out of a curve etc.  :wink:

That's why I think using physics here is a bit exaggerated, as all the car- and wheel-stuff needs alot of fine tuning to get it behaving like you want.



I recommend to compute/alter the current position of each wagon and rotate it according to the track-tangent at that point.

Derailments should be one of the features - but it is quiet easy. Just calculate the forces and see if they are less then some "derailment value". I have a book on train dynamics:) More complicate thing is rotating of wheels, bogies and the whole car.



Should i calculate forces manually - not using phycics subsystem?:frowning:

And what is the algorithm for moving a car?

Where i should place code for rotating a car?



Please, in few words…


Ok, in this case: use jmephysics! Have a look at the BuggeDemo.

I don't think someone has tested that with a railway - so it may get tougher, but my feeling says it can be done with jmephysics.

wouldn't it be possible to use curve controllers to define paths/rotations. see TestBezierCurve



I dont know if they would work with the physics system though but it feels like that curves would help

I've looked in… am i right:



I have objects of TrackSection class that can be straight or curved.

This class has method of "entering" and "exiting".

So every RollingStock object may enter and exit it.



In TrackSection's update method i go over all "entered" RollingStocks

and call



setMinAngleStop(currentTrackDegree);

setMaxAngleStop(currentTrackDegree);



on the wagons's bogeys (actually bogeys are rotated, but not wheels as it is in cars)



Something like that?

Also i check what is the value of angle change. If it is too much or the speed is too much (for example 20 degrees at 5km/h or even 2 degrees at 200km/h), then that car derails.

Or i should to it in onContact()?:slight_smile:

You can take a look at my PipeRunner game, which you can find under the

Show Case section!

There i used beziercurves, you will just have to calculate the speeds, etc. physics yourself!

It works very well!

Another solution I can think of right now, is to create train tracks in a 3d modeler, then

set them as StaticPhysicsObjects in jME and then use a sphere with DynamicPhysics right at the center of the two tracks.

Then set that sphere to be invisible "setForceCull(true)" an have your train model be at the same location of the

sphere every update!

I don't know how you will handle the rotation though? :wink: