# Bounding box of geometry in screen space?

So I was wondering, how would one get a 2D bounding box of a geometry in screen space (guiNode coordinates)?

The getWorldBound method isn’t much use since the only useful thing it has is the getCenter method. Perhaps colliding it with a screen aligned quad could help?

Here’s a symbolic picture: I’d be most interested in getting the points marked with red dots.

Umm… cast it to BoundingBox which it most certainly is?

Oh, I didn’t think that was possible.

Neat, that solves it Hi, guys! Sorry for possible necropost, but i have pretty same problem as TS and don’t see solution. I need to know 2D coordinates of BB like it is shown on pictures above. Not just world bounds, but 2D coordinates of red points on screen. I thinks their values depends of camera position and i don’t understand how to calculate it.
For example center position can be calc by this
`position = camera.getScreenCoordinates(node.getWorldTranslation());`
How can i calc red points positions at the same way?

It’s simple really, that’s why I didn’t mention it.

After you get the BoundingBox you can get the X,Y and ZExtend parameters which tell you how large the object is. Then you have to calculate the 8 vectors that mark the vertices of our BoundingBox.

You take the object’s world translation and add these vectors to it (after multiplying them by the object’s rotation).

Now you have 8 vectors in world space that mark the box’s world coords and you project them to the screen using the method you mentioned.

If you want a bounding square on the monitor you just have to figure out which are the max and min X and Y coords of the projected points. Then you just have to draw a box from minx, miny to maxx, maxy.

Thx for quick responce! Ur solution should work, need to test it. Have u tried using

``````Vector3f min = camera.getScreenCoordinates(boundingBox.getMin(null));
Vector3f max = camera.getScreenCoordinates(boundingBox.getMax(null));
``````

I mean is this code produce same result as ur? I ask cause making 8 vectors seems like overkill.
Thank u for help

A box has 8 vertices, each one of those can stick out more than the others. What you’re saying would probably work in the case where those points happen to be the onscreen min and max too. So if it works at all it’ll be less accurate.

In other words, the bounding box in question is (presumably) axis-aligned in 3D world space. It is not axis aligned in screen space.

If you need a tight bounds that is axis-aligned in screen space then you will have to calculate it yourself from points… presuming the object is not in the guiNode.

Yep, i checked this and understood why i have what i have in results. Surely have to get all 8 points to choose 4 of them. Thank u for clarify my problem and pay attension to it.

1 Like