@Test public void testBoxSphereCameraPack() { MockPSSMCamera camera = new MockPSSMCamera(); camera.setLocation(0, 0, -10); camera.setFrustumPerspective(50, 1, 1, 100); final BoundingBox boundingBox = new BoundingBox(); boundingBox.setCenter(new Vector3(0, 0, 10)); boundingBox.setXExtent(2); boundingBox.setYExtent(2); boundingBox.setZExtent(2); camera.pack(boundingBox); final double boxNear1 = camera.getFrustumNear(); final double boxFar1 = camera.getFrustumFar(); Assert.assertEquals(new Vector3(2, 2, 2), camera.getExtents()); camera = new MockPSSMCamera(); camera.setLocation(0, 0, -10); camera.setFrustumPerspective(50, 1, 1, 100); final BoundingSphere boundingSphere = new BoundingSphere(); boundingSphere.setCenter(new Vector3(0, 0, 10)); boundingSphere.setRadius(2); camera.pack(boundingSphere); final double boxNear2 = camera.getFrustumNear(); final double boxFar2 = camera.getFrustumFar(); Assert.assertEquals(new Vector3(2, 2, 2), camera.getExtents()); Assert.assertEquals(boxNear1, boxNear2); Assert.assertEquals(boxFar1, boxFar2); }
public void pack(final BoundingVolume sceneBounds) { final ReadOnlyVector3 center = sceneBounds.getCenter(); for (int i = 0; i < _corners.length; i++) { _corners[i].set(center); } if (sceneBounds instanceof BoundingBox) { final BoundingBox bbox = (BoundingBox) sceneBounds; bbox.getExtent(_extents); } else if (sceneBounds instanceof BoundingSphere) { final BoundingSphere bsphere = (BoundingSphere) sceneBounds; _extents.set(bsphere.getRadius(), bsphere.getRadius(), bsphere.getRadius()); } _corners[0].addLocal(_extents.getX(), _extents.getY(), _extents.getZ()); _corners[1].addLocal(_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[2].addLocal(_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[3].addLocal(_extents.getX(), -_extents.getY(), -_extents.getZ()); _corners[4].addLocal(-_extents.getX(), _extents.getY(), _extents.getZ()); _corners[5].addLocal(-_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[6].addLocal(-_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[7].addLocal(-_extents.getX(), -_extents.getY(), -_extents.getZ()); final ReadOnlyMatrix4 mvMatrix = getModelViewMatrix(); double optimalCameraNear = Double.MAX_VALUE; double optimalCameraFar = -Double.MAX_VALUE; final Vector4 position = Vector4.fetchTempInstance(); for (int i = 0; i < _corners.length; i++) { position.set(_corners[i].getX(), _corners[i].getY(), _corners[i].getZ(), 1); mvMatrix.applyPre(position, position); optimalCameraNear = Math.min(-position.getZ(), optimalCameraNear); optimalCameraFar = Math.max(-position.getZ(), optimalCameraFar); } Vector4.releaseTempInstance(position); optimalCameraNear = Math.min(Math.max(getFrustumNear(), optimalCameraNear), getFrustumFar()); optimalCameraFar = Math.max(optimalCameraNear, Math.min(_maxFarPlaneDistance, optimalCameraFar)); final double change = optimalCameraNear / _frustumNear; setFrustumLeft(getFrustumLeft() * change); setFrustumRight(getFrustumRight() * change); setFrustumTop(getFrustumTop() * change); setFrustumBottom(getFrustumBottom() * change); setFrustumNear(optimalCameraNear); setFrustumFar(optimalCameraFar); }
PSSMCamera extends Camera { public void pack(final BoundingVolume sceneBounds) { final ReadOnlyVector3 center = sceneBounds.getCenter(); for (int i = 0; i < _corners.length; i++) { _corners[i].set(center); } if (sceneBounds instanceof BoundingBox) { final BoundingBox bbox = (BoundingBox) sceneBounds; bbox.getExtent(_extents); } else if (sceneBounds instanceof BoundingSphere) { final BoundingSphere bsphere = (BoundingSphere) sceneBounds; _extents.set(bsphere.getRadius(), bsphere.getRadius(), bsphere.getRadius()); } _corners[0].addLocal(_extents.getX(), _extents.getY(), _extents.getZ()); _corners[1].addLocal(_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[2].addLocal(_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[3].addLocal(_extents.getX(), -_extents.getY(), -_extents.getZ()); _corners[4].addLocal(-_extents.getX(), _extents.getY(), _extents.getZ()); _corners[5].addLocal(-_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[6].addLocal(-_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[7].addLocal(-_extents.getX(), -_extents.getY(), -_extents.getZ()); final ReadOnlyMatrix4 mvMatrix = getModelViewMatrix(); double optimalCameraNear = Double.MAX_VALUE; double optimalCameraFar = -Double.MAX_VALUE; final Vector4 position = Vector4.fetchTempInstance(); for (int i = 0; i < _corners.length; i++) { position.set(_corners[i].getX(), _corners[i].getY(), _corners[i].getZ(), 1); mvMatrix.applyPre(position, position); optimalCameraNear = Math.min(-position.getZ(), optimalCameraNear); optimalCameraFar = Math.max(-position.getZ(), optimalCameraFar); } Vector4.releaseTempInstance(position); optimalCameraNear = Math.min(Math.max(getFrustumNear(), optimalCameraNear), getFrustumFar()); optimalCameraFar = Math.max(optimalCameraNear, Math.min(_maxFarPlaneDistance, optimalCameraFar)); final double change = optimalCameraNear / _frustumNear; setFrustumLeft(getFrustumLeft() * change); setFrustumRight(getFrustumRight() * change); setFrustumTop(getFrustumTop() * change); setFrustumBottom(getFrustumBottom() * change); setFrustumNear(optimalCameraNear); setFrustumFar(optimalCameraFar); } }
PSSMCamera extends Camera { public void pack(final BoundingVolume sceneBounds) { final ReadOnlyVector3 center = sceneBounds.getCenter(); for (int i = 0; i < _corners.length; i++) { _corners[i].set(center); } if (sceneBounds instanceof BoundingBox) { final BoundingBox bbox = (BoundingBox) sceneBounds; bbox.getExtent(_extents); } else if (sceneBounds instanceof BoundingSphere) { final BoundingSphere bsphere = (BoundingSphere) sceneBounds; _extents.set(bsphere.getRadius(), bsphere.getRadius(), bsphere.getRadius()); } _corners[0].addLocal(_extents.getX(), _extents.getY(), _extents.getZ()); _corners[1].addLocal(_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[2].addLocal(_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[3].addLocal(_extents.getX(), -_extents.getY(), -_extents.getZ()); _corners[4].addLocal(-_extents.getX(), _extents.getY(), _extents.getZ()); _corners[5].addLocal(-_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[6].addLocal(-_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[7].addLocal(-_extents.getX(), -_extents.getY(), -_extents.getZ()); final ReadOnlyMatrix4 mvMatrix = getModelViewMatrix(); double optimalCameraNear = Double.MAX_VALUE; double optimalCameraFar = -Double.MAX_VALUE; final Vector4 position = Vector4.fetchTempInstance(); for (int i = 0; i < _corners.length; i++) { position.set(_corners[i].getX(), _corners[i].getY(), _corners[i].getZ(), 1); mvMatrix.applyPre(position, position); optimalCameraNear = Math.min(-position.getZ(), optimalCameraNear); optimalCameraFar = Math.max(-position.getZ(), optimalCameraFar); } Vector4.releaseTempInstance(position); optimalCameraNear = Math.min(Math.max(getFrustumNear(), optimalCameraNear), getFrustumFar()); optimalCameraFar = Math.max(optimalCameraNear, Math.min(_maxFarPlaneDistance, optimalCameraFar)); final double change = optimalCameraNear / _frustumNear; setFrustumLeft(getFrustumLeft() * change); setFrustumRight(getFrustumRight() * change); setFrustumTop(getFrustumTop() * change); setFrustumBottom(getFrustumBottom() * change); setFrustumNear(optimalCameraNear); setFrustumFar(optimalCameraFar); } PSSMCamera();  PSSMCamera(final int width, final int height);  PSSMCamera(final Camera source); }
PSSMCamera extends Camera { public void pack(final BoundingVolume sceneBounds) { final ReadOnlyVector3 center = sceneBounds.getCenter(); for (int i = 0; i < _corners.length; i++) { _corners[i].set(center); } if (sceneBounds instanceof BoundingBox) { final BoundingBox bbox = (BoundingBox) sceneBounds; bbox.getExtent(_extents); } else if (sceneBounds instanceof BoundingSphere) { final BoundingSphere bsphere = (BoundingSphere) sceneBounds; _extents.set(bsphere.getRadius(), bsphere.getRadius(), bsphere.getRadius()); } _corners[0].addLocal(_extents.getX(), _extents.getY(), _extents.getZ()); _corners[1].addLocal(_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[2].addLocal(_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[3].addLocal(_extents.getX(), -_extents.getY(), -_extents.getZ()); _corners[4].addLocal(-_extents.getX(), _extents.getY(), _extents.getZ()); _corners[5].addLocal(-_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[6].addLocal(-_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[7].addLocal(-_extents.getX(), -_extents.getY(), -_extents.getZ()); final ReadOnlyMatrix4 mvMatrix = getModelViewMatrix(); double optimalCameraNear = Double.MAX_VALUE; double optimalCameraFar = -Double.MAX_VALUE; final Vector4 position = Vector4.fetchTempInstance(); for (int i = 0; i < _corners.length; i++) { position.set(_corners[i].getX(), _corners[i].getY(), _corners[i].getZ(), 1); mvMatrix.applyPre(position, position); optimalCameraNear = Math.min(-position.getZ(), optimalCameraNear); optimalCameraFar = Math.max(-position.getZ(), optimalCameraFar); } Vector4.releaseTempInstance(position); optimalCameraNear = Math.min(Math.max(getFrustumNear(), optimalCameraNear), getFrustumFar()); optimalCameraFar = Math.max(optimalCameraNear, Math.min(_maxFarPlaneDistance, optimalCameraFar)); final double change = optimalCameraNear / _frustumNear; setFrustumLeft(getFrustumLeft() * change); setFrustumRight(getFrustumRight() * change); setFrustumTop(getFrustumTop() * change); setFrustumBottom(getFrustumBottom() * change); setFrustumNear(optimalCameraNear); setFrustumFar(optimalCameraFar); } PSSMCamera();  PSSMCamera(final int width, final int height);  PSSMCamera(final Camera source); void calculateSplitDistances(final int splitCount); void pack(final BoundingVolume sceneBounds); void updateMaxCameraFar(); void calculateFrustum(final double fNear, final double fFar); double getLambda(); void setLambda(final double lambda); double[] getSplitDistances(); double getMaxFarPlaneDistance(); void setMaxFarPlaneDistance(final double maxFarPlaneDistance); }
PSSMCamera extends Camera { public void pack(final BoundingVolume sceneBounds) { final ReadOnlyVector3 center = sceneBounds.getCenter(); for (int i = 0; i < _corners.length; i++) { _corners[i].set(center); } if (sceneBounds instanceof BoundingBox) { final BoundingBox bbox = (BoundingBox) sceneBounds; bbox.getExtent(_extents); } else if (sceneBounds instanceof BoundingSphere) { final BoundingSphere bsphere = (BoundingSphere) sceneBounds; _extents.set(bsphere.getRadius(), bsphere.getRadius(), bsphere.getRadius()); } _corners[0].addLocal(_extents.getX(), _extents.getY(), _extents.getZ()); _corners[1].addLocal(_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[2].addLocal(_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[3].addLocal(_extents.getX(), -_extents.getY(), -_extents.getZ()); _corners[4].addLocal(-_extents.getX(), _extents.getY(), _extents.getZ()); _corners[5].addLocal(-_extents.getX(), -_extents.getY(), _extents.getZ()); _corners[6].addLocal(-_extents.getX(), _extents.getY(), -_extents.getZ()); _corners[7].addLocal(-_extents.getX(), -_extents.getY(), -_extents.getZ()); final ReadOnlyMatrix4 mvMatrix = getModelViewMatrix(); double optimalCameraNear = Double.MAX_VALUE; double optimalCameraFar = -Double.MAX_VALUE; final Vector4 position = Vector4.fetchTempInstance(); for (int i = 0; i < _corners.length; i++) { position.set(_corners[i].getX(), _corners[i].getY(), _corners[i].getZ(), 1); mvMatrix.applyPre(position, position); optimalCameraNear = Math.min(-position.getZ(), optimalCameraNear); optimalCameraFar = Math.max(-position.getZ(), optimalCameraFar); } Vector4.releaseTempInstance(position); optimalCameraNear = Math.min(Math.max(getFrustumNear(), optimalCameraNear), getFrustumFar()); optimalCameraFar = Math.max(optimalCameraNear, Math.min(_maxFarPlaneDistance, optimalCameraFar)); final double change = optimalCameraNear / _frustumNear; setFrustumLeft(getFrustumLeft() * change); setFrustumRight(getFrustumRight() * change); setFrustumTop(getFrustumTop() * change); setFrustumBottom(getFrustumBottom() * change); setFrustumNear(optimalCameraNear); setFrustumFar(optimalCameraFar); } PSSMCamera();  PSSMCamera(final int width, final int height);  PSSMCamera(final Camera source); void calculateSplitDistances(final int splitCount); void pack(final BoundingVolume sceneBounds); void updateMaxCameraFar(); void calculateFrustum(final double fNear, final double fFar); double getLambda(); void setLambda(final double lambda); double[] getSplitDistances(); double getMaxFarPlaneDistance(); void setMaxFarPlaneDistance(final double maxFarPlaneDistance);  }