| [1963] | 1 | /* | 
|---|
|  | 2 | Bullet Continuous Collision Detection and Physics Library | 
|---|
|  | 3 | Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/ | 
|---|
|  | 4 |  | 
|---|
|  | 5 | This software is provided 'as-is', without any express or implied warranty. | 
|---|
|  | 6 | In no event will the authors be held liable for any damages arising from the use of this software. | 
|---|
|  | 7 | Permission is granted to anyone to use this software for any purpose, | 
|---|
|  | 8 | including commercial applications, and to alter it and redistribute it freely, | 
|---|
|  | 9 | subject to the following restrictions: | 
|---|
|  | 10 |  | 
|---|
|  | 11 | 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. | 
|---|
|  | 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | 
|---|
|  | 13 | 3. This notice may not be removed or altered from any source distribution. | 
|---|
|  | 14 | */ | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #include "BulletCollision/CollisionShapes/btCollisionShape.h" | 
|---|
|  | 17 |  | 
|---|
|  | 18 |  | 
|---|
| [2882] | 19 | btScalar gContactThresholdFactor=btScalar(0.02); | 
|---|
|  | 20 |  | 
|---|
|  | 21 |  | 
|---|
| [1963] | 22 | /* | 
|---|
|  | 23 | Make sure this dummy function never changes so that it | 
|---|
|  | 24 | can be used by probes that are checking whether the | 
|---|
|  | 25 | library is actually installed. | 
|---|
|  | 26 | */ | 
|---|
|  | 27 | extern "C" | 
|---|
|  | 28 | { | 
|---|
|  | 29 | void btBulletCollisionProbe (); | 
|---|
|  | 30 |  | 
|---|
|  | 31 | void btBulletCollisionProbe () {} | 
|---|
|  | 32 | } | 
|---|
|  | 33 |  | 
|---|
|  | 34 |  | 
|---|
|  | 35 |  | 
|---|
|  | 36 | void    btCollisionShape::getBoundingSphere(btVector3& center,btScalar& radius) const | 
|---|
|  | 37 | { | 
|---|
|  | 38 | btTransform tr; | 
|---|
|  | 39 | tr.setIdentity(); | 
|---|
|  | 40 | btVector3 aabbMin,aabbMax; | 
|---|
|  | 41 |  | 
|---|
|  | 42 | getAabb(tr,aabbMin,aabbMax); | 
|---|
|  | 43 |  | 
|---|
|  | 44 | radius = (aabbMax-aabbMin).length()*btScalar(0.5); | 
|---|
|  | 45 | center = (aabbMin+aabbMax)*btScalar(0.5); | 
|---|
|  | 46 | } | 
|---|
|  | 47 |  | 
|---|
| [2430] | 48 | btScalar        btCollisionShape::getContactBreakingThreshold() const | 
|---|
|  | 49 | { | 
|---|
| [2882] | 50 | return getAngularMotionDisc() * gContactThresholdFactor; | 
|---|
| [2430] | 51 | } | 
|---|
| [1963] | 52 | btScalar        btCollisionShape::getAngularMotionDisc() const | 
|---|
|  | 53 | { | 
|---|
| [2430] | 54 | ///@todo cache this value, to improve performance | 
|---|
| [1963] | 55 | btVector3       center; | 
|---|
|  | 56 | btScalar disc; | 
|---|
|  | 57 | getBoundingSphere(center,disc); | 
|---|
|  | 58 | disc += (center).length(); | 
|---|
|  | 59 | return disc; | 
|---|
|  | 60 | } | 
|---|
|  | 61 |  | 
|---|
|  | 62 | void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const | 
|---|
|  | 63 | { | 
|---|
|  | 64 | //start with static aabb | 
|---|
|  | 65 | getAabb(curTrans,temporalAabbMin,temporalAabbMax); | 
|---|
|  | 66 |  | 
|---|
|  | 67 | btScalar temporalAabbMaxx = temporalAabbMax.getX(); | 
|---|
|  | 68 | btScalar temporalAabbMaxy = temporalAabbMax.getY(); | 
|---|
|  | 69 | btScalar temporalAabbMaxz = temporalAabbMax.getZ(); | 
|---|
|  | 70 | btScalar temporalAabbMinx = temporalAabbMin.getX(); | 
|---|
|  | 71 | btScalar temporalAabbMiny = temporalAabbMin.getY(); | 
|---|
|  | 72 | btScalar temporalAabbMinz = temporalAabbMin.getZ(); | 
|---|
|  | 73 |  | 
|---|
|  | 74 | // add linear motion | 
|---|
|  | 75 | btVector3 linMotion = linvel*timeStep; | 
|---|
| [2430] | 76 | ///@todo: simd would have a vector max/min operation, instead of per-element access | 
|---|
| [1963] | 77 | if (linMotion.x() > btScalar(0.)) | 
|---|
|  | 78 | temporalAabbMaxx += linMotion.x(); | 
|---|
|  | 79 | else | 
|---|
|  | 80 | temporalAabbMinx += linMotion.x(); | 
|---|
|  | 81 | if (linMotion.y() > btScalar(0.)) | 
|---|
|  | 82 | temporalAabbMaxy += linMotion.y(); | 
|---|
|  | 83 | else | 
|---|
|  | 84 | temporalAabbMiny += linMotion.y(); | 
|---|
|  | 85 | if (linMotion.z() > btScalar(0.)) | 
|---|
|  | 86 | temporalAabbMaxz += linMotion.z(); | 
|---|
|  | 87 | else | 
|---|
|  | 88 | temporalAabbMinz += linMotion.z(); | 
|---|
|  | 89 |  | 
|---|
|  | 90 | //add conservative angular motion | 
|---|
|  | 91 | btScalar angularMotion = angvel.length() * getAngularMotionDisc() * timeStep; | 
|---|
|  | 92 | btVector3 angularMotion3d(angularMotion,angularMotion,angularMotion); | 
|---|
|  | 93 | temporalAabbMin = btVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz); | 
|---|
|  | 94 | temporalAabbMax = btVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz); | 
|---|
|  | 95 |  | 
|---|
|  | 96 | temporalAabbMin -= angularMotion3d; | 
|---|
|  | 97 | temporalAabbMax += angularMotion3d; | 
|---|
|  | 98 | } | 
|---|