Pick a Shape on MOUSE_ENTERED event
I am using PickCanvas in my Java3D application and it is correct to pick a shape on MOUSE_PRESSED or MOUSE_CLICKED event in MyBehaviour object. Though MyBehaviour object could receive MOUSE_ENTERED or MOUSE_EXITED event, the PickCanvas could not pick a shape (it always returns a null PickResult).
My scene graph tree:
BG
|-> TG -> S
|-> TG -> S
|-> Behaviour
I appreciate if you could give me some advices. Thanks in advance.
[484 byte] By [
hoa123a] at [2007-10-3 10:55:39]

Can you please elaborate the MOUSE_EXITED event picking logic you have created? It seems illogical to pick on mouse exit. As far as the MOUSE_ENTER event goes, are there any objects to pick at the edge of the canvas? Perhaps you want to pick all objects in view when the mouse enters the canvas?
regards
Hi Messengers,
Thanks for your reply. I understand what you mean.
My problem is to make a highlight shape when mouse enters it and make (back to) a normal shape when mouse exits it. I don't know how to do this case in Java3D, could you please give me some more advices?
Thanks in advance.
Regards, Hoa123.
This example should be useful to you. It highlights a shape by using ColoringAttributes to change its color when it is detected. It works by detecting collisions with another shape.
http://www.java-tips.org/other-api-tips/java3d/collision-detection-with-java3d3.html
regards
class CollisionDetector extends Behavior {
private static final Color3f highlightColor = new Color3f(0.0f, 1.0f, 0.0f);
private static final ColoringAttributes highlight = new ColoringAttributes(
highlightColor, ColoringAttributes.SHADE_GOURAUD);
private boolean inCollision = false;
private Shape3D shape;
private ColoringAttributes shapeColoring;
private Appearance shapeAppearance;
private WakeupOnCollisionEntry wEnter;
private WakeupOnCollisionExit wExit;
public CollisionDetector(Shape3D s) {
shape = s;
shapeAppearance = shape.getAppearance();
shapeColoring = shapeAppearance.getColoringAttributes();
inCollision = false;
}
public void initialize() {
wEnter = new WakeupOnCollisionEntry(shape);
wExit = new WakeupOnCollisionExit(shape);
wakeupOn(wEnter);
}
public void processStimulus(Enumeration criteria) {
inCollision = !inCollision;
if (inCollision) {
shapeAppearance.setColoringAttributes(highlight);
wakeupOn(wExit);
} else {
shapeAppearance.setColoringAttributes(shapeColoring);
wakeupOn(wEnter);
}
}
}
Hi Messengers,
Thanks again very much for your advice.
It is a good example for highlighting a shape in a collision however it is not enough to solve my problem which needs to track if mouse is over a shape or not.
I appreciate if you could give me an example about mouse entering over a shape, mouse leaving a shape and two shapes are not moved so that there aren't any collisions between them.
Regards, Hoa123.
I would suggest that you do a series of PickRay or PickCylinder intersects as you move the mouse, and highlight objects that are closest intersects.
Of course, this may be exactly what you initially tried, which is returning nulls, so this suggestion may be of no help at all. You might try both GEOMETRY and BOUNDS picking, if you haven't already.
Hi Bryanr,
Thanks for your advices.
Your advices sound to resolve my problem. I am now using:
pickCanvas = new PickCanvas(canvas3D, root);
pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO);
pickCanvas.setTolerance(.0f);
I appreciate very much if you could give me an example (may be a link) which is closest to my problem.
Regards, Hoa123.
Hi, Hoa123What version of Java3D are you using, 1.4 or 1.5?I'm using j3d1.4 and have an compile error of "PickCanvas.GEOMETRY_INTERSECT_INFO" for your second statement: pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO);regards
Hi QingxinXu,
I am using j3d1.4 and have no problem at all.
1. Check the package you are using:
com.sun.j3d.utils.picking.PickCanvas
2. See Example how to use it in link:
http://www.java-tips.org/other-api-tips/java3d/intersect-test.html
3. If two above steps couldn't resolve your compile issue, please post your compile error in more details.
Hope this helps.
Regards, Hoa123.
Hi Hoa123,The code does be no problem. The problem is that I imported com.sun.j3d.utils.pickfast.PickCanvas, which collides with com.sun.j3d.utils.picking.PickCanvas. Wondering what's the difference between these two packages?Thanks:)
Hi Hoa123,The codes do be no problem. I found the problem is I have imported com.sun.j3d.utils.pickfast.PickCanvas, which collides with com.sun.j3d.utils.picking.PickCanvas.Thanks :)
The code does be no problem. Well done.Wondering what's the difference between these two packages?Pickfast is the later api. Same functionality with the capacity to grow with future releases.regards
Hi Messenger,Recently, I have wondered what is the different between two packages. Thanks for your information, Messengers.Regards, Hoa123.