From 66dc186fb6f6fd4d95b429fba6d31c764000bde0 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Fri, 5 Aug 2005 22:10:27 +0000 Subject: fixed sphere shape, added non-uniform scaling (making it an ellipsoid) removed bug-fixing comments --- extern/bullet/Bullet/CollisionShapes/BoxShape.cpp | 21 ----------- .../bullet/Bullet/CollisionShapes/SphereShape.cpp | 44 +++++++++++++++------- extern/bullet/Bullet/CollisionShapes/SphereShape.h | 2 +- .../CcdPhysics/CcdPhysicsController.cpp | 3 +- 4 files changed, 32 insertions(+), 38 deletions(-) (limited to 'extern') diff --git a/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp b/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp index 98f2a3d5444..727af3ae499 100644 --- a/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp +++ b/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp @@ -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 diff --git a/extern/bullet/Bullet/CollisionShapes/SphereShape.cpp b/extern/bullet/Bullet/CollisionShapes/SphereShape.cpp index 182b458ec7b..6afb0fe5091 100644 --- a/extern/bullet/Bullet/CollisionShapes/SphereShape.cpp +++ b/extern/bullet/Bullet/CollisionShapes/SphereShape.cpp @@ -17,42 +17,58 @@ 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 diff --git a/extern/bullet/Bullet/CollisionShapes/SphereShape.h b/extern/bullet/Bullet/CollisionShapes/SphereShape.h index 6765c59f18a..240d9befce8 100644 --- a/extern/bullet/Bullet/CollisionShapes/SphereShape.h +++ b/extern/bullet/Bullet/CollisionShapes/SphereShape.h @@ -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; } diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp index f1f7ba2c1d2..c16a31ee18d 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp @@ -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); -- cgit v1.2.3