Handmade Hero»Forums»Code
55 posts
Flipping coordinates
I don't mean to criticize, I only want to verify if I understand this correctly.

At the start, the option was chosen to flip the coordinates of the screen in Windows. What is the benefit of doing so? I thought it was because of the way the physical screen accesses the framebuffer (top-down)? But since we can just change the way Windows interprets the buffer we pass to it, this doesn't matter?

As far as I understand the benefits of a bottom-up framebuffer are:
- More intuitive
- "Math" uses y-axis up as well
- OpenGL, by default, reads bitmaps/textures bottom-up?

After changing how Windows blits the screen to the default setting, now we don't even have to invert the y-axis in the renderer anymore, right?

Why would anyone choose to invert the y-axis? This doesn't necessarily equal a left handed coordinate system, right? But rather a right handed one with the y-axis inverted?
Andrew Chronister
194 posts / 2 projects
Developer, administrator, and style wrangler
Flipping coordinates
A coordinate system which is the same as a right hand one but with one axis flipped IS a left handed coordinate system.

One way to define the handed-ness of the system is by what axis you end up at after doing rotations: in a right handed system, rotating counter-clockwise about the Z-axis will get you from +X to +Y, then to -X, then to -Y, whereas in a left-handed system, rotating counter-clockwise will get you from +X to -Y, then to -X, then to +Y.

Another way is using vector cross-products. In a right-handed system, if you cross the unit vector along the x-axis (+x, sometimes called î) with the unit vector along the y-axis (+y, sometimes called ĵ), you get the unit vector along the z-axis (+z, also called k̂):
î x ĵ = k̂
In a left handed system, this cross product yields -k̂ instead:
î x ĵ = -k̂
The term right-handed versus left-handed usually refers to which "rule of thumb" (literally) you use when determining these cross products. The way I learned is that you use your right hand in a right-handed system, with fingers curling from +x to +y, and your thumb is along the +z axis (in terms of the screen, that'd be straight out at you). If you used your left hand, your thumb would end up pointing the other direction (in terms of the screen, into the screen). To keep the Z-axis in the same direction, you'd have to flip the y-axis -- and it'd be top-down.

I've had a hard time following the design of the coordinate systems in handmade hero myself, since I'm usually paying more attention to the chat, but if I recall correctly we defined most of the game math in terms of a bottom-up coordinate system and then flipped at the last minute for rendering. The recent changes, as I understand it, have been to rectify it so that it continues being bottom-up all the way through rendering.

The only reason to have the top-down system in place at all was essentially because it's the more common way to deal with graphics. It might have been possible to do it the other way from the beginning, but we didn't.

I hope that answers your questions.