user1883264
user1883264

Reputation: 31

Rotate object in Java 3d

I try to make a rotation to a cube according to the movement of the mouse in Java3D. No matter the rotation of the cube, I want that when I drag my cursor up, the cube rotates in the same direction. And this for all possible movements.

How can I proceed? I guess it must be placed in the camera coordinates...

Here is my function :

public void objectRotate(TransformGroup objectInInteraction, double dh,
        double dp, double dr) {

    Transform3D oldT3D = new Transform3D();
    objectInInteraction.getTransform(oldT3D);       

    Transform3D tx = new Transform3D();
    Transform3D ty = new Transform3D();
    Transform3D tz = new Transform3D();

    Transform3D tc = new Transform3D();
    //camera.getTransform(tc);

    double x = 0, y = 0, z = 0;
    x = Math.PI * dh / 180;
    y = Math.PI * dp / 180;
    z = Math.PI * dr / 180;

    tx.rotX(x);
    tc.mul(tx);

    ty.rotY(y);
    tc.mul(ty);

    tz.rotZ(z);     
    tc.mul(tz);

    oldT3D.mul(tc);


    objectInInteraction.setTransform(oldT3D);
}

dh is a left right movement, dp, up and down

Thanks !

Upvotes: 1

Views: 1594

Answers (1)

pete
pete

Reputation: 21

that works for me...

public void objectRotate(TransformGroup objectInInteraction, double dh,
    double dp, double dr)
{

    // Transform3D oldT3D = new Transform3D();
    // objectInInteraction.getTransform(oldT3D);       

    Transform3D tx = new Transform3D();
    Transform3D ty = new Transform3D();
    Transform3D tz = new Transform3D();

    Transform3D tc = new Transform3D();
    //camera.getTransform(tc);

    double x = 0, y = 0, z = 0;
    x = Math.PI * dh / 180;
    y = Math.PI * dp / 180;
    z = Math.PI * dr / 180;

    tx.rotX(x);
    tc.mul(tx);

    ty.rotY(y);
    tc.mul(ty);

    tz.rotZ(z);     
    tc.mul(tz);

    // oldT3D.mul(tc);

    objectInInteraction.setTransform(tc);
}

;-)

Upvotes: 2

Related Questions