Search in sources :

Example 6 with Cinematic

use of com.jme3.cinematic.Cinematic in project jmonkeyengine by jMonkeyEngine.

the class Cinematic method fitDuration.

/**
     * fits the duration of the cinematic to the duration of all its child
     * cinematic events
     */
public void fitDuration() {
    KeyFrame kf = timeLine.getKeyFrameAtIndex(timeLine.getLastKeyFrameIndex());
    float d = 0;
    for (int i = 0; i < kf.getCinematicEvents().size(); i++) {
        CinematicEvent ce = kf.getCinematicEvents().get(i);
        float dur = timeLine.getKeyFrameTime(kf) + ce.getDuration() * ce.getSpeed();
        if (d < dur) {
            d = dur;
        }
    }
    initialDuration = d;
}
Also used : AbstractCinematicEvent(com.jme3.cinematic.events.AbstractCinematicEvent) CinematicEvent(com.jme3.cinematic.events.CinematicEvent)

Example 7 with Cinematic

use of com.jme3.cinematic.Cinematic in project jmonkeyengine by jMonkeyEngine.

the class Cinematic method setSpeed.

/**
     * sets the speed of the cinematic. Note that it will set the speed of all
     * events in the cinematic. 1 is normal speed. use 0.5f to make the
     * cinematic twice slower, use 2 to make it twice faster
     *
     * @param speed the speed
     */
@Override
public void setSpeed(float speed) {
    super.setSpeed(speed);
    for (int i = 0; i < cinematicEvents.size(); i++) {
        CinematicEvent ce = cinematicEvents.get(i);
        ce.setSpeed(speed);
    }
}
Also used : AbstractCinematicEvent(com.jme3.cinematic.events.AbstractCinematicEvent) CinematicEvent(com.jme3.cinematic.events.CinematicEvent)

Example 8 with Cinematic

use of com.jme3.cinematic.Cinematic in project jmonkeyengine by jMonkeyEngine.

the class TestCinematic method simpleInitApp.

@Override
public void simpleInitApp() {
    //just some text
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(getAssetManager(), getInputManager(), getAudioRenderer(), getGuiViewPort());
    Nifty nifty;
    nifty = niftyDisplay.getNifty();
    nifty.fromXmlWithoutStartScreen("Interface/Nifty/CinematicTest.xml");
    getGuiViewPort().addProcessor(niftyDisplay);
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    final BitmapText text = new BitmapText(guiFont, false);
    text.setSize(guiFont.getCharSet().getRenderedSize());
    text.setText("Press enter to play/pause cinematic");
    text.setLocalTranslation((cam.getWidth() - text.getLineWidth()) / 2, cam.getHeight(), 0);
    guiNode.attachChild(text);
    createScene();
    cinematic = new Cinematic(rootNode, 20);
    stateManager.attach(cinematic);
    createCameraMotion();
    //creating spatial animation for the teapot
    AnimationFactory factory = new AnimationFactory(20, "teapotAnim");
    factory.addTimeTranslation(0, new Vector3f(10, 0, 10));
    factory.addTimeTranslation(20, new Vector3f(10, 0, -10));
    factory.addTimeScale(10, new Vector3f(4, 4, 4));
    factory.addTimeScale(20, new Vector3f(1, 1, 1));
    factory.addTimeRotationAngles(20, 0, 4 * FastMath.TWO_PI, 0);
    AnimControl control = new AnimControl();
    control.addAnim(factory.buildAnimation());
    teapot.addControl(control);
    //fade in
    cinematic.addCinematicEvent(0, new FadeEvent(true));
    // cinematic.activateCamera(0, "aroundCam");
    cinematic.addCinematicEvent(0, new AnimationEvent(teapot, "teapotAnim", LoopMode.DontLoop));
    cinematic.addCinematicEvent(0, cameraMotionEvent);
    cinematic.addCinematicEvent(0, new SoundEvent("Sound/Environment/Nature.ogg", LoopMode.Loop));
    cinematic.addCinematicEvent(3f, new SoundEvent("Sound/Effects/kick.wav"));
    cinematic.addCinematicEvent(3, new SubtitleTrack(nifty, "start", 3, "jMonkey engine really kicks A..."));
    cinematic.addCinematicEvent(5.1f, new SoundEvent("Sound/Effects/Beep.ogg", 1));
    cinematic.addCinematicEvent(2, new AnimationEvent(model, "Walk", LoopMode.Loop));
    cinematic.activateCamera(0, "topView");
    //  cinematic.activateCamera(10, "aroundCam");
    //fade out
    cinematic.addCinematicEvent(19, new FadeEvent(false));
    //        cinematic.addCinematicEvent(19, new AbstractCinematicEvent() {
    //
    //            @Override
    //            public void onPlay() {
    //                fade.setDuration(1f / cinematic.getSpeed());
    //                fade.fadeOut();
    //
    //            }
    //
    //            @Override
    //            public void onUpdate(float tpf) {
    //            }
    //
    //            @Override
    //            public void onStop() {
    //            }
    //
    //            @Override
    //            public void onPause() {
    //            }
    //        });
    cinematic.addListener(new CinematicEventListener() {

        public void onPlay(CinematicEvent cinematic) {
            chaseCam.setEnabled(false);
            System.out.println("play");
        }

        public void onPause(CinematicEvent cinematic) {
            System.out.println("pause");
        }

        public void onStop(CinematicEvent cinematic) {
            chaseCam.setEnabled(true);
            fade.setValue(1);
            System.out.println("stop");
        }
    });
    //cinematic.setSpeed(2);
    flyCam.setEnabled(false);
    chaseCam = new ChaseCamera(cam, model, inputManager);
    initInputs();
}
Also used : NiftyJmeDisplay(com.jme3.niftygui.NiftyJmeDisplay) Cinematic(com.jme3.cinematic.Cinematic) ChaseCamera(com.jme3.input.ChaseCamera) Nifty(de.lessvoid.nifty.Nifty) AnimControl(com.jme3.animation.AnimControl) BitmapText(com.jme3.font.BitmapText) AnimationFactory(com.jme3.animation.AnimationFactory) Vector3f(com.jme3.math.Vector3f)

