Hello all. I have a been working on a collision detection algo and I think I've got something wrong. I have been going off of the tutorial from j3d.org with some modifications.
Here is the code for detecting if a collision happened.
curTrans is the current position of the object.
nextTrans is the position we are checking for a collision with. Meaning, if we move the object to this position, will there be a collision.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public void detect(Transform3D curTrans, Transform3D nextTrans){ curTrans.get(locationVector); nextTrans.get(collisionVector); locationPoint.set(locationVector); locationEndPoint.set(collisionVector); cylinderPicker.set(locationPoint, locationEndPoint,0.01);
SceneGraphPath[] closest = collidables.pickAllSorted(cylinderPicker);
if((closest == null) || (closest.length == 0)){ } length = (float)collisionVector.length();
for(int i = 0; (i < closest.length); i++){ Transform3D local_tx = closest[i].getTransform(); Shape3D i_shape = (Shape3D)closest[i].getObject(); PickResult pr = new PickResult(i_shape,local_tx,cylinderPicker); PickIntersection pis = pr.getClosestIntersection(locationPoint); if(pis != null){ } } } |
This is the code that calls the function.
We basically need to get the world coordinates, so thats what most of this code does.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| TransformGroup currentTransG; Transform3D nextTrans;
Transform3D t1 = new Transform3D(); currentTransG.getLocalToVworld(t1); Transform3D tempT = new Transform3D(); currentTransG.getTransform(tempT); t1.mul(tempT);
Transform3D t2 = new Transform3D(); currentTransG.getLocalToVworld(t2); currentTransG.mul(nextTrans);
detect(t1,t2); |
Anyone have any suggestions on what I need to fix?
Thanks