Hi all
I’m currently learning Vulkan and implementing ModelViewProjection to map 3D points to the 2D screen using GLM, however I’m quite confused due to the way GLM works, and due to the conflicting information online.
For context I’ve never programmed in OpenGL before so I’m unfamiliar with it. I understand the mathematics of matrix multiplication and projection. I understand that Vulkan uses a different screen space coordinate system than OpenGL, and then GLM was designed for the latter.
I’m trying to implement a lefthanded, y up, world coordinate system which I then need to project onto Vulkan’s 2D coordinate space, WITHOUT flipping the viewport. At the moment I’m drawing a unit cube with local coordinates (0,0,0) (1,0,0) … (1,1,1) etc. This way I can easily see where positive world space maps to in NDC space, and thus screen space.
This is the code I’m using for projection:
#define GLM_FORCE_LEFT_HANDED
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp
#include <glm/gtc/matrix_transform.hpp>
...
model = glm::mat4(1.0);
view = glm::lookAt(
glm::vec3(0.0f, 0.0f, 5.0f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f));
proj = glm::perspective(
glm::radians(45.0f),
width / height,
0.1f,
100.0f);
This maps the cube to the bottom right corner of the screen, facing away, so righthanded with +y down, +x right, and +z is into the screen. This is expected for Vulkan since that is NDC space, but what’s confusing me is why I need to specify GLM_FORCE_LEFT_HANDED, when the finished transformation is right handed. Removing it projects the cube using lefthanded space.

Vulkan uses a righthanded NDC coordinate space. So why does GLM in setup.hpp specify Vulkan uses lefthandedness? Is GLM referring to something else here? Neither OpenGL or Vulkan enforce a word coordinate system. But GLM does, correct? so I’m assuming that GLM_FORCE_LEFT_HANDED is to swap explicitly for whatever world space you want.

Does GLM implicitly swap left and right handedness when projecting to NDC space? This might be a stupid question but I’ve consistently read online that OpenGL is right handed which isn’t true in NDC space, so what is being referred to here? It would also explain why my cube was projected the opposite of what I expected.

What is the significance of the camera facing the Z axis? Many examples online assume this is the case without any explanation. I understand what that means mathematically but not why it’s necessary in the implementation, or if it’s needed at all. My example doesn’t do that, because I wanted +z to be into the screen, but I’d still like an explanation.