Back to index

supertuxkart  0.5+dfsg1
btCylinderShape.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 #include "btCylinderShape.h"
00016 #include "LinearMath/btPoint3.h"
00017 
00018 btCylinderShape::btCylinderShape (const btVector3& halfExtents)
00019 :btBoxShape(halfExtents),
00020 m_upAxis(1)
00021 {
00022        recalcLocalAabb();
00023 }
00024 
00025 
00026 btCylinderShapeX::btCylinderShapeX (const btVector3& halfExtents)
00027 :btCylinderShape(halfExtents)
00028 {
00029        m_upAxis = 0;
00030        recalcLocalAabb();
00031 }
00032 
00033 
00034 btCylinderShapeZ::btCylinderShapeZ (const btVector3& halfExtents)
00035 :btCylinderShape(halfExtents)
00036 {
00037        m_upAxis = 2;
00038        recalcLocalAabb();
00039 }
00040 
00041 void btCylinderShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
00042 {
00043        //skip the box 'getAabb'
00044        btPolyhedralConvexShape::getAabb(t,aabbMin,aabbMax);
00045 }
00046 
00047 
00048 SIMD_FORCE_INLINE btVector3 CylinderLocalSupportX(const btVector3& halfExtents,const btVector3& v) 
00049 {
00050 const int cylinderUpAxis = 0;
00051 const int XX = 1;
00052 const int YY = 0;
00053 const int ZZ = 2;
00054 
00055        //mapping depends on how cylinder local orientation is
00056        // extents of the cylinder is: X,Y is for radius, and Z for height
00057 
00058 
00059        btScalar radius = halfExtents[XX];
00060        btScalar halfHeight = halfExtents[cylinderUpAxis];
00061 
00062 
00063     btVector3 tmp;
00064        btScalar d ;
00065 
00066     btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
00067     if (s != btScalar(0.0))
00068        {
00069         d = radius / s;  
00070               tmp[XX] = v[XX] * d;
00071               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00072               tmp[ZZ] = v[ZZ] * d;
00073               return tmp;
00074        }
00075     else
00076        {
00077            tmp[XX] = radius;
00078               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00079               tmp[ZZ] = btScalar(0.0);
00080               return tmp;
00081     }
00082 
00083 
00084 }
00085 
00086 
00087 
00088 
00089 
00090 
00091 inline  btVector3 CylinderLocalSupportY(const btVector3& halfExtents,const btVector3& v) 
00092 {
00093 
00094 const int cylinderUpAxis = 1;
00095 const int XX = 0;
00096 const int YY = 1;
00097 const int ZZ = 2;
00098 
00099 
00100        btScalar radius = halfExtents[XX];
00101        btScalar halfHeight = halfExtents[cylinderUpAxis];
00102 
00103 
00104     btVector3 tmp;
00105        btScalar d ;
00106 
00107     btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
00108     if (s != btScalar(0.0))
00109        {
00110         d = radius / s;  
00111               tmp[XX] = v[XX] * d;
00112               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00113               tmp[ZZ] = v[ZZ] * d;
00114               return tmp;
00115        }
00116     else
00117        {
00118            tmp[XX] = radius;
00119               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00120               tmp[ZZ] = btScalar(0.0);
00121               return tmp;
00122     }
00123 
00124 }
00125 
00126 inline btVector3 CylinderLocalSupportZ(const btVector3& halfExtents,const btVector3& v) 
00127 {
00128 const int cylinderUpAxis = 2;
00129 const int XX = 0;
00130 const int YY = 2;
00131 const int ZZ = 1;
00132 
00133        //mapping depends on how cylinder local orientation is
00134        // extents of the cylinder is: X,Y is for radius, and Z for height
00135 
00136 
00137        btScalar radius = halfExtents[XX];
00138        btScalar halfHeight = halfExtents[cylinderUpAxis];
00139 
00140 
00141     btVector3 tmp;
00142        btScalar d ;
00143 
00144     btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
00145     if (s != btScalar(0.0))
00146        {
00147         d = radius / s;  
00148               tmp[XX] = v[XX] * d;
00149               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00150               tmp[ZZ] = v[ZZ] * d;
00151               return tmp;
00152        }
00153     else
00154        {
00155            tmp[XX] = radius;
00156               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00157               tmp[ZZ] = btScalar(0.0);
00158               return tmp;
00159     }
00160 
00161 
00162 }
00163 
00164 btVector3     btCylinderShapeX::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
00165 {
00166        return CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vec);
00167 }
00168 
00169 
00170 btVector3     btCylinderShapeZ::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
00171 {
00172        return CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vec);
00173 }
00174 btVector3     btCylinderShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
00175 {
00176        return CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vec);
00177 }
00178 
00179 void   btCylinderShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
00180 {
00181        for (int i=0;i<numVectors;i++)
00182        {
00183               supportVerticesOut[i] = CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vectors[i]);
00184        }
00185 }
00186 
00187 void   btCylinderShapeZ::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
00188 {
00189        for (int i=0;i<numVectors;i++)
00190        {
00191               supportVerticesOut[i] = CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vectors[i]);
00192        }
00193 }
00194 
00195 
00196 
00197 
00198 void   btCylinderShapeX::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
00199 {
00200        for (int i=0;i<numVectors;i++)
00201        {
00202               supportVerticesOut[i] = CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vectors[i]);
00203        }
00204 }
00205 
00206