some more changes related to PS3 SPU optimizations (16-byte alignment, allowing non-virtual access to data)
This commit is contained in:
@@ -32,6 +32,15 @@ btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int
|
|||||||
}
|
}
|
||||||
|
|
||||||
recalcLocalAabb();
|
recalcLocalAabb();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void btConvexHullShape::addPoint(const btPoint3& point)
|
||||||
|
{
|
||||||
|
m_points.push_back(point);
|
||||||
|
recalcLocalAabb();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btVector3 btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
|
btVector3 btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
|
||||||
|
|||||||
@@ -24,21 +24,30 @@ subject to the following restrictions:
|
|||||||
///No connectivity is needed. localGetSupportingVertex iterates linearly though all vertices.
|
///No connectivity is needed. localGetSupportingVertex iterates linearly though all vertices.
|
||||||
///on modern hardware, due to cache coherency this isn't that bad. Complex algorithms tend to trash the cash.
|
///on modern hardware, due to cache coherency this isn't that bad. Complex algorithms tend to trash the cash.
|
||||||
///(memory is much slower then the cpu)
|
///(memory is much slower then the cpu)
|
||||||
class btConvexHullShape : public btPolyhedralConvexShape
|
ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexShape
|
||||||
{
|
{
|
||||||
btAlignedObjectArray<btPoint3> m_points;
|
btAlignedObjectArray<btPoint3> m_points;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
///this constructor optionally takes in a pointer to points. Each point is assumed to be 3 consecutive btScalar (x,y,z), the striding defines the number of bytes between each point, in memory.
|
///this constructor optionally takes in a pointer to points. Each point is assumed to be 3 consecutive btScalar (x,y,z), the striding defines the number of bytes between each point, in memory.
|
||||||
///It is easier to not pass any points in the constructor, and just add one point at a time, using addPoint.
|
///It is easier to not pass any points in the constructor, and just add one point at a time, using addPoint.
|
||||||
///btConvexHullShape make an internal copy of the points.
|
///btConvexHullShape make an internal copy of the points.
|
||||||
btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(btPoint3));
|
btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(btPoint3));
|
||||||
|
|
||||||
void addPoint(const btPoint3& point)
|
void addPoint(const btPoint3& point);
|
||||||
|
|
||||||
|
btPoint3* getPoints()
|
||||||
{
|
{
|
||||||
m_points.push_back(point);
|
return &m_points[0];
|
||||||
recalcLocalAabb();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getNumPoints()
|
||||||
|
{
|
||||||
|
return m_points.size();
|
||||||
|
}
|
||||||
|
|
||||||
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
||||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
||||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
|
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
|
||||||
|
|||||||
@@ -119,35 +119,16 @@ void btPolyhedralConvexShape::calculateLocalInertia(btScalar mass,btVector3& ine
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void btPolyhedralConvexShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
|
void btPolyhedralConvexShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
|
||||||
{
|
{
|
||||||
|
getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin());
|
||||||
//lazy evaluation of local aabb
|
|
||||||
btAssert(m_isLocalAabbValid);
|
|
||||||
|
|
||||||
btAssert(m_localAabbMin.getX() <= m_localAabbMax.getX());
|
|
||||||
btAssert(m_localAabbMin.getY() <= m_localAabbMax.getY());
|
|
||||||
btAssert(m_localAabbMin.getZ() <= m_localAabbMax.getZ());
|
|
||||||
|
|
||||||
|
|
||||||
btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
|
|
||||||
btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
|
|
||||||
|
|
||||||
btMatrix3x3 abs_b = trans.getBasis().absolute();
|
|
||||||
|
|
||||||
btPoint3 center = trans(localCenter);
|
|
||||||
|
|
||||||
btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
|
|
||||||
abs_b[1].dot(localHalfExtents),
|
|
||||||
abs_b[2].dot(localHalfExtents));
|
|
||||||
extent += btVector3(getMargin(),getMargin(),getMargin());
|
|
||||||
|
|
||||||
aabbMin = center - extent;
|
|
||||||
aabbMax = center + extent;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void btPolyhedralConvexShape::recalcLocalAabb()
|
void btPolyhedralConvexShape::recalcLocalAabb()
|
||||||
{
|
{
|
||||||
m_isLocalAabbValid = true;
|
m_isLocalAabbValid = true;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ subject to the following restrictions:
|
|||||||
class btPolyhedralConvexShape : public btConvexShape
|
class btPolyhedralConvexShape : public btConvexShape
|
||||||
{
|
{
|
||||||
|
|
||||||
|
protected:
|
||||||
btVector3 m_localAabbMin;
|
btVector3 m_localAabbMin;
|
||||||
btVector3 m_localAabbMax;
|
btVector3 m_localAabbMax;
|
||||||
bool m_isLocalAabbValid;
|
bool m_isLocalAabbValid;
|
||||||
@@ -40,7 +41,38 @@ public:
|
|||||||
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
|
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
|
||||||
|
|
||||||
|
|
||||||
|
inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const
|
||||||
|
{
|
||||||
|
|
||||||
|
//lazy evaluation of local aabb
|
||||||
|
btAssert(m_isLocalAabbValid);
|
||||||
|
|
||||||
|
btAssert(m_localAabbMin.getX() <= m_localAabbMax.getX());
|
||||||
|
btAssert(m_localAabbMin.getY() <= m_localAabbMax.getY());
|
||||||
|
btAssert(m_localAabbMin.getZ() <= m_localAabbMax.getZ());
|
||||||
|
|
||||||
|
|
||||||
|
btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
|
||||||
|
btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
|
||||||
|
|
||||||
|
btMatrix3x3 abs_b = trans.getBasis().absolute();
|
||||||
|
|
||||||
|
btPoint3 center = trans(localCenter);
|
||||||
|
|
||||||
|
btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
|
||||||
|
abs_b[1].dot(localHalfExtents),
|
||||||
|
abs_b[2].dot(localHalfExtents));
|
||||||
|
extent += btVector3(margin,margin,margin);
|
||||||
|
|
||||||
|
aabbMin = center - extent;
|
||||||
|
aabbMax = center + extent;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
||||||
|
|
||||||
void recalcLocalAabb();
|
void recalcLocalAabb();
|
||||||
|
|
||||||
virtual int getNumVertices() const = 0 ;
|
virtual int getNumVertices() const = 0 ;
|
||||||
|
|||||||
Reference in New Issue
Block a user