www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: dl.zerocool on May 30, 2010, 04:32:12 pm

Title: Collision between 2 models.
Post by: dl.zerocool on May 30, 2010, 04:32:12 pm
Hi,

I'm using :
Code: [Select]
cId = checkForCollision(dir, step);where step =2f and dir is a direction SimpleVector from a projectile (he moves along this dir)

My problem is :

I've a projectile :  That I want to move except if there's a collision and in this case I want to do something else.
So basicaly I use checkForCollision each time before moving.
Code: [Select]
if(cId==NO_OJBECT)then I move
else
do something else.

My projectiles are configured like this when I create a project :
Code: [Select]
       addCollisionListener(this);
setCollisionMode(COLLISION_CHECK_SELF);
setCollisionOptimization(COLLISION_DETECTION_OPTIMIZED);

Now the objects I want to collide with have this settings
Code: [Select]
addCollisionListener(this);
setCollisionMode(COLLISION_CHECK_OTHERS);
setCollisionOptimization(COLLISION_DETECTION_OPTIMIZED);

The problem is that even I'm seeing that the 2 objects are colliding cID still equal to NO_OBJECT
so no collision detected.


Am I doing something wrong ?


Title: Re: Collision between 2 models.
Post by: dl.zerocool on May 30, 2010, 05:18:24 pm
Well sometimes it works...

But it's like It have to touch exactly the center of the object. Not the bounding box.

Do I need to do something special ? Add a box around my models or something else ?
Title: Re: Collision between 2 models.
Post by: dl.zerocool on May 30, 2010, 05:53:10 pm
Okay it worked with big models.

Apparently due to imprecision of my movement with sensors it's very difficult to get a target in the ray way.

Is it possible to grow bouding box without having to set it again completly ?

Because I don't know how to calculate it, and something like -> setBoundingBoxScale(float f)
would be awesome.

[edit]
another question is boudingBox calculate with the scale factor ? Here 20f for example.
Loader.load3DS(res.openRawResource(R.raw.bear), 20f)[0];
Title: Re: Collision between 2 models.
Post by: EgonOlsen on May 30, 2010, 09:38:03 pm
The bounding box does scale with scaling but that doesn't really matter, because collisions in jPCT are always ray/sphere/ellipsoid against polygons, not against the bounding box. That means that your ray (cast from the center of the colliding object) has to hit one of the polygons of the other object. Maybe that's not always the case in your application!? You might try to use spherical or ellipsoid collision detection instead, where the colliding object has an actually "size" and isn't a simple ray with no size at all.
Title: Re: Collision between 2 models.
Post by: dl.zerocool on May 31, 2010, 01:16:42 am
I will try with elipsoid, but tomorrow (need some sleep) Thanks for advice.

and probably that's the problem, because at moment I do see the objects going trough each other and only in very few cases collisions occur.

Thank you.
Title: Re: Collision between 2 models.
Post by: dl.zerocool on May 31, 2010, 09:30:03 am
Well I just changed how I do things and reworked my model changed the center to middle of the models and not the feets, apparently it works better.
But perhaps it can be improved.
I'll share results tomorrow ;)
Title: Re: Collision between 2 models.
Post by: smither on September 15, 2010, 04:50:36 pm
I'd run in the same problem, sometimes the collision worked and sometimes didn't. I was using the ellipsoid approach, I decreased the ellipse size and started to work for all the cases.  :D