Choice of axes and scaling factor

Started by
5 comments, last by Omid Ghavami 17 years ago
I've been thinking a bit about the arbitrary coordinate system I use for my 2D game graphics system, and was wondering what other people use for the scaling factor on their axes. My understanding is that as long as you do not pick ridiculous values then it's really just down to whatever you feel is comfortable, but I'm curious as to what other people use. For example, in my 2D OpenGL system, I set up my camera to use the following coordinates using glOrtho with code like this:
glOrtho(-1.0, 1.0, -0.75, 0.75, -1.0, 1.0);
where the x-axis along the width of screen ranges from -1.0 (left) to 1.0 (right), the y-axis along the height of the screen goes from -0.75 (bottom) to 0.75 (top) and the z-axis for the depth layering of sprites in my 2D game goes from -1.0 (closest) to 1.0 (furthest away). This gives me (0,0) being the centre of the screen, and a normalised factor of 1.0 along the width of the screen. The height is adjusted to 0.75 at the top to give it the same proportion on 4:3 width-to-height ratio screens. I use a cartesian x-y system where the y-axis increases when heading up. I've been thinking about other attractive scale and coordinate systems to use, and am interested in what everyone else is using in their games. Anyone have another coordinate system that they favour?
Advertisement
http://upload.wikimedia.org/wikipedia/commons/thumb/4/4e/Axes01.jpg/200px-Axes01.jpg
--------------------------------------------[size="1"]Ratings are Opinion, not Fact
As much as I love puns involving axes, I am serious with my curiousity about what people prefer for their 2D projection coordinate systems. [smile]
I used
gluOrtho2D (0, dispWidth, dispHeight,0 )
which sets the viewport to a normal screen coordinates system (origin in upper-left corner with y increasing down). Variables dispWidth and dispHeight are set to the game's current window size.

This was mainly because I wanted to be able to switch between a OpenGL and a software renderer without doing a lot of conversions in between. Also most graphics tools and 2D libraries use the screen system so it was convenient and standard. Lastly, I was lazy and didn't want to think about scaling factors and such:)

I can see ,though, how a decoupled system would aid in scaling to different resolutions and aspect ratios. Especially for vector graphics.
0xa0000000
Well, in 3D, I try to set it up so that 1 unit == 1 meter (it's easier to deal with all the physics stuff if that's the case).

I did something similar with my 2D game (one unit was a meter, the character was just shy of 2 units tall), but I made the screen such that it was 16 units by 9 units (a perfect widescreen setup - it worked out rather well).

I'm pretty sure 0,0 was at the screen's center. So it went from [-8, 8] along x and [-4.5, 4.5] for y ( with (-8, -4.5) being lower-left, +x is to the right, +y is up).

Now, confusingly, my UI coordinates were (0,0) in the upper left to (16, 9) in the lower right, meaning that +y was DOWN in UI coordinates. I did that because I generally think of the screen with 0,0 in the upper-left, but in the world I usually think with +y as up, so I did each in the way that made the most sense to me. Not that the differences didn't get confusing occasionally...I'm not sure I recommend it.
Quote:Original post by Drilian
Well, in 3D, I try to set it up so that 1 unit == 1 meter (it's easier to deal with all the physics stuff if that's the case).

I did something similar with my 2D game (one unit was a meter, the character was just shy of 2 units tall), but I made the screen such that it was 16 units by 9 units (a perfect widescreen setup - it worked out rather well).

That's a pretty useful alternative basing the coordinates on a scaling factor. I think it's intuitive in 3D games but I hadn't considered using it for something like a tile based 2D game.

Although after posting this I realised that in my case it doesn't matter what scaling factor I use, as I use symbolic constants for nearly everything (in my actual glOrtho call I don't use the magic numbers I listed here [smile]). As such everything is presented as a fraction of the screen unit factors (which just happen to be 1.0, but that doesn't mean it's an excuse to get rid of the factor).
I use something similar to yours Trapper Zoid, except I have [-1, 1] for y aswell.
Best regards, Omid

This topic is closed to new replies.

Advertisement