Keeping object same size when zooming/moving the camera

I am trying to implement a user interface widget that allows me to drag a 3D model around a scene similar to what you use in Blender or Unity (xyz tool with arrows to drag the selected meshes).

I have created a model that the user can interact with the mouse and successfully drag the selected object in the desired x, y or z axis. I have created a separate UI camera to overlay this model above all models rendered by the game camera.

My issue comes when i zoom in. When i zoom my camera in (z+/-) i would like to prevent the perceived scaling of the widget so that it remains the same size regardless of the zoom level. Tried a couple things i found from Google but i am struggling to figure out the best solution.

How does your zoom work. Is the camera moving closer to the object as you zoom in, or do you change the field of view of the projection matrix?

If you move the camera closer, you could just multiply the objects scale by the distance between the object and the camera. So if the camera is twice the distance away, the object get’s twice as big, so it should take up the same space on the screen.

If you are changing the camera’s FOV, you could just multiply the object’s scale by the FOV value.


Thanks for the reply.

I am just moving the camera closer. Your explanation about multiplying the scale by the distance between the object and camera makes sense. I will have a crack at implementing that.