This discussion is archived
0 Replies Latest reply: Dec 27, 2010 1:41 PM by 809845 RSS

How can i get objects points?

809845 Newbie
Currently Being Moderated
Hi!

i write a code which can do: load an object and when i click i could draw points where i click before.

i have a problem width it,i think i did the picking incorrectly, because not always there you are swarming where I clicked.

somebody knows it possibly what his problem solution.

i say thank you for the help very much
public class example extends Applet implements ActionListener,MouseListener{
     boolean select = true;
     public example(){
          
          init();
          
     }
     public void init() {
     
          setLayout(new BorderLayout());
          GraphicsConfiguration config = SimpleUniverse
             .getPreferredConfiguration();     

          canvas = new Canvas3D(config);
          canvas.setVisible(true);
          add(canvas, BorderLayout.CENTER);                    
          
          add(fejlec, BorderLayout.NORTH); 
          
          sceneBranchGroup = createSceneBranchGroup();
           
          universe = new SimpleUniverse(canvas);
              universe.getViewingPlatform().setNominalViewingTransform();
            OrbitBehavior orbit = new OrbitBehavior(canvas);
              orbit.setSchedulingBounds(new BoundingSphere());
              universe.getViewingPlatform().setViewPlatformBehavior(orbit);
              universe.addBranchGraph(sceneBranchGroup);
              pickCanvas = new PickCanvas(canvas, sceneBranchGroup); 
              pickCanvas.setMode(PickCanvas.BOUNDS); 
          pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO); 
          canvas.addMouseListener(this); 
           
     }

     ....
     protected BranchGroup createSceneBranchGroup(){

          BranchGroup objRoot = new BranchGroup();
              objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
              objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
              objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
              objRoot.setCapability(BranchGroup.ALLOW_DETACH);
         
              objRoot.setName("Root");
              transformGroup = new TransformGroup();

          transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE );
          transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ );
             transformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
              transformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
              transformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);

             objRoot.addChild(transformGroup);

          BoundingSphere bounds =     new BoundingSphere();
          
          Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
          Color3f directionalColor = new Color3f(1.0f, 1.0f, 0.9f);
          Vector3f direction1 = new Vector3f(-1, -1, -1);
          Vector3f direction2 = new Vector3f(1, 1, 1);
          
          AmbientLight ambientLight = new AmbientLight(ambientColor);
          ambientLight.setInfluencingBounds(bounds);
          
          DirectionalLight directionalLight1 = new DirectionalLight(directionalColor, direction1);
          directionalLight1.setInfluencingBounds(bounds); 
          
          DirectionalLight directionalLight2 = new DirectionalLight(directionalColor, direction2);
          directionalLight2.setInfluencingBounds(bounds);
          

          ObjectFile objFile = new ObjectFile(ObjectFile.RESIZE);
          
          try {            
                                        
                      scene = objFile.load("teapot.obj"); 
          } catch (Exception e) {
                 
                     System.err.println(e+"Load Error");
                     System.exit(1);                 
          }
          TransformGroup tg = new TransformGroup(scale);
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
              tg.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

          objRoot.addChild(ambientLight);
          objRoot.addChild(directionalLight1);
          objRoot.addChild(directionalLight2);
          bg.addChild(tg);

          
          return objRoot;
     }

     ....

     public void mouseClicked(MouseEvent event) {
              pickCanvas.setShapeLocation(event);
             result = pickCanvas.pickClosest();
            if (result == null) {
               System.out.println("Empty Place");
          }else{

               PickIntersection intersection = result.getIntersection(0);

                  Vector3f pointNormal = intersection.getPointNormal();

                  Point3d points = intersection.getPointCoordinates();
               
               if(select){
                    pointNormal.get(normal_0);
                       point0.x = (float)points.getX();
                          point0.y = (float)points.getY();
                          point0.z = (float)points.getZ();
                    select = false;
                    ...
               }else{
                    pointNormal.get(normal_0);
                    point0.x = (float)points.getX();
                          point0.y = (float)points.getY();
                          point0.z = (float)points.getZ();
                    select = true;
                    ...
               }
          ...
          }


     }

     ...

     public static void main (String args[]){     
          
           example content = new example();
           JFrame frame = new JFrame();                    
           frame.add(content);
           frame.setContentPane(content);
           frame.setSize(800,600);
           frame.setVisible(true);
           frame.setLocationRelativeTo(null);
            
     }
}

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points