CRefice
CRefice

Reputation: 430

OpenGL: How can I change my coordinate setup?

From what I understand, OpenGL uses a right-hand coordinate system, that, at least in clip space, works like this:

This means that, without any modifications to all the matrices used for transformations, world space coordinates work like this:

What if I want to change it so that the Z axis is the one pointing up? How could I go about doing this? I've thought about multiplying all matrices by a rotation matrix that just shifts all coordinates by 90 degrees, or maybe I could change the Y and Z components of a vector once I send data to the GPU, but those seem more like workarounds than actual solutions, and they might also take a hit on performance if done for every mesh in the scene. Is there any standard way to do this? Am I getting something wrong?

Upvotes: 1

Views: 763

Answers (1)

Ripi2
Ripi2

Reputation: 7198

The clip and NDC spaces are left-handed axis system, not as you defined each X,Y,Z, axis.

You can have several axis systems. For example some "objects store" use a left-handed system. If you're starting with OpenGL, try to set everything in right-handed system, will be easier for you to understand.

Your objects are normally defined in its own local system (right handed or not). You place them by a "world" matrix. And you see the world from a camera position, which requieres a "view" matrix. And then you project all of them, another "proj" matrix.
As you can see, matrices are used everywhere. Don't be afraid of them.

Changing from an axis system to another is just another matrix. There are many examples in the web.

Upvotes: 1

Related Questions