Blender  V3.3
btCapsuleShape.cpp
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 #include "btCapsuleShape.h"
17 
19 
21 {
22  m_collisionMargin = radius;
23  m_shapeType = CAPSULE_SHAPE_PROXYTYPE;
24  m_upAxis = 1;
25  m_implicitShapeDimensions.setValue(radius, 0.5f * height, radius);
26 }
27 
29 {
30  btVector3 supVec(0, 0, 0);
31 
33 
34  btVector3 vec = vec0;
35  btScalar lenSqr = vec.length2();
36  if (lenSqr < btScalar(0.0001))
37  {
38  vec.setValue(1, 0, 0);
39  }
40  else
41  {
42  btScalar rlen = btScalar(1.) / btSqrt(lenSqr);
43  vec *= rlen;
44  }
45 
46  btVector3 vtx;
47  btScalar newDot;
48 
49  {
50  btVector3 pos(0, 0, 0);
52 
53  vtx = pos;
54  newDot = vec.dot(vtx);
55  if (newDot > maxDot)
56  {
57  maxDot = newDot;
58  supVec = vtx;
59  }
60  }
61  {
62  btVector3 pos(0, 0, 0);
63  pos[getUpAxis()] = -getHalfHeight();
64 
65  vtx = pos;
66  newDot = vec.dot(vtx);
67  if (newDot > maxDot)
68  {
69  maxDot = newDot;
70  supVec = vtx;
71  }
72  }
73 
74  return supVec;
75 }
76 
77 void btCapsuleShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
78 {
79  for (int j = 0; j < numVectors; j++)
80  {
82  const btVector3& vec = vectors[j];
83 
84  btVector3 vtx;
85  btScalar newDot;
86  {
87  btVector3 pos(0, 0, 0);
89  vtx = pos;
90  newDot = vec.dot(vtx);
91  if (newDot > maxDot)
92  {
93  maxDot = newDot;
94  supportVerticesOut[j] = vtx;
95  }
96  }
97  {
98  btVector3 pos(0, 0, 0);
99  pos[getUpAxis()] = -getHalfHeight();
100  vtx = pos;
101  newDot = vec.dot(vtx);
102  if (newDot > maxDot)
103  {
104  maxDot = newDot;
105  supportVerticesOut[j] = vtx;
106  }
107  }
108  }
109 }
110 
112 {
113  //as an approximation, take the inertia of the box that bounds the spheres
114 
115  btTransform ident;
116  ident.setIdentity();
117 
118  btScalar radius = getRadius();
119 
120  btVector3 halfExtents(radius, radius, radius);
121  halfExtents[getUpAxis()] += getHalfHeight();
122 
123  btScalar lx = btScalar(2.) * (halfExtents[0]);
124  btScalar ly = btScalar(2.) * (halfExtents[1]);
125  btScalar lz = btScalar(2.) * (halfExtents[2]);
126  const btScalar x2 = lx * lx;
127  const btScalar y2 = ly * ly;
128  const btScalar z2 = lz * lz;
129  const btScalar scaledmass = mass * btScalar(.08333333);
130 
131  inertia[0] = scaledmass * (y2 + z2);
132  inertia[1] = scaledmass * (x2 + z2);
133  inertia[2] = scaledmass * (x2 + y2);
134 }
135 
137 {
138  m_collisionMargin = radius;
139  m_upAxis = 0;
140  m_implicitShapeDimensions.setValue(0.5f * height, radius, radius);
141 }
142 
144 {
145  m_collisionMargin = radius;
146  m_upAxis = 2;
147  m_implicitShapeDimensions.setValue(radius, radius, 0.5f * height);
148 }
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble x2
SIMD_FORCE_INLINE btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
btConvexShape Interface
Definition: btBox2dShape.h:62
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
Definition: btConeShape.h:54
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
Definition: btBox2dShape.h:71
@ CAPSULE_SHAPE_PROXYTYPE
btScalar getRadius() const
int getUpAxis() const
btCapsuleShape()
only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
btScalar getHalfHeight() const
btScalar m_collisionMargin
btConvexInternalShape()
btVector3 m_implicitShapeDimensions
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define BT_LARGE_FLOAT
Definition: btScalar.h:316
SIMD_FORCE_INLINE btScalar btSqrt(btScalar y)
Definition: btScalar.h:466
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
SIMD_FORCE_INLINE long maxDot(const btVector3 *array, long array_count, btScalar &dotOut) const
returns index of maximum dot product between this and vectors in array[]
Definition: btVector3.h:998
btCapsuleShapeX(btScalar radius, btScalar height)
btCapsuleShapeZ(btScalar radius, btScalar height)
uint pos