I have a sphere in the scene with position P_world and radius R_world.
I want to be able to create a circle with position P_screen and radius R_screen.
This is for a gameplay purpose like creating a 2D circle collider that matches the sphere.
What I did so far:
I know that I can convert P_world to screen space via Camera.WorldToScreenPoint.
I don’t know the math to convert a “World Space Length” into a “Screen Space Length”.
My best guess here is to do something where I find how far the sphere is away from the camera, use it as some ratio to scale down the radius?
You’re describing a circle along a round cone, where the cone’s point is at the camera A, and the cone touches the sphere of radius RS. This circle has a calculated radius RC and its distance from the camera is calculated as H.
I found the thread below with the formulas you’d need to calculate RC and distance H.
Once you have RC at distance H representing a sphere RS at distance D, you can calculate any other radius at any other distance, as they scale proportionally.
A projected sphere is an ellipse, not a disk.
If you are fine with conservative bounds, you can use its 2d polyhedral bounds as described in this paper by Michael Mara and Morgan McGuire:
So currently I am using a Perspective camera which would be A in the diagram. It creates a view fulcrum and the near plane of that view fulcrum is a plane somewhere along V. If I bring h to the distance between A and the near plane, I should be able to find rc which would be the radius of my circle.
The only thing I’m not too clear about and maybe this is because I wasn’t very clear in my question is… once I get rc wouldn’t that be all in world units? I want to do some screen space manipulations with it and also have it interact with GUI elements. This would mean I would need them to be calculated in pixels? Is there some way to convert this into pixels?