Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.h @ 10022

Last change on this file since 10022 was 8393, checked in by rgrieder, 14 years ago

Updated Bullet from v2.77 to v2.78.
(I'm not going to make a branch for that since the update from 2.74 to 2.77 hasn't been tested that much either).

You will HAVE to do a complete RECOMPILE! I tested with MSVC and MinGW and they both threw linker errors at me.

  • Property svn:eol-style set to native
File size: 5.8 KB
RevLine 
[1963]1/*
2Bullet Continuous Collision Detection and Physics Library
[8351]3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
[1963]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
[8393]16#ifndef BT_CYLINDER_MINKOWSKI_H
17#define BT_CYLINDER_MINKOWSKI_H
[1963]18
19#include "btBoxShape.h"
20#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
21#include "LinearMath/btVector3.h"
22
23/// The btCylinderShape class implements a cylinder shape primitive, centered around the origin. Its central axis aligned with the Y axis. btCylinderShapeX is aligned with the X axis and btCylinderShapeZ around the Z axis.
[8351]24class btCylinderShape : public btConvexInternalShape
[1963]25
26{
27
28protected:
29
30        int     m_upAxis;
31
32public:
[8351]33
34        btVector3 getHalfExtentsWithMargin() const
35        {
36                btVector3 halfExtents = getHalfExtentsWithoutMargin();
37                btVector3 margin(getMargin(),getMargin(),getMargin());
38                halfExtents += margin;
39                return halfExtents;
40        }
41       
42        const btVector3& getHalfExtentsWithoutMargin() const
43        {
44                return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included
45        }
46
[1963]47        btCylinderShape (const btVector3& halfExtents);
48       
49        void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
50
[8351]51        virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
52
[1963]53        virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
54
55        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
56
[8351]57        virtual void setMargin(btScalar collisionMargin)
58        {
59                //correct the m_implicitShapeDimensions for the margin
60                btVector3 oldMargin(getMargin(),getMargin(),getMargin());
61                btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
62               
63                btConvexInternalShape::setMargin(collisionMargin);
64                btVector3 newMargin(getMargin(),getMargin(),getMargin());
65                m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
66
67        }
68
[1963]69        virtual btVector3       localGetSupportingVertex(const btVector3& vec) const
70        {
71
72                btVector3 supVertex;
73                supVertex = localGetSupportingVertexWithoutMargin(vec);
74               
75                if ( getMargin()!=btScalar(0.) )
76                {
77                        btVector3 vecnorm = vec;
78                        if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
79                        {
80                                vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
81                        } 
82                        vecnorm.normalize();
83                        supVertex+= getMargin() * vecnorm;
84                }
85                return supVertex;
86        }
87
88
89        //use box inertia
90        //      virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
91
92
93        int     getUpAxis() const
94        {
95                return m_upAxis;
96        }
97
98        virtual btScalar getRadius() const
99        {
100                return getHalfExtentsWithMargin().getX();
101        }
102
[8351]103        virtual void    setLocalScaling(const btVector3& scaling)
104        {
105                btVector3 oldMargin(getMargin(),getMargin(),getMargin());
106                btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
107                btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
108
109                btConvexInternalShape::setLocalScaling(scaling);
110
111                m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
112
113        }
114
[1963]115        //debugging
116        virtual const char*     getName()const
117        {
118                return "CylinderY";
119        }
120
[8351]121        virtual int     calculateSerializeBufferSize() const;
[1963]122
[8351]123        ///fills the dataBuffer and returns the struct name (and 0 on failure)
124        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
[1963]125
126};
127
128class btCylinderShapeX : public btCylinderShape
129{
130public:
131        btCylinderShapeX (const btVector3& halfExtents);
132
133        virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
134        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
135       
136                //debugging
137        virtual const char*     getName()const
138        {
139                return "CylinderX";
140        }
141
142        virtual btScalar getRadius() const
143        {
144                return getHalfExtentsWithMargin().getY();
145        }
146
147};
148
149class btCylinderShapeZ : public btCylinderShape
150{
151public:
152        btCylinderShapeZ (const btVector3& halfExtents);
153
154        virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
155        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
156
157                //debugging
158        virtual const char*     getName()const
159        {
160                return "CylinderZ";
161        }
162
163        virtual btScalar getRadius() const
164        {
165                return getHalfExtentsWithMargin().getX();
166        }
167
168};
169
[8351]170///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
171struct  btCylinderShapeData
172{
173        btConvexInternalShapeData       m_convexInternalShapeData;
[1963]174
[8351]175        int     m_upAxis;
176
177        char    m_padding[4];
178};
179
180SIMD_FORCE_INLINE       int     btCylinderShape::calculateSerializeBufferSize() const
181{
182        return sizeof(btCylinderShapeData);
183}
184
185        ///fills the dataBuffer and returns the struct name (and 0 on failure)
186SIMD_FORCE_INLINE       const char*     btCylinderShape::serialize(void* dataBuffer, btSerializer* serializer) const
187{
188        btCylinderShapeData* shapeData = (btCylinderShapeData*) dataBuffer;
189       
190        btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
191
192        shapeData->m_upAxis = m_upAxis;
193       
194        return "btCylinderShapeData";
195}
196
197
198
[8393]199#endif //BT_CYLINDER_MINKOWSKI_H
[1963]200
Note: See TracBrowser for help on using the repository browser.