# SpatialTransform, Question for CEP

Hi Cep.

I would like to animate a rolling dice each time the end user uses Arrow key (the rolling direction depending on the stroke key).

The dice should only rotate PI/2 on the given direction and then stop.

I have several questions in fact:

How to animate the rolling dice ?

How to know that the animation ended ?

I would like to use SpatialTransofrm but it doesn’t leverage setMaxTime() and setRepeatType();

Do you think you could provide those functionalites ?

Do you think it will fullfil my needs ?

SpatialTransformer is for transforms that repeat in a pattern. What you’re looking for (I think) is to apply cumulitive transformations. For something like that, you’ll need to do your own kind of thing.

Hello Cep,

You are right, and this is something i started to do but i still have some trouble.

I can not ( or i do not know how) perform my rotation in the World coordinates. The result is that i cannot perform twice the same transformation getting the some effects (The first time my dice seems to rotate around the XAxis, the second time it seems to rotate around the Z Axis).

I think this is due to the Axis of the Node that have rotated too.

How can i specify that i always want to perform the transformation with the World Axis.

Here is the sample of what i’m doing …

Can you help me ?

``` Quaternion rot= node.getWorldRotation(); Quaternion incr= new Quaternion(); incr.fromAngleAxis(FastMath.DEG_TO_RAD*speed,axis); rot = rot.mult(incr);             node.setLocalRotation(rot); ```

If i execute twice this code with at first time

``` axis = Vector3f(1,0,0); ```

and the second time

``` axis = Vector3f(0,1,0); ```

The dice rotates along the ZAxis the second time

Which seems to be ok BUT this is not the expected behvior ...

How can i make the roation correctly please ?
It seems i have to call something else but set LocalRotation but what ?

Thank you very much for your help because i'm trully stick.

I can’t understand too much here, but I think it could be a perspective problem. In your example, you rortate (0,1,0) and see it rotate around the Z axis. That’s actually right. If you rotate around the Y axis, you end up rotating along the Z axis. If you wanted to rotate along the Y axis, you’ld have to rotate around the Z. With rotations, you have to visualize putting a big stick through the middle of a box. If the stick goes up/down, then when you turn the box it’ll go along the Z even though the stick is going along the Y.

About the repeatType thing, you could insert this after line 123 in SpatialTransformer to get it work correctly.

``` if (this.getRepeatType() == RT_CLAMP && keyframes.size() <= curTime) this.setActive(false); ```

Thank you