What's the best (high performance) way to do this search?
P.S.: Iterating over all objects and checking if it's distance from my pulsing object is lesser than the radius is obvious...I'm trying not to do this!
P.S. 2: Collisions with a sphere covering this radius are faulty, mainly because this sphere is huge comparing to the other objects.
Thanks in advance guys!
My code looks like this right now:
Code: Select all
Transform from = this->object->getCollisionObject()->getWorldTransform();
Transform to = from;
to.setOrigin(to.getOrigin() + btVector3(0.0f, 0.1f, 0.0f));
AllButMeConvexResultCallback callback(this->object->getCollisionObject().get());
callback.m_collisionFilterGroup = btBroadphaseProxy::DefaultFilter;
callback.m_collisionFilterMask = btBroadphaseProxy::AllFilter;
// this->range = 20.0f;
ConvexShapePtr shape(new SphereShape(this->range));
if (this->collisionTester->convexSweepTest(shape, from, to, callback)) {
foreach (CollisionObject* collisionObject, callback.hits) {
if (!collisionObject->isStaticOrKinematicObject()) {
Vector3dPtr pulseDirection = Vector3dPtr(new BulletVector3Adapter(collisionObject->getWorldTransform().getOrigin())) - this->object->getPosition();
float distance = pulseDirection->norm();
btVector3 objectImpulse = toBullet(this->impulse*(1.0f - distance/this->range)*pulseDirection); //linear
RigidBody::upcast(collisionObject)->applyCentralImpulse(objectImpulse);
}
}
}