Testing a specific RB?

Post Reply
Brian Beuken
Posts: 46
Joined: Sat Jul 29, 2017 9:19 pm

Testing a specific RB?

Post by Brian Beuken »

I have enclosed some of my RB's in what I term proximity sphere's. Essentially ghost objects which works really well to provide info on close proximity collision tests without triggering any actual reactions. I use this for object avoidance systems its very effective.

But when I do a mouse pick, raycasting to the object to ID it, I am of course detecting the sphere... ok, well thats fine, since the sphere has info on the RB and object its protecting... but what I would like to do is refine things and double test the ray against the RB alone... But I'm finding that a bit tricky, as I only have vec3 to and from, the RB* and the raycallback struct... and none of the individual tests can use those...

any advice?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Testing a specific RB?

Post by drleviathan »

The btCollisionWorld::RayResultCallback has collision group and mask data members. By setting the collision group and mask bits of your RB, proximity sphere, and RayResultCallback correctly you could configure the ray to hit the RB but not the proximity sphere.

Perhaps read this thread for more info.
Brian Beuken
Posts: 46
Joined: Sat Jul 29, 2017 9:19 pm

Re: Testing a specific RB?

Post by Brian Beuken »

thanks, this might be what I'm looking for, I'll try to digest it and see if I can impliment it
Brian Beuken
Posts: 46
Joined: Sat Jul 29, 2017 9:19 pm

Re: Testing a specific RB?

Post by Brian Beuken »

This was a great help thank you, and led me to other uses for the filters.
Brian Beuken
Posts: 46
Joined: Sat Jul 29, 2017 9:19 pm

Re: Testing a specific RB?

Post by Brian Beuken »

edit sorry
my mistake i was doing it right I made a small edit that stopped it working, fine now...
Brian Beuken
Posts: 46
Joined: Sat Jul 29, 2017 9:19 pm

Re: Testing a specific RB?

Post by Brian Beuken »

But.... I do have a question that is still relevent to this.

Once I have the RB's group and mask set, is there a way to change it in game? For example to exclude a particular object from the ray cast? I'm thinking that when I have an object selected already, and another object is projected quite close to it, I'd like to exclude the current object from the cast?
Last edited by Brian Beuken on Mon Aug 30, 2021 11:19 pm, edited 1 time in total.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Testing a specific RB?

Post by drleviathan »

If you change the collision group/mask then you must remove it from the world and re-add it. This is because the group/mask information does not live at the btRigidBody but at its axis aligned bounding box (AABB) in the broadphase data structure which computes potential overlaps which are then passed to the narrowphase which computes the details of the collision.

An alternative way to exclude selected objects at runtime is to derive your own custom AvoidSelectionRayResultCallback from ClosestRayResultCallback and override the implementation of addSingleResult() to NOT update its data members when a selected object is encountered. In other words the method might look something like this (in pseudo-code):

Code: Select all

btScalar AvoidSelectionRayResultCallback::addSingleResult(LocalRayResult& rayResult, bool normalInWorldSpace) {
	if (!isSelected(rayResult.m_collisionObject) {
	        // not selected --> fallback to ClosestRayResultCallback behavior
		return ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
	} else {
		// is selected --> skip
	}
	return m_closestHitFraction;
}
Brian Beuken
Posts: 46
Joined: Sat Jul 29, 2017 9:19 pm

Re: Testing a specific RB?

Post by Brian Beuken »

Thanks that sounds plausable, I'll see what I can do.

Appreciate the help
Post Reply