Does camera.frustum.planes
array contain the frustum planes in world coordinate space? Or must I do something more? I tried it but doesn’t seem to work but I suspect it’s because the frustum planes are calculated in local coordinate space of the camera by default? Or not? Not too sure…
I need a basis of using camera.frustum.planes
(if possible), to try and do standard frustum culling in world/local coordinate spaces.
I don’t get it… It seems the plane’s x,y,z property for the frustum is matching global space, but the offset seems to be tied in the reverse direction? I’m guessing here…
TerrainManage.prototype.calculateFrustum = function() {
var fru = this.frustum;
var planes = this.activeCamera.camera.frustum.planes;
var len = planes.length;
var i;
var p;
var camPos = this.activeCamera.getPosition();
for(i=0; i<len; i++) {
p = planes[i];
fru.x = p[0];
fru.y = p[1];
fru.z = p[2];
fru.offset = fru.x*camPos.x + fru.y*camPos.y + fru.z*camPos.z; //p[3];
fru = fru.next;
}
console.log(planes);
this.entity.terrainLOD.frustum = this.frustum;
};
[SOLVED]
Oh yes, i forgot, The offset for far clip plane[4] vs near-clip plane[5] should be adjusted NOT based off dot product of camera’s position to camera plane, but based off teh camera’s position + nearClip forward vector and camera’s position + farClip forward vector respectively. Doh! Common sense …bleh.
Could the devs explain what p[3] consist off?
Anyway, the fixed code is as follows:
TerrainManage.prototype.calculateFrustum = function() {
var fru = this.frustum;
var planes = this.activeCamera.camera.frustum.planes;
var i;
var p;
var camPos = this.activeCamera.getPosition();
var camForward = this.activeCamera.forward;
var farClip = this.activeCamera.camera.farClip;
var nearClip = this.activeCamera.camera.nearClip;
p = planes[5]; // near clip
fru.x = p[0];
fru.y = p[1];
fru.z = p[2];
fru.offset = fru.x * (camPos.x +camForward.x*nearClip) + fru.y * (camPos.y +camForward.y*nearClip) + fru.z * (camPos.z +camForward.z*nearClip);
fru = fru.next;
p = planes[4]; // far clip
fru.x = p[0];
fru.y = p[1];
fru.z = p[2];
fru.offset = fru.x * (camPos.x +camForward.x*farClip) + fru.y * (camPos.y +camForward.y*farClip) + fru.z * (camPos.z +camForward.z*farClip);
fru = fru.next;
for(i=0; i<4; i++) {
p = planes[i];
fru.x = p[0];
fru.y = p[1];
fru.z = p[2];
fru.offset = fru.x*camPos.x + fru.y*camPos.y + fru.z*camPos.z; //p[3];
fru = fru.next;
}
// console.log(planes);
this.entity.terrainLOD.frustum = this.frustum;
};
1 Like