How to position the camera so that the given world coordinate is projected on the given screen position

I want the camera to be positioned so that the center of the object is rendered at the given pixel coordinates( for example (10, 20)) of the screen.

The center of the object is given in the world coordinate system. Maybe someone can give me a hint on how to solve it. Thank you.

Here is a hint. The position of the camera cannot be determined uniquely – i.e. there are many positions that will achieve the same effect. Here is one possible solution with camera panning (see lines 69-82):

https://codepen.io/boytchev/full/oNaGqXX

image

If you need to position the camera with other types of camera motions (e.g. dolly and rotate), you have to make the appropriate calculations. Good luck with your project.

this is really helpful.
thank you, very much!

1 Like