[SOLVED] Understanding Controllers / Should I use Controllers?

You could try looking here:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:cinematics



Translate the items in your trace file into events for the cinematic system and then let it do the work. At least that seems like the easiest approach.

I am not, but thats how the rotation was working because I was re-instantiating the controller and thus calling setSpation automatically and taking the new arguments (horrible approach I know). So now that I am trying to do it the right way by only adding the control once, how would I pass those arguments?



The way I am doing it is by passing the time read so far to the controller which will compare it to the current counter (tpf) and call events accordingly (which really doesn’t seem to be such a bad approach to me)



Yes, i’ll definitely look into it…

garnaout said:
I am not, but thats how the rotation was working because I was re-instantiating the controller and thus calling setSpation automatically and taking the new arguments (horrible approach I know). So now that I am trying to do it the right way by only adding the control once, how would I pass those arguments?


You can put whatever methods you want on your control. So you could have a method on your control called "addMyEventStuff" that takes however many arguments you want. This method could then create an event object and add it to the list inside your control... the one that update() will consult so that it knows which event to run next after the current one finishes.

Then when you read the file:
spatial.getControl( MyControl.class ).addMyEventStuff( all of the arguments of the event );

...though I've said pretty much that exact thing a few times now maybe there is enough context that it makes sense now.

garnaout said:
The way I am doing it is by passing the time read so far to the controller which will compare it to the current counter (tpf) and call events accordingly (which really doesn't seem to be such a bad approach to me)

Yes, i'll definitely look into it..


Yeah, from my reading of the docs, jme.cinematic does everything you want. At the very least, you could look in the code and see how it does it.
passing the LAST time read

i assume you havent learned arrays yet ?
1) rename set methods, to add methods.
2) addMethod stores the variable inside an array in the class.
3) when update is called it traverses the array from 0 until end and processes the data.
4) then it removes everything this array contains.
5) gg, now you have all method calls of the past until current call.

this doesn’t make sense. Why must I create an array if I am already parsing line by line?

Do you want the events to run right when you read them or at some later time?



If you want them to run right when you read them then we are all confused. And how are you keeping them from just all running at once? Are you reading it on a background thread and sleeping or something? Otherwise, all of your updates will happen instantly and there was never any reason to use a control.



The scene is updating many many times a second and your control’s update is called every time.



The common way to do this sort of animation is to read it into a list and then figure out where the spatial needs to be at a particular time based on the list of a events.

So you would read one line at a time from update? And just not read the next line until you needed it?



Even so, I think you are making your job harder.



Load the file. For each line create an Event object of your own design with the data necessary for the event. Add these events a java.util.List (don’t bother with arrays). Each update, see if you are supposed to be running the next event yet and remove it from the list or whatever.



Or just use jme.cinematic and read your file and convert the lines into cinematic events.

your update() sucks,

if you dont use an array/collection only the last data will be played.

Because you just skip your 0 until n-1 update calls (you have 0 commands inside, because booleans inside are false).

yup like u said. Cinematics does it all… Thanks!