# Constant size geometries

How can I display objects in a 3D perspective projection that look like as if their size does not change, despite of the camera's position? I am using DirectX 9.0. I know of PositionTransformed declaration usage, but I was thinking of scaling the objects in every frame as the camera zooms in/out to achieve this. Is there a way to know the "scale" of a perspective projection?

An example usage would be to show lines with constant width. E.g. roads on a map.

Update, I've found the solution

-
Is there a reason you have to use a perspective projection? Could you not change to an orthographic projection for just those objects? – Josh Petrie Mar 8 '12 at 16:14
Hello, sorry i'm a newbie here, I will post it as an answer. I have both ortho 2D and perspective 3D. I want to display 3-axis when the user selects an object, in order to move it. – kagelos Mar 8 '12 at 17:37

Suppose we want an object to appear that it has constant size, regardless of the camera's position, in a 3D perspective projection. The solution is to scale the object in every frame, to increase/reduce it's size. Suppose we want the object to be 1/4 of the size of the viewport. This can be calculated as follows :

``````const double fov = Math.PI / 4.0;  //suppose 45 degrees FOV
float cameraObjectDistance = Vector3.Distance(Camera.Position, Object.Position);
float worldSize = (2 * Math.Tan(fov / 2.0)) * cameraObjectDistance;
float size = 0.25f * worldSize;
``````

I hope this will be useful to others as well.

-
Thatwas extremely unobvious and awesome. Thanks. – comprehensible Jun 26 '14 at 14:37

I haven't tried this but theoretically you could create the matrix without the 1/D projection transform. http://msdn.microsoft.com/en-us/library/bb147302.aspx to render these and you'd still get them settled properly into the 3D scene.

-

Just thinking out loud here:

Depending on if you zoom by changing camera position or changing FOV, apply this concept to the view matrix for the former, the projection matrix for the latter.

If you want some objects in the scene to follow normal size changes during zoom, but others to not change... You could use two view (or projection) matrices. One for everything in the scene that changes normally, and one for the object you are trying to keep uniform size. Simply keep it's position (or FOV) a constant distance (or value) but in alignment and orientation with the other normally zooming matrix.

-