Collision masks once again...

Post Reply
Andy_gt
Posts: 3
Joined: Wed Jan 21, 2015 1:47 pm

Collision masks once again...

Post by Andy_gt »

I've dug through multiple threads on this issue but still nothing has helped me.

I want to implement a roulette wheel, which requires the wheel to rotate and collide with the ball but not with the static base. Especially since I want to make this as simple as possible - i.e. the geometry and collision shapes of the wheel are actually intersecting the base.

But for some reason, even the wheel (never mind the ball - that actually is of no concern) keeps getting stuck in the base, even when its collision mask (and that of the base) is 0.
It only works if I set CollisionFlags.NO_CONTACT_RESPONSE and CollisionObject.DISABLE_DEACTIVATION. But of course that's not helping me once I would like to make the ball work too. ;)
Skuzz
Posts: 11
Joined: Wed Aug 25, 2010 12:57 am

Re: Collision masks once again...

Post by Skuzz »

the geometry and collision shapes of the wheel are actually intersecting the base.
Obvious question, can't you prevent the intersection from happening?

Are you working with a custom 3D mesh?
Wil McV
Posts: 18
Joined: Tue Aug 26, 2014 5:46 am

Re: Collision masks once again...

Post by Wil McV »

The way I like to think of the whole collision masking situation is as follows. Think of the group as what ever group the object belongs to and the mask as a list of groups that object can collide with.

Internally Bullet just does a bitwise & with the mask and group of either object respectively and if the result isn't zero they will collide. You can have objects in multiple groups but in general I would suggest limiting the number of groups an object belongs to to just one to keep it simple since if just one of the groups collides with one in the mask the collision will occur even if the other groups the object belongs to are not supposed to collide.

If I have understood your question correctly you would want to do something like the following

Code: Select all

#define BASE_GROUP    1<<0
#define WHEEL_GROUP   1<<1
#define BALL_GROUP    1<<2

const short ball_group = BALL_GROUP
const short ball_mask  = BASE_GROUP | WHEEL_GROUP | BALL_GROUP  ///< assuming the ball collides with everything

const short wheel_group = WHEEL_GROUP
const short wheel_mask =  BALL_GROUP   ///< assuming we only want to wheel to collide with the ball

dynamics_world->addRigidBody(ball_body,  ball_group,  ball_mask );
dynamics_world->addRigidBody(wheel_body, wheel_group, wheel_mask);
If you want to change these groups while the objects are simulating my understanding is you must remove them from the world and re-add them with the new groups.

Does that answer your question?
Andy_gt
Posts: 3
Joined: Wed Jan 21, 2015 1:47 pm

Re: Collision masks once again...

Post by Andy_gt »

Unfortunately, that's exactly what I already have (except that it seems you forgot to add the base?):

Code: Select all

public class COL_TYPES {
    public static final short BALL = ((short)1);
    public static final short BASE = ((short)2);
    public static final short WHEEL = ((short)4);
}

[...]

	public RigidBody localCreateRigidBody(float mass, Transform startTransform, CollisionShape shape, short colID, short colWith) {
[...]
		dynamicsWorld.addRigidBody(body, colID, colWith);
		return body;
	}

[...]

RigidBody body = super.localCreateRigidBody(0f, tGround, colGround, COL_TYPES.BASE, COL_TYPES.BALL);

body = super.localCreateRigidBody(0f, tWheel, colWheel, COL_TYPES.WHEEL, COL_TYPES.BALL);

bodyBall = super.localCreateRigidBody(mass, tBall, colBall, COL_TYPES.BALL, (short)(COL_TYPES.BASE | COL_TYPES.WHEEL));
Last edited by Andy_gt on Thu Jan 22, 2015 9:29 am, edited 1 time in total.
Andy_gt
Posts: 3
Joined: Wed Jan 21, 2015 1:47 pm

Re: Collision masks once again...

Post by Andy_gt »

Skuzz wrote:
the geometry and collision shapes of the wheel are actually intersecting the base.
Obvious question, can't you prevent the intersection from happening?

Are you working with a custom 3D mesh?
No, I'm not. It's all made out of primitives that jBullet offers.
And why would I invest the time in getting rid of the intersection when it's supposed to work the way it is already?
Before doing that, I'll just set the wheel to be a kinematic object and rotate it manually during the simulation steps instead of assigning it an initial force. Which also works but is of course less elegant/flexible and seems to produce stuttering movement sometimes.
Wil McV
Posts: 18
Joined: Tue Aug 26, 2014 5:46 am

Re: Collision masks once again...

Post by Wil McV »

I haven't used JBullet before so i'm not 100% sure how it works, you could dig into bullets code to ascertain why the objects are colliding. btCollisionWorld has a function called needsCollision which checks the groups and masks to see if they should collide.

I don't know if you can step in there with JBullet though
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Collision masks once again...

Post by xexuxjy »

You can step in with JBullet, just depending on which version you're using you may have to update your ide to run the instrumentation on the stackalloc created objects
Post Reply