Hi everybody,
I'm a new user of java3D and I have a poor english but I hope you will
understand my problem.
I use class KeyNavigatorBehavior for change my view, and for move some
object. When I start in application, theappletviewer of Kawa doesn't give
me problem. But when I start in applet (with file .html), if my mouse is in
the window when it appears, the keys (arrow) are inactive. My mouse must go
out and in for active arrow and KeyNavigatorBehavior.
But, in the same applet, I use the Rotate, Translate and Zoom mouse
behavior too. But, here, in the both case, mouse behavior work well: my
arrows are inactive, but I can move my object.
What I do wrong?? Why my mouse must go out and in of window for activate
arrow?? Do you have the same bug when you loading my applet??
The attach file give the code I did. Note that I want to use
VirtualUniverse with Locale object, and not SimpleUniverse.
Thank for your help.
Vincent
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.picking.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;
import com.sun.j3d.utils.geometry.Cylinder;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
public class Test002 extends Applet {
private View constructView(Canvas3D myCanvas3D) {
View myView = new View();
myView.addCanvas3D(myCanvas3D);
myView.setPhysicalBody(new PhysicalBody());
myView.setPhysicalEnvironment(new PhysicalEnvironment());
return(myView);
}
private Locale constructViewBranch(View myView, Canvas3D canvas) {
VirtualUniverse myUniverse = new VirtualUniverse();
Locale myLocale = new Locale(myUniverse);
BranchGroup myBranchGroup = new BranchGroup();
TransformGroup myTransformGroup = new TransformGroup();
KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(myTransformGroup);
keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0),
1000));
myBranchGroup.addChild(keyNavBeh);
myTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
myTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
myTransformGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
ViewPlatform myViewPlatform = new ViewPlatform();
myBranchGroup.addChild(myTransformGroup);
myTransformGroup.addChild(myViewPlatform);
BranchGroup object = constructContentBranch(canvas);
myBranchGroup.addChild(object);
myBranchGroup.compile();
myLocale.addBranchGraph(myBranchGroup);
myView.attachViewPlatform(myViewPlatform);
return(myLocale);
}
public BranchGroup constructContentBranch(Canvas3D canvas) {
BranchGroup root = new BranchGroup();
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
Transform3D t3d = new Transform3D();
t3d.setTranslation(new Vector3d(0, 0, -30));
TransformGroup trans = new TransformGroup(t3d);
root.addChild(trans);
TransformGroup spinGroup = new TransformGroup();
spinGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
spinGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
spinGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
trans.addChild(spinGroup);
Shape3D cube = new ColorCube();
spinGroup.addChild(cube);
PickRotateBehavior behavior1 = new PickRotateBehavior(root, canvas,
bounds,
PickObject.USE_BOUNDS);
root.addChild(behavior1);
PickZoomBehavior behavior2 = new PickZoomBehavior(root, canvas, bounds,
PickObject.USE_BOUNDS);
root.addChild(behavior2);
PickTranslateBehavior behavior3 = new PickTranslateBehavior(root, canvas, bounds,
PickObject.USE_BOUNDS);
root.addChild(behavior3);
return root;
}
public Test002() {
setLayout(new BorderLayout());
Canvas3D myCanvas3D = new Canvas3D(null);
add("Center", myCanvas3D);
View myView = constructView(myCanvas3D);
Locale myLocale = constructViewBranch(myView, myCanvas3D);
}
public static void main(String[] args) {
new MainFrame(new Test002(), 700, 700);
}
}
Vincent Lalibert�
�tudiant en G�nie Informatique
Universit� Laval
E-Mail: [EMAIL PROTECTED]
T�l: (418) 687-0885
ICQ: 4392769