[SOLVED] onPause() causes animation order to become messy when animation is speeded up

Hello all,



I am using cinematics and I have onPause() in all my function that is always empty (as it is in most of the examples provided). It works fine whenever I pause the animation at animationSpeed = 1x however using a built in function animation.setSpeed(2) // for example



the pause feature is no longer working fine, as the animation gets messy and strange behaviors occur. What should I add in order to fix this issue and keep things synchronized??

tried to sacrifice a chicken?

very professional

Are you a pro customer paying him? If not I guess you can expect as much professionalism than you show in your attempts.

You had an answer reflecting the quality of the question.

You posted around 30 posts on this forum and almost every time the first answer is “could you post some code?”

Still…you come here with your 31st post saying “I have an error, what is it? could you help?”



I just got tired of saying the same thing over and over so i tried the chicken way…



So, i’m gonna cool down and do it the “professional” way… wait no… it’s not my work!!! I do it on my free time…

Tried to sacrifice a chicken?

I know that posting the code will always help in clarifying the issue but in this case it really doesn’t. The question was simple. onPause in cinematics works perfect until I use



[java]cinematic.setSpeed()[/java]



so the question is what’s related to onPause that might mess the sequence of events in cinematics (especially that you developed it). And I already looked into the source code and couldn’t find it.

“did you try sacrificing a chicken” is not much of an insult compared to “very professional” ^^

That’s not an insult, it’s sarcasm (except if you are a chicken)


@garnaout said:
PS: what do you mean it's not your job? do you guys do so for free?? I don't mind sending donations...

Ho you didn't know that you're serious? Well yeah we do it for free, and we have other jobs...
Anyway we don't want money...we just want you to make an effort and try a little bit to find the issue on your side before asking questions.

@garnaout said:
I know that posting the code will always help in clarifying the issue but in this case it really doesn't. The question was simple. onPause in cinematics works perfect until I use

[java]cinematic.setSpeed()[/java]

so the question is what's related to onPause that might mess the sequence of events in cinematics (especially that you developed it). And I already looked into the source code and couldn't find it.

What does fail? -> onPause. Still you didn't post the code of your onPause....It's very likely that something in your onPause does not support a change in speed...you probably does not account for it ... but it's just guessing and it could be anything so it's a waste of time. I can't be sure without seeing your code -> so post your code!

Also...did you look at setSpeed(float speed) code? That's what you should have done first.

read this http://www.mikeash.com/getting_answers.html
It's not an insult, nor sarcasm it's really to make you understand how much time we'll both spare if you follow those rules.

Ok so, your issue is : When you pause your cinematic and resume it, the cinematic is messy, and this only occur when speed is not 1

right?



What happens when you remove your AccelerationTrack? does it work? replace it with a PositionTrack for example and see if it works.

If it does, then the issue might be in your AccelerationTrack, if it doesn’t, a test case would be appreciated so i could see what’s going on.

I’ll try to test it on my side, but first test it without your AccelerationTrack

I tested w/o the accelerateTrack and it doesn’t work well still when I resume. I do think it’s the function itself (onPause()) and that something needs to be added in it. I’ll wrap up a testCase today.

To be honest, I’ve been trying to get a testCase showing the issue but I can’t show it. I wrote a similar code with:



[java]cinematic.addCinematicEvent(0, new PositionTrack(model, new Vector3f(5, 0, 0), 4));



cinematic.addCinematicEvent(4, new RotationTrack(model, rotation, 1));

cinematic.addCinematicEvent(5, new PositionTrack(model, new Vector3f(-5, 0, 0), 3));

cinematic.addCinematicEvent(8, new RotationTrack(model, rotation2, 1));

cinematic.addCinematicEvent(9, new PositionTrack(model, new Vector3f(-5, 0, 5), 2));

cinematic.addCinematicEvent(11, new PositionTrack(model, new Vector3f(-5, 0, 10), 2));

cinematic.addCinematicEvent(13, new PositionTrack(model, new Vector3f(-5, 0, 20), 2));

cinematic.addCinematicEvent(13, new RotationTrack(model, rotation, 2));[/java]





EDIT:



