| 248 | } |
| 249 | |
| 250 | std::vector<RayTestResult> PhysicsSystem::raytraceAll(const Math::float3& from, const Math::float3& to, CollisionShape::ECollisionType filtertype) |
| 251 | { |
| 252 | struct FilteredAllHitsRayResultCallback : public btCollisionWorld::RayResultCallback |
| 253 | { |
| 254 | FilteredAllHitsRayResultCallback(const btVector3& rayFromWorld, const btVector3& rayToWorld) |
| 255 | : m_rayFromWorld(rayFromWorld) |
| 256 | , m_rayToWorld(rayToWorld) |
| 257 | { |
| 258 | } |
| 259 | |
| 260 | btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) override |
| 261 | { |
| 262 | const btRigidBody* rb = btRigidBody::upcast(rayResult.m_collisionObject); |
| 263 | |
| 264 | if (rb->getCollisionShape()->getUserIndex() != -1) |
| 265 | { |
| 266 | // We don't have the generation of the handle here, but it should be okay! |
| 267 | Handle::CollisionShapeHandle csh; |
| 268 | csh.index = static_cast<uint32_t>(rb->getCollisionShape()->getUserIndex()); |
| 269 | |
| 270 | CollisionShape& s = m_ShapeAlloc->getElementForce(csh); |
| 271 | |
| 272 | // TODO: There is some filtering functionality in bullet. Maybe use that instead? |
| 273 | if ((s.collisionType & m_filterType) == 0) |
| 274 | return 0; |
| 275 | |
| 276 | m_hitCollisionTypes.push_back(s.collisionType); |
| 277 | } |
| 278 | |
| 279 | if (rb) |
| 280 | return addSingleResult_close(rayResult, normalInWorldSpace); |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | btAlignedObjectArray<const btCollisionObject*> m_collisionObjects; |
| 285 | |
| 286 | btVector3 m_rayFromWorld; //used to calculate hitPointWorld from hitFraction |
| 287 | btVector3 m_rayToWorld; |
| 288 | |
| 289 | btAlignedObjectArray<btVector3> m_hitNormalWorld; |
| 290 | btAlignedObjectArray<btVector3> m_hitPointWorld; |
| 291 | btAlignedObjectArray<btScalar> m_hitFractions; |
| 292 | |
| 293 | std::vector<uint32_t> m_hitTriangleIndex; |
| 294 | std::vector<CollisionShape::ECollisionType> m_hitCollisionTypes; |
| 295 | CollisionShape::ECollisionType m_filterType; |
| 296 | CollisionShapeAllocator* m_ShapeAlloc; |
| 297 | |
| 298 | virtual btScalar addSingleResult_close(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) |
| 299 | { |
| 300 | m_collisionObject = rayResult.m_collisionObject; |
| 301 | m_collisionObjects.push_back(rayResult.m_collisionObject); |
| 302 | btVector3 hitNormalWorld; |
| 303 | if (normalInWorldSpace) |
| 304 | { |
| 305 | hitNormalWorld = rayResult.m_hitNormalLocal; |
| 306 | } |
| 307 | else |
no test coverage detected