use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestReadWrite method loadTerrain.
private void loadTerrain() {
FileInputStream fis = null;
try {
long start = System.currentTimeMillis();
// remove the existing terrain and detach it from the root node.
if (terrain != null) {
Node existingTerrain = (Node) terrain;
existingTerrain.removeFromParent();
existingTerrain.removeControl(TerrainLodControl.class);
existingTerrain.detachAllChildren();
terrain = null;
}
// import the saved terrain, and attach it back to the root node
File f = new File("terrainsave.jme");
fis = new FileInputStream(f);
BinaryImporter imp = BinaryImporter.getInstance();
imp.setAssetManager(assetManager);
terrain = (TerrainQuad) imp.load(new BufferedInputStream(fis));
rootNode.attachChild((Node) terrain);
float duration = (System.currentTimeMillis() - start) / 1000.0f;
System.out.println("Load took " + duration + " seconds");
// now we have to add back the camera to the LOD control
TerrainLodControl lodControl = ((Node) terrain).getControl(TerrainLodControl.class);
if (lodControl != null)
lodControl.setCamera(getCamera());
} catch (IOException ex) {
Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException ex) {
Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class SpotLight method intersectsFrustum.
@Override
public boolean intersectsFrustum(Camera cam, TempVars vars) {
if (spotRange == 0) {
// The algorithm below does not support infinite spot range.
return true;
}
Vector3f farPoint = vars.vect1.set(position).addLocal(vars.vect2.set(direction).multLocal(spotRange));
for (int i = 5; i >= 0; i--) {
//check origin against the plane
Plane plane = cam.getWorldPlane(i);
float dot = plane.pseudoDistance(position);
if (dot < 0) {
// outside, check the far point against the plane
dot = plane.pseudoDistance(farPoint);
if (dot < 0) {
// outside, check the projection of the far point along the normal of the plane to the base disc perimeter of the cone
//computing the radius of the base disc
float farRadius = (spotRange / outerAngleCos) * outerAngleSin;
//computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector
Vector3f perpDirection = vars.vect2.set(direction).crossLocal(plane.getNormal()).normalizeLocal().crossLocal(direction);
//projecting the far point on the base disc perimeter
Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius));
//checking against the plane
dot = plane.pseudoDistance(projectedPoint);
if (dot < 0) {
// Outside, the light can be culled
return false;
}
}
}
}
return true;
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class ChaseCamera method read.
/**
* Read the camera
* @param im
* @throws IOException
*/
public void read(JmeImporter im) throws IOException {
InputCapsule ic = im.getCapsule(this);
maxDistance = ic.readFloat("maxDistance", 40);
minDistance = ic.readFloat("minDistance", 1);
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class ChaseCamera method setSpatial.
/**
* Sets the spacial for the camera control, should only be used internally
* @param spatial
*/
public void setSpatial(Spatial spatial) {
target = spatial;
if (spatial == null) {
return;
}
computePosition();
prevPos = new Vector3f(target.getWorldTranslation());
cam.setLocation(pos);
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class DefaultLightFilter method filterLights.
@Override
public void filterLights(Geometry geometry, LightList filteredLightList) {
TempVars vars = TempVars.get();
try {
LightList worldLights = geometry.getWorldLightList();
for (int i = 0; i < worldLights.size(); i++) {
Light light = worldLights.get(i);
// If this light is not enabled it will be ignored.
if (!light.isEnabled()) {
continue;
}
if (light.frustumCheckNeeded) {
processedLights.add(light);
light.frustumCheckNeeded = false;
light.intersectsFrustum = light.intersectsFrustum(camera, vars);
}
if (!light.intersectsFrustum) {
continue;
}
BoundingVolume bv = geometry.getWorldBound();
if (bv instanceof BoundingBox) {
if (!light.intersectsBox((BoundingBox) bv, vars)) {
continue;
}
} else if (bv instanceof BoundingSphere) {
if (!Float.isInfinite(((BoundingSphere) bv).getRadius())) {
if (!light.intersectsSphere((BoundingSphere) bv, vars)) {
continue;
}
}
}
if (light.getType() == Light.Type.Probe) {
probeBlendStrat.registerProbe((LightProbe) light);
} else {
filteredLightList.add(light);
}
}
probeBlendStrat.populateProbes(geometry, filteredLightList);
} finally {
vars.release();
}
}
Aggregations