At 21:34 01/01/01 -0600, you wrote:
>   Once a collision has occurred and a behavior  triggered - is there a way
>to get the normal of the face of the object with  which the collision
>occurred?   I read something on www.j3d.org  I tried  this, but have a
>couple questions:   I only want to pick out the object that the object
>collided  with.   I tried printing out the  bounds for the moving object
>and it stayed the same - so do I need to transform  it to another
>coordinate system before passing it into the  PickTool?   Or is there a
>better way?   Thanks, Keith

One of the methods for the Behavior node is getTriggeringPath.  This gives
you a path to the node which has been collided with, so you can get the
object that way.  That's the easy bit!

    SceneGraphPath sg = wEnter.getTriggeringPath();
    Node n = sg.getObject();                             //Object causing
collision

If you need the normal then you have to find out which face has been
collided with.  Once you know the face, then you can get a normal to it,
fairly easy.

Get any three vertices from the face and make these into two vectors (eg A
to B and A to C).  Now calculate their cross product (using cross) and
that's the normal, so with a quad geometry (triangle would use points 0, 1
and 2)

 Vector3d calculateNormal(Point3d[] Pointlist){
   /*
     Create two vectors from point 0 to 1 and point 0 to 3 (ie two edges)
and then
     the cross product is a vector perpendicular to this, ie the normal
   */
   Vector3d v = new Vector3d();
   Vector3d a = new Vector3d();
   Vector3d b = new Vector3d();
   a.x = Pointlist[1].x - Pointlist[0].x;
   a.y = Pointlist[1].y - Pointlist[0].y;
   a.z = Pointlist[1].z - Pointlist[0].z;
   b.x = Pointlist[3].x - Pointlist[0].x;
   b.y = Pointlist[3].y - Pointlist[0].y;
   b.z = Pointlist[3].z - Pointlist[0].z;
   v.cross(a, b);
   v.normalize();                                        // Make it a
sensible size
   return(v);
 }

I can't give you a general way of figuring which face has been collided
with.  I've only used a colliding sphere, which is easy, get the normal at
each face and see if one going through the face also goes through the
sphere centre.  If it does and the separation is less than for any other
similar face, this is the one collided with.  I'd welcome a better approach
from anyone.

Cheers

Microsoft is not the answer.
Microsoft is the question.

Avoid the Gates of Hell.  Use Linux

Tony

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