fixed sphere shape, added non-uniform scaling (making it an ellipsoid)
authorErwin Coumans <blender@erwincoumans.com>
Fri, 5 Aug 2005 22:10:27 +0000 (22:10 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Fri, 5 Aug 2005 22:10:27 +0000 (22:10 +0000)
removed bug-fixing comments

extern/bullet/Bullet/CollisionShapes/BoxShape.cpp
extern/bullet/Bullet/CollisionShapes/SphereShape.cpp
extern/bullet/Bullet/CollisionShapes/SphereShape.h
extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
source/gameengine/Ketsji/KX_RaySensor.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp

index 98f2a3d54448a399f9e28888bd553a065db57fd9..727af3ae49962cc53f07bca03d7a3324b7cf76b4 100644 (file)
@@ -54,25 +54,4 @@ void BoxShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
        inertia[2] = mass/(12.0f) * (lx*lx + ly*ly);
 
 
-//             float radius = GetHalfExtents().length();
-//             SimdScalar elem = 0.4f * mass * radius*radius;
-//     inertia[0] = inertia[1] = inertia[2] = elem;
-return;
-/*
-       float margin = GetMargin();
-       SimdVector3 halfExtents = GetHalfExtents();
-
-       SimdScalar lx=2.f*(halfExtents.x()+margin);
-       SimdScalar ly=2.f*(halfExtents.y()+margin);
-       SimdScalar lz=2.f*(halfExtents.z()+margin);
-       const SimdScalar x2 = lx*lx;
-       const SimdScalar y2 = ly*ly;
-       const SimdScalar z2 = lz*lz;
-       const SimdScalar scaledmass = mass * 0.08333333f;
-
-       inertia = scaledmass * (SimdVector3(y2+z2,x2+z2,x2+y2));
-*/
-//             inertia.x() = scaledmass * (y2+z2);
-//             inertia.y() = scaledmass * (x2+z2);
-//             inertia.z() = scaledmass * (x2+y2);
 }
\ No newline at end of file
index 182b458ec7b9d0df3889731635ef721797f67ba6..6afb0fe50913e11e0f21b5e94a64248fe780374c 100644 (file)
 
 SphereShape ::SphereShape (SimdScalar radius)
 : m_radius(radius)
