Getting from Rigidbody to GameObject (architecture question)

Post Reply
Lewa
Posts: 5
Joined: Wed May 31, 2017 8:55 pm

Getting from Rigidbody to GameObject (architecture question)

Post by Lewa »

This is more of an architectural question regarding bullet physics.
I have the following szenario:
I have gameobject which stores a pointer to a Rigidbody. (which is then added with addRigidbody to the physics world)
This gameobject can also store other data like a 3D Model, healthpoints, etc...

Now what i want to do is to delete the whole gameobject after colliding with the rigidbody or picking it with a raycast.

With a raycast it would look like this:

Code: Select all

btCollisionWorld::ClosestRayResultCallback RayCallback(start, end);
			this->collisionWorld->getDynamicsWorld()->rayTest(start, end, RayCallback);
			if (RayCallback.hasHit()) {
				//get the pointer of the collisionObject.
				const btCollisionObject* hitObj = RayCallback.m_collisionObject;
			}

Now, my question is what is the most common/efficient way of modifying/deleting the gameobject which stores the pointer to this rigidbody (which was returned by the raycast)?

Does Bullet have some form of built-in support for that type of stuff?
Or do i have to store the pointer of this rigidbody manually in (as an example) map datastructure as a key and store the pointer of the gameobject as the value? (So that i can simply retrieve the gameobject by looking up the pointer returned by the raycast.)

I'm relatively new to bullet and trying to grasp it's architecture.
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: Getting from Rigidbody to GameObject (architecture question)

Post by hyyou »

Yes, it supports.
See btCollisionObject::setUserPointer(void*) / getUserPointer.
Post Reply