Skip to main content

Rotating multiple objects at once

9 replies [Last post]
edm
Offline
Joined: 2010-09-30

First off thanks for the swift response to my last question. I know it can't be fun constantly answering newb questions.

I am currently building a scene that contains an object, ie a multicoloured cube, in each corner of the screen. These are four separate objects.

I would like to be able to rotate one of these cubes and for all the other cubes to rotate in the same way. Each cube would rotate around its own centre.

So if I rotate one cube from its red face to its yellow face, I'd like all the other cubes to do the same.

I've been going through examples and forums trying to find an answer but haven't been able to find anything quite like what I'm trying to do.

Any help would be greatly appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
m3nelvagor
Offline
Joined: 2010-09-22

Hi edm,

I'm also fairly new to java3D, but it would seem to me that you need to construct a TransformGroup for each cube and add a behavior to each TranformGroup that reacts to the same stimuli.

Could be wrong, but I think that's the way to approach this.

Greetings,

m3

edm
Offline
Joined: 2010-09-30

I agree that that sounds like the logical way of doing it, but I have not been able to accomplish it in practice or find any examples showing something similar.

I can easily make cubes that individually rotate, but can't bind them together in any way.

darwinjob
Offline
Joined: 2004-11-16

>I can easily make cubes that individually rotate, but can't bind them together in any way.

BG
I I I I
TGR1 TGR2 TGR3 TGR4 - these do rotation, apply the same transform to all of them
I I I I
TGT1 TGT2 TGT3 TGT4 - these do translation into the corners, they all are different but constant.

darwinjob
Offline
Joined: 2004-11-16

Damn, all markup is ruined. I hope you got the point - first rotate then translate. And TGR1, TGR2, TGR3, TGR4 can be replaced by just one TG containing the rotation.

edm
Offline
Joined: 2010-09-30

Thanks darwinjob, that put me on the right track and I've got it fixed now.

However if I try to set the start position of the camera then none of the rotations work. I previously had this working when I had all the shapes moving around the same centre point, but now they are rotating around their own centres this has stopped working.

I am using the following code to set the start camera position :

TransformGroup VpTG = u.getViewingPlatform().getViewPlatformTransform();
Transform3D Trfcamera = new Transform3D();
Trfcamera.setTranslation(cameraTrans);
Trfcamera.setRotation(cameraRot);
VpTG.setTransform( Trfcamera );

Any suggestions?

Once again thank you for putting me in the right direction, I really appreciate the help.

darwinjob
Offline
Joined: 2004-11-16

I don't get what stopped working, you don't see the shapes?

edm
Offline
Joined: 2010-09-30

I can see the shapes, but I can't rotate them.

If I do not reposition the camera, then I can rotate the shapes, but the camera is too close to begin with and I have to zoom out.

If I reposition the camera to be further away so I can see the shapes from the correct distance then I can no longer rotate them.

darwinjob
Offline
Joined: 2004-11-16

I was actually wrong :)

A Behavior node is active (can receive stimuli) whenever an active ViewPlatform's activation volume intersects a Behavior object's scheduling region. Only active behaviors can receive stimuli.

So check (increase) that region.
http://download.java.net/media/java3d/javadoc/1.5.2/javax/media/j3d/Beha...

edm
Offline
Joined: 2010-09-30

That's it! Got it all sorted now :)

Thank you very much for all your help.

Hope I've not been too much of a newb.