Title: RE: [JAVA3D] collisions

To check for a collision over terrain, here's a function, where bg is the branchgroup of the terrain, loc is your avatar's (or camera) location, down is Vector3d(0.0,-1.0,0.0).  "py" is the value returned if a intersection is found, and defaults to -1.0 if not found.  DOWN could be replaced by any vector, but down looks down from our location to see where the terrain is. 

This seems fast enough for general use, I've hit 200+ FPS with this being hit every frame against a medium sized terrain mesh.  One thing that could speed it up is if your terrain is in separate mesh blocks (as mine is), and you can check just against the portion of the terrain you're over, rather than the entire terrain branchgroup.

Collisions against your model will be similar, but I'm still working out the details of that myself, and how complicated it gets depends on if you're always going to be standing on terrain, or on part of the model, if you can walk _under_ part of the model, if you can climb up on parts of the model, etc.

PS: I think parts of this function came from a newsgroup post or website, I can't recall--I'm not claiming this to be my code!

Scott
Virtopia 2 3D Project
http://vp2.onebigvillage.com


        private double getBranchGroupIntersection(BranchGroup bg, Point3d loc){
                double py=-1.0;
                PickTool picktool=new PickTool(bg);
                picktool.setShapeRay(loc,DOWN);
                picktool.setMode(PickTool.BOUNDS);
                PickResult pr=picktool.pickClosest();
                if (pr!=null){
                        picktool.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
                        pr=picktool.pickClosest();
                        if (pr!=null){
                                PickIntersection pi=pr.getIntersection(0);
                                Point3d intPt = pi.getPointCoordinatesVW();
                                py=intPt.y;
                                pr=null;
                                return py;
                        }
                }
                return py;
               
        }



-----Original Message-----
From: Mauro Dito [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 15, 2002 2:47 AM
To: [EMAIL PROTECTED]
Subject: [JAVA3D] collisions


i've realized a Shape3D object representing an ancient theatre. Now in the Virtual universe containing it,  i want to use collision detection with this Shape3D and terrain following. Could someone help me with suggestions or sample code?

Thanks,
Mauro

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