We are trying detect face of a box. An example is attached.
The example consist of an applet where the scenegraph is only a box.
Clicks on canvas are captured and then we compare the shape3D returned
with the different faces of the box, but wrong identification is done.
Best Grettings.
Kelvin Chung wrote:
> Hi,
>
> Can you please send a test case to us ?
>
> We'll take a look into this.
>
> Thanks.
>
> - Kelvin
>
> ---------
> Java 3D Team
> Sun Microsystems Inc.
>
> >X-Unix-From: [EMAIL PROTECTED] Fri Jun 16 04:16:19 2000
> >X-Accept-Language: es,en
> >MIME-Version: 1.0
> >Content-Transfer-Encoding: 7bit
> >Date: Fri, 16 Jun 2000 13:15:17 +0200
> >From: V�ctor <[EMAIL PROTECTED]>
> >Subject: [JAVA3D] Detecting the Picked Face of a Box ( bug? )
> >To: [EMAIL PROTECTED]
> >
> >Hi all:
> >
> >We are trying to detect the selected face of a box by using PickCanvas
> >and
> >PickResult. But getNode(PickResult.SHAPE3D) return wrong information. It
> >
> >return BACK face when FRONT was expected.
> >
> >Is this a bug?
> >
> >How can we detect selected face box?
> >
> > PRISMAKER TEAM
> >
> >===========================================================================
> >To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> >of the message "signoff JAVA3D-INTEREST". For general help, send email to
> >[EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.PickShape;
import com.sun.j3d.utils.picking.PickResult;
import com.sun.j3d.utils.picking.PickCanvas;
import javax.vecmath.*;
import java.util.Enumeration;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.applet.MainFrame;
import java.applet.*;
import java.awt.event.MouseEvent;
import com.sun.j3d.utils.picking.behaviors.*;
public class Applet1 extends Applet {
BorderLayout borderLayout1 = new BorderLayout();
private SimpleUniverse u;
public Applet1() {
this.setLayout(borderLayout1);
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
c.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
canvas_mouseClicked(e);
}
});
add("Center", c);
u = new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(createSceneGraph(c));
}
public BranchGroup createSceneGraph(Canvas3D canvas){
TransformGroup objScale;
BranchGroup objRoot1;
TransformGroup objr;
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
BranchGroup objRoot = new BranchGroup();
objRoot.setCapability(objRoot.ALLOW_CHILDREN_READ);
objRoot.setCapability(objRoot.ALLOW_CHILDREN_EXTEND);
objRoot.setCapability(objRoot.ALLOW_DETACH);
objRoot.setCapability(objRoot.ENABLE_PICK_REPORTING);
objScale = new TransformGroup();
objScale.setCapability(objScale.ALLOW_CHILDREN_READ);
objScale.setCapability(objScale.ALLOW_CHILDREN_EXTEND);
objScale.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objScale.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objScale.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
Transform3D t3d = new Transform3D();
t3d.setScale(0.2);
objScale.setTransform(t3d);
objRoot.addChild(objScale);
objScale.addChild(new Box(1.4f, 1.4f, 1.4f, new Appearance()));
PickTranslateBehavior p1 = new PickTranslateBehavior(objRoot, canvas, bounds);
objRoot.addChild(p1);
PickRotateBehavior p2 = new PickRotateBehavior(objRoot, canvas, bounds);
objRoot.addChild(p2);
return objRoot;
}
void canvas_mouseClicked(MouseEvent e) {
TransformGroup tg = null;
Shape3D sh = null;
Box box = null;
PickCanvas pickCanvas = new PickCanvas(u.getCanvas(), u.getLocale());
pickCanvas.setShapeLocation(e);
PickResult pr = pickCanvas.pickClosest();
if ((pr != null)&&
((sh = (Shape3D) pr.getNode(PickResult.SHAPE3D)) != null)&&
((box = (Box) pr.getNode(PickResult.PRIMITIVE)) != null)){
String mensaje = "";
if (sh.equals(box.getShape(box.FRONT))) mensaje += "FRONT was clicked";
if (sh.equals(box.getShape(box.BACK))) mensaje += "BACK was clicked";
if (sh.equals(box.getShape(box.BOTTOM))) mensaje += "BOTTOM was clicked";
if (sh.equals(box.getShape(box.LEFT))) mensaje += "LEFT was clicked";
if (sh.equals(box.getShape(box.RIGHT))) mensaje += "RIGHT was clicked";
if (sh.equals(box.getShape(box.TOP))) mensaje += "TOP was clicked";
System.out.println(mensaje);
}
}
public static void main(String[] args) {
new MainFrame(new Applet1(), 300, 256);
}
}