Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  car simulation  (Read 1281 times)
0 Members and 1 Guest are viewing this topic.
Offline stevy

Innocent Bystander





« Posted 2005-07-26 13:28:39 »

I'd like to simulate a car driving on a highway. The car is controlled by an artificial intelligence and should be able to keep a distance to the front car and to overtake slower cars.

How can I simulate the movement  with java?

The highway can be straight on (no curves). So the car always stays in the middle and the highway "scrolls down".

Which techniques could I use?
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #1 - Posted 2005-07-27 18:50:30 »

Rather than looking at techniques, I suggest you first consider what the simulation should look like:

i) Top down 2D view or a 3D view?
ii) If 3D is this 1st person or 3rd person view?
iii) Do you need to accurately simulate steering, or is sideways movement sufficient?
iv) Do you need textured graphics or is drawing the simulation from solid colour polygons sufficient?

2D will be easier than 3D.  Cars can be drawn in top down view in a graphics editor and saved in .png format.   These can then be loaded into an ImageBuffer using methods in the ImageIO class.  You might also look at the Image class, which is simpler to use but less versatile.  If you want to simulate steering, you will need a number of images, with cars shown at different angles.  Since the camera will follow the car, some indication of forward movement is required.  I suggest drawing a series of rectangles to represent the white (yellow for US) lines on the road.  These are redrawn every frame in a new position dependent on the car's velocity.

3D is harder.  Draw a picture of the back end of a car in a graphics editor.  Load it into an ImageBuffer.  Draw it in the correct place on the screen, scaling the size according to the distance that the car is away from you.  This requires 3D maths.  Most of this can be done with similar triangles.  Buy a book on 3D graphics to explain how this works.  If the road can be drawn in a single grey colour then you can represent it as a triangle, one point is at the screen centre, the other two are at the screen bottom and are slight off screen to the left and right, when you are in the centre of the road.  Drawing the lines in the centre of the road is harder, as you will now have to calculate the 2D position on the screen for the 3D position of each corner of the line rectangle.  The line, as drawn on the screen won't be a rectangle, but a trapezium.  It can be drawn as two triangles.  If you need to show the cars steering, you will need several pictures of the back of the cars, shown at slightly different angles.

For 3D third person view, you can draw your car the same as the others but (say) in a different colour.  For a 1st person view, you can omit drawing your car.  However, if you are simulating steering, this means that the road will not always be in front of you, making drawing it much more complex.  A similar issue applies to the view shown of the other cars, where the image shown is now a function of both your and their steering angles.  Best to stick to a 3rd person view to keep it simple.

All of the above assumed that the road and verges are drawn in a single colour.  This can all be handled by the built in Java2D graphics library.  However if you want a more realistic terrain, then you need to consider texture mapping.  There is no built in support for this, but you can use 3rd party libraries like LWJGL or JOGL to access OpenGL which does support texturing.  OpenGL provides 3D drawing support, which saves you from having to do all that similar triangle stuff too.

If this all looks new & hard, I would suggest a top down 2D view, with no depiction of steering.  You can still simulate steering in the AI model, if you want to make that realistic (I assume that the AI is the object of the exercise).

Time flies like a bird. Fruit flies like a banana.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (38 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (34 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (54 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!