Controller.getCurrentTime() - Float

Hi all,

This is related to animation stuff. The KeyFrameController is brilliant, you can set the minimum frame using setMinTime(float x) and maximum frame using setMaxTime(float x). So heres my dilema. How would I know when the time in the contoller has reached the maximum time?



I am currently doing this:



lastTime += time;
if (lastTime > 8.0f && !animationLooping) { // animation has 8 frames
  playerKey.setMinTime(animationMin);
  playerKey.setMaxTime(animationMax);
  armsKey.setMinTime(animationMin);
  armsKey.setMaxTime(animationMax);
  lastTime = 0;
  animationLooping = true;
} else if (lastTime > 8.0f && animationLooping) {
  animationLooping = false;
}



This works just fine, but its a bit on the ugly side. I was hoping do to something like:


if (animating) {
  playerKey.setMinTime(0);
  playerKey.setMaxTime(2);
  if (playerKey.getCurrentTime() > (playerKey.getMaxTime() - playerKey.getMinTime())) {
    animating = false;
  }
}



Its just so I know when the selected animation has come to an end.

If you do understand what I mean, do you have any ideas?

If you have CVS you can add it if you want to KeyframeController. (I won’t be too jealous). If not, I’ll add it when I get home.



Or would you rather be able to add a ‘hook’ class kind of like AWT does with input effects?



Or are you asking that Controller have this function, which would kind of make sense because Controller has setMinTime and setMaxTime.

I meant to the "Controller" class in general. I mean I could do it myself:



public void update(float time) {
  curTime += time;

  if (curTime > (c.getMaxTime() - c.getMinTime())) {
    doSomething();
    curTime = 0;
  }

  doSomethingElse();
}



But I think if this was to go into the controller, it would be better.

I see, I did a quick search of all classes that extend Controller and I found



DeformationJointController (unused with new .ms3d animator)

VertexKeyframeController (unused with KeyframeController)

CurveController (uses a currentTime variable)

FadeInOutController (Doesn’t seem to use a currentTime variable)

KeyframeController (uses a currentTime variable)

JointController (uses a currentTime variable)

Partical Manager (uses a currentTime variable)

Shake (ignores time totally)



Considering Controller’s setup assumes a minTime and maxTime use, and that most classes that extend Controller are using a currentTime variable somehow (code repetition) it doesn’t seem to me like too much of a stretch to have Controller keep track of time. (just one monkey’s opinion)



One comment about your code, on the way I use KeyframeController curTime is literally the “current time” between MinTime and MaxTime, it would be more like

if (curTime> c.getMaxTime()) curTime=c.getMinTime();

aaah, your idea of currentTime would be even better actually. I dotn want to go and mess around with stuff, so il wait for mojo and renanse’s approval to do this. Because they might have other opinions as to why we shouldn’t include it in.

Mojo would have a lot more to say about this idea than I would, but I can speak to the use in the particle system. Basically there are two uses for current time, both related to the idea of particle flow control.



The first is a check on currentTime versus another internal time field to see if 1000 ms have passed (for controlling the flow rate in terms of particles per sec) All I need there is for the current time field to properly increase over time. If the currentTime field were to suddenly reset to a lower number and flowControl was enabled, particles would stop flowing for a length of time (determined by how far back currentTime was set.) Maybe that could be a desired effect in some cases… hmm…



The second is a check to see if time is between a start and end period. Basically this was an after thought to conform to the Controller spec. The thought though was that the start and end times could be used as a timer for special effects. Looking back, I don’t like the idea and have doubts as to it’s use.



So long story short, if controller held a current time field I believe that is fine. As to the exact behavior when start and end times are encountered though, Mojo’s the man to talk to. Particles don’t really need to worry about that aspect at this time.

In an ‘abstract’ view of things, by giving Controller a maxTime and minTime you are saying that controller and “time” are related. So the “current time relative to maxTime and minTime” should be a use of controller.



Also, in the javadoc for Controller it says applications take the “current time” but that’s not really what’s happening (right??). What really happens is applications take the “time between update calls”. The first implies you would get calls like update(1) then a second later update(2) then a second later update(3), while what really happens is update(0) update(1) update(1). I’ll add some javadoc for Controller to reflect what I -think- it’s doing (along with what I -think- it’s functions are suppost to do), and if someone knowledgable with jME could look it over and make sure it’s correct that’ld be good. (no changes to the code, just the doc)