Camera & Viewport - Getting corner vectors

Hi,

I’m trying to get the vector3 positions of the camera viewport corners (TopLeft, TopRight, BtmLeft & BtmRight). I have:

https://playground.babylonjs.com/#9310J2

But it’s far from correct, as it doesn’t take into account the camera’s rotation.

What is the size of the camera’s view as a vector on x & y?
How do you get the corner vector3’s A,B,C,D (see image) of the camera at any angle?

Thanks

DCameraViewport

I thinks its
https://doc.babylonjs.com/api/classes/babylon.frustum
:slight_smile:

If not then there are ways, but off the top of my head I think this does it.

@Darcey did you work this out? I want to do something similar and can’t find any examples of Frustum static method use in Playground search.

Nope, but this was a long time ago… I either worked out an alternative way to achieve what I wanted or jumped over to three, which has lots of resource online for moving object to fit in camera view, of which i used to get what i need via boundingbox. Can do the same in babylon. Could also make a plane adjust it so that it fits the viewport perfectly hide it and then when you need those vectors just move the plane while hidden to the camera position, get camera direction/normal, apply that to the plane and get its bounding box again which you can eork out the 4 corner vectors from. This is if you dont change the cameras zoom/fov values.

Hi.

I had similar situation before. Here it is a link to that thread.

Here is above playground adjusted using NDC space

1 Like

Thanks so much @nogalo ! That’s exactly what I needed.

1 Like