jPCT - a 3d engine for Java => Bugs => Topic started by: pitt on April 19, 2006, 05:35:18 pm

Title: checkCollision
Post by: pitt on April 19, 2006, 05:35:18 pm
Object3D obj=Primitives.getPlane(1,500);
int p1=world.checkCollision(new SimpleVector(0,0,-100),new SimpleVector(0,0,1),200f);
SimpleVector p2=world.checkCollisionSpherical(new SimpleVector(0,0,-100),new SimpleVector(0,0,200),10f);
SimpleVector p3=world.checkCollisionEllipsoid(new SimpleVector(0,0,-100),new SimpleVector(1f,1f,1f),1);


?? Something wrong
Title: checkCollision
Post by: EgonOlsen on April 19, 2006, 06:23:44 pm
No, seems fine to me. At first, your translation quite long. I don't advise to use such long translation for a single check, but anyway...if you want or have to, adjust Config.collideOffset accordingly, for example Config.collideOffset=500;
With this, your first test will return the plane's ID as it should. The ellipsoid collision detection is fine too (albeit your example code is wrong for this, but that's not the point). The remaining "problem" is the spherical one...well, it's not a swept algorithm like the ellipsoid one is. The ellipsoid one detects any collision during the translation where the spherical approach only looks for a collision at the end of the translation. If you "jump behind" the plane (which is what you do in your code), no collision will be detected, because at the end of the translation, there is none. You may have a look in the "manual" to learn more about the different types of collision detection.
For general purpose collisions, i suggest to stick with ellipsoid.
Title: checkCollision
Post by: culli on July 01, 2006, 05:10:35 am
I had this problem too with a small object I am putting together with addTriangle.  I just couldn't get the collision detection to work, so I tried a plane too.  That didn't work either, until I flipped the plane over.

Code: [Select]
Object3D aPlane = Primitives.getPlane(4, 5);
aPlane.rotateAxis(aPlane.getXAxis(), (float)Math.PI/2);
SimpleVector cameraPosition;
cameraPosition = aPlane.getCenter();
cameraPosition.y = cameraPosition.y - 40;
cameraPosition.z = cameraPosition.z - 65;
SimpleVector testMove = someObject.getTransformedCenter();
SimpleVector dir = new SimpleVector(0, -5, 0);
int collisionObject = theWorld.checkCollision(testMove, dir, 10);
Camera camera = theWorld.getCamera();

Results in: collisionObject == Object3D.NO_OBJECT
but if I rotate the plane the opposite way:
Code: [Select]
aPlane.rotateAxis(aPlane.getXAxis(), -(float)Math.PI/2);
it works.  However, the texture does not display, it is on the side of the plane away from the camera.

 :?: Just curious, why does flipping the plane over the other way fix this?  Normals, aabbs, or something else?

Title: checkCollision
Post by: EgonOlsen on July 01, 2006, 11:20:39 am
Collisions aren't detected on backfaces. Your collision seems to happen on the backface of the plane, because your translation vector is (0, -5, 0), which means that you are moving "out of the screen". So i assume that "someObject" it places behind the plane (when viewed from the camera's position). After the first rotation, you are hitting the back of the plane, so there's no collision. After the second rotation, you are hitting the front plane. In short: If the angle between the translation vector and the plane's normal is between +-90 degrees, you are hitting the front plane, i.e. there is a collision. If it's not, you are hitting the back plane, i.e. no collision.