btConeShape.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
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 #ifndef BT_CONE_MINKOWSKI_H
00017 #define BT_CONE_MINKOWSKI_H
00018 
00019 #include "btConvexInternalShape.h"
00020 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
00021 
00023 ATTRIBUTE_ALIGNED16(class) btConeShape : public btConvexInternalShape
00024 
00025 {
00026 
00027         btScalar m_sinAngle;
00028         btScalar m_radius;
00029         btScalar m_height;
00030         int             m_coneIndices[3];
00031         btVector3 coneLocalSupport(const btVector3& v) const;
00032 
00033 
00034 public:
00035         BT_DECLARE_ALIGNED_ALLOCATOR();
00036         
00037         btConeShape (btScalar radius,btScalar height);
00038         
00039         virtual btVector3       localGetSupportingVertex(const btVector3& vec) const;
00040         virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
00041         virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
00042 
00043         btScalar getRadius() const { return m_radius;}
00044         btScalar getHeight() const { return m_height;}
00045 
00046 
00047         virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const
00048         {
00049                 btTransform identity;
00050                 identity.setIdentity();
00051                 btVector3 aabbMin,aabbMax;
00052                 getAabb(identity,aabbMin,aabbMax);
00053 
00054                 btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5);
00055 
00056                 btScalar margin = getMargin();
00057 
00058                 btScalar lx=btScalar(2.)*(halfExtents.x()+margin);
00059                 btScalar ly=btScalar(2.)*(halfExtents.y()+margin);
00060                 btScalar lz=btScalar(2.)*(halfExtents.z()+margin);
00061                 const btScalar x2 = lx*lx;
00062                 const btScalar y2 = ly*ly;
00063                 const btScalar z2 = lz*lz;
00064                 const btScalar scaledmass = mass * btScalar(0.08333333);
00065 
00066                 inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
00067 
00068 //              inertia.x() = scaledmass * (y2+z2);
00069 //              inertia.y() = scaledmass * (x2+z2);
00070 //              inertia.z() = scaledmass * (x2+y2);
00071         }
00072 
00073 
00074                 virtual const char*     getName()const 
00075                 {
00076                         return "Cone";
00077                 }
00078                 
00080                 void    setConeUpIndex(int upIndex);
00081                 
00082                 int     getConeUpIndex() const
00083                 {
00084                         return m_coneIndices[1];
00085                 }
00086 
00087         virtual btVector3       getAnisotropicRollingFrictionDirection() const
00088         {
00089                 return btVector3 (0,1,0);
00090         }
00091 
00092         virtual void    setLocalScaling(const btVector3& scaling);
00093 
00094 };
00095 
00097 class btConeShapeX : public btConeShape
00098 {
00099         public:
00100                 btConeShapeX(btScalar radius,btScalar height);
00101 
00102         virtual btVector3       getAnisotropicRollingFrictionDirection() const
00103         {
00104                 return btVector3 (1,0,0);
00105         }
00106 
00107 };
00108 
00110 class btConeShapeZ : public btConeShape
00111 {
00112         public:
00113                 btConeShapeZ(btScalar radius,btScalar height);
00114 
00115         virtual btVector3       getAnisotropicRollingFrictionDirection() const
00116         {
00117                 return btVector3 (0,0,1);
00118         }
00119 
00120 };
00121 #endif //BT_CONE_MINKOWSKI_H
00122