Back to index

supertuxkart  0.5+dfsg1
btCompoundShape.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 "btCompoundShape.h"
00017 
00018 
00019 #include "btCollisionShape.h"
00020 
00021 
00022 btCompoundShape::btCompoundShape()
00023 :m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
00024 m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
00025 m_aabbTree(0),
00026 m_collisionMargin(btScalar(0.)),
00027 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
00028 {
00029 }
00030 
00031 
00032 btCompoundShape::~btCompoundShape()
00033 {
00034 }
00035 
00036 void   btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape)
00037 {
00038        //m_childTransforms.push_back(localTransform);
00039        //m_childShapes.push_back(shape);
00040        btCompoundShapeChild child;
00041        child.m_transform = localTransform;
00042        child.m_childShape = shape;
00043        child.m_childShapeType = shape->getShapeType();
00044        child.m_childMargin = shape->getMargin();
00045 
00046        m_children.push_back(child);
00047 
00048        //extend the local aabbMin/aabbMax
00049        btVector3 localAabbMin,localAabbMax;
00050        shape->getAabb(localTransform,localAabbMin,localAabbMax);
00051        for (int i=0;i<3;i++)
00052        {
00053               if (m_localAabbMin[i] > localAabbMin[i])
00054               {
00055                      m_localAabbMin[i] = localAabbMin[i];
00056               }
00057               if (m_localAabbMax[i] < localAabbMax[i])
00058               {
00059                      m_localAabbMax[i] = localAabbMax[i];
00060               }
00061 
00062        }
00063 }
00064 
00065 
00066 
00068 void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
00069 {
00070        btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
00071        btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
00072        
00073        btMatrix3x3 abs_b = trans.getBasis().absolute();  
00074 
00075        btPoint3 center = trans(localCenter);
00076 
00077        btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
00078                  abs_b[1].dot(localHalfExtents),
00079                 abs_b[2].dot(localHalfExtents));
00080        extent += btVector3(getMargin(),getMargin(),getMargin());
00081 
00082        aabbMin = center - extent;
00083        aabbMax = center + extent;
00084 }
00085 
00086 void   btCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
00087 {
00088        //approximation: take the inertia from the aabb for now
00089        btTransform ident;
00090        ident.setIdentity();
00091        btVector3 aabbMin,aabbMax;
00092        getAabb(ident,aabbMin,aabbMax);
00093        
00094        btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5);
00095        
00096        btScalar lx=btScalar(2.)*(halfExtents.x());
00097        btScalar ly=btScalar(2.)*(halfExtents.y());
00098        btScalar lz=btScalar(2.)*(halfExtents.z());
00099 
00100        inertia[0] = mass/(btScalar(12.0)) * (ly*ly + lz*lz);
00101        inertia[1] = mass/(btScalar(12.0)) * (lx*lx + lz*lz);
00102        inertia[2] = mass/(btScalar(12.0)) * (lx*lx + ly*ly);
00103 
00104 }
00105 
00106        
00107