Get the ground viewport of camera view

Hello!
I would like to know how can i get the position, x, z and the width, height of the visible ground from a camera view.

Or to say differently the x, z coordinate of the (top,left)(top,right)(bottom,left)(bottom,right) ground mesh visible on the screen.

Considering the camera is moving and rotating

Here some picture to help you understand.

I tried camera.viewport but all i got is {x: 0, y: 0, width: 1, height: 1}

Please help

Thanks

Viewport is meant to know where in the canvas it will be displayed (equivalent of the gl viewport but in normalized space to make it more user friendly)

In your case you will need to compute the intersection of the ground plane and the camera frustrum volume.

Maybe @JohnK or @Evgeni_Popov have some maths tricks to pull this one ?

I’m not sure I fully understand what needs to be done.

Is the ground always perpendicular to the camera view direction (in which case it is not really a ground but more of a wall :slight_smile:)?

If the camera can rotate in your 2nd drawing, then a (x,z) + width/height data won’t be enough to describe the intersection of the green pyramid with the black rectangle.

Maybe you can try to setup a PG so that we can visualize better what you want to achieve?

1 Like