View Single Post
Old 30 January 2012, 23:38   #101
P-J
Registered User
 
P-J's Avatar
 
Join Date: Mar 2001
Location: Moorpark, California
Age: 44
Posts: 1,153
Quote:
Originally Posted by Dunny View Post
Ditto to that - I'd love to see if I can write a lotus/outrun clone in BASIC. Actually, PJ - would you be willing to share some algorithm descriptions, especially regarding road storage and generation? Not source code, just a description of how it's done?

D.
Nothing to it really

To start drawing the track, you draw 128 horizontal lines that go into the distance, the spacing getting less and less as you draw higher up the screen, and the width getting less and less too. Just a really basic 3D projection in 2D.

Code:
           ---
          -----

        ---------


     ---------------
Then you interpolate between these lines with lines that fill in the gaps.

Code:
           ---
          -----
         -------
        ---------
       -----------
      -------------
     ---------------
That's the basics of drawing the straight track. There's formulas for working out where each line would be, but I just used trial and error to work all that out (with the help of Shaun, obviously!).

Then, for corners, you'd have a value of '4' for a corner. This means you shift each line across exponentially by four from the front to the back. (4, 8, 16, 32, 64, 128, 256...). Because you've projected the lines in 3D (on a 2D surface) the track appears to curve (rather than take a straight line off to one side).

To do hills, it's the same principal. It's just a curve that operates on the y-axis instead of the x-axis (and uses smaller adjustments so it doesn't end up looking like a cliff ).

That's simplified quite a bit in that there's a lot more going on to achieve the Lotus look over, say, the Pole Position look, but that's the basics.

Once the game is further through and I have time I'll take some screenshots with certain stuff disabled and some debug info which should de-mystify the process a bit.
P-J is offline  
 
Page generated in 0.05499 seconds with 11 queries