The program works fine with this set of shape, but why it doesn't work for
the previous case??? Does any one have a clue? ---white

/*
 * PickAllTest.java
 *
 * Created on July 23, 2002, 10:15 AM
 */

/**
 *
 * @author
 */
import javax.vecmath.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.picking.PickTool;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import java.awt.*;

public class PickAllTest extends javax.swing.JFrame {

    /** Creates new form PickAllTest */
    public PickAllTest() {
        initComponents();
        initGraphics();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        pack();
        java.awt.Dimension screenSize = 
java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setSize(new java.awt.Dimension(640, 480));
        setLocation((screenSize.width-640)/2,(screenSize.height-480)/2);
    }

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }

    private void initGraphics(){
        GraphicsConfiguration config =
            SimpleUniverse.getPreferredConfiguration();

        canvas = new Canvas3D(config);
        u = new SimpleUniverse(canvas);

        imagePanel = new javax.swing.JPanel(new java.awt.BorderLayout());
        getContentPane().add(imagePanel, java.awt.BorderLayout.CENTER);

        imagePanel.add(canvas, java.awt.BorderLayout.CENTER);

        BranchGroup scene = createSceneGraph();


        ViewingPlatform viewingPlatform = u.getViewingPlatform();
        Transform3D t = new Transform3D();
        Point3d cp = new Point3d();
        bounds.getCenter(cp);
        System.out.println("The bounding center is "+cp.x+", "+cp.y+", "+cp.z);

        t.set(new Vector3d(cp.x, cp.y, cp.z + 3.0*bounds.getRadius()));
        (viewingPlatform.getViewPlatformTransform()).setTransform(t);

        u.addBranchGraph(scene);


        imagePanel.updateUI();
    }

    private BranchGroup createSceneGraph(){

        double vertices[] = {1.72312,5.68e-017,1.21023,  1.72558,0.3,1.20129,
          1.7188,0.46365,1.16968,  1.24463,0.496766,1.11588,  1.03678,0.471573,1.06775,
          1.0119,0.22479,1.08473,  1.00554,2.578e-006,1.08912, 
1.41353,5.68e-017,1.18693,
          1.0119,-0.22479,1.08473,  1.037,-0.4716,1.068,  1.245,-0.4968,1.116,
          1.719,-0.4636,1.17,  1.72558,-0.3,1.20129};

        Shape3D part1 = new Shape3D();


        // Counterclockwise order
        int []part1Index = {0, 1, 2, 3, 4, 5, 6, 7};
        int []part2Index = {6, 8, 9, 10, 11, 12, 0, 7};


        int []stripCounts1 = new int[1];
        int []stripCounts2 = new int[1];

        stripCounts1[0] = part1Index.length;

        GeometryInfo gi1 = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
        gi1.setCoordinates(vertices);
        gi1.setCoordinateIndices(part1Index);
        gi1.setStripCounts(stripCounts1);

        IndexedGeometryArray ga1 = gi1.getIndexedGeometryArray();
        //GeometryArray ga1 = gi1.getGeometryArray();


        part1.setGeometry(ga1);

        Appearance myApp1 = new Appearance();
        ColoringAttributes colorAttr1 = new ColoringAttributes(0.5f, 0.4f, 0.0f,
                                              ColoringAttributes.SHADE_GOURAUD);

        myApp1.setColoringAttributes(colorAttr1);
        part1.setAppearance(myApp1);
        PickTool.setCapabilities(part1, PickTool.INTERSECT_FULL);




        Shape3D part2 = new Shape3D();


        // Construct triangleArrays using GeometryInfo Class
        GeometryInfo gi2 = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
        //gi2.setCoordinates(vertices1);
        gi2.setCoordinates(vertices);
        gi2.setCoordinateIndices(part2Index);
        stripCounts2[0] = part2Index.length;
        gi2.setStripCounts(stripCounts2);

        IndexedGeometryArray ga2 = gi2.getIndexedGeometryArray();
        //GeometryArray ga2 = gi2.getGeometryArray();



        part2.setGeometry(ga2);


        Appearance myApp2 = new Appearance();
        ColoringAttributes colorAttr2 = new ColoringAttributes(0.2f, 0.7f, 0.0f,
                                              ColoringAttributes.SHADE_GOURAUD);

        myApp2.setColoringAttributes(colorAttr2);
        part2.setAppearance(myApp2);
        PickTool.setCapabilities(part2, PickTool.INTERSECT_FULL);


        BranchGroup group = new BranchGroup();

        group.addChild(part1);
        group.addChild(part2);

        bounds = new BoundingSphere(group.getBounds());
        WindowPickBehavior pick = new WindowPickBehavior(group, canvas, bounds);
        pick.setEnable(true);
        group.addChild(pick);

        group.compile();

        return group;
    }


    public static void main(String args[]) {
        new PickAllTest().show();
    }


    // Variables declaration - do not modify
    // End of variables declaration

    private BoundingSphere bounds;
    private SimpleUniverse u;
    private Canvas3D canvas;
    private javax.swing.JPanel imagePanel;
}

===========================================================================
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".

Reply via email to