Hi Ashish,

     I found out your problem. When you pick the object with

SceneGraphPath  closest = obj.pickClosest(0, 0), you are casting a ray
in the point (0,0) in window space. In your geometry that ray wont  intersect
with any geometry at all.

 What you need to do is  get the co-ordinates in window space of the mouse event
and cast a ray in that direction in the window. I have tried to modify your
processStimulus()
method for including this. Here is it,

I have tested this code, it works except for throwing an ArrayIndexOutofBounds
exception
when you first click the window.

Hope I am helpful.

Regards,

Anand

Anand Pillai
DELMIA Solutions India.
680, 8th Main,  JP NAGAR II Phase,
Bangalore 560 078.
Tel: +91-80- 658 9858/59   Fax: +91-80- 658 9855.
[EMAIL PROTECTED]




 WakeupOnAWTEvent trigger = new WakeupOnAWTEvent(MouseEvent.MOUSE_CLICKED);

 public void processStimulus (Enumeration criteria)
        {
         this.wakeupOn(trigger);

                Point3d cg[]=new Point3d[10];
                 PickShape shape=null;
                 PickObject obj = new PickObject(canvas,scene);

         if ( obj != null )
         {
          AWTEvent myEvent[] = trigger.getAWTEvent();
          MouseEvent event1=null;

           event1 = (MouseEvent) myEvent[0];

          int xpos = 0;
          int ypos = 0;

          if ( event1 != null )
          {
              xpos = event1.getX();
              ypos = event1.getY();

                                      // For debugging purposes
              System.out.println(xpos + " " + ypos);
          }


          SceneGraphPath closest = obj.pickClosest(xpos, ypos);

          if ( closest != null )
          {
              Shape3D myShape=null;

                                       // get the first node in the path

              Node node = closest.getNode(1);
              int nodeCount = closest.nodeCount();
              System.out.println(nodeCount);

                                  // Identify your object
              if ( node instanceof Box)
              {
               System.out.println("Touched a box!");
              }

              if ( node instance of Cylinder)
                                     {{

System.out.println("Touched a cylinder");
                                      }

              if ( myShape != null )
              {
               cg[count++] = (Point3d)myShape.getUserData();
               LineArray la=new LineArray(count+1,LineArray.COORDINATES);
              }
          }
          else
          {
              System.out.println("scenegraph path is null...");
          }
         }







Ashish Aggarwal <[EMAIL PROTECTED]> on 06/25/2001 10:50:02 PM

Please respond to Discussion list for Java 3D API <[EMAIL PROTECTED]>

To:   [EMAIL PROTECTED]
cc:    (bcc: Anand PILLAI/dassault-systemes)
Subject:  [JAVA3D]



Hello Anand!

Thanks very much for your help. I really appreciate it
and because of this, I went a long way in the program.
But one problem is coming, once objects are on the
screen and you click with the mouse to draw line
between them, null pointer exception is thrown. I
tried to use PickCanvas also in place of PickObject,
which is now deprecated. But the problem is that
PickResult object is null. I don't know, what is
happening.


Thanks very much for your help.

regards

Ashish


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

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

Reply via email to