cascade
Junior Member
Java games rock!


«
Reply #1  Posted
20040422 07:44:04 » 

I am doing something like this for a simulation of a robotic vehicle driving on a heightfield based terrain.
You may use a rayIntersectsTriangle algorithm.
For my simulation I use a complete geometry outside Xith since I just started to work with Xith and have no idea about the collision stuff.
The following algorithm does the computation based on a plane defined by 3 points in 3d space. So its used like plane.rayIntersectsTriangle(beamStart,beamEnd, returnHitPoint); Original is: // From the rayIntersectsTriangle Algorithm of Tomas M?ller & Prosolvia Clarus AB // ========================================= public boolean rayIntersectsTriangle (minimally faster (510%) than v2 (does not create new intersection point) public boolean rayIntersectsTriangle3(point3d _s1, point3d _s2, point3d _rtn) { //System.out.println("RAY TRIANGLE INTERSECTION !");
vector3d dir = new vector3d(_s2,_s1,false); vector3d edge1 = va; vector3d edge2 = vb; vector3d pvec = new vector3d(dir,edge2,false); double det = edge1.dotProduct(pvec); if ( det > EPSILON && det < EPSILON ) { //System.out.println("IS PARALLEL !"); return false; } double inv_det = 1.0 / det; vector3d tvec = new vector3d(_s1,a,false); double u = tvec.dotProduct(pvec) * inv_det; //System.out.println("u="+u);
if (u < 0.0  u > 1.0) { //System.out.println("NO INTERSECTION [1]!"); return false;
}
vector3d qvec = new vector3d(tvec,edge1,false); double v = dir.dotProduct(qvec) * inv_det; //System.out.println("v="+v); if ( v < 0.0  (u+v) > 1.0 ) { // System.out.println("NO INTERSECTION [2] !"); return false; } double t = edge2.dotProduct(qvec)*inv_det; _s1.translate(dir,t,_rtn); //System.out.println("FOUND INTERSECTION ["+t+"] @ "+_rtn.x+" "+_rtn.y+" "+_rtn.z+" !"); return true; } Warning: the code may possibly incomplete due to cut and paste formatting problems.
This algorithm is based on my point,vector,plane classes which I coded without knowledge of javax.vecmath and I had no time yet to port them.
If thats what you are looking for contact me and I'll send (explay) the code.
evilscientist at gmx net