this is not a valid testCase as I am using an outdated JMP, I am having issues updating the SDK on it but that really narrows the problem that it might be “time” related when PAUSED in the updated SDK

I tried with the TestCinematic and there is no problem.

I cannot run your code because there are missing dependencies, this is not a test case.

I’m interested to know, did you manage to fix the issue? yes you should add active = false to avoid memory leaks but that won’t solve ur problem.



Try simplifying it as much as you can so u can narrow down the issue.

1 Like

yes I simplified it. I took everything down except the PositionTrack (which is moving at constant speed). I took off all the extra features I have trying to narrow down the problem and have a testCase with no luck.



What surprises me is that at cinematic speed of 1X everything runs well, I can pause and resume just fine. It’s when I play around with the speed variables when things get messy. Which leads me to think that there is something I am not taking into account when I update the speed or when I pause. Now I don’t think there’s much you can do for the pause, so it might be when I increase the speed which I do using: cinematic.setSpeed(4);







Also I am reading the animation from a trace file where the time is not constant for example:

[java]

time 0.00

move spatial_1 to (23,45,0);

time 3.45

move spatial_1 to (56, 322);

time 4.66

move spatial_1 to (23, 33,0);

etcccc

[/java]



not sure that would be an issue but thought I’d throw it out there.


I’ll try to test it on my side, but first test it without your AccelerationTrack


@nehon did you have time to test it? I disabled AccelerationTrack and even with a very simple example (presented above) the animation gets messy when paused. It has something to do with time as the time does not pause when cinematics pause.

I wanted to write a testCase but realized that my JMP is not up to date (I think the update caused the problem), and I cannot update it because I am getting an error that the server is down to try again later.

Here’s a testCase, I couldn’t write one before since I was having issues updating my JMP. It’s already set to speed X3 let it play see how it should behave. Then, replay it and pause it in the middle, and resume, it will go out of synch.



[java]package mygame;



import com.jme3.cinematic.Cinematic;

import com.jme3.animation.LoopMode;

import com.jme3.cinematic.events.CinematicEvent;

import com.jme3.cinematic.events.MotionTrack;

import com.jme3.cinematic.MotionPath;

import com.jme3.app.SimpleApplication;

import com.jme3.asset.AssetManager;

import com.jme3.cinematic.events.AbstractCinematicEvent;

import com.jme3.cinematic.PlayState;

import com.jme3.cinematic.events.CinematicEventListener;

import com.jme3.cinematic.events.PositionTrack;

import com.jme3.cinematic.events.RotationTrack;

import com.jme3.input.ChaseCamera;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.post.FilterPostProcessor;

import com.jme3.post.filters.FadeFilter;

import com.jme3.scene.CameraNode;

import com.jme3.scene.Geometry;

import com.jme3.scene.Spatial;

import com.jme3.scene.shape.Box;

import com.jme3.system.JmeSystem;









