Hey all.
I didn’t really know where to post this, but I decided to post it here.
I am encountering a problem with frustrum culling. Or actually, with correctly defining the frustrum.
I use this code:
Matrix4 mLeftTop = new Matrix4();
mLeftTop.rotY(viewAngle * -.5f);
mLeftTop.rotX(viewAngle/widthHeightRatio * .5f);
Vec3 vOrigin = new Vec3(camPos.x,camPos.y,camPos.z);
Vec3 vFarTopL = new Vec3(0f, 0f, -distanceFar/2f);
mLeftTop.transform(vFarTopL);
System.out.println("vFarTopL: "+vFarTopL);
Vec3 vFarBottomL = new Vec3(vFarTopL.x,-vFarTopL.y, vFarTopL.z);
Vec3 vFarTopR = new Vec3(-vFarTopL.x, vFarTopL.y, vFarTopL.z);
Vec3 vFarBottomR = new Vec3(-vFarBottomL.x,vFarBottomL.y, vFarTopL.z);
matrix.transform(vFarTopL);
matrix.transform(vFarBottomL);
matrix.transform(vFarTopR);
matrix.transform(vFarBottomR);
Plane leftPlane = new Plane(vOrigin,vFarTopL,vFarBottomL);
Plane rightPlane = new Plane(vOrigin,vFarBottomR,vFarTopR);
Plane topPlane = new Plane(vOrigin,vFarTopR,vFarTopL);
Plane bottomPlane = new Plane(vOrigin,vFarBottomL,vFarBottomR);
Plane farPlane = new Plane(vFarTopL,vFarTopR,vFarBottomR);
Where ‘matrix’ is the camera matrix. The width/heigth ratio of the frustrum correctly matches the ratio of the 3d canvas, but it’s too small.
I am drawing my planes, and they all ‘follow’ the camera, as they should (I can’t see them), but the far plane is not the size of the window,
so all objects get marked as invisible way to early.
The far distance is set to 10000, the viewAngle (FOV) to 60 degrees.
I have some screenshots attached so you can see what I mean. (The background color is white, the tower is black, and the other is the far plane.)
Note 1: I am use ‘-distanceFar/2f’ so that I actually can see the far plane, for testing purposes. This does not affect the size of the frustrum.
Note 2: As I decrease the width of the screen, the far plane comes closer to the screen.
Note 3: I works fine with a square screen…
Thanks,
~Matt
P.S.: For more info, ask me.