Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp @ 7287

Last change on this file since 7287 was 5781, checked in by rgrieder, 15 years ago

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#include "BulletCollision/CollisionShapes/btCollisionShape.h"
17
18
19btScalar gContactThresholdFactor=btScalar(0.02);
20
21
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*/
27extern "C" 
28{
29void btBulletCollisionProbe ();
30
31void btBulletCollisionProbe () {}
32}
33
34
35
36void    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
48btScalar        btCollisionShape::getContactBreakingThreshold() const
49{
50        return getAngularMotionDisc() * gContactThresholdFactor;
51}
52btScalar        btCollisionShape::getAngularMotionDisc() const
53{
54        ///@todo cache this value, to improve performance
55        btVector3       center;
56        btScalar disc;
57        getBoundingSphere(center,disc);
58        disc += (center).length();
59        return disc;
60}
61
62void 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;
76        ///@todo: simd would have a vector max/min operation, instead of per-element access
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}
Note: See TracBrowser for help on using the repository browser.