Getting user data into InternalTickCallback
-
- Posts: 71
- Joined: Thu May 22, 2008 8:03 pm
Getting user data into InternalTickCallback
I need to get a pointer to my physics manager in Bullet's TickCallback,
Any ideas on the best way to do this?
Any ideas on the best way to do this?
-
- Posts: 71
- Joined: Thu May 22, 2008 8:03 pm
Re: Getting user data into InternalTickCallback
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?
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?
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Getting user data into InternalTickCallback
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 (-;
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 (-;
-
- Posts: 71
- Joined: Thu May 22, 2008 8:03 pm
Re: Getting user data into InternalTickCallback
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?
Ya, this really really needs to be patched in, are you going to submit it for 2.70?
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Getting user data into InternalTickCallback
I think I just did?are you going to submit it for 2.70?
Gary (-;
-
- Posts: 71
- Joined: Thu May 22, 2008 8:03 pm
Re: Getting user data into InternalTickCallback
hehe ok, I thought you could actually submit it as a patch to the google code project or something like source forge
-
- Posts: 71
- Joined: Thu May 22, 2008 8:03 pm
Re: Getting user data into InternalTickCallback
Should we modify the patch to nitialize the userPointer to NULL in the dynamics world constructor?
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Getting user data into InternalTickCallback
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 (-;
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 (-;
-
- Posts: 71
- Joined: Thu May 22, 2008 8:03 pm
Re: Getting user data into InternalTickCallback
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
-
- Posts: 16
- Joined: Wed Apr 23, 2008 9:57 am
Re: Getting user data into InternalTickCallback
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);
-
- Posts: 71
- Joined: Thu May 22, 2008 8:03 pm
Re: Getting user data into InternalTickCallback
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.
This is something that nearly anyone using the tick callback would need, so it's providing a necessary improvement to the Open Source project.
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Getting user data into InternalTickCallback
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 (-;
Gary (-;
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Getting user data into InternalTickCallback
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:
Thanks a lot,
Erwin
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;
}
Erwin
-
- Posts: 71
- Joined: Thu May 22, 2008 8:03 pm
Re: Getting user data into InternalTickCallback
awesome, great to hear. Just out of curosity, was this implemented in Collision world or dynamics world?