Get top, bottom, left, right values from near frustum plane

Hi,
I’m currently trying to port the camera controls from a C++ program to Javascript using the great Babylon.JS library.
I don’t have much experience with 3D rendering and the mathematics behind that and didn’t write the original camera view logic, so much of the code is a black box for me.

I need the distance from the camera view center (I guess that would be the target of the FreeCamera that i’m using) to the left, right, top and bottom edge of the near frustum plane as you can see in this graphic here, otherwise the existing logic doesn’t seem to work.
https://www.researchgate.net/figure/parametres-de-la-camera-OpenGL-frustum-WNDS99_fig1_278797375

Do you have any idea how i could get those values? They need to be just a normal number for left, right, top and bottom.
I’ve already managed to get the near frustum plane by scene.frustumPlanes[0] but i don’t know how i could calculate the distances from the center.
Best wishes and thanks already for reading

Edit: So in the end, I need the size of this “camera-rectangle” in the near frustum plane. I guess then i can simply divide the height/ length of it by 2 and should get the desired values.

Welcome aboard!

That (the camera center) would probably be the position of the camera instead.

I don’t really understand what you mean by “distance to the left edge”. Well, in fact I understand it but I’m not sure it’s what you want… If it is, this page explains how to compute the distance from a point to a line:

And if it is really what you want, you will need to compute first the line of intersection between the near plane and another plane (so the intersection between two planes):

3 Likes

Thanks for the explanation.
Having read your answer, I think what i really need is not the distance from the camera center point rather than the distance between the left and right intersection of the near plane with the left and right plane.

So i guess, first i need to find the line of intersection between the left and near plane (same for right, bottom and top).
When i got those 4 lines of intersections i can calculate the intersection points of the 4 lines and then hopefully i have the sizes of the rectangle that i’m looking for.
Man my maths really got rusty over the last years doing mostly web development :laughing: I will try this out next week :slight_smile: