Get Fov from ProjectionMatrix?

Hi there,

i am trying to figure out how i would get the FOV from the projection Matrix from camera. but i cannot really get the right informations.
in the end i need to change the projectionMatrix so that it represents a bigger FOV.

what i have:

const babylonProjectionMatrix = camera.getProjectionMatrix(true).clone();

wich looks like:

{
    "0": -0.8108331561088562,
    "1": -0.42402830719947815,
    "2": -0.4034222960472107,
    "3": 0,
    "4": 0,
    "5": 0.6892840266227722,
    "6": -0.7244912385940552,
    "7": 0,
    "8": 0.5852773189544678,
    "9": -0.5874415636062622,
    "10": -0.5588943362236023,
    "11": 0,
    "12": -2744.837890625,
    "13": -814.970703125,
    "14": -511.23333740234375,
    "15": 1
}

this should represent a camera with a 45° FOV. what do i need to change or calculate so that it represents a for example 50° FOV?

i tried to use this logic here but it seems that the babylon matrix is not like openGL

Bildschirmfoto vom 2023-10-26 15-32-47

Any help would be awesome!

(i want to do this, because i am feeding the matrix into loaders.gl to receive tiling information from the actual camera perspective. but my virtual camera needs a little bigger fov)

guess in the meantime i do this:

      const loadersCamera = camera.clone("loadersCam")
      loadersCamera.fov = camera.fov + 1

it does exactly what i need… Anyway. If someone could explain what i am doing here with the matrix it still would be very nice!!

Thanks a lot!

The best way is to look at how the matrix is computed:

The b variable is 1/tan(fov*0.5) (because by default isVerticalFovFixed==true), so by reading the 5th value of the matrix, you could easily deduce the fov value.

2 Likes