SpatialTransformer Repetition

Ok… so i have a box… loverly… now i have learned how to rotate it i want to do it in an animated way, i am planning on using SpatialTransformer for this job however it appears that SpatialTransformer repeats over and over (i want to basically make a single movement each time a specific function is called). I have had a play with the setRepeatType and set it to RT_CLAMP which is pritty much what i wanted, says it moves through it’s various stages of animation and then simply stops. However… and here is where the problem lies… It doesn’t. No matter what i set the RepeatType to it doesn’t appear to make the slightest bit of difference! Any advice helpful…




   public void Rotate(int givenDegree, int time) {
      SpatialTransformer st=new SpatialTransformer(1);
      st.setObject(CompleteDancer,0,-1);
      Quaternion start=new Quaternion();
      start.fromAngleAxis(FastMath.DEG_TO_RAD*currentDegree,new Vector3f(0,1,0));
      currentDegree += givenDegree;
      st.setRotation(0,0,start);
      Quaternion Degree=new Quaternion();
      Degree.fromAngleAxis(FastMath.DEG_TO_RAD*currentDegree,new Vector3f(0,1,0));
      st.setRotation(0,time,Degree);
      st.interpolateMissing();
      st.setRepeatType(SpatialTransformer.RT_CLAMP);
      CompleteDancer.addController(st);
   }



Regards,
Roja

Perhaps this Thread could help you:



http://www.jmonkeyengine.com/jmeforum/viewtopic.php?t=1399

Yeh… I have read that thread a couple of times and to be honest it doesn’t seem to show too many signs of promice, i altered the SpatialTransformer code as you mentioned on your reply to the thread but the only difference it managed to make was to make the class rather unstable



Rotate(90,5)



caused the objects to rotate about 20 degrees (only once)..


Rotate(90,2)



caused the objects to rotate the full 90 degrees but repetidly..

Very spurious results IMHO.. i am going to go through the class with a fine tooth comb and see if i can find a fault. Anyway, help appreciated :)

Regards
Roja

Well… after a bit of testing i am happy with my altered implementation of SpatialTransformer, for those who would like the same functionality (RT_CLAMP) here is the alteration needed:



From SpatialTransformer:




    public void update(float time) {
        if (!isActive()) return;
        curTime += time * getSpeed();
        setBeginAndEnd();
        Arrays.fill(haveChanged, false);
        delta = endPointTime.time - beginPointTime.time;
        if (delta != 0f) delta = (curTime - beginPointTime.time) / delta;
        for (int i = 0; i < numObjects; i++) {
            updatePivot(i);
            pivots[i].applyToSpatial(toChange[i]);
        }
    }



to:



    private float lastCurTime;
   
    public void update(float time) {
        if (!isActive()) return;
        if((lastCurTime > (curTime += time * getSpeed()))&& this.getRepeatType() == RT_CLAMP) {
           setActive(false);
           curTime = endPointTime.time;
        }
        lastCurTime = curTime;
        setBeginAndEnd();
        Arrays.fill(haveChanged, false);
        delta = endPointTime.time - beginPointTime.time;
        if (delta != 0f) delta = (curTime - beginPointTime.time) / delta;
        for (int i = 0; i < numObjects; i++) {
            updatePivot(i);
            pivots[i].applyToSpatial(toChange[i]);
        }
    }



i imagine there is 1000 cleaner ways of implementing this but i don't have much time so this dirty but working solution suits me :) the additional variable stores the last value of the current time (again i think it would be posserble to implement without the need for an additional variable).

Anyway.. on with the slog,

Roja

Small improvement/fix/update… delete as applicable:




    public void update(float time) {
        if (!isActive()) return;
        if(((lastCurTime > (curTime += time * getSpeed())) || (curTime > ((PointInTime)keyframes.get(keyframes.size()-1)).time)) && this.getRepeatType() == RT_CLAMP) {
           setActive(false);
           curTime = ((PointInTime)keyframes.get(keyframes.size()-1)).time;
        }
        lastCurTime = curTime;
        setBeginAndEnd();
        Arrays.fill(haveChanged, false);
        delta = endPointTime.time - beginPointTime.time;
        if (delta != 0f) delta = (curTime - beginPointTime.time) / delta;
        for (int i = 0; i < numObjects; i++) {
            updatePivot(i);
            pivots[i].applyToSpatial(toChange[i]);
        }
    }



Roja