public override Frustum.VISIBILTY GetVisibility(TerrainNode t, Box3d localBox) { Vector3d2[] deformedBox = new Vector3d2[4]; deformedBox[0] = LocalToDeformed(new Vector3d2(localBox.xmin, localBox.ymin, localBox.zmin)); deformedBox[1] = LocalToDeformed(new Vector3d2(localBox.xmax, localBox.ymin, localBox.zmin)); deformedBox[2] = LocalToDeformed(new Vector3d2(localBox.xmax, localBox.ymax, localBox.zmin)); deformedBox[3] = LocalToDeformed(new Vector3d2(localBox.xmin, localBox.ymax, localBox.zmin)); double a = (localBox.zmax + R) / (localBox.zmin + R); double dx = (localBox.xmax - localBox.xmin) / 2 * a; double dy = (localBox.ymax - localBox.ymin) / 2 * a; double dz = localBox.zmax + R; double f = Math.Sqrt(dx * dx + dy * dy + dz * dz) / (localBox.zmin + R); Vector4d[] deformedFrustumPlanes = t.GetDeformedFrustumPlanes(); Frustum.VISIBILTY v0 = GetVisibility(deformedFrustumPlanes[0], deformedBox, f); if (v0 == Frustum.VISIBILTY.INVISIBLE) { return(Frustum.VISIBILTY.INVISIBLE); } Frustum.VISIBILTY v1 = GetVisibility(deformedFrustumPlanes[1], deformedBox, f); if (v1 == Frustum.VISIBILTY.INVISIBLE) { return(Frustum.VISIBILTY.INVISIBLE); } Frustum.VISIBILTY v2 = GetVisibility(deformedFrustumPlanes[2], deformedBox, f); if (v2 == Frustum.VISIBILTY.INVISIBLE) { return(Frustum.VISIBILTY.INVISIBLE); } Frustum.VISIBILTY v3 = GetVisibility(deformedFrustumPlanes[3], deformedBox, f); if (v3 == Frustum.VISIBILTY.INVISIBLE) { return(Frustum.VISIBILTY.INVISIBLE); } Frustum.VISIBILTY v4 = GetVisibility(deformedFrustumPlanes[4], deformedBox, f); if (v4 == Frustum.VISIBILTY.INVISIBLE) { return(Frustum.VISIBILTY.INVISIBLE); } Vector3d2 c = t.GetDeformedCameraPos(); double lSq = c.SqrMagnitude(); double rm = R + Math.Min(0.0, localBox.zmin); double rM = R + localBox.zmax; double rmSq = rm * rm; double rMSq = rM * rM; Vector4d farPlane = new Vector4d(c.x, c.y, c.z, Math.Sqrt((lSq - rmSq) * (rMSq - rmSq)) - rmSq); Frustum.VISIBILTY v5 = GetVisibility(farPlane, deformedBox, f); if (v5 == Frustum.VISIBILTY.INVISIBLE) { return(Frustum.VISIBILTY.INVISIBLE); } if (v0 == Frustum.VISIBILTY.FULLY && v1 == Frustum.VISIBILTY.FULLY && v2 == Frustum.VISIBILTY.FULLY && v3 == Frustum.VISIBILTY.FULLY && v4 == Frustum.VISIBILTY.FULLY && v5 == Frustum.VISIBILTY.FULLY) { return(Frustum.VISIBILTY.FULLY); } return(Frustum.VISIBILTY.PARTIALLY); }
public override Frustum.VISIBILTY GetVisibility(TerrainNode t, Box3d localBox) { Vector3d2[] deformedBox = new Vector3d2[4]; deformedBox[0] = LocalToDeformed(new Vector3d2(localBox.xmin, localBox.ymin, localBox.zmin)); deformedBox[1] = LocalToDeformed(new Vector3d2(localBox.xmax, localBox.ymin, localBox.zmin)); deformedBox[2] = LocalToDeformed(new Vector3d2(localBox.xmax, localBox.ymax, localBox.zmin)); deformedBox[3] = LocalToDeformed(new Vector3d2(localBox.xmin, localBox.ymax, localBox.zmin)); double a = (localBox.zmax + R) / (localBox.zmin + R); double dx = (localBox.xmax - localBox.xmin) / 2 * a; double dy = (localBox.ymax - localBox.ymin) / 2 * a; double dz = localBox.zmax + R; double f = Math.Sqrt(dx * dx + dy * dy + dz * dz) / (localBox.zmin + R); Vector4d[] deformedFrustumPlanes = t.GetDeformedFrustumPlanes(); Frustum.VISIBILTY v0 = GetVisibility(deformedFrustumPlanes[0], deformedBox, f); if (v0 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Frustum.VISIBILTY v1 = GetVisibility(deformedFrustumPlanes[1], deformedBox, f); if (v1 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Frustum.VISIBILTY v2 = GetVisibility(deformedFrustumPlanes[2], deformedBox, f); if (v2 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Frustum.VISIBILTY v3 = GetVisibility(deformedFrustumPlanes[3], deformedBox, f); if (v3 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Frustum.VISIBILTY v4 = GetVisibility(deformedFrustumPlanes[4], deformedBox, f); if (v4 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Vector3d2 c = t.GetDeformedCameraPos(); double lSq = c.SqrMagnitude(); double rm = R + Math.Min(0.0, localBox.zmin); double rM = R + localBox.zmax; double rmSq = rm * rm; double rMSq = rM * rM; Vector4d farPlane = new Vector4d(c.x, c.y, c.z, Math.Sqrt((lSq - rmSq) * (rMSq - rmSq)) - rmSq); Frustum.VISIBILTY v5 = GetVisibility(farPlane, deformedBox, f); if (v5 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } if (v0 == Frustum.VISIBILTY.FULLY && v1 == Frustum.VISIBILTY.FULLY && v2 == Frustum.VISIBILTY.FULLY && v3 == Frustum.VISIBILTY.FULLY && v4 == Frustum.VISIBILTY.FULLY && v5 == Frustum.VISIBILTY.FULLY) { return Frustum.VISIBILTY.FULLY; } return Frustum.VISIBILTY.PARTIALLY; }