Getting user data into InternalTickCallback

Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Getting user data into InternalTickCallback

Post by Wavesonics »

I need to get a pointer to my physics manager in Bullet's TickCallback,

Any ideas on the best way to do this?
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Getting user data into InternalTickCallback

Post by Wavesonics »

Right now this is how I'm trying to do it:

1) Get collision object array from dynamics world (since that is passed to the callback)
(It's my understanding that all objects are CollisionObjects, thus getting the CollisionObjectArray from the dynamics world should include all the objects in the Dynamics world, is that right?)

2) Get the first object from the array, and grab it's stored user pointer, this should be my data that I set when creating the physics objects right?

3) Go to town with my new shinny user data

But this doesn't work. The user data doesn't seem to be correct.
Any other ideas?
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Getting user data into InternalTickCallback

Post by chunky »

http://chunkyks.com/world_userdata.diff ?

In fact, thinking about it, I'd like to put that forward as a request to be added to the main codebase, if there isn't already something obviously similar that I'm missing...

Gary (-;
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Getting user data into InternalTickCallback

Post by Wavesonics »

I was trying to not modify the source for upgradability, but i suppose this is the only way.

Ya, this really really needs to be patched in, are you going to submit it for 2.70?
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Getting user data into InternalTickCallback

Post by chunky »

are you going to submit it for 2.70?
I think I just did?

Gary (-;
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Getting user data into InternalTickCallback

Post by Wavesonics »

hehe ok, I thought you could actually submit it as a patch to the google code project or something like source forge
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Getting user data into InternalTickCallback

Post by Wavesonics »

Should we modify the patch to nitialize the userPointer to NULL in the dynamics world constructor?
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Getting user data into InternalTickCallback

Post by chunky »

http://chunkyks.com/world_userdata.diff
Updated

EDIT: I also noticed that btDynamicsWorld is actually derived from btCollisionWorld, so it may make more sense to put this userpointer in there... That's a question someone smarter than me would have to answer though

Gary (-;
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Getting user data into InternalTickCallback

Post by Wavesonics »

Ya Chunky I think your right, mostly since the userPointer is in CollisionObject and not RigidBody, so it would be in keeping with the current SOP
Sly
Posts: 16
Joined: Wed Apr 23, 2008 9:57 am

Re: Getting user data into InternalTickCallback

Post by Sly »

Why hack the code? Derive your own world class with the info you want.

Code: Select all

class MyPhysicsWorld : public btDiscreteDynamicsWorld
{
public:
	MyPhysicsWorld(MyPhysicsManager *manager, btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration)
    : btDiscreteDynamicsWorld(dispatcher, pairCache, constraintSolver, collisionConfiguration)
  {
    m_manager = manager;
  }

  static void InternalTickCallback(const btDynamicsWorld *world, btScalar timeStep)
  {
    MyPhysicsWorld *myWorld = (MyPhysicsWorld *)world;
    // Do something with myWorld->m_manager
  }

  MyPhysicsManager *m_manager;
};

    manager = new MyPhysicsManager;
    world = new MyPhysicsWorld(manager, collisionDispatcher, broadphaseInterface, constraintSolver, collisionConfig);
    world->setInternalTickCallback(MyPhysicsWorld::InternalTickCallback);
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Getting user data into InternalTickCallback

Post by Wavesonics »

It's not hacking, this is how Open Source projects get better.

This is something that nearly anyone using the tick callback would need, so it's providing a necessary improvement to the Open Source project.
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Getting user data into InternalTickCallback

Post by chunky »

Technically the callback was only added in the last version or two, so the project still lacking other stuff that's central and useful to callbacks is hardly a surprise :-)

Gary (-;
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Getting user data into InternalTickCallback

Post by Erwin Coumans »

If you have useful patches, please make sure to submit it to the Googlecode issue tracker, so it will get the right attention.

This one already got into the latest SVN:

Code: Select all

	/// Set the callback for when an internal tick (simulation substep) happens, optional user info
		void setInternalTickCallback(btInternalTickCallback cb,	void* worldUserInfo=0) 
		{ 
			m_internalTickCallback = cb; 
			m_worldUserInfo = worldUserInfo;
		}

		void	setWorldUserInfo(void* worldUserInfo)
		{
			m_worldUserInfo = worldUserInfo;
		}

		void*	getWorldUserInfo() const
		{
			return m_worldUserInfo;
		}
Thanks a lot,
Erwin
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Getting user data into InternalTickCallback

Post by Wavesonics »

awesome, great to hear. Just out of curosity, was this implemented in Collision world or dynamics world?