diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-11-13 00:05:10 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-11-13 00:05:10 +0300 |
commit | 3a1b7ece402001f2f93669a7b36c32f5e7827bab (patch) | |
tree | a91e600407b0709922b7df3fa2a53f380cf7eb76 /extern/bullet2/src/LinearMath | |
parent | 22d97b2e346e3cb3fc38704a0460e2dd4d9a0abb (diff) |
updating Bullet 2.x with latest changes. The integration + C-API will follow at some stage.
Diffstat (limited to 'extern/bullet2/src/LinearMath')
-rw-r--r-- | extern/bullet2/src/LinearMath/CMakeLists.txt | 1 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btAabbUtil2.h | 70 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btDefaultMotionState.h | 11 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btGeometryUtil.cpp | 168 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btGeometryUtil.h | 39 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btMotionState.h | 9 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btQuickprof.cpp | 37 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btQuickprof.h | 40 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btScalar.h | 19 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btSimdMinMax.h | 1 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btTransformUtil.h | 20 |
11 files changed, 350 insertions, 65 deletions
diff --git a/extern/bullet2/src/LinearMath/CMakeLists.txt b/extern/bullet2/src/LinearMath/CMakeLists.txt index b9546167534..207eed94a3e 100644 --- a/extern/bullet2/src/LinearMath/CMakeLists.txt +++ b/extern/bullet2/src/LinearMath/CMakeLists.txt @@ -5,5 +5,6 @@ ${BULLET_PHYSICS_SOURCE_DIR}/src } ADD_LIBRARY(LibLinearMath btQuickprof.cpp +btGeometryUtil.cpp ) diff --git a/extern/bullet2/src/LinearMath/btAabbUtil2.h b/extern/bullet2/src/LinearMath/btAabbUtil2.h index 1cc7d4ebdf2..2eacb8e242b 100644 --- a/extern/bullet2/src/LinearMath/btAabbUtil2.h +++ b/extern/bullet2/src/LinearMath/btAabbUtil2.h @@ -18,6 +18,8 @@ subject to the following restrictions: #define AABB_UTIL2 #include "LinearMath/btVector3.h" +#include "LinearMath/btSimdMinMax.h" + #define btMin(a,b) ((a < b ? a : b)) #define btMax(a,b) ((a > b ? a : b)) @@ -53,5 +55,73 @@ SIMD_FORCE_INLINE bool TestTriangleAgainstAabb2(const btVector3 *vertices, return true; } + +SIMD_FORCE_INLINE int btOutcode(const btVector3& p,const btVector3& halfExtent) +{ + return (p.getX() < -halfExtent.getX() ? 0x01 : 0x0) | + (p.getX() > halfExtent.getX() ? 0x08 : 0x0) | + (p.getY() < -halfExtent.getY() ? 0x02 : 0x0) | + (p.getY() > halfExtent.getY() ? 0x10 : 0x0) | + (p.getZ() < -halfExtent.getZ() ? 0x4 : 0x0) | + (p.getZ() > halfExtent.getZ() ? 0x20 : 0x0); +} + + +SIMD_FORCE_INLINE bool btRayAabb(const btVector3& rayFrom, + const btVector3& rayTo, + const btVector3& aabbMin, + const btVector3& aabbMax, + btScalar& param, btVector3& normal) +{ + btVector3 aabbHalfExtent = (aabbMax-aabbMin)* 0.5f; + btVector3 aabbCenter = (aabbMax+aabbMin)* 0.5f; + btVector3 source = rayFrom - aabbCenter; + btVector3 target = rayTo - aabbCenter; + int sourceOutcode = btOutcode(source,aabbHalfExtent); + int targetOutcode = btOutcode(target,aabbHalfExtent); + if ((sourceOutcode & targetOutcode) == 0x0) + { + btScalar lambda_enter = btScalar(0.0); + btScalar lambda_exit = param; + btVector3 r = target - source; + int i; + btScalar normSign = 1; + btVector3 hitNormal(0,0,0); + int bit=1; + + for (int j=0;j<2;j++) + { + for (i = 0; i != 3; ++i) + { + if (sourceOutcode & bit) + { + btScalar lambda = (-source[i] - aabbHalfExtent[i]*normSign) / r[i]; + if (lambda_enter <= lambda) + { + lambda_enter = lambda; + hitNormal.setValue(0,0,0); + hitNormal[i] = normSign; + } + } + else if (targetOutcode & bit) + { + btScalar lambda = (-source[i] - aabbHalfExtent[i]*normSign) / r[i]; + btSetMin(lambda_exit, lambda); + } + bit<<=1; + } + normSign = -1.f; + } + if (lambda_enter <= lambda_exit) + { + param = lambda_enter; + normal = hitNormal; + return true; + } + } + return false; +} + + #endif diff --git a/extern/bullet2/src/LinearMath/btDefaultMotionState.h b/extern/bullet2/src/LinearMath/btDefaultMotionState.h index 805631ac56f..6b85b37fb9e 100644 --- a/extern/bullet2/src/LinearMath/btDefaultMotionState.h +++ b/extern/bullet2/src/LinearMath/btDefaultMotionState.h @@ -19,16 +19,25 @@ struct btDefaultMotionState : public btMotionState } ///synchronizes world transform from user to physics - virtual void getWorldTransform(btTransform& centerOfMassWorldTrans ) + virtual void getWorldTransform(btTransform& centerOfMassWorldTrans ) const { centerOfMassWorldTrans = m_centerOfMassOffset.inverse() * m_graphicsWorldTrans ; } ///synchronizes world transform from physics to user + ///Bullet only calls the update of worldtransform for active objects virtual void setWorldTransform(const btTransform& centerOfMassWorldTrans) { m_graphicsWorldTrans = centerOfMassWorldTrans * m_centerOfMassOffset ; } + + ///Bullet gives a callback for objects that are about to be deactivated (put asleep) + /// You can intercept this callback for your own bookkeeping. + ///Also you can return false to disable deactivation for this object this frame. + virtual bool deactivationCallback(void* userPointer) { + return true; + } + }; #endif //DEFAULT_MOTION_STATE_H diff --git a/extern/bullet2/src/LinearMath/btGeometryUtil.cpp b/extern/bullet2/src/LinearMath/btGeometryUtil.cpp new file mode 100644 index 00000000000..69d061d27d0 --- /dev/null +++ b/extern/bullet2/src/LinearMath/btGeometryUtil.cpp @@ -0,0 +1,168 @@ +/* +Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + + +#include "btGeometryUtil.h" + +bool btGeometryUtil::isPointInsidePlanes(const std::vector<btVector3>& planeEquations, const btVector3& point, float margin) +{ + int numbrushes = planeEquations.size(); + for (int i=0;i<numbrushes;i++) + { + const btVector3& N1 = planeEquations[i]; + float dist = float(N1.dot(point))+float(N1[3])-margin; + if (dist>0.f) + { + return false; + } + } + return true; + +} + + +bool btGeometryUtil::areVerticesBehindPlane(const btVector3& planeNormal, const std::vector<btVector3>& vertices, float margin) +{ + int numvertices = vertices.size(); + for (int i=0;i<numvertices;i++) + { + const btVector3& N1 = vertices[i]; + float dist = float(planeNormal.dot(N1))+float(planeNormal[3])-margin; + if (dist>0.f) + { + return false; + } + } + return true; +} + +bool notExist(const btVector3& planeEquation,const std::vector<btVector3>& planeEquations) +{ + int numbrushes = planeEquations.size(); + for (int i=0;i<numbrushes;i++) + { + const btVector3& N1 = planeEquations[i]; + if (planeEquation.dot(N1) > 0.999f) + { + return false; + } + } + return true; +} + +void btGeometryUtil::getPlaneEquationsFromVertices(std::vector<btVector3>& vertices, std::vector<btVector3>& planeEquationsOut ) +{ + const int numvertices = vertices.size(); + // brute force: + for (int i=0;i<numvertices;i++) + { + const btVector3& N1 = vertices[i]; + + + for (int j=i+1;j<numvertices;j++) + { + const btVector3& N2 = vertices[j]; + + for (int k=j+1;k<numvertices;k++) + { + + const btVector3& N3 = vertices[k]; + + btVector3 planeEquation,edge0,edge1; + edge0 = N2-N1; + edge1 = N3-N1; + float normalSign = 1.f; + for (int ww=0;ww<2;ww++) + { + planeEquation = normalSign * edge0.cross(edge1); + if (planeEquation.length2() > 0.0001f) + { + planeEquation.normalize(); + if (notExist(planeEquation,planeEquationsOut)) + { + planeEquation[3] = -planeEquation.dot(N1); + + //check if inside, and replace supportingVertexOut if needed + if (areVerticesBehindPlane(planeEquation,vertices,0.01f)) + { + planeEquationsOut.push_back(planeEquation); + } + } + } + normalSign = -1.f; + } + + } + } + } + +} + +void btGeometryUtil::getVerticesFromPlaneEquations(const std::vector<btVector3>& planeEquations , std::vector<btVector3>& verticesOut ) +{ + const int numbrushes = planeEquations.size(); + // brute force: + for (int i=0;i<numbrushes;i++) + { + const btVector3& N1 = planeEquations[i]; + + + for (int j=i+1;j<numbrushes;j++) + { + const btVector3& N2 = planeEquations[j]; + + for (int k=j+1;k<numbrushes;k++) + { + + const btVector3& N3 = planeEquations[k]; + + btVector3 n2n3; n2n3 = N2.cross(N3); + btVector3 n3n1; n3n1 = N3.cross(N1); + btVector3 n1n2; n1n2 = N1.cross(N2); + + if ( ( n2n3.length2() > 0.0001f ) && + ( n3n1.length2() > 0.0001f ) && + ( n1n2.length2() > 0.0001f ) ) + { + //point P out of 3 plane equations: + + // d1 ( N2 * N3 ) + d2 ( N3 * N1 ) + d3 ( N1 * N2 ) + //P = ------------------------------------------------------------------------- + // N1 . ( N2 * N3 ) + + + float quotient = (N1.dot(n2n3)); + if (btFabs(quotient) > 0.000001f) + { + quotient = -1.f / quotient; + n2n3 *= N1[3]; + n3n1 *= N2[3]; + n1n2 *= N3[3]; + btVector3 potentialVertex = n2n3; + potentialVertex += n3n1; + potentialVertex += n1n2; + potentialVertex *= quotient; + + //check if inside, and replace supportingVertexOut if needed + if (isPointInsidePlanes(planeEquations,potentialVertex,0.01f)) + { + verticesOut.push_back(potentialVertex); + } + } + } + } + } + } +}
\ No newline at end of file diff --git a/extern/bullet2/src/LinearMath/btGeometryUtil.h b/extern/bullet2/src/LinearMath/btGeometryUtil.h new file mode 100644 index 00000000000..3170c215008 --- /dev/null +++ b/extern/bullet2/src/LinearMath/btGeometryUtil.h @@ -0,0 +1,39 @@ +/* +Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#ifndef BT_GEOMETRY_UTIL_H +#define BT_GEOMETRY_UTIL_H +#include <vector> +#include "btVector3.h" + +class btGeometryUtil +{ + public: + + + static void getPlaneEquationsFromVertices(std::vector<btVector3>& vertices, std::vector<btVector3>& planeEquationsOut ); + + static void getVerticesFromPlaneEquations(const std::vector<btVector3>& planeEquations , std::vector<btVector3>& verticesOut ); + + static bool isInside(const std::vector<btVector3>& vertices, const btVector3& planeNormal, float margin); + + static bool isPointInsidePlanes(const std::vector<btVector3>& planeEquations, const btVector3& point, float margin); + + static bool areVerticesBehindPlane(const btVector3& planeNormal, const std::vector<btVector3>& vertices, float margin); + +}; + + +#endif //BT_GEOMETRY_UTIL_H
\ No newline at end of file diff --git a/extern/bullet2/src/LinearMath/btMotionState.h b/extern/bullet2/src/LinearMath/btMotionState.h index 4bbb3d44888..a9e212d3c71 100644 --- a/extern/bullet2/src/LinearMath/btMotionState.h +++ b/extern/bullet2/src/LinearMath/btMotionState.h @@ -29,10 +29,15 @@ class btMotionState } - virtual void getWorldTransform(btTransform& worldTrans )=0; + virtual void getWorldTransform(btTransform& worldTrans ) const =0; + //Bullet only calls the update of worldtransform for active objects virtual void setWorldTransform(const btTransform& worldTrans)=0; - + + //future: when Bullet makes attempt to deactivate object, you can intercept this callback (return false to disable deactivation for this object this frame) + virtual bool deactivationCallback(void* userPointer) { + return true; + } }; #endif //BT_MOTIONSTATE_H diff --git a/extern/bullet2/src/LinearMath/btQuickprof.cpp b/extern/bullet2/src/LinearMath/btQuickprof.cpp index 23b8b8b2c40..4d013a65853 100644 --- a/extern/bullet2/src/LinearMath/btQuickprof.cpp +++ b/extern/bullet2/src/LinearMath/btQuickprof.cpp @@ -1,25 +1,18 @@ -/************************************************************************ -* QuickProf * -* Copyright (C) 2006 * -* Tyler Streeter tylerstreeter@gmail.com * -* All rights reserved. * -* Web: http://quickprof.sourceforge.net * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of EITHER: * -* (1) The GNU Lesser bteral Public License as published by the Free * -* Software Foundation; either version 2.1 of the License, or (at * -* your option) any later version. The text of the GNU Lesser * -* bteral Public License is included with this library in the * -* file license-LGPL.txt. * -* (2) The BSD-style license that is included with this library in * -* the file license-BSD.txt. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * -* license-LGPL.txt and license-BSD.txt for more details. * -************************************************************************/ +/* +Copyright (c) 2006 Tyler Streeter + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. + +*/ + // Please visit the project website (http://quickprof.sourceforge.net) // for usage instructions. diff --git a/extern/bullet2/src/LinearMath/btQuickprof.h b/extern/bullet2/src/LinearMath/btQuickprof.h index 801ef07a946..ec560c8e33e 100644 --- a/extern/bullet2/src/LinearMath/btQuickprof.h +++ b/extern/bullet2/src/LinearMath/btQuickprof.h @@ -1,26 +1,18 @@ -/************************************************************************ -* QuickProf * -* Copyright (C) 2006 * -* Tyler Streeter tylerstreeter@gmail.com * -* All rights reserved. * -* Web: http://quickprof.sourceforge.net * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of EITHER: * -* (1) The GNU Lesser bteral Public License as published by the Free * -* Software Foundation; either version 2.1 of the License, or (at * -* your option) any later version. The text of the GNU Lesser * -* bteral Public License is included with this library in the * -* file license-LGPL.txt. * -* (2) The BSD-style license that is included with this library in * -* the file license-BSD.txt. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * -* license-LGPL.txt and license-BSD.txt for more details. * -************************************************************************/ +/* +Copyright (c) 2006 Tyler Streeter +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. + +*/ + // Please visit the project website (http://quickprof.sourceforge.net) // for usage instructions. @@ -46,6 +38,10 @@ typedef uint64_t __int64; #endif +#if defined (SUNOS) || defined (__SUNOS__) + #include <stdio.h> +#endif + #if defined(WIN32) || defined(_WIN32) #define USE_WINDOWS_TIMERS #include <windows.h> diff --git a/extern/bullet2/src/LinearMath/btScalar.h b/extern/bullet2/src/LinearMath/btScalar.h index dea040a80bd..aa046b89df0 100644 --- a/extern/bullet2/src/LinearMath/btScalar.h +++ b/extern/bullet2/src/LinearMath/btScalar.h @@ -88,13 +88,13 @@ SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } #endif -const btScalar SIMD_2_PI = 6.283185307179586232f; -const btScalar SIMD_PI = SIMD_2_PI * btScalar(0.5f); -const btScalar SIMD_HALF_PI = SIMD_2_PI * btScalar(0.25f); -const btScalar SIMD_RADS_PER_DEG = SIMD_2_PI / btScalar(360.0f); -const btScalar SIMD_DEGS_PER_RAD = btScalar(360.0f) / SIMD_2_PI; -const btScalar SIMD_EPSILON = FLT_EPSILON; -const btScalar SIMD_INFINITY = FLT_MAX; +#define SIMD_2_PI 6.283185307179586232f +#define SIMD_PI (SIMD_2_PI * btScalar(0.5f)) +#define SIMD_HALF_PI (SIMD_2_PI * btScalar(0.25f)) +#define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0f)) +#define SIMD_DEGS_PER_RAD (btScalar(360.0f) / SIMD_2_PI) +#define SIMD_EPSILON FLT_EPSILON +#define SIMD_INFINITY FLT_MAX SIMD_FORCE_INLINE bool btFuzzyZero(btScalar x) { return btFabs(x) < SIMD_EPSILON; } @@ -114,13 +114,14 @@ SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atanf(x); } SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2f(x, y); } */ -SIMD_FORCE_INLINE int btSign(btScalar x) { - return x < 0.0f ? -1 : x > 0.0f ? 1 : 0; +SIMD_FORCE_INLINE int btIsNegative(btScalar x) { + return x < 0.0f ? 1 : 0; } SIMD_FORCE_INLINE btScalar btRadians(btScalar x) { return x * SIMD_RADS_PER_DEG; } SIMD_FORCE_INLINE btScalar btDegrees(btScalar x) { return x * SIMD_DEGS_PER_RAD; } +#define BT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name #endif //SIMD___SCALAR_H diff --git a/extern/bullet2/src/LinearMath/btSimdMinMax.h b/extern/bullet2/src/LinearMath/btSimdMinMax.h index 16c31552f88..2731c8b09f3 100644 --- a/extern/bullet2/src/LinearMath/btSimdMinMax.h +++ b/extern/bullet2/src/LinearMath/btSimdMinMax.h @@ -16,6 +16,7 @@ subject to the following restrictions: #ifndef SIMD_MINMAX_H #define SIMD_MINMAX_H +#include "LinearMath/btScalar.h" template <class T> SIMD_FORCE_INLINE const T& btMin(const T& a, const T& b) { diff --git a/extern/bullet2/src/LinearMath/btTransformUtil.h b/extern/bullet2/src/LinearMath/btTransformUtil.h index 12ca634c232..39fa830f4df 100644 --- a/extern/bullet2/src/LinearMath/btTransformUtil.h +++ b/extern/bullet2/src/LinearMath/btTransformUtil.h @@ -108,7 +108,16 @@ public: static void calculateVelocity(const btTransform& transform0,const btTransform& transform1,btScalar timeStep,btVector3& linVel,btVector3& angVel) { linVel = (transform1.getOrigin() - transform0.getOrigin()) / timeStep; -#ifdef USE_QUATERNION_DIFF + btVector3 axis; + btScalar angle; + calculateDiffAxisAngle(transform0,transform1,axis,angle); + angVel = axis * angle / timeStep; + } + + static void calculateDiffAxisAngle(const btTransform& transform0,const btTransform& transform1,btVector3& axis,btScalar& angle) + { + + #ifdef USE_QUATERNION_DIFF btQuaternion orn0 = transform0.getRotation(); btQuaternion orn1a = transform1.getRotation(); btQuaternion orn1 = orn0.farthest(orn1a); @@ -118,9 +127,7 @@ public: btQuaternion dorn; dmat.getRotation(dorn); #endif//USE_QUATERNION_DIFF - - btVector3 axis; - btScalar angle; + angle = dorn.getAngle(); axis = btVector3(dorn.x(),dorn.y(),dorn.z()); axis[3] = 0.f; @@ -130,13 +137,8 @@ public: axis = btVector3(1.f,0.f,0.f); else axis /= btSqrt(len); - - - angVel = axis * angle / timeStep; - } - }; #endif //SIMD_TRANSFORM_UTIL_H |