I'm trying to rotate a few cylinders on the z-axis 90 degrees and then each on the y-axis at varying degrees. My problem is that using the setRotation function only allows me to pick one angle but apply it to multiple axes. If I add another setRotation, it just changes it and doesn't add to it. What can I do to apply multiple rotations, or even multiple or the same transformations to the same object? Here is a snippet of my code showing what I do.
Cylinder EtoPeg = new Cylinder(1.5f, 130f, Primitive.GENERATE_NORMALS, paint);
tr = new Transform3D();
tr.setTranslation(new Vector3f((-284f) * (1f / 400), (-23f + 0 * 6) * (1f / 400), (26.24375f + (7 * 10.09375f / 8)) * (1f / 400)));
tr.setScale(1f / 400);
tr.setRotation(new AxisAngle4d(0, 0, 1, Math.PI / 2));
tg = new TransformGroup(tr);
spin.addChild(tg);
tg.addChild(EtoPeg);
That’s right, the
setRotation
method resets the rotation aspects of transformation matrix to be a rotation at the angle you specified. To combine rotations, you createTransform3D
objects that represent the different rotations you want, and then callmul
to multiply those rotations together (this modifies theTransform3D
object on which you calledmul
). You probably want to do this withTransform3D
objects that contain only rotations, because the meaning can get tricky if you start multiplying transforms that contain both rotations and translations.