Calculating position of object so it matches screen pixels

932 Views Asked by At

I would like to move a 3D plane in a 3D space, and have the movement match the screens pixels so I can snap the plane to the edges of the screen.

I have played around with the focal length, camera position and camera scale, and I have managed to get a plane to match the screen pixels in terms of size, however when moving the plane things are not correct anymore.

So basically my current status is that I feed the plane size with values assuming that I am working with standard 2D graphics. So if I set the plane size to 128x128, it more or less is viewed as a 2D sqaure with that exact size.

I am not using and will not use Orthographic view, I am using and will be using Projection view because my application needs some perspective to it.

How can this be calculated?

Does anyone have any links to resources that I can read?

1

There are 1 best solutions below

4
ratchet freak On

you need to grab the transformation matrices you use in the vertex shader and apply them to the point/some points that represents the plane

that will result in a set of points in -1,-1 to 1,1 (after dividing by w) which you will need to map to the viewport