UnixNerd
UnixNerd

Reputation: 343

Programatically rotating a java3d scene (using OrbitBehaviour?)

I have a java3d scene comprised of a 3D CAD drawing and various attached shapes centred on 0,0,0. I'm using OrbitBehaviour to let the user move around it.

I'd like to have buttons that rotate the scene around one axis by a fixed amount (say 10 degrees but obviously in radians). I already have a "home" button that goes back to the initial viewing point using lookAt.

Sounds simple compared to the other work I've done but I just can't get it to work no matter what approach I try.

Am I right in thinking I should ask OrbitBehaviour for its getViewPlatformTransform() and move to 0,0,0 -> rotate it -> move back to original position somehow?

Upvotes: 1

Views: 281

Answers (1)

Dariusz
Dariusz

Reputation: 22241

The easiest way would be to put all the objects in a TransformGroup and apply a rotation matrix to it.

TransformGroup tg = new TransformGroup();
Transform3D transform = new Transform3D();
/// add objects to transform group 
tg.setTransform(transform);

If you want to change the transfrom in runtime, you will also have to add appropriate hints to that transform group.

Upvotes: 2

Related Questions