How would I calculate the size the object needs to be, to be the same size on the screen?

2860699--209309--upload_2016-11-22_22-14-2.png

So what I want to do is, keep the size on the screen of the red object the same, no matter what the distance to the camera.

So variables that I know are:

public float d; //The distance to the object.
float fov; //The fov of the camera.

Could you make use of Pythagoras’ theorem? Consider the height of the object to be the 2x the other side of the triangle off the right angle of the triangle.

Normally with this right angle triangles, the sides will be X, Y and Z making the equation X^2 + Y^2 = Z^2. You already know X as its D. Y = Object Height / 2. Z will be the distance from the locked camera point to the point in world space (drawing a line until it crosses the plane of the front of the object). Once you have Z you can solve for Y.

1 Like