Bullet Collision Detection & Physics Library: btUniformScalingShape.cpp Source File

Bullet Collision Detection & Physics Library

btUniformScalingShape.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 "btUniformScalingShape.h"
17
18 btUniformScalingShape::btUniformScalingShape( btConvexShape* convexChildShape,btScalar uniformScalingFactor):
19 btConvexShape (), m_childConvexShape(convexChildShape),
20 m_uniformScalingFactor(uniformScalingFactor)
21 {
22 m_shapeType = UNIFORM_SCALING_SHAPE_PROXYTYPE;
23 }
24
25 btUniformScalingShape::~btUniformScalingShape()
26 {
27 }
28
29
30 btVector3 btUniformScalingShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
31 {
32 btVector3 tmpVertex;
33 tmpVertex = m_childConvexShape->localGetSupportingVertexWithoutMargin(vec);
34 return tmpVertex*m_uniformScalingFactor;
35 }
36
37 void btUniformScalingShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
38 {
39 m_childConvexShape->batchedUnitVectorGetSupportingVertexWithoutMargin(vectors,supportVerticesOut,numVectors);
40 int i;
41 for (i=0;i<numVectors;i++)
42 {
43 supportVerticesOut[i] = supportVerticesOut[i] * m_uniformScalingFactor;
44 }
45 }
46
47
48 btVector3 btUniformScalingShape::localGetSupportingVertex(const btVector3& vec)const
49 {
50 btVector3 tmpVertex;
51 tmpVertex = m_childConvexShape->localGetSupportingVertex(vec);
52 return tmpVertex*m_uniformScalingFactor;
53 }
54
55
56 void btUniformScalingShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
57 {
58
60 btVector3 tmpInertia;
61 m_childConvexShape->calculateLocalInertia(mass,tmpInertia);
62 inertia = tmpInertia * m_uniformScalingFactor;
63 }
64
65
67 void btUniformScalingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
68 {
69 getAabbSlow(trans,aabbMin,aabbMax);
70
71 }
72
73 void btUniformScalingShape::getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
74 {
75 #if 1
76 btVector3 _directions[] =
77 {
78 btVector3( 1., 0., 0.),
79 btVector3( 0., 1., 0.),
80 btVector3( 0., 0., 1.),
81 btVector3( -1., 0., 0.),
82 btVector3( 0., -1., 0.),
83 btVector3( 0., 0., -1.)
84 };
85
86 btVector3 _supporting[] =
87 {
88 btVector3( 0., 0., 0.),
89 btVector3( 0., 0., 0.),
90 btVector3( 0., 0., 0.),
91 btVector3( 0., 0., 0.),
92 btVector3( 0., 0., 0.),
93 btVector3( 0., 0., 0.)
94 };
95
96 for (int i=0;i<6;i++)
97 {
98 _directions[i] = _directions[i]*t.getBasis();
99 }
100
101 batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
102
103 btVector3 aabbMin1(0,0,0),aabbMax1(0,0,0);
104
105 for ( int i = 0; i < 3; ++i )
106 {
107 aabbMax1[i] = t(_supporting[i])[i];
108 aabbMin1[i] = t(_supporting[i + 3])[i];
109 }
110 btVector3 marginVec(getMargin(),getMargin(),getMargin());
111 aabbMin = aabbMin1-marginVec;
112 aabbMax = aabbMax1+marginVec;
113
114 #else
115
116 btScalar margin = getMargin();
117 for (int i=0;i<3;i++)
118 {
119 btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
120 vec[i] = btScalar(1.);
121 btVector3 sv = localGetSupportingVertex(vec*t.getBasis());
122 btVector3 tmp = t(sv);
123 aabbMax[i] = tmp[i]+margin;
124 vec[i] = btScalar(-1.);
125 sv = localGetSupportingVertex(vec*t.getBasis());
126 tmp = t(sv);
127 aabbMin[i] = tmp[i]-margin;
128 }
129
130 #endif
131 }
132
133 void btUniformScalingShape::setLocalScaling(const btVector3& scaling)
134 {
135 m_childConvexShape->setLocalScaling(scaling);
136 }
137
138 const btVector3& btUniformScalingShape::getLocalScaling() const
139 {
140 return m_childConvexShape->getLocalScaling();
141 }
142
143 void btUniformScalingShape::setMargin(btScalar margin)
144 {
145 m_childConvexShape->setMargin(margin);
146 }
147 btScalar btUniformScalingShape::getMargin() const
148 {
149 return m_childConvexShape->getMargin() * m_uniformScalingFactor;
150 }
151
152 int btUniformScalingShape::getNumPreferredPenetrationDirections() const
153 {
154 return m_childConvexShape->getNumPreferredPenetrationDirections();
155 }
156
157 void btUniformScalingShape::getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
158 {
159 m_childConvexShape->getPreferredPenetrationDirection(index,penetrationVector);
160 }
btUniformScalingShape::btUniformScalingShape
btUniformScalingShape(btConvexShape *convexChildShape, btScalar uniformScalingFactor)
Definition: btUniformScalingShape.cpp:18
btConvexShape::localGetSupportingVertex
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const =0
btCollisionShape::calculateLocalInertia
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const =0
btConvexShape::getPreferredPenetrationDirection
virtual void getPreferredPenetrationDirection(int index, btVector3 &penetrationVector) const =0
btUniformScalingShape::calculateLocalInertia
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
Definition: btUniformScalingShape.cpp:56
btUniformScalingShape::setMargin
virtual void setMargin(btScalar margin)
Definition: btUniformScalingShape.cpp:143
btUniformScalingShape::getPreferredPenetrationDirection
virtual void getPreferredPenetrationDirection(int index, btVector3 &penetrationVector) const
Definition: btUniformScalingShape.cpp:157
btConvexShape::localGetSupportingVertexWithoutMargin
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const =0
btUniformScalingShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)
Definition: btUniformScalingShape.cpp:133
btUniformScalingShape::m_childConvexShape
btConvexShape * m_childConvexShape
Definition: btUniformScalingShape.h:26
btUniformScalingShape::getAabbSlow
virtual void getAabbSlow(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
Definition: btUniformScalingShape.cpp:73
btConvexShape
The btConvexShape is an abstract shape interface, implemented by all convex shapes such as btBoxShape...
Definition: btConvexShape.h:31
UNIFORM_SCALING_SHAPE_PROXYTYPE
Definition: btBroadphaseProxy.h:46
btUniformScalingShape::m_uniformScalingFactor
btScalar m_uniformScalingFactor
Definition: btUniformScalingShape.h:28
btConvexShape::getLocalScaling
virtual const btVector3 & getLocalScaling() const =0
btUniformScalingShape.h
btConvexShape::getNumPreferredPenetrationDirections
virtual int getNumPreferredPenetrationDirections() const =0
btTransform::getBasis
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
btUniformScalingShape::batchedUnitVectorGetSupportingVertexWithoutMargin
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
Definition: btUniformScalingShape.cpp:37
btConvexShape::batchedUnitVectorGetSupportingVertexWithoutMargin
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const =0
btConvexShape::getMargin
virtual btScalar getMargin() const =0
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btUniformScalingShape::getLocalScaling
virtual const btVector3 & getLocalScaling() const
Definition: btUniformScalingShape.cpp:138
btUniformScalingShape::localGetSupportingVertex
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const
Definition: btUniformScalingShape.cpp:48
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btUniformScalingShape::getMargin
virtual btScalar getMargin() const
Definition: btUniformScalingShape.cpp:147
btConvexShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)=0
btUniformScalingShape::getNumPreferredPenetrationDirections
virtual int getNumPreferredPenetrationDirections() const
Definition: btUniformScalingShape.cpp:152
btConvexShape::setMargin
virtual void setMargin(btScalar margin)=0
btUniformScalingShape::~btUniformScalingShape
virtual ~btUniformScalingShape()
Definition: btUniformScalingShape.cpp:25
btUniformScalingShape::localGetSupportingVertexWithoutMargin
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
Definition: btUniformScalingShape.cpp:30
btUniformScalingShape::getAabb
void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb&#39;s default implementation is brute force, expected derived classes to implement a fast dedicat...
Definition: btUniformScalingShape.cpp:67
btCollisionShape::m_shapeType
int m_shapeType
Definition: btCollisionShape.h:30
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279