Example 9 with Cinematic

use of com.jme3.cinematic.Cinematic in project jmonkeyengine by jMonkeyEngine.

the class TestJaime method setupCinematic.

public void setupCinematic(final Node jaime) {
    cinematic = new Cinematic(rootNode, 60);
    stateManager.attach(cinematic);
    jaime.move(0, 0, -3);
    AnimationFactory af = new AnimationFactory(0.7f, "JumpForward");
    af.addTimeTranslation(0, new Vector3f(0, 0, -3));
    af.addTimeTranslation(0.35f, new Vector3f(0, 1, -1.5f));
    af.addTimeTranslation(0.7f, new Vector3f(0, 0, 0));
    jaime.getControl(AnimControl.class).addAnim(af.buildAnimation());
    cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle", 3, LoopMode.DontLoop));
    float jumpStart = cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "JumpStart", LoopMode.DontLoop));
    cinematic.addCinematicEvent(jumpStart + 0.2f, new AnimationEvent(jaime, "JumpForward", LoopMode.DontLoop, 1));
    cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "JumpEnd", LoopMode.DontLoop));
    cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Punches", LoopMode.DontLoop));
    cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "SideKick", LoopMode.DontLoop));
    float camStart = cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Taunt", LoopMode.DontLoop));
    cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle", 1, LoopMode.DontLoop));
    cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Wave", LoopMode.DontLoop));
    cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle", LoopMode.DontLoop));
    CameraNode camNode = cinematic.bindCamera("cam", cam);
    camNode.setLocalTranslation(new Vector3f(1.1f, 1.2f, 2.9f));
    camNode.lookAt(new Vector3f(0, 0.5f, 0), Vector3f.UNIT_Y);
    MotionPath path = new MotionPath();
    path.addWayPoint(new Vector3f(1.1f, 1.2f, 2.9f));
    path.addWayPoint(new Vector3f(0f, 1.2f, 3.0f));
    path.addWayPoint(new Vector3f(-1.1f, 1.2f, 2.9f));
    path.enableDebugShape(assetManager, rootNode);
    path.setCurveTension(0.8f);
    MotionEvent camMotion = new MotionEvent(camNode, path, 6);
    camMotion.setDirectionType(MotionEvent.Direction.LookAt);
    camMotion.setLookAt(new Vector3f(0, 0.5f, 0), Vector3f.UNIT_Y);
    cinematic.addCinematicEvent(camStart, camMotion);
    cinematic.activateCamera(0, "cam");
    cinematic.fitDuration();
    cinematic.setSpeed(1.2f);
    cinematic.setLoopMode(LoopMode.Loop);
    cinematic.play();
}
Also used : AnimationEvent(com.jme3.cinematic.events.AnimationEvent) Cinematic(com.jme3.cinematic.Cinematic) AnimationFactory(com.jme3.animation.AnimationFactory) Vector3f(com.jme3.math.Vector3f) CameraNode(com.jme3.scene.CameraNode) MotionPath(com.jme3.cinematic.MotionPath) AnimControl(com.jme3.animation.AnimControl) MotionEvent(com.jme3.cinematic.events.MotionEvent)

Aggregations

AnimControl (com.jme3.animation.AnimControl)3 AbstractCinematicEvent (com.jme3.cinematic.events.AbstractCinematicEvent)3 CinematicEvent (com.jme3.cinematic.events.CinematicEvent)3 AnimationFactory (com.jme3.animation.AnimationFactory)2 Cinematic (com.jme3.cinematic.Cinematic)2 AnimationEvent (com.jme3.cinematic.events.AnimationEvent)2 Vector3f (com.jme3.math.Vector3f)2 CameraNode (com.jme3.scene.CameraNode)2 Animation (com.jme3.animation.Animation)1 AudioNode (com.jme3.audio.AudioNode)1 MotionPath (com.jme3.cinematic.MotionPath)1 MotionEvent (com.jme3.cinematic.events.MotionEvent)1 InputCapsule (com.jme3.export.InputCapsule)1 BitmapText (com.jme3.font.BitmapText)1 ChaseCamera (com.jme3.input.ChaseCamera)1 NiftyJmeDisplay (com.jme3.niftygui.NiftyJmeDisplay)1 Node (com.jme3.scene.Node)1 CameraControl (com.jme3.scene.control.CameraControl)1 Nifty (de.lessvoid.nifty.Nifty)1 Test (org.junit.Test)1