Frustum planes with floating origin camera

How would you go to get the frustum planes “data” for a floating origin camera, using doublepos and doubletgt?

in a non-floating origin context, I do this:

const frustum_planes = BABYLON.Frustum.GetPlanes(scene.getTransformMatrix());
    const frustum_planes_data = frustum_planes.flatMap(function(plane){
        return [
            plane.normal.x,
            plane.normal.y,
            plane.normal.z,
            plane.d
        ];
    });

and it works as well as I end up with something similar to this:

[
    0.0031999240366749203,
    0.005199982482976804,
    0.9999813601604463,
    19199.542948220645,
    -0.002929624637749523,
    -0.005859249275499046,
    -0.9999785430185038,
    819182.4224407583,
    0.6102906021382052,
    0.00412428984551793,
    0.7921668834122373,
    15209.604781064781,
    -0.6052083133177224,
    0.0041345972614600015,
    0.7960564066676452,
    15284.283624444593,
    0.00125362471484348,
    -0.9190235789387331,
    0.394200570496437,
    7568.651255740652,
    0.0012385934462409228,
    0.923073515638596,
    0.38462156805472797,
    7384.734410531041
]

thank you!

The equation of the new plane will be the same than the original plane, save for the d value:

Original plane:
ax+by+cz+d = 0

New plane:
ax+by+cz+dnew = 0

I think doing something like this should work to calculate dnew:

dnew=-(aX+bY+cZ-d)

where (X,Y,Z) is the floating origin.

For eg, for the first plane in your example:

a=0.0031999240366749203
b=0.005199982482976804
c=0.9999813601604463
d=19199.542948220645

so:

dnew = -(0.0031999240366749203*X+0.005199982482976804*Y+0.9999813601604463*Z-19199.542948220645)
1 Like

Evgeni <3 <3 <3 Many thanks man.

of course you gave the solution :slight_smile:

Hello again :slight_smile:

Well now something weird has emerged.

Using a Floating origin camera with maxZ = 154.34375891847327 (the result of some internal stuff going on), and on initial load (i.e., no movement!), this is what I get:

scene transform matrix:

{
      "0": 1.830667495727539,
      "1": 0,
      "2": 0,
      "3": 0,
      "4": 0,
      "5": 2.365222454071045,
      "6": 0,
      "7": 0,
      "8": 0,
      "9": 0,
      "10": 1.0000001192092896,
      "11": 1,
      "12": 0,
      "13": 0,
      "14": -0.000021140085664228536,
      "15": 0
    }

doublepos:

[0, 0, -23.15056383777099]

and the far plane individual components:

0, 0, -1, 177.3369140625

all good there.

But compare it when the only thing that changes is setting maxZ to 771.7187945923663

scene transform matrix:

{
      "0": 1.830667495727539,
      "1": 0,
      "2": 0,
      "3": 0,
      "4": 0,
      "5": 2.365222454071045,
      "6": 0,
      "7": 0,
      "8": 0,
      "9": 0,
      "10": 1,
      "11": 1,
      "12": 0,
      "13": 0,
      "14": -0.000021140085664228536,
      "15": 0
    }

doublepos is the same.

and my problem for the far plane, whose components then become (when logging planes[1]):

**0, 0, 0, 0**

which, as one might guess, creates some slight visibility problems xD

the code is the following (as a method of OriginCamera):

compute_frustum_planes(mesh){

    var self = this;
    const frustum_planes = BABYLON.Frustum.GetPlanes(this._scene.getTransformMatrix());
    // console.log(planes[1]);
    const frustum_planes_data = frustum_planes.flatMap(function(plane){
        return [
            plane.normal.x,
            plane.normal.y,
            plane.normal.z,
            -(
                plane.normal.x * self.doublepos.x
                + plane.normal.y * self.doublepos.y
                + plane.normal.z * self.doublepos.z
                - plane.d
            )
        ];
    });

    return frustum_planes_data;
}

any idea of what I am doing wrong?