Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualic0de

Posted 22 July 2013 - 11:01 AM

In my game I use the Bullet physics engine to do physics. Bullet has a class called btRigidBody which represents a single rigid object in the physics world. My enemy class contains a pointer to a btRigidBody which represents the enemy's physical body. I also have some code to create an explosion, the code gathers all btRigidBodys close to the center of the explosion and apply's a force to them proportional to their distance from the center. The problem is that at this point the explosion code can only obtain a reference to a btRigidBody but not the class that contains it. I need access to the enemy that contains the btRigidBody so I can apply damage to it. At this time what I do is look through my list of enemies until I find one that contains a btRigidBody with the same address as the one which is being hit with the explosion and then apply damage to that enemy. While this seems works pretty reliably it is terribly inefficient and doesn't scale well when the list of enemies becomes larger. given that I cannot actually modify the btRigidBody class how can I store a reference to its owner in order to avoid an expensive search?


#1ic0de

Posted 22 July 2013 - 11:01 AM

In my game I use the Bullet physics engine to do physics. Bullet has a class called btRigidBody which represents a single rigid object in the physics world. My enemy class contains a pointer to a btRigidBody which represents the enemy's physical body. I also have some code to create an explosion, the code gathers all btRigidBodys close to the center of the explosion and apply's a force to them proportional to their distance from the center. The problem is that at this point the explosion code can only obtain a reference to a btRigidBody but not the class that contains it. I need access to the enemy that contains the btRigidBody so I can apply damage to it. At this time what I do is look through my list of enemies until I find one that contains a btRigidBody with the same address as the one which is being hit with the explosion and then apply damage to that enemy. While this seems works pretty reliably it is terribly inefficient and doesn't scale well when the list of enemies becomes larger. Because I cannot actually modify the btRigidBody class how can I store a reference to its owner in order to avoid an expensive search?


PARTNERS