Nearing the end of Amarillion's tutorial, [url http://pixwiki.bafsoft.com/mags/5/articles/circle/sincos.htm]Sin & Cos: The Programmer's Pals![/url], I started getting confused with some things, namely the whole "space cordinates to screen coordinates" concept. I was hoping someone could clear this up for me by justifying the math behind his code (circ11.c and circ12.c [url http://pixwiki.bafsoft.com/mags/5/articles/circle/circle_examples.zip]here[/url]) or coming up with some crazy analogies 
PS:
Go easy on the math terms, I don't want to look anything up (which is pointless because for every mathematical term, there's an accompanying 99 that you have to look up as well...)
circ12.c:
Space coordinate as what you, as the programmer, make up. In OpenGL, for example, you will often find programmers using 1.0f to represent the top of the screen, -1.0f for the bottom, -1.0f for the left side of the screen, and 1.0f for the right side of the screen.
So a dot at the right side of the screen in the middle would be defined (in code) as (1.0f, 0.0f). A dot in the middle of the screen would be (0.0f, 0.0f). A dot at the bottom of the screen in the middle would be (0.0f, -1.0f).
(-1, 1) ------- (0, 1) ---------- (1, 1) | | | (-1, 0) (0, 0) (1, 0) | | | (-1,-1) --------- (0, -1) ------- (1, -1)
Now the screen, in memory, can really defined by a 2 dimentional array defiend as video_mem[height][width]. This is what's called screen coordinates. It usually goes from (0,0) - Upper Left, to (width_resolution, height_resolution) - Lower Right. So to convert world coordinates to screen coordinates, you would have to take the coordiantes you made up, like from -1 to 1, and convert them into which pixels in the array. So if you're running in 640 x 480, you would convert the word coordinates (1, -1) from above as (639, 479) in screen coordinates to represent the bottom right hand side of the screen.
In other words, World Coordinates are what the programmer makes up to best fit whatever the program is supposed to do, while screen coordinates are made up by the hardware and video memory.
In the sin/cos tutorial, those sections are describing a technique for representing a 3D world in 2D. To do this, you need to be able to take points in 3D space and know where to place them on the screen -- i.e. in 2D space. The simplest method for this is to just divide the 3D coordinates by their 'z' value, or their distance from the screen, which has the effect of squishing together pixels which are farther from the screen.
So this gives us his equation:
space_x / space_z = screen_x
space_y / spaze_z = screen_y
space_z / space_z = 1
So now we have a way of 'translating' pixels in 3D space to pixels in 2D space. But we can't just pick pixels in 3D space, translate them, and fill the screen -- what if we pick pixels that are too far apart, and we miss parts of the screen? So we need a way of saying, 'for this pixel on the screen, what part of 3D space did it come from?'. Note that he is trying to draw a plane of fixed 'y', so space_y is a known constant.
This gives us his equations:
space_z = space_y / screen_y
space_x = screen_x * space_y / screen_y
Due to the nature of the technique he gives for rendering, he wants to turn the space_x variable into a value which means 'the amount of movement in x, in space, we need to move one pixel in x, in the screen', so he replaces screen_x with the constant 1:
space_x = 1 * space_y / screen_y
His variables scale_x and scale_y are introduced to solve the issues described by Nyan; they scale the space coordinates so that the screen coordinates that result from this translation correspond to the right amount of screen-space. They're constants that you may adjust, and should be set to 'whatever looks good'.
edit: I missed one: The horizon variable is also a constant which can be set to 'whatever looks good' -- it determines where on the screen the horizon should be ... it's just an offset you add to screen_y.
Also, horizontal_scale in the code is essentially space_x in the description.
There's more to the algorithm, but this should cover most of the details of the world-space to screen-space translation. Hope it helps
Slowly but surely.. -.-
Thanks guys.