public class Main extends SimpleApplication {



private Spatial model;

private MotionPath path;

private MotionTrack cameraMotionTrack;

private Cinematic cinematic;

private ChaseCamera chaseCam;

private double counter;



public static void main(String[] args) {

Main app = new Main();

app.start();



}





@Override

public void simpleInitApp() {



createScene();



cinematic = new Cinematic(rootNode, 20);

//cinematic.bindUi(“Interface/Nifty/CinematicTest.xml”);

stateManager.attach(cinematic);



// createCameraMotion()



cinematic.addCinematicEvent(0, new AbstractCinematicEvent() {



@Override

public void onPlay() {

// fade.setValue(0);

// fade.fadeIn();

}



@Override

public void onUpdate(float tpf) {



counter += tpf;

System.out.println("Simulation Timer: "+counter);





}



@Override

public void onStop() {

}



@Override

public void onPause() {

}

});

cinematic.addCinematicEvent(0, new PositionTrack(model, new Vector3f(5, 0, 0), 4));

float[] rotation = {0, 3, 0};

float[] rotation2 = {0, 4.5f, 0};

//cinematic.addCinematicEvent(4, new RotationTrack(model, rotation, 1));

cinematic.addCinematicEvent(5, new PositionTrack(model, new Vector3f(-5, 0, 0), 3));

//cinematic.addCinematicEvent(8, new RotationTrack(model, rotation2, 1));

cinematic.addCinematicEvent(9, new PositionTrack(model, new Vector3f(-5, 0, 5), 2));

cinematic.addCinematicEvent(11, new PositionTrack(model, new Vector3f(-5, 0, 10), 2));

cinematic.addCinematicEvent(13, new PositionTrack(model, new Vector3f(-5, 0, 20), 2));

//cinematic.addCinematicEvent(13, new RotationTrack(model, rotation, 2));





cinematic.addListener(new CinematicEventListener() {



public void onPlay(CinematicEvent cinematic) {

chaseCam.setEnabled(false);

System.out.println(“play”);

System.out.println("Animation Speed: "+cinematic.getSpeed());

System.out.println("Animation State: "+cinematic.getPlayState());

System.out.println("Animation Time: "+cinematic.getTime());

}



public void onPause(CinematicEvent cinematic) {

chaseCam.setEnabled(false);

System.out.println(“pause”);

System.out.println("Animation Speed: "+cinematic.getSpeed());

System.out.println("Animation State: "+cinematic.getPlayState());

System.out.println("Animation Time: "+cinematic.getTime());

}



public void onStop(CinematicEvent cinematic) {

chaseCam.setEnabled(false);

// fade.setValue(1);

System.out.println(“stop”);

}

});



flyCam.setEnabled(false);

chaseCam = new ChaseCamera(cam, model, inputManager);

initInputs();

cinematic.setSpeed(3);



}



private void createCameraMotion() {



CameraNode camNode = cinematic.bindCamera(“topView”, cam);

camNode.setLocalTranslation(new Vector3f(0, 50, 0));

camNode.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y);



CameraNode camNode2 = cinematic.bindCamera(“aroundCam”, cam);

path = new MotionPath();

path.setCycle(true);

path.addWayPoint(new Vector3f(20, 3, 0));

path.addWayPoint(new Vector3f(0, 3, 20));

path.addWayPoint(new Vector3f(-20, 3, 0));

path.addWayPoint(new Vector3f(0, 3, -20));

path.setCurveTension(0.83f);

cameraMotionTrack = new MotionTrack(camNode2, path);

cameraMotionTrack.setLoopMode(LoopMode.Loop);

cameraMotionTrack.setLookAt(model.getWorldTranslation(), Vector3f.UNIT_Y);

cameraMotionTrack.setDirectionType(MotionTrack.Direction.LookAt);



}



private void createScene() {



Box drive_unit = new Box(new Vector3f(0, 0, 0), 1, .25f, .5f); // must take from config xml file (TODO)

model = new Geometry(“Drive #”, drive_unit );



if(assetManager == null)

{

System.out.println(“Asset Manager is null”);

}



AssetManager assetManager = null;

assetManager = JmeSystem.newAssetManager(Thread.currentThread().getContextClassLoader().getResource(“com/jme3/asset/Desktop.cfg”));

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat1.setColor(“Color”, ColorRGBA.Orange);

model.setMaterial(mat1);





model.center();



rootNode.attachChild(model);





Material matSoil = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

matSoil.setBoolean(“UseMaterialColors”, true);

matSoil.setColor(“Ambient”, ColorRGBA.Gray);

matSoil.setColor(“Diffuse”, ColorRGBA.Green);

matSoil.setColor(“Specular”, ColorRGBA.Black);



}



private void initInputs() {

inputManager.addMapping(“togglePause”, new KeyTrigger(keyInput.KEY_RETURN));

ActionListener acl = new ActionListener() {

public void onAction(String name, boolean keyPressed, float tpf) {

if (name.equals(“togglePause”) && keyPressed) {

if (cinematic.getPlayState() == PlayState.Playing) {

cinematic.pause();

} else {

cinematic.play();

}

}



}

};

inputManager.addListener(acl, “togglePause”);

}

}[/java]

2 Likes

Good, thanks i’ll test it tonight

1 Like

OK, there was an issue indeed.

It’s fixed in last SVN.



See? the effort of making a good test case is always awarded.

1 Like

haha Thanks @nehon, lesson learned test case is the way to go

1 Like

@nehon problem solved after the latest SVN update.



thanks again