| 343 | } |
| 344 | |
| 345 | RayTestResult PhysicsSystem::raytrace(const Math::float3& from, const Math::float3& to, CollisionShape::ECollisionType filtertype) |
| 346 | { |
| 347 | /*btVector3 btFrom(from.x, from.y, from.z); |
| 348 | btVector3 btTo(to.x, to.y, to.z); |
| 349 | btCollisionWorld::ClosestRayResultCallback res(btFrom, btTo); |
| 350 | |
| 351 | m_DynamicsWorld.rayTest(btFrom, btTo, res); // m_btWorld is btDiscreteDynamicsWorld |
| 352 | |
| 353 | return res.hasHit() ? Math::float3(res.m_hitPointWorld.m_floats) : to;*/ |
| 354 | |
| 355 | struct FilteredRayResultCallback : public btCollisionWorld::RayResultCallback |
| 356 | { |
| 357 | FilteredRayResultCallback() {} |
| 358 | btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) override |
| 359 | { |
| 360 | const btRigidBody* rb = btRigidBody::upcast(rayResult.m_collisionObject); |
| 361 | if (rb->getCollisionShape()->getUserIndex() != -1) |
| 362 | { |
| 363 | // We don't have the generation of the handle here, but it should be okay! |
| 364 | Handle::CollisionShapeHandle csh; |
| 365 | csh.index = static_cast<uint32_t>(rb->getCollisionShape()->getUserIndex()); |
| 366 | |
| 367 | CollisionShape& s = m_ShapeAlloc->getElementForce(csh); |
| 368 | |
| 369 | // TODO: There is some filtering functionality in bullet. Maybe use that instead? |
| 370 | if ((s.collisionType & m_filterType) == 0) |
| 371 | return 0; |
| 372 | |
| 373 | m_hitCollisionType = s.collisionType; |
| 374 | } |
| 375 | |
| 376 | if (rb) |
| 377 | return addSingleResult_close(rayResult, normalInWorldSpace); |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | btVector3 m_rayFromWorld; |
| 383 | btVector3 m_rayToWorld; |
| 384 | |
| 385 | btVector3 m_hitNormalWorld; |
| 386 | btVector3 m_hitPointWorld; |
| 387 | uint32_t m_hitTriangleIndex; |
| 388 | CollisionShape::ECollisionType m_hitCollisionType; |
| 389 | CollisionShape::ECollisionType m_filterType; |
| 390 | CollisionShapeAllocator* m_ShapeAlloc; |
| 391 | |
| 392 | virtual btScalar addSingleResult_close(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) |
| 393 | { |
| 394 | //caller already does the filter on the m_closestHitFraction |
| 395 | btAssert(rayResult.m_hitFraction <= m_closestHitFraction); |
| 396 | |
| 397 | m_closestHitFraction = rayResult.m_hitFraction; |
| 398 | m_collisionObject = rayResult.m_collisionObject; |
| 399 | if (normalInWorldSpace) |
| 400 | { |
| 401 | m_hitNormalWorld = rayResult.m_hitNormalLocal; |
| 402 | } |
no outgoing calls
no test coverage detected