Search in sources :

Example 51 with Camera

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);
}
Also used : Camera(com.jme3.renderer.Camera)

Example 52 with Camera

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);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Example 53 with Camera

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;
        }
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 54 with Camera

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);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule)

Example 55 with Camera

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);
}
Also used : BoundingVolume(com.jme3.bounding.BoundingVolume) Camera(com.jme3.renderer.Camera)

Aggregations

Camera (com.jme3.renderer.Camera)63 Vector3f (com.jme3.math.Vector3f)51 Material (com.jme3.material.Material)26 Geometry (com.jme3.scene.Geometry)26 Quaternion (com.jme3.math.Quaternion)23 Spatial (com.jme3.scene.Spatial)19 TempVars (com.jme3.util.TempVars)16 Box (com.jme3.scene.shape.Box)13 ViewPort (com.jme3.renderer.ViewPort)11 Node (com.jme3.scene.Node)11 DirectionalLight (com.jme3.light.DirectionalLight)10 FrameBuffer (com.jme3.texture.FrameBuffer)10 Texture (com.jme3.texture.Texture)10 FilterPostProcessor (com.jme3.post.FilterPostProcessor)9 Texture2D (com.jme3.texture.Texture2D)9 ArrayList (java.util.ArrayList)9 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)8 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)8 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)8 CameraNode (com.jme3.scene.CameraNode)7