Hello,
I’m trying to use a JSlider to control the rotation of a 3D object, but the object doesn’t move at all.
Can anyone help me with some sample src code ?
Thanks,
Mik
Hello,
I’m trying to use a JSlider to control the rotation of a 3D object, but the object doesn’t move at all.
Can anyone help me with some sample src code ?
Thanks,
Mik
You will have to explicitly wake up the rotation behavior when the JSlider gets a change event. You can do this manually or via the WakeupOnAWTEventCriterion.
See this thread for more info: http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=3D;action=display;num=1086112170
Thanks.
I found a simple solution: I do not set any behaviour to my object and I simply modify its transform in the stateChanged(). It works very well.
initialization:
objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTrans);
in the slider event handling
Transform3D yAxis = new Transform3D();
yAxis.setRotation(new AxisAngle4d(offset/1000d, offset/1000d, offset/1000d, offset/1000d));
objTrans.setTransform(yAxis);
Cheers,
Mik
That’s a good solution if the JSlider is the only place that you will be changing the transform.
If you find in the future that are modifying the transform from several different controls, then you might want to consider consolidating all the changes into one place (like a behavior).
can you please be a bit more precise on that issue?
Are you talking about problems when doing concurrent modifications to scenegraph?
No, I was actually talking about having several different types of controls that can all modify a transform.
For example, in our current game you can use the keyboard, mouse, and navigation buttons to move around the world, and we might add joystick as well. These all feed into one behavior that controls navigation. So none of the controls directly modify the transforms. Instead they all call different methods on the navigation behavior, which integrates them all into one transformation.
Another example is animations that can be initiated by user input, or by network messages, or by timers. Something like that should be controlled by one behavior.
Some people like to bundle absolutely everything into one uber-behavior, but personally I prefer to use separate behaviors for animation, picking, etc, and it has worked well so far. But our game is not as fast-paced as some others, so YRMV