# Re: Custom auto rotation

```Hi Ugo,

> First we need a bit of maths background to understand my problem.
>
> I have a 3D display which originally is in the default position. Imagine
> a vector (u,v,w) which is perpendicular to the xy-plane - that is, is
> also parallel to the display's own z-axis. Now, I rotate the display and
> this vector changes (with respect to the original vector, which I'm
> calling (x,y,z)).
>
> The "problem" is that I have a cute little button which says "Auto
> Rotate" and is supposed to auto-rotate the display around a fixed axis
> (the *display's* z axis, in my case).
>
> The code to do this is:
>
> // get the proj. control matrix
> double[] matrix = display.getProjectionControl().getMatrix();
>
> // the rotation matrix
> double[] mult = display.make_matrix(
>    rotX,
>    rotY,
>    rotZ,
>    scale,
>    transX,
>    transY,
>    transZ);
>
> /*
> where everything is zero, except rotZ = 1.0 and scale = 1.0
> This is what rotates the display; when in a loop -> auto rotation:
> */
> display.getProjectionControl()
>    .setMatrix(display.multiply_matrix(mult, matrix));

Try reversing the order of the multiply:

display.getProjectionControl()
.setMatrix(display.multiply_matrix(matrix, mult));

That should move the Z-axis rotation to a different
coordinate system.

If that doesn't solve the problem, please let us know
what it does.

Cheers,
Bill

> The result of this is rotation around the original z-axis and not the
> display's z (called here the w axis).
>
> What I first need to do, is to use the projection matrix to apply a
> transformation from (x,y,z) to (u,v,w)
>
> (Proj.Matrix (3 x 3)) X (0,0,1) = (new rotation vector) = (x',y',z')
>
> and then use x',y' and z' in my mult matrix above. Isn't that right?
>
> if (true){
>
>    Is there a way to do this in VisAD? (I mean, without using JAMA.)
>    Has anyone done that?
>
> }else
>    What am I doing wrong? (I mean, apart from programming gimmicks to
> impress the public, rather than doing all the work pilling up on my desk ;-)
>
• Search the `visad` archives: