Search in sources :

Example 36 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class HelloCollision method simpleInitApp.

public void simpleInitApp() {
    /** Set up Physics */
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    // We re-use the flyby camera for rotation, while positioning is handled by physics
    viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
    flyCam.setMoveSpeed(100);
    setUpKeys();
    setUpLight();
    // We load the scene from the zip file and adjust its size.
    assetManager.registerLocator("town.zip", ZipLocator.class);
    sceneModel = assetManager.loadModel("main.scene");
    sceneModel.setLocalScale(2f);
    // We set up collision detection for the scene by creating a
    // compound collision shape and a static RigidBodyControl with mass zero.
    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);
    landscape = new RigidBodyControl(sceneShape, 0);
    sceneModel.addControl(landscape);
    // We set up collision detection for the player by creating
    // a capsule collision shape and a CharacterControl.
    // The CharacterControl offers extra settings for
    // size, stepheight, jumping, falling, and gravity.
    // We also put the player in its starting position.
    CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
    player = new CharacterControl(capsuleShape, 0.05f);
    player.setJumpSpeed(20);
    player.setFallSpeed(30);
    player.setGravity(30);
    player.setPhysicsLocation(new Vector3f(0, 10, 0));
    // We attach the scene and the player to the rootnode and the physics space,
    // to make them appear in the game world.
    rootNode.attachChild(sceneModel);
    bulletAppState.getPhysicsSpace().add(landscape);
    bulletAppState.getPhysicsSpace().add(player);
}
Also used : CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) ColorRGBA(com.jme3.math.ColorRGBA) CharacterControl(com.jme3.bullet.control.CharacterControl) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 37 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class TestChaseCamera method simpleInitApp.

public void simpleInitApp() {
    // Load a teapot model
    teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teaGeom.setMaterial(mat_tea);
    rootNode.attachChild(teaGeom);
    // Load a floor model
    Material mat_ground = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Geometry ground = new Geometry("ground", new Quad(50, 50));
    ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    ground.setLocalTranslation(-25, -1, 25);
    ground.setMaterial(mat_ground);
    rootNode.attachChild(ground);
    // Disable the default first-person cam!
    flyCam.setEnabled(false);
    // Enable a chase cam
    chaseCam = new ChaseCamera(cam, teaGeom, inputManager);
    //Uncomment this to invert the camera's vertical rotation Axis 
    //chaseCam.setInvertVerticalAxis(true);
    //Uncomment this to invert the camera's horizontal rotation Axis
    //chaseCam.setInvertHorizontalAxis(true);
    //Comment this to disable smooth camera motion
    chaseCam.setSmoothMotion(true);
    //Uncomment this to disable trailing of the camera 
    //WARNING, trailing only works with smooth motion enabled. It is true by default.
    //chaseCam.setTrailingEnabled(false);
    //Uncomment this to look 3 world units above the target
    //chaseCam.setLookAtOffset(Vector3f.UNIT_Y.mult(3));
    //Uncomment this to enable rotation when the middle mouse button is pressed (like Blender)
    //WARNING : setting this trigger disable the rotation on right and left mouse button click
    //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    //Uncomment this to set mutiple triggers to enable rotation of the cam
    //Here spade bar and middle mouse button
    //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE));
    //registering inputs for target's movement
    registerInput();
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Quaternion(com.jme3.math.Quaternion) ChaseCamera(com.jme3.input.ChaseCamera) Material(com.jme3.material.Material)

Example 38 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class OSVR method getHMDMatrixProjectionLeftEye.

@Override
public Matrix4f getHMDMatrixProjectionLeftEye(Camera cam) {
    if (eyeLeftInfo == null)
        return cam.getProjectionMatrix();
    if (eyeMatrix[EYE_LEFT] == null) {
        FloatBuffer tfb = FloatBuffer.allocate(16);
        com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.osvrClientGetViewerEyeSurfaceProjectionMatrixf(displayConfig, 0, (byte) EYE_LEFT, 0, cam.getFrustumNear(), cam.getFrustumFar(), (short) 0, tfb);
        eyeMatrix[EYE_LEFT] = new Matrix4f();
        eyeMatrix[EYE_LEFT].set(tfb.get(0), tfb.get(4), tfb.get(8), tfb.get(12), tfb.get(1), tfb.get(5), tfb.get(9), tfb.get(13), tfb.get(2), tfb.get(6), tfb.get(10), tfb.get(14), tfb.get(3), tfb.get(7), tfb.get(11), tfb.get(15));
    }
    return eyeMatrix[EYE_LEFT];
}
Also used : Matrix4f(com.jme3.math.Matrix4f) FloatBuffer(java.nio.FloatBuffer)

Example 39 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class OSVRInput method getFinalObserverPosition.

@Override
public Vector3f getFinalObserverPosition(int index) {
    VRViewManagerOSVR vrvm = (VRViewManagerOSVR) environment.getVRViewManager();
    if (vrvm == null || isInputDeviceTracking(index) == false)
        return null;
    Object obs = environment.getObserver();
    Vector3f pos = getPosition(index);
    if (obs instanceof Camera) {
        ((Camera) obs).getRotation().mult(pos, pos);
        return pos.addLocal(((Camera) obs).getLocation());
    } else {
        ((Spatial) obs).getWorldRotation().mult(pos, pos);
        return pos.addLocal(((Spatial) obs).getWorldTranslation());
    }
}
Also used : VRViewManagerOSVR(com.jme3.util.VRViewManagerOSVR) Vector3f(com.jme3.math.Vector3f) Camera(com.jme3.renderer.Camera)

Example 40 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class OpenVRInput method getFinalObserverPosition.

@Override
public Vector3f getFinalObserverPosition(int index) {
    if (environment != null) {
        VRViewManagerOpenVR vrvm = (VRViewManagerOpenVR) environment.getVRViewManager();
        if (vrvm != null) {
            if (isInputDeviceTracking(index) == false) {
                return null;
            }
            Object obs = environment.getObserver();
            Vector3f pos = getPosition(index);
            if (obs instanceof Camera) {
                ((Camera) obs).getRotation().mult(pos, pos);
                return pos.addLocal(((Camera) obs).getLocation());
            } else {
                ((Spatial) obs).getWorldRotation().mult(pos, pos);
                return pos.addLocal(((Spatial) obs).getWorldTranslation());
            }
        } else {
            throw new IllegalStateException("VR environment has no valid view manager.");
        }
    } else {
        throw new IllegalStateException("VR input is not attached to a VR environment.");
    }
}
Also used : VRViewManagerOpenVR(com.jme3.util.VRViewManagerOpenVR) Vector3f(com.jme3.math.Vector3f) 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