attempt to support negative local scaling for convex hull, box,sphere, cylinder,...
authorErwin Coumans <blender@erwincoumans.com>
Sat, 20 Sep 2008 23:45:45 +0000 (23:45 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Sat, 20 Sep 2008 23:45:45 +0000 (23:45 +0000)
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp

index deb3954b5c351a59fb515749fe5468e2de79eb0c..2596858bc3a05e06c66630434005f0473e1be335 100644 (file)
@@ -36,6 +36,13 @@ btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int
 }
 
 
+
+void btConvexHullShape::setLocalScaling(const btVector3& scaling)
+{
+       m_localScaling = scaling;
+       recalcLocalAabb();
+}
+
 void btConvexHullShape::addPoint(const btPoint3& point)
 {
        m_points.push_back(point);
index c029ca19403aec1b7e5a6e94dc945d705ec5b439..4773de2dc513ad8a045ccfd3b3b9756ecb885113 100644 (file)
@@ -71,7 +71,8 @@ public:
        virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
        virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
 
-
+       ///in case we receive negative scaling
+       virtual void    setLocalScaling(const btVector3& scaling);
 
 };
 
index f828d28e18c876c6b29b215e2fccfbe77c9b78e1..fb81c8a5bde7b46104c198771f7ffa0219a840a4 100644 (file)
@@ -26,7 +26,7 @@ m_collisionMargin(CONVEX_DISTANCE_MARGIN)
 
 void   btConvexInternalShape::setLocalScaling(const btVector3& scaling)
 {
-       m_localScaling = scaling;
+       m_localScaling = scaling.absolute();
 }
 
 
index 5a17b4e2df016b7091e41121a855c54c5861e28e..845a5e3005d031ba621077b47c9c7eef79717a9b 100644 (file)
@@ -56,8 +56,18 @@ void btScaledBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callb
        btScaledTriangleCallback scaledCallback(callback,m_localScaling);
        
        btVector3 invLocalScaling(1.f/m_localScaling.getX(),1.f/m_localScaling.getY(),1.f/m_localScaling.getZ());
-       btVector3 scaledAabbMin = aabbMin * invLocalScaling;
-       btVector3 scaledAabbMax = aabbMax * invLocalScaling;
+       btVector3 scaledAabbMin,scaledAabbMax;
+
+       ///support negative scaling
+       scaledAabbMin[0] = m_localScaling.getX() >= 0. ? aabbMin[0] * invLocalScaling[0] : aabbMax[0] * invLocalScaling[0];
+       scaledAabbMin[1] = m_localScaling.getY() >= 0. ? aabbMin[1] * invLocalScaling[1] : aabbMax[1] * invLocalScaling[1];
+       scaledAabbMin[2] = m_localScaling.getZ() >= 0. ? aabbMin[2] * invLocalScaling[2] : aabbMax[2] * invLocalScaling[2];
+       
+       scaledAabbMax[0] = m_localScaling.getX() <= 0. ? aabbMin[0] * invLocalScaling[0] : aabbMax[0] * invLocalScaling[0];
+       scaledAabbMax[1] = m_localScaling.getY() <= 0. ? aabbMin[1] * invLocalScaling[1] : aabbMax[1] * invLocalScaling[1];
+       scaledAabbMax[2] = m_localScaling.getZ() <= 0. ? aabbMin[2] * invLocalScaling[2] : aabbMax[2] * invLocalScaling[2];
+       
+       
        m_bvhTriMeshShape->processAllTriangles(&scaledCallback,scaledAabbMin,scaledAabbMax);
 }
 
@@ -66,8 +76,16 @@ void btScaledBvhTriangleMeshShape::getAabb(const btTransform& trans,btVector3& a
 {
        btVector3 localAabbMin = m_bvhTriMeshShape->getLocalAabbMin();
        btVector3 localAabbMax = m_bvhTriMeshShape->getLocalAabbMax();
-       localAabbMin *= m_localScaling;
-       localAabbMax *= m_localScaling;
+
+       btVector3 tmpLocalAabbMin = localAabbMin * m_localScaling;
+       btVector3 tmpLocalAabbMax = localAabbMax * m_localScaling;
+
+       localAabbMin[0] = (m_localScaling.getX() >= 0.) ? tmpLocalAabbMin[0] : tmpLocalAabbMax[0];
+       localAabbMin[1] = (m_localScaling.getY() >= 0.) ? tmpLocalAabbMin[1] : tmpLocalAabbMax[1];
+       localAabbMin[2] = (m_localScaling.getZ() >= 0.) ? tmpLocalAabbMin[2] : tmpLocalAabbMax[2];
+       localAabbMax[0] = (m_localScaling.getX() <= 0.) ? tmpLocalAabbMin[0] : tmpLocalAabbMax[0];
+       localAabbMax[1] = (m_localScaling.getY() <= 0.) ? tmpLocalAabbMin[1] : tmpLocalAabbMax[1];
+       localAabbMax[2] = (m_localScaling.getZ() <= 0.) ? tmpLocalAabbMin[2] : tmpLocalAabbMax[2];
 
        btVector3 localHalfExtents = btScalar(0.5)*(localAabbMax-localAabbMin);
        btScalar margin = m_bvhTriMeshShape->getMargin();