Back to index

supertuxkart  0.5+dfsg1
btCollisionShape.cpp
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
00017 
00018 
00019 /*
00020   Make sure this dummy function never changes so that it
00021   can be used by probes that are checking whether the
00022   library is actually installed.
00023 */
00024 extern "C" void btBulletCollisionProbe () {}
00025 
00026 
00027 
00028 void   btCollisionShape::getBoundingSphere(btVector3& center,btScalar& radius) const
00029 {
00030        btTransform tr;
00031        tr.setIdentity();
00032        btVector3 aabbMin,aabbMax;
00033 
00034        getAabb(tr,aabbMin,aabbMax);
00035 
00036        radius = (aabbMax-aabbMin).length()*btScalar(0.5);
00037        center = (aabbMin+aabbMax)*btScalar(0.5);
00038 }
00039 
00040 btScalar      btCollisionShape::getAngularMotionDisc() const
00041 {
00042        btVector3     center;
00043        btScalar disc;
00044        getBoundingSphere(center,disc);
00045        disc += (center).length();
00046        return disc;
00047 }
00048 
00049 void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const
00050 {
00051        //start with static aabb
00052        getAabb(curTrans,temporalAabbMin,temporalAabbMax);
00053 
00054        btScalar temporalAabbMaxx = temporalAabbMax.getX();
00055        btScalar temporalAabbMaxy = temporalAabbMax.getY();
00056        btScalar temporalAabbMaxz = temporalAabbMax.getZ();
00057        btScalar temporalAabbMinx = temporalAabbMin.getX();
00058        btScalar temporalAabbMiny = temporalAabbMin.getY();
00059        btScalar temporalAabbMinz = temporalAabbMin.getZ();
00060 
00061        // add linear motion
00062        btVector3 linMotion = linvel*timeStep;
00063        //todo: simd would have a vector max/min operation, instead of per-element access
00064        if (linMotion.x() > btScalar(0.))
00065               temporalAabbMaxx += linMotion.x(); 
00066        else
00067               temporalAabbMinx += linMotion.x();
00068        if (linMotion.y() > btScalar(0.))
00069               temporalAabbMaxy += linMotion.y(); 
00070        else
00071               temporalAabbMiny += linMotion.y();
00072        if (linMotion.z() > btScalar(0.))
00073               temporalAabbMaxz += linMotion.z(); 
00074        else
00075               temporalAabbMinz += linMotion.z();
00076 
00077        //add conservative angular motion
00078        btScalar angularMotion = angvel.length() * getAngularMotionDisc() * timeStep;
00079        btVector3 angularMotion3d(angularMotion,angularMotion,angularMotion);
00080        temporalAabbMin = btVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz);
00081        temporalAabbMax = btVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz);
00082 
00083        temporalAabbMin -= angularMotion3d;
00084        temporalAabbMax += angularMotion3d;
00085 }