Bullet Collision Detection & Physics Library
btConeShape.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef BT_CONE_MINKOWSKI_H
17 #define BT_CONE_MINKOWSKI_H
18 
19 #include "btConvexInternalShape.h"
21 
24 
25 {
26 
30  int m_coneIndices[3];
31  btVector3 coneLocalSupport(const btVector3& v) const;
32 
33 
34 public:
36 
37  btConeShape (btScalar radius,btScalar height);
38 
39  virtual btVector3 localGetSupportingVertex(const btVector3& vec) const;
40  virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
41  virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
42 
43  btScalar getRadius() const { return m_radius;}
44  btScalar getHeight() const { return m_height;}
45 
46 
47  virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const
48  {
49  btTransform identity;
50  identity.setIdentity();
51  btVector3 aabbMin,aabbMax;
52  getAabb(identity,aabbMin,aabbMax);
53 
54  btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5);
55 
56  btScalar margin = getMargin();
57 
58  btScalar lx=btScalar(2.)*(halfExtents.x()+margin);
59  btScalar ly=btScalar(2.)*(halfExtents.y()+margin);
60  btScalar lz=btScalar(2.)*(halfExtents.z()+margin);
61  const btScalar x2 = lx*lx;
62  const btScalar y2 = ly*ly;
63  const btScalar z2 = lz*lz;
64  const btScalar scaledmass = mass * btScalar(0.08333333);
65 
66  inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
67 
68 // inertia.x() = scaledmass * (y2+z2);
69 // inertia.y() = scaledmass * (x2+z2);
70 // inertia.z() = scaledmass * (x2+y2);
71  }
72 
73 
74  virtual const char* getName()const
75  {
76  return "Cone";
77  }
78 
80  void setConeUpIndex(int upIndex);
81 
82  int getConeUpIndex() const
83  {
84  return m_coneIndices[1];
85  }
86 
88  {
89  return btVector3 (0,1,0);
90  }
91 
92  virtual void setLocalScaling(const btVector3& scaling);
93 
94 };
95 
97 class btConeShapeX : public btConeShape
98 {
99  public:
100  btConeShapeX(btScalar radius,btScalar height);
101 
103  {
104  return btVector3 (1,0,0);
105  }
106 
107 };
108 
110 class btConeShapeZ : public btConeShape
111 {
112  public:
113  btConeShapeZ(btScalar radius,btScalar height);
114 
116  {
117  return btVector3 (0,0,1);
118  }
119 
120 };
121 #endif //BT_CONE_MINKOWSKI_H
122