use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class BillboardControl method controlRender.
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
Camera cam = vp.getCamera();
rotateBillboard(cam);
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class CameraControl method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
controlDir = ic.readEnum(CONTROL_DIR_NAME, ControlDirection.class, ControlDirection.SpatialToCamera);
camera = (Camera) ic.readSavable(CAMERA_NAME, null);
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class CameraControl method controlUpdate.
// fields used, when inversing ControlDirection:
@Override
protected void controlUpdate(float tpf) {
if (spatial != null && camera != null) {
switch(controlDir) {
case SpatialToCamera:
camera.setLocation(spatial.getWorldTranslation());
camera.setRotation(spatial.getWorldRotation());
break;
case CameraToSpatial:
// set the localtransform, so that the worldtransform would be equal to the camera's transform.
// Location:
TempVars vars = TempVars.get();
Vector3f vecDiff = vars.vect1.set(camera.getLocation()).subtractLocal(spatial.getWorldTranslation());
spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation()));
// Rotation:
Quaternion worldDiff = vars.quat1.set(camera.getRotation()).subtractLocal(spatial.getWorldRotation());
spatial.setLocalRotation(worldDiff.addLocal(spatial.getLocalRotation()));
vars.release();
break;
}
}
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class CameraControl method write.
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(controlDir, CONTROL_DIR_NAME, ControlDirection.SpatialToCamera);
oc.write(camera, CAMERA_NAME, null);
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class LodControl method controlRender.
protected void controlRender(RenderManager rm, ViewPort vp) {
BoundingVolume bv = spatial.getWorldBound();
Camera cam = vp.getCamera();
float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop());
float ratio = (FastMath.PI / (8f * atanNH));
float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio;
int level;
if (Math.abs(newDistance - lastDistance) <= distTolerance) {
// we haven't moved relative to the model, send the old measurement back.
level = lastLevel;
} else if (lastDistance > newDistance && lastLevel == 0) {
// we're already at the lowest setting and we just got closer to the model, no need to keep trying.
level = lastLevel;
} else if (lastDistance < newDistance && lastLevel == numLevels - 1) {
// we're already at the highest setting and we just got further from the model, no need to keep trying.
level = lastLevel;
} else {
lastDistance = newDistance;
// estimate area of polygon via bounding volume
float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth());
float trisToDraw = area * trisPerPixel;
level = numLevels - 1;
for (int i = numLevels; --i >= 0; ) {
if (trisToDraw - numTris[i] < 0) {
break;
}
level = i;
}
lastLevel = level;
}
spatial.setLodLevel(level);
}
Aggregations