Animation using SpatialTransform (Resolved)

Hi,



This is my first post in the forum.  I am trying to use SpatialTransform to translate an object from one place to the next.  However, I would like to be able to see the movement on the screen.  I have looked at the testSpatialTransform, but I am rather lost with the for loop.



private void setTranslation()
    {
        Vector3f transRef = new Vector3f();
        
        float translation;
        
        //iterate over the range, go over by one step to accommodate mathematical error
      for(float timeElp=0;timeElp<(this.time+(this.time/this.timeDivision));timeElp+=(this.time/this.timeDivision))
        {
            translation = (float)((timeElp/this.time)*(Math.PI*2));
            
            //correct for mathematical errors
            if(translation>(Math.PI*2))
                translation=(float)Math.PI*2;

         transRef.x = (float)(translation)*2;
            transRef.y = (float)(translation)*2;
            transRef.z = (float) (translation)*2;
         
                          
/*            transRef.x = (float)Math.sin(translation)*5;
            transRef.y = (float)Math.cos(translation)*2.5f;
            transRef.z = (float)Math.cos(translation)*5;
 */        
       //this.spt.setPosition(0,time,transRef);
            this.spt.setPosition(0,timeElp,transRef);
        }
   
/*   transRef.x = (float) 2;
        transRef.y = (float) 2;
        transRef.z = (float) 2;
      this.spt.setPosition(0,time,transRef);
*/      
      }
   



When I use the following:


        transRef.x = (float) 2;
        transRef.y = (float) 2;
        transRef.z = (float) 2;
   this.spt.setPosition(0,time,transRef);



The box is moved into that position at start up without showing the animation.  I had the following assumptions.

setPosition(int indexInST, float time, Vector3f position)
         Sets object with index indexInST to translate by position at time time.

means the following:
Translate the object 0 to the position in the time indicated.  Or do we have to do it manually?

Thanks.

this for-loop just adds a bunch of different positions.

Time is a keyframe at that time-stamp. So you should do something like

(contr is the SpatialTransformer):



contr.setPosition(0,0,startPos);
contr.setPosition(0,2,secondPos); // be at position secondPos at keyframe at time 2; need 2 secs
contr.setPosition(0,5,lastPos); //  be at position lastPos at Keyframe 5; needs 3 secs from secondPos to lastPos



Once you have set you positions (you can add rotations as well) you have to calculate the movement between the keyframes:

contr.interpolateMissing();



In your case you set every position to (2,2,2) even the start position, so it is clear that
it is at the end-position from the beginning. SpatialTransformer is not doing relative translations,
you have to specify the start-point at the beginning.

EDIT:
Maybe HelloAnimation in pacakge jmetest.TutorialGuide is a better start-point for SpatialTransformer

Thank you for the example!  I have managed to make the box animate to where I want it to be. :D  So, this worked now because the other setPosition() was added and now it can move between them.



I had assumed that since I had given the box an origin at the start, the setPosition() would take that origin and then move it to the position I had placed in setPositon().  I did not realise that I needed another setPosition() statement.