// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #include #include namespace anki { PhysicsSphere::PhysicsSphere(F32 radius) : PhysicsCollisionShape(ShapeType::kSphere) { m_sphere.construct(radius); m_sphere->setMargin(PhysicsWorld::getSingleton().getCollisionMargin()); m_sphere->setUserPointer(static_cast(this)); } PhysicsSphere::~PhysicsSphere() { m_sphere.destroy(); } PhysicsBox::PhysicsBox(const Vec3& extend) : PhysicsCollisionShape(ShapeType::kBox) { m_box.construct(toBt(extend)); m_box->setMargin(PhysicsWorld::getSingleton().getCollisionMargin()); m_box->setUserPointer(static_cast(this)); } PhysicsBox::~PhysicsBox() { m_box.destroy(); } PhysicsTriangleSoup::PhysicsTriangleSoup(ConstWeakArray positions, ConstWeakArray indices, Bool convex) : PhysicsCollisionShape(ShapeType::kTrimesh) { if(!convex) { ANKI_ASSERT((indices.getSize() % 3) == 0); m_mesh.construct(); for(U32 i = 0; i < indices.getSize(); i += 3) { m_mesh->addTriangle(toBt(positions[indices[i]]), toBt(positions[indices[i + 1]]), toBt(positions[indices[i + 2]])); } // Create the dynamic shape m_triMesh.m_dynamic.construct(m_mesh.get()); m_triMesh.m_dynamic->setMargin(PhysicsWorld::getSingleton().getCollisionMargin()); m_triMesh.m_dynamic->updateBound(); m_triMesh.m_dynamic->setUserPointer(static_cast(this)); // And the static one m_triMesh.m_static.construct(m_mesh.get(), true); m_triMesh.m_static->setMargin(PhysicsWorld::getSingleton().getCollisionMargin()); m_triMesh.m_static->setUserPointer(static_cast(this)); } else { m_type = ShapeType::kConvex; // Fake the type m_convex.construct(&positions[0][0], I32(positions.getSize()), U32(sizeof(Vec3))); m_convex->setMargin(PhysicsWorld::getSingleton().getCollisionMargin()); m_convex->setUserPointer(static_cast(this)); } } PhysicsTriangleSoup::~PhysicsTriangleSoup() { if(m_type == ShapeType::kTrimesh) { m_triMesh.m_dynamic.destroy(); m_triMesh.m_static.destroy(); m_mesh.destroy(); } else { ANKI_ASSERT(m_type == ShapeType::kConvex); m_convex.destroy(); } } } // end namespace anki