3:11 PM
I used yesterday to help my partner move house and this morning to go with mum to the hospital for her checkup. I've got a few hours of work time available today until I need to attend to a personal manner tonight.
I'm working on adding food back into the world. The tricky part is figuring out how to call a function when robots touch food. Bullet creates a btPersistantManifold for each pair of touching objects of class btCollisionObject. My class Robot has a pointer to class btRigidBody that inherits from class btCollisionObject. The problem is that btCollisionObject does not have a pointer to class Robot. From the Bullet code I can only get a pointer to btCollisionObject so I can't for example, call a function to increase the amount of energy in class Robot when the robot is touching food.
//Assume world->stepSimulation or world->performDiscreteCollisionDetection has been called int numManifolds = world->getDispatcher()->getNumManifolds(); for (int i=0;ihttp://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_TriggersgetDispatcher()->getManifoldByIndexInternal(i); btCollisionObject* obA = static_cast (contactManifold->getBody0()); btCollisionObject* obB = static_cast (contactManifold->getBody1()); int numContacts = contactManifold->getNumContacts(); for (int j=0;j getContactPoint(j); if (pt.getDistance()<0.f) { const btVector3& ptA = pt.getPositionWorldOnA(); const btVector3& ptB = pt.getPositionWorldOnB(); const btVector3& normalOnB = pt.m_normalWorldOnB; } } }
(The code is a bit messed up, will fix soon)
Need coffee.
I've got a few choices. Class Robot can inherit from class btCollisionObject and I can call class Robot functions from inside the physics code.
I can create class MyCollisionObject that inherits from class btCollisionObject that has a pointer to an object of class Robot. Class Robot can also have a pointer to an object of class MyCollisionObject. I don't know.
4:20 PM
Still thinking. I'm going for the second approach. I want to keep inheritance to a minimum. I hope this doesn't come back to bite me.
6:05 PM
Worked out how to check for collisions during a simulation tick, using callbacks.
void MyTickCallback( btDynamicsWorld* dynamicsWorld, btScalar ) { // call about code to check for collisions } bool PhysicsBullet::Init( void ) { // create a dynamics world ... // set callback void* worldUserInfo = 0; bool isPreTick = false; dynamicsWorld->setInternalTickCallback( MyTickCallback, worldUserInfo, isPreTick ); ... }
Added a piece of food. Will re-enable code to eat food soon.
http://farm1.static.flickr.com/72/152956077_ab6382ee70.jpg
RELATED
No comments:
Post a Comment