I have picking set up, and finds things, but it doesn’t find them where I think it should find them. It’s as if the PickCanvas thinks the camera is somewhere other than where I see it. However it still responds to my changes in angle when I rotate the camera. Initially in my scene I see the objects I’m working with in the center of the view. However I can’t pick anything. If I rotate the camera a whole lot, all of a sudden I can pick one of the objects on like half of the entire screen even though it’s not very thick. This makes me think that the camera view it THINKS it has is very up close on the objects, maybe initially facing away from them.
Here’s the code that creates my scene.
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config);
BranchGroup branchGroup = new BranchGroup();
branchGroup.setCapability(javax.media.j3d.Group.ALLOW_CHILDREN_EXTEND);
root = new TransformGroup();
root.setCapability(javax.media.j3d.Group.ALLOW_CHILDREN_EXTEND);
root.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
root.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
branchGroup.addChild(root);
camera = new org.opensourcephysics.display3d.java3d.Camera(this);
camera.setTransformGroup(root);
universe = new SimpleUniverse(canvas);
universe.getViewingPlatform().setNominalViewingTransform();
universe.getViewer().getView().setLocalEyeLightingEnable(true);
universe.getViewer().getView().setCompatibilityModeEnable(true);
Transform3D t = new Transform3D();
t.perspective(Math.PI/4, getScreenRatio(), .1, maxObjectDistance);
universe.getViewer().getView().setLeftProjection(t);
universe.getViewer().getView().setRightProjection(t);
pickCanvas = new PickCanvas(canvas, branchGroup);
universe.addBranchGraph(branchGroup);
I use this code to pick the target when I want to:
pickCanvas.setShapeLocation(lastMotionEvent.getX(), lastMotionEvent.getY());
PickResult pr = pickCanvas.pickClosest();
where lastMotionEvent is the last MouseEvent that was processed on the screen.
Here is the code that handles the mouse rotation on the screen:
Transform3D currXform = new Transform3D();
Vector3d position = getPerspectivePosition();
currXform.lookAt(
new Point3d(position.x, position.y, position.z),
new Point3d(focusX, focusY, focusZ),
new Vector3d(0, 0, 1)); //so that our coordinate system is in the
//same direction as the simple3d one usually 0, 1, 0 is used
root.setTransform(currXform);
Any ideas on why my PickCanvas isn’t picking from the same perspective as the one shown on my screen? Thanks!
EDIT: Oh I just remembered I had another question. All of this perspective setup is identical to what I’ve done in JOGL. I’m basically trying to create two scenes that are identical in JOGL and Java3D. However even though I’m passing the same perspective matrix and the same camera transformation, I don’t get exactly the same perspective. Maybe this is related to how the PickCanvas sees something different also?
EDIT 2: I found that if I remove the line:
universe.getViewingPlatform().setNominalViewingTransform();
Then my perspective looks as it should, but the picking problem still remains.