# Thread: car racing game

1. ## car racing game

Hi,

I m into the development of a car racing game.

Regarding the path i m clear as far as straight path is concerned.

Can anybody suggest me the technique(s) for creating circular/zigzag path??

as a referece u can refer
http://sumea.com/racingfever2/index.html

i tried using drawArc method in a applet (for testing) to create a circular path but its too tedious and hectic.

Any suggesstions always appreciated.

2. It's not done with drawArc().
What is usually done is to cut up the straight track graphics into horizontal strips, and move these strips left or right by the right amount according to the curve. To find out about the math involved in calculating the x-offset of the strips you should google for a technique called "perspective projection" to give it a true 3D-ish look.

shmoove

3. Hi shmoove,

Thanks a lot for ur suggesstion.

am working on prespective projection.

4. ## making a transition from straight path to curve path

Hi shmoove,

i worked on ur suggesstion and i m abe to get a curved path, but the problem lies in the transition frm straingth to curved and curved to straight path.

Acc to my code transition happens , but in a shot and not gradually as most racing games have.

Can u (or ne one) provide me with a more detailed idea as to how the path of the game can be structured (designed).

-- Gaurav.

5. Without knowing exactly how you model the track I can't say for sure, but here's a guess:
When you're still on the straight part, but you are getting close to the curve the part of the road that's far (the top of the image) has to start showing the curve. Basically what I'm saying is that you have to start rendering the curve before you're actually there, so that at the begginning only the top of the road starts curving and that curve "moves down" along your road.

shmoove

6. ## work prototype

Thanx for the reply shmoove

This is wat i m trying to do :

I have divided the path area into 8 horizontal strips of increasing height.
In all i have 16 strips (8 of the left side and the other 8 on the right side)
These strips have alternate colors so that it gives the impression that the vehicle is moving ahead.

The prototype of wat i have done is kept at the following link
http://us.f1f.yahoofs.com/bc/2151579...65HrABU1KmTySV

The blue and the black strips in the image are all png's.

Is this the right way of structuring the track. Or wat u meant was something different?

7. Actually I meant model as in the abstract data behind it, not the graphics. What is the data structure you use to save the track information?
But even without that information you can still try what I said on the previous post: you have to start "seeing" the curves a few frames before you actually "reach" the curve.
If you looked up perspective projections and general 3D theory then you probably know that there are far and near clipping planes. So when the distance from where you are to where the curve should start places the curve before the far clipping plane you should start "seeing" the curve. From there, you need to be able to calculate how far to the left or right the road starts to move (according to the perspective projection calculations). So you get a frame sequence that looks something like this (hopefully my ascii art hold up ;p):
Code:
```Straight track:
/ \
/   \
/     \
/       \
/         \
----------------------
The 1st frame where the curve is in "viewable" distance:
/ \
/   \
/     \
/       \
/         \
----------------------
/ \
/   \
/     \
/       \
/         \
----------------------
/ \
/   \
/     \
/       \
/         \
----------------------
/ \
/   \
/     \
/       \
/         \
----------------------
Full curve - the car reaches the curve:
/ \
/   \
/     \
/       \
/         \
----------------------```
shmoove

PS: The link doesn't work (Web Site cannot be found)

8. thanx a lot shmoove.
I really appreciate ur interest in my query.

i have done in the same way as u've explained in the ascii chart.

the only left out part was the perspective projection and the far and near clipping concepts.

as the previous link did not work, u can chekc the the below 2 links to get an exact (graphical) idea of wat i have done.

Can u just tell me where can i find some good and very basic material about perspective projection or in the case ne good material relative to my project?

http://www.hungama.com/temp/cargame/straight.jpg
http://www.hungama.com/temp/cargame/curved.jpg

awaiting for ur reply on it )

--Gaurav.

9. I think you better buy a nice book that teaches the mathematics for 3D graphics.
As far as online tutorials, I've never seen any that really explain it very well, but there are a couple at flipcode, particularly this one (although it's not in Java).

shmoove

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•