Main Menu

checkCollision

Started by pitt, April 19, 2006, 05:35:18 PM

Previous topic - Next topic

pitt

Object3D obj=Primitives.getPlane(1,500);
obj.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
world.addObject(obj);
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);



p1=Object3D.NO_OBJECT
p2=(0,0,200)
p3=(0,0,89)                        


?? Something wrong

EgonOlsen

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.

culli

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.

Object3D aPlane = Primitives.getPlane(4, 5);
aPlane.rotateAxis(aPlane.getXAxis(), (float)Math.PI/2);
aPlane.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
aPlane.setTexture("wood");
aPlane.build();
theWorld.addObject(aPlane);
SimpleVector cameraPosition;
cameraPosition = aPlane.getCenter();
cameraPosition.y = cameraPosition.y - 40;
cameraPosition.z = cameraPosition.z - 65;
camera.setPosition(cameraPosition);
camera.lookAt(aPlane.getCenter());
...
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:
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?

Thanks,
Jim

EgonOlsen

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.