Search code examples
coordinate-systemsvulkan

Why doesn't Vulkan use the "standard cartesian" coordinate system?


Vulkan uses a coordinate system where (-1, -1) is in the top left quadrant, instead of the bottom left quadrant as in the standard cartesian coordinate system one typically learns about in school. So (-1, 1) is in the bottom left quadrant in Vulkan's coordinate system.

Image from: http://vulkano.rs/guide/vertex-input

(image from: http://vulkano.rs/guide/vertex-input)

What are the advantages of using Vulkan's coordinate system? One plain advantage I can see is pedagogical: it forces people to realize that coordinate systems are arbitrary, and one can easily map between them. However, I doubt that's the design reason.

So what are the design reasons for this choice?


Solution

  • Many coordinate systems in computer graphics put the origin at the top-left and point the y axis down.

    This is because in early televisions and monitors, the electron beam that draws the picture starts at the top-left of the screen and progresses downward.

    The pixels on the screen were generally made by reading memory in sequential addresses as the beam moved down the screen, and modulating that electron beam in accordance with each byte read in sequence. So the y axis corresponds to time, which corresponds to memory address.

    Even today, virtually all representations of a bitmap in memory, or in a bitmapped file, start at the top-left.

    It is natural when drawing bitmaps in such a medium to use a coordinate system that starts at the top-left too.

    Things become a little more complicated when you use a bottom-left origin because finding the byte that corresponds to a pixel requires a little more math and needs to account for the height of the bitmap. There is usually just no reason to introduce the extra complexity.

    When you start to introduce matrix transformations however, it becomes much more convenient to work with an upward-pointing y axis, because that lets you use all the vector algebra you learned in school without having to reverse the y axis and all the rotations in your thinking.

    So what you'll usually find is that when you are working in a system that lets you do matrix operations, translations, rotations, etc., then you will have an upward-pointing y axis. At some point deep inside, however, the calculations will transform the coordinates into a downward-pointing y axis for the low-level operations.