Physics/Geom: CompoundGeom can now include other CompounedGeom pieces

Former-commit-id: 8e421be85985bfb86ee7f6fd24569e36afdb34b4
This commit is contained in:
Lynix 2015-04-19 18:11:04 +02:00
parent 1642536a0e
commit f7d6107ec7
2 changed files with 17 additions and 1 deletions

View File

@ -118,9 +118,13 @@ class NAZARA_API NzCompoundGeom : public NzPhysGeom
public: public:
NzCompoundGeom(NzPhysWorld* physWorld, NzPhysGeom** geoms, unsigned int geomCount); NzCompoundGeom(NzPhysWorld* physWorld, NzPhysGeom** geoms, unsigned int geomCount);
const std::vector<NzPhysGeomRef>& GetGeoms() const;
nzGeomType GetType() const override; nzGeomType GetType() const override;
template<typename... Args> static NzCompoundGeomRef New(Args&&... args); template<typename... Args> static NzCompoundGeomRef New(Args&&... args);
private:
std::vector<NzPhysGeomRef> m_geoms;
}; };
class NzConeGeom; class NzConeGeom;

View File

@ -178,17 +178,29 @@ NzPhysGeom(physWorld)
m_collision = NewtonCreateCompoundCollision(physWorld->GetHandle(), 0); m_collision = NewtonCreateCompoundCollision(physWorld->GetHandle(), 0);
NewtonCompoundCollisionBeginAddRemove(m_collision); NewtonCompoundCollisionBeginAddRemove(m_collision);
m_geoms.reserve(geomCount);
for (unsigned int i = 0; i < geomCount; ++i) for (unsigned int i = 0; i < geomCount; ++i)
{ {
if (geoms[i]->GetType() == nzGeomType_Compound) if (geoms[i]->GetType() == nzGeomType_Compound)
NazaraError("Cannot add compound geoms to other compound geoms"); {
NzCompoundGeom* compoundGeom = static_cast<NzCompoundGeom*>(geoms[i]);
for (const NzPhysGeomRef& geom : compoundGeom->GetGeoms())
NewtonCompoundCollisionAddSubCollision(m_collision, geom->GetHandle());
}
else else
NewtonCompoundCollisionAddSubCollision(m_collision, geoms[i]->GetHandle()); NewtonCompoundCollisionAddSubCollision(m_collision, geoms[i]->GetHandle());
m_geoms.emplace_back(geoms[i]);
} }
NewtonCompoundCollisionEndAddRemove(m_collision); NewtonCompoundCollisionEndAddRemove(m_collision);
} }
const std::vector<NzPhysGeomRef>& NzCompoundGeom::GetGeoms() const
{
return m_geoms;
}
nzGeomType NzCompoundGeom::GetType() const nzGeomType NzCompoundGeom::GetType() const
{ {
return nzGeomType_Compound; return nzGeomType_Compound;