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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btConvexInternalShape.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
17 #include "btConvexInternalShape.h"
18
19
20
21 btConvexInternalShape::btConvexInternalShape()
22 : m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
23 m_collisionMargin(CONVEX_DISTANCE_MARGIN)
24 {
25 }
26
27
28 void btConvexInternalShape::setLocalScaling(const btVector3& scaling)
29 {
30 m_localScaling = scaling.absolute();
31 }
32
33
34
35 void btConvexInternalShape::getAabbSlow(const btTransform& trans,btVector3&minAabb,btVector3&maxAabb) const
36 {
37 #ifndef __SPU__
38 //use localGetSupportingVertexWithoutMargin?
39 btScalar margin = getMargin();
40 for (int i=0;i<3;i++)
41 {
42 btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
43 vec[i] = btScalar(1.);
44
45 btVector3 sv = localGetSupportingVertex(vec*trans.getBasis());
46
47 btVector3 tmp = trans(sv);
48 maxAabb[i] = tmp[i]+margin;
49 vec[i] = btScalar(-1.);
50 tmp = trans(localGetSupportingVertex(vec*trans.getBasis()));
51 minAabb[i] = tmp[i]-margin;
52 }
53 #endif
54 }
55
56
57
58 btVector3 btConvexInternalShape::localGetSupportingVertex(const btVector3& vec)const
59 {
60 #ifndef __SPU__
61
62 btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
63
64 if ( getMargin()!=btScalar(0.) )
65 {
66 btVector3 vecnorm = vec;
67 if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
68 {
69 vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
70 }
71 vecnorm.normalize();
72 supVertex+= getMargin() * vecnorm;
73 }
74 return supVertex;
75
76 #else
77 btAssert(0);
78 return btVector3(0,0,0);
79 #endif //__SPU__
80
81 }
82
83
84 btConvexInternalAabbCachingShape::btConvexInternalAabbCachingShape()
85 : btConvexInternalShape(),
86 m_localAabbMin(1,1,1),
87 m_localAabbMax(-1,-1,-1),
88 m_isLocalAabbValid(false)
89 {
90 }
91
92
93 void btConvexInternalAabbCachingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
94 {
95 getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin());
96 }
97
98 void btConvexInternalAabbCachingShape::setLocalScaling(const btVector3& scaling)
99 {
100 btConvexInternalShape::setLocalScaling(scaling);
101 recalcLocalAabb();
102 }
103
104
105 void btConvexInternalAabbCachingShape::recalcLocalAabb()
106 {
107 m_isLocalAabbValid = true;
108
109 #if 1
110 static const btVector3 _directions[] =
111 {
112 btVector3( 1., 0., 0.),
113 btVector3( 0., 1., 0.),
114 btVector3( 0., 0., 1.),
115 btVector3( -1., 0., 0.),
116 btVector3( 0., -1., 0.),
117 btVector3( 0., 0., -1.)
118 };
119
120 btVector3 _supporting[] =
121 {
122 btVector3( 0., 0., 0.),
123 btVector3( 0., 0., 0.),
124 btVector3( 0., 0., 0.),
125 btVector3( 0., 0., 0.),
126 btVector3( 0., 0., 0.),
127 btVector3( 0., 0., 0.)
128 };
129
130 batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
131
132 for ( int i = 0; i < 3; ++i )
133 {
134 m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
135 m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
136 }
137
138 #else
139
140 for (int i=0;i<3;i++)
141 {
142 btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
143 vec[i] = btScalar(1.);
144 btVector3 tmp = localGetSupportingVertex(vec);
145 m_localAabbMax[i] = tmp[i]+m_collisionMargin;
146 vec[i] = btScalar(-1.);
147 tmp = localGetSupportingVertex(vec);
148 m_localAabbMin[i] = tmp[i]-m_collisionMargin;
149 }
150 #endif
151 }
SIMD_EPSILON
#define SIMD_EPSILON
Definition: btScalar.h:494
CONVEX_DISTANCE_MARGIN
#define CONVEX_DISTANCE_MARGIN
The CONVEX_DISTANCE_MARGIN is a default collision margin for convex collision shapes derived from btC...
Definition: btCollisionMargin.h:22
btConvexInternalShape::m_collisionMargin
btScalar m_collisionMargin
Definition: btConvexInternalShape.h:39
btVector3::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:640
btConvexInternalShape
The btConvexInternalShape is an internal base class, shared by most convex shape implementations.
Definition: btConvexInternalShape.h:29
btAssert
#define btAssert(x)
Definition: btScalar.h:113
btConvexInternalAabbCachingShape::m_localAabbMax
btVector3 m_localAabbMax
Definition: btConvexInternalShape.h:185
btVector3::absolute
btVector3 absolute() const
Return a vector will the absolute values of each element.
Definition: btVector3.h:360
btConvexInternalShape::btConvexInternalShape
btConvexInternalShape()
Definition: btConvexInternalShape.cpp:21
btConvexInternalShape::m_localScaling
btVector3 m_localScaling
Definition: btConvexInternalShape.h:35
btConvexShape::localGetSupportingVertexWithoutMargin
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const =0
btConvexInternalShape::getMargin
virtual btScalar getMargin() const
Definition: btConvexInternalShape.h:113
btVector3::normalize
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition: btVector3.h:297
btConvexInternalAabbCachingShape::getNonvirtualAabb
void getNonvirtualAabb(const btTransform &trans, btVector3 &aabbMin, btVector3 &aabbMax, btScalar margin) const
Definition: btConvexInternalShape.h:206
btTransform::getBasis
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
btConvexInternalShape.h
btConvexShape::batchedUnitVectorGetSupportingVertexWithoutMargin
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const =0
btConvexInternalShape::localGetSupportingVertex
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const
Definition: btConvexInternalShape.cpp:58
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btConvexInternalAabbCachingShape::btConvexInternalAabbCachingShape
btConvexInternalAabbCachingShape()
Definition: btConvexInternalShape.cpp:84
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btConvexInternalAabbCachingShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)
Definition: btConvexInternalShape.cpp:98
btConvexInternalShape::getAabbSlow
virtual void getAabbSlow(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
Definition: btConvexInternalShape.cpp:35
btConvexInternalAabbCachingShape::recalcLocalAabb
void recalcLocalAabb()
Definition: btConvexInternalShape.cpp:105
btConvexInternalShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)
Definition: btConvexInternalShape.cpp:28
btConvexInternalAabbCachingShape::m_isLocalAabbValid
bool m_isLocalAabbValid
Definition: btConvexInternalShape.h:186
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278
btConvexInternalAabbCachingShape::m_localAabbMin
btVector3 m_localAabbMin
Definition: btConvexInternalShape.h:184
btConvexInternalAabbCachingShape::getAabb
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb's default implementation is brute force, expected derived classes to implement a fast dedicat...
Definition: btConvexInternalShape.cpp:93