x


Screen Coordinates of an object's corners

I'm wondering how to tell where the furthest left and "top" screen coordinates of an object is.

I had thought to use the transform.collider.min and doing worldtoscreenpoint, but as the camera rotates around the object (especially around the x axis) this doesn't always hold up.

Thanks!

more ▼

asked Jun 20 '10 at 05:08 AM

Adamv gravatar image

Adamv
3 1 1 4

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I'm afraid there's no easy solution for this. You could go over all the points of your collider, calculate screencoords and calculate min/max values on them.

more ▼

answered Jun 20 '10 at 07:18 AM

Jaap Kreijkamp gravatar image

Jaap Kreijkamp
6.4k 20 26 70

Yeah, that sounds painful. If it can't be done, it can't be done though. Maybe I'll add a comment about this in the GUI thread at http://feedback.unity3d.com.

Jun 20 '10 at 04:55 PM Adamv
(comments are locked)
10|3000 characters needed characters left

If you still havent found an easier solution for this, here is my complicated and not very accurate solution.

This is the function you need for getting an objects PIXEL SIZE (size drawn on screen)

    //Gives pixel size of an object
    public static float angularSize (float diam, float dist, Camera cam) {
        float aSize = (diam / dist) * Mathf.Rad2Deg;
        float pSize = ((aSize * Scr.height) / cam.fieldOfView);
            return pSize;
    }

Where diam is, diam = transform.collider.bounds.extents.magnitude; dist is, dist = Vector3.Distance (transform.position, Camera.main.transform.position); cam is the camera you are using.

This works for square or circular objects best. Then you can work your way through objects screen position and the objects screen size to find your answer.

Regards,

Aubergine

more ▼

answered Sep 27 '10 at 02:39 PM

Auberhine gravatar image

Auberhine
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2987
x480
x151

asked: Jun 20 '10 at 05:08 AM

Seen: 2002 times

Last Updated: Jun 20 '10 at 05:08 AM