0
votes

How to convert (x,y,z) coordinates from inside the perspective pyramid, to (x',y',z') coordinates inside the perspective cube? (in a right hand coordinate system)

I tried to multiply this perspective matrix with the (x,y,z) vector, but the result isn't what I expected.

projection matrix

I tried it with: fov=70°, aspect=4/3, near=100, far=100; x=100, y=100, z=-300;

The result was (158.28, 211.05, -344.44)

All I want is this:

plan

Thanks in advance,

1
if you had near and far both set to the same value, you'll get a divide-by-zero. Is that a typo?Roger Rowland

1 Answers

2
votes

Though a perspective matrix generally transforms space such that the desired view frustum maps to a canonical volume (could be a unit cube, but not all graphics pipelines are the same - for example, D3D is different to OpenGL), this volume is described in homogeneous (projective) coordinates. This is because the actual projection is a non-linear transform, but using a projective coordinate system allows the use of linear transformations for the bulk of the pipeline.

So you still need to perform the projection, if you want a point in 3D (or 2D) space.

This is simply a divide.

When you multiply a point (x, y, z, 1) by a perspective matrix, you get a vector-4 (x', y', z', w'). You then need to divide x', y' and z' by w' to do the projection.