Page 1 of 1

Testing a specific RB?

Posted: Tue Aug 10, 2021 1:13 pm
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?

Re: Testing a specific RB?

Posted: Tue Aug 10, 2021 2:30 pm
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.

Re: Testing a specific RB?

Posted: Tue Aug 10, 2021 2:39 pm
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

Re: Testing a specific RB?

Posted: Thu Aug 19, 2021 12:30 pm
by Brian Beuken
This was a great help thank you, and led me to other uses for the filters.

Re: Testing a specific RB?

Posted: Sat Aug 28, 2021 6:08 pm
by Brian Beuken
edit sorry
my mistake i was doing it right I made a small edit that stopped it working, fine now...

Re: Testing a specific RB?

Posted: Sat Aug 28, 2021 7:20 pm
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?

Re: Testing a specific RB?

Posted: Sat Aug 28, 2021 9:30 pm
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;
}

Re: Testing a specific RB?

Posted: Mon Aug 30, 2021 11:20 pm
by Brian Beuken
Thanks that sounds plausable, I'll see what I can do.

Appreciate the help