Frustum { public Frustum setToModelviewProjection(Matrix4 projection, Matrix4 modelview, Viewport viewport) { if (projection == null || modelview == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Frustum", "setToModelviewProjection", "missingMatrix")); } if (viewport == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Frustum", "setToModelviewProjection", "missingViewport")); } this.scratchMatrix.transposeMatrix(modelview); double[] m = projection.m; double x, y, z, w; x = m[12] + m[0]; y = m[13] + m[1]; z = m[14] + m[2]; w = m[15] + m[3]; this.left.set(x, y, z, w); this.left.transformByMatrix(this.scratchMatrix); x = m[12] - m[0]; y = m[13] - m[1]; z = m[14] - m[2]; w = m[15] - m[3]; this.right.set(x, y, z, w); this.right.transformByMatrix(this.scratchMatrix); x = m[12] + m[4]; y = m[13] + m[5]; z = m[14] + m[6]; w = m[15] + m[7]; this.bottom.set(x, y, z, w); this.bottom.transformByMatrix(this.scratchMatrix); x = m[12] - m[4]; y = m[13] - m[5]; z = m[14] - m[6]; w = m[15] - m[7]; this.top.set(x, y, z, w); this.top.transformByMatrix(this.scratchMatrix); x = m[12] + m[8]; y = m[13] + m[9]; z = m[14] + m[10]; w = m[15] + m[11]; this.near.set(x, y, z, w); this.near.transformByMatrix(this.scratchMatrix); x = m[12] - m[8]; y = m[13] - m[9]; z = m[14] - m[10]; w = m[15] - m[11]; this.far.set(x, y, z, w); this.far.transformByMatrix(this.scratchMatrix); this.viewport.set(viewport); return this; } Frustum();  Frustum(Plane left, Plane right, Plane bottom, Plane top, Plane near, Plane far, Viewport viewport); Frustum setToUnitFrustum(); Frustum setToModelviewProjection(Matrix4 projection, Matrix4 modelview, Viewport viewport); Frustum setToModelviewProjection(Matrix4 projection, Matrix4 modelview, Viewport viewport, Viewport subViewport); boolean containsPoint(Vec3 point); boolean intersectsSegment(Vec3 pointA, Vec3 pointB); boolean intersectsViewport(Viewport viewport);  }
@Test public void testSetToModelviewProjection() throws Exception { LookAt lookAt = new LookAt().set(34.15, -119.15, 0, WorldWind.ABSOLUTE, 2e4 , 0 , 45 , 0 ); Navigator navigator = new Navigator(); navigator.setAsLookAt(globe, lookAt); Viewport viewport = new Viewport(0, 0, 100, 100); double nearDistance = navigator.getAltitude() * 0.75; double farDistance = globe.horizonDistance(navigator.getAltitude()) + globe.horizonDistance(160000); Matrix4 projection = new Matrix4(); projection.setToPerspectiveProjection(viewport.width, viewport.height, 45d , nearDistance, farDistance); Matrix4 modelview = new Matrix4(); navigator.getAsViewingMatrix(globe, modelview); Frustum frustum = new Frustum(); frustum.setToModelviewProjection(projection, modelview, viewport); Plane bottom = new Plane(0.17635740224291638, 0.9793994030381801, 0.09836094754823524, -2412232.453445458); Plane left = new Plane(-0.12177864151960982, 0.07203573632653165, 0.9899398038070459, 1737116.8972521012); Plane right = new Plane(0.7782605589154529, 0.07203573632653174, -0.6237959242640989, 1737116.8972521003); Plane top = new Plane(0.48012451515292665, -0.8353279303851167, 0.2677829319947119, 5886466.24794966); Plane near = new Plane(0.8577349603804412, 0.1882384504636923, 0.4783900328269719, 4528686.830908618); Plane far = new Plane(-0.8577349603804412, -0.1882384504636923, -0.4783900328269719, -2676528.6881595235); assertEquals("left", left, frustum.left); assertEquals("right", right, frustum.right); assertEquals("bottom", bottom, frustum.bottom); assertEquals("top", top, frustum.top); assertEquals("near", near, frustum.near); assertEquals("far", far, frustum.far); assertEquals("viewport", viewport, frustum.viewport); }
@Test public void testSetToModelviewProjection_SubViewport() throws Exception { LookAt lookAt = new LookAt().set(34.15, -119.15, 0, WorldWind.ABSOLUTE, 2e4 , 0 , 45 , 0 ); Navigator navigator = new Navigator(); navigator.setAsLookAt(globe, lookAt); Viewport viewport = new Viewport(0, 0, 100, 100); Viewport pickViewport = new Viewport(49, 49, 3, 3); double nearDistance = navigator.getAltitude() * 0.75; double farDistance = globe.horizonDistance(navigator.getAltitude()) + globe.horizonDistance(160000); Matrix4 projection = new Matrix4(); projection.setToPerspectiveProjection(viewport.width, viewport.height, 45d , nearDistance, farDistance); Matrix4 modelview = new Matrix4(); navigator.getAsViewingMatrix(globe, modelview); Frustum frustum = new Frustum(); frustum.setToModelviewProjection(projection, modelview, viewport, pickViewport); Plane bottom = new Plane(-0.15728647066358287, 0.9836490211411795, -0.0877243942936819, -4453465.7217097925); Plane left = new Plane(-0.4799755263103557, 0.001559364875310035, 0.8772804925018466, 37603.54528193692); Plane right = new Plane(0.5012403287200531, 0.003118408767628064, -0.8653024953109584, 75199.35019616158); Plane top = new Plane(0.17858448447919384, -0.9788701700756626, 0.09960307243927863, 4565806.392885632); Plane near = new Plane(0.8577349603809148, 0.18823845046641746, 0.4783900328250505, 4528686.830896157); Plane far = new Plane(-0.8577349603804465, -0.1882384504638284, -0.4783900328269087, -2676528.6881588553); assertEquals("left", left, frustum.left); assertEquals("right", right, frustum.right); assertEquals("bottom", bottom, frustum.bottom); assertEquals("top", top, frustum.top); assertEquals("near", near, frustum.near); assertEquals("far", far, frustum.far); assertEquals("viewport", pickViewport, frustum.viewport); }