Skip to main content
GameDev.net gamedev.net
🔒 Locked

2D / 3D road question

Started by hex4def6 Feb 3, 2003 at 11:00 PM 5 replies 2.5k views
Original Post
hex4def6
hex4def6
Ok, I posted my code last time, and no one noticed (*sob*), so im gonna as a more general question. how do I draw a scrolling road? This is how I do it at the moment; I draw line by line the road from the bottom of the screen to half way up. Each time it is decreased using a ratio, so that you get perspective. I am also trying to use sin to allow me to make the road "turn", and am having a little luck doing that but not much. Is my concept worng? Is theer a better way of doing it?
llyod
llyod
the technique you describe is called "mode 7" (from the snes console, iirc). here''s a rundown on how it works

http://echellon.hybd.net/issues/5/articles/circle/sincos.htm

hope it helps

2DNow - Specializing in yesterday''s technology today!
Jason Doucette
Jason Doucette
I think he is reffering to the classic scan-line type road, like the classic Pole Position and even in roads with hills like Out Run. I made one of these a LONG time ago when I was in grade 8, so it''s not too hard. I have a demo I made in university based on this model: http://jasondoucette.com/games.html#FullTilt, you may wish to check it out.

First - forget about hills, and get the basic Pole Position flat road working. Calculate a distance for each scan line using the 3D formula. Draw the road, scaling it by the inverse of the distance, so it''s the proper size. When it moves fom side to side when the camera moves, the size of each scan line is proportional to its size.

I don''t want to give all the secrets away (I still have plans for my engine), so take it from here, and let me know if you run into any problems.

Jason Doucette
www.jasondoucette.com
hex4def6
hex4def6
______________________
ok so assuming the line should be a hundred pixels at the start;

track size = 1/distance * 100;
distance ++;

right?

I draw from the bottom up. is that better or worse then from top down?

[edited by - hex4def6 on February 4, 2003 9:54:38 PM]
Jason Doucette
Jason Doucette
Draw from bottom up. It helps when you add hills, so you don't redraw over the scan lines that should be covered up. You'll draw your sprites from back to front, though.

distance does not increase linearly. The inverse of it increases linearly. Please learn about the 3D formula first so this all makes sense:

ScreenX = WorldX / WorldZ
ScreenY = WorldY / WorldZ

....edit....

Actually, you are on the right track... the problem is is that you are finding the scanlines by distance = 1,2,3,4.... when you should be finding the scanlines by their Y coordinate on the screen, yscreen = 639,638,637,636....321,320 (for a 640x480 screen resolution). The way you are doing it means you have to compute many more scanlines than you need to at far distances, and not enough at close ones PLUS you need to computer the Yscreen coordinate to draw the scan line at the same time. My method doesn't require any of this.

Jason Doucette
www.jasondoucette.com

[edited by - Jason Doucette on February 5, 2003 8:55:45 AM]
Lord Alexion
Lord Alexion
but what is this 3D formula, and how do I use it to calculate distance?

where can I find documentation on this issue? I want to do the same thing...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.