-{
-       SetMargin( radius );
+{      
 }
 
 SimdVector3    SphereShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const
 {
-       return SimdVector3(0.f,0.f,0.f);
-}
+       float radius = m_radius - GetMargin();
 
-SimdVector3    SphereShape::LocalGetSupportingVertex(const SimdVector3& vec)const
-{
        SimdScalar len = vec.length2();
        if (fabsf(len) < 0.0001f)
        {
-               return SimdVector3(GetMargin(),GetMargin(),GetMargin());
+               return SimdVector3(m_localScaling[0] * radius,m_localScaling[1]*radius,m_localScaling[2]*radius);
        } 
-       return vec *  (GetMargin() / sqrtf(len));
+       return vec *  (m_localScaling*(radius / sqrtf(len)));
 }
 
+SimdVector3    SphereShape::LocalGetSupportingVertex(const SimdVector3& vec)const
+{
+       SimdVector3 supVertex;
+       supVertex = LocalGetSupportingVertexWithoutMargin(vec);
 
+       if ( GetMargin()!=0.f )
+       {
+               SimdVector3 vecnorm = vec;
+               if (vecnorm .length2() == 0.f)
+               {
+                       vecnorm.setValue(-1.f,-1.f,-1.f);
+               } 
+               vecnorm.normalize();
+               supVertex+= GetMargin() * vecnorm;
+       }
+       return supVertex;
+}
+
+/*
+//broken due to scaling
 void SphereShape::GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const
 {
        const SimdVector3& center = t.getOrigin();
-       SimdScalar radius = m_radius + CONVEX_DISTANCE_MARGIN;
-       radius += 1;
-
-       const SimdVector3 extent(radius,radius,radius);
+       SimdScalar radius = m_radius;
+       
+       SimdVector3 extent = m_localScaling*radius;
+       extent+= SimdVector3(GetMargin(),GetMargin(),GetMargin());
 
        aabbMin = center - extent;
        aabbMax = center + extent;
 }
-
+*/
 
 
 void   SphereShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
 {
-  SimdScalar elem = 0.4f * mass * m_radius*m_radius;
+       SimdScalar elem = 0.4f * mass * m_radius*m_radius;
        inertia[0] = inertia[1] = inertia[2] = elem;
+
 }
\ No newline at end of file
index 6765c59f18af773298b7b567fdf531b284bd5601..240d9befce83dcf4c0accedb0550f5a432352c19 100644 (file)
@@ -31,7 +31,7 @@ public:
 
        virtual void    CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
 
-       virtual void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const;
+       //virtual void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const;
 
        virtual int     GetShapeType() const { return SPHERE_SHAPE_PROXYTYPE; }
 
index f1f7ba2c1d21bc02e672355bb43a60546bab25ab..c16a31ee18d6df402a9f95db2a5a6b550e030c88 100644 (file)
@@ -163,8 +163,7 @@ void                CcdPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,floa
 }
 void           CcdPhysicsController::applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ)
 {
-       printf("CcdPhysicsController::applyImpulse\n");
-
+       
        SimdVector3 impulse(impulseX,impulseY,impulseZ);
        SimdVector3 pos(attachX,attachY,attachZ);
 
index ee12efec684f1da83db47e5459811ce206d48864..da81439fccb852a40ddf8afd2fd848d87dce003d 100644 (file)
@@ -949,27 +949,16 @@ PyObject* KX_GameObject::PyApplyImpulse(PyObject* self,
                                                                                PyObject* args, 
                                                                                PyObject* kwds)
 {
-       
-       
        PyObject* pyattach;
        PyObject* pyimpulse;
-
-       printf("impulse1\n");
-       
-       
        if (PyArg_ParseTuple(args, "OO", &pyattach, &pyimpulse))
        {
                MT_Point3  attach;
                MT_Vector3 impulse;
-               printf("impulse2\n");
-       
                if (m_pPhysicsController1)
                {
-                               printf("impulse3\n");
-
                        if (PyVecTo(pyattach, attach) && PyVecTo(pyimpulse, impulse))
                        {
-                               printf("impulse4\n");
                                m_pPhysicsController1->applyImpulse(attach, impulse);
                                Py_Return;
                        }
index af24627f8fec63cadf95ad7741821e6693c9cc8f..b42c66fc4f90e681993746b7bd220463c67f443b 100644 (file)
@@ -345,7 +345,6 @@ PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self,
 {
        if (m_hitObject)
        {
-               printf("hitObject!\n");
                return m_hitObject->AddRef();
        }
        Py_Return;
index 73eb95d606ef2f3694ccf6f50df36be8d7540ecd..b35d9b00540868244bb3c78f3706d099fce9623b 100644 (file)
@@ -106,13 +106,12 @@ bool KX_RaySensor::IsPositiveTrigger()
 
 bool KX_RaySensor::RayHit(KX_ClientObjectInfo* info, MT_Point3& hit_point, MT_Vector3& hit_normal, void* const data)
 {
-       printf("KX_RaySensor::RayHit\n");
 
        KX_GameObject* obj = (KX_GameObject*)GetParent();
        SCA_IObject *hitgameobj = info->m_gameobject;
        if (hitgameobj == obj || info->m_type > KX_ClientObjectInfo::ACTOR)
        {
-               printf("false hit\n");
+//             printf("false hit\n");
                // false hit
                return false;
        }
index f1f7ba2c1d21bc02e672355bb43a60546bab25ab..c16a31ee18d6df402a9f95db2a5a6b550e030c88 100644 (file)
@@ -163,8 +163,7 @@ void                CcdPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,floa
 }
 void           CcdPhysicsController::applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ)
 {
-       printf("CcdPhysicsController::applyImpulse\n");
-
+       
        SimdVector3 impulse(impulseX,impulseY,impulseZ);
        SimdVector3 pos(attachX,attachY,attachZ);