Handmade Network»Forums»Career Advice
Oliver Marsh
193 posts / 1 project
Olster1.github.io
Unprojecting mouse position
Edited by Oliver Marsh on
Hi,

I'm trying to project the mouse position from screen space into world space, and I've come across two questions:

1. When the graphics api does the divide by the homogenous coordinate (z value), is it the z-value in camera space or ndc space?

2. Is the perspective matrix (one that was made using FOV) normalized & orthogonal? I.e. Does the transpose equal the inverse, or do I have to do a proper inverse to move NDC coordinates to camera space? (I assume have to do the inverse because the columns equal more than one)
511 posts
Unprojecting mouse position
1. it's the w value in clipspace, which is cameraspace transformed with the projection matrix.

2. no the perspective matrix is not an affine matrix at all. The last row is not the 0,0,0,1 but instead 0,0,1,0. This is what allows z to become w and effectively divide by z.

The most basic perspective-like matrix looks something like:

1
2
3
4
1,0,0,0
0,1,0,0
0,0,0,1
0,0,1,0


however this only does a very specific projection so a few scale and translate operations are added before and after the perspective transform.
Oliver Marsh
193 posts / 1 project
Olster1.github.io
Unprojecting mouse position
Thanks, I forgot about clip space. I was combining clip space and NDC space into the same thing.
Chen
102 posts / 2 projects
Some guy trying to make some video game.
Unprojecting mouse position
Hmm... Wrong section perhaps? :P