Hi Jonathan,

Java 3D can do what you want, but it will take a bit more setup when creating
the scene graph.  Lets start by looking at the geometry primitives ColorCube
and Sphere.  These are a subclass of Primitive which is a subclass of Group.
This allows each primitve to be created with a small subgraph.

Now lets look at how collision gets reported.  getTriggeringPath() returns
a SceneGraphPath object.  If we ignore SharedGroup's for the moment, the
minimal SceneGraphPath has a Locale and a Node object.  This will identify
a Node in the scene graph.  Since, in your case, you are doing collision
against Shape3D nodes (the ones in the primitve subgraph), that is what
is getting reported to you in the collision.

In order to identify which Primitive is being collided with, there needs
to be some up front work.  A SceneGraphPath may contain intermediate Nodes
from the Locale to the object itself.  To get collision to include one
of these intermediate nodes in the SceneGraphPath, you need to set the
ENABLE_COLLISION_REPORTING capability bit on the Group node you want
included in the SceneGraphPath.  If this is enough to identify the
node in your code, then your done.  Otherwise, you could use user data
to further identify the node.

So, in summary, to get what you want you will need to do the following
during construction of the scene graph.

    primitive = new Sphere() or ColorCube()
    primitive.setCapability(Node.ENABLE_COLLISION_REPORTING);
    primitive.setUserData("Some Object");  // This is optional

And, when your collision triggers, do the following:

    sceneGraphPath = wakeup.getTriggeringPath();
    primitive = sceneGrapPath.getNode(0);
    userData = primitive.getUserData(); // optional

Whew, this got long.

Hope it helps.

Doug Twilleager
Sun Microsystems


>MIME-Version: 1.0
>Subject: [JAVA3D] Collision detection...
>To: [EMAIL PROTECTED]
>
>Hi everyone,
>
>I'm having a bit of trouble with collision detection.  I have a very simple
>scene that consists of only two objects -- a Sphere and a ColorCube.  I've
>set up a collision detection behavior, attached to the cube (using
>wakeupOnCollisionEntry).  This works....when the two objects come into
>contact the behavior is triggered.
>
>Eventually, my application will contain a number of spheres, so I'd like to
>be able to identify which sphere the ColorCube collided with.  For now, as I
>mentioned above, I have only one sphere.  When the behavior is triggered, I
>use the wakeupOnCollisionEntry method getTriggeringPath() to retrieve the
>path to what I would *assume* is the either the ColorCube or the Sphere
>(since these are the only two objects that exist).  I then call the
>getObject() method of SceneGraphPath to grab and examine the leaf at the end
>of the path.  Here is where my problem occurs:  the leaf at the end of the
>path is a Shape3D object....but it's not the ColorCube or the Sphere.
>
>Does anyone know what might be happening?  I'm just not sure what the
>Shape3D corresponds to?  Is it possible that it's one of the faces of the
>ColorCube?  Or something else?
>
>Also, perhaps my procedure isn't the best way to determine which objects are
>involved in a collision?
>
>Thanks very much.
>
>> Jonathan Kelly
>>
>>
>
>===========================================================================
>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