Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource3/src/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp @ 5739

Last change on this file since 5739 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
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#include "btCylinderShape.h"
16
17btCylinderShape::btCylinderShape (const btVector3& halfExtents)
18:btBoxShape(halfExtents),
19m_upAxis(1)
20{
21        m_shapeType = CYLINDER_SHAPE_PROXYTYPE;
22        recalcLocalAabb();
23}
24
25
26btCylinderShapeX::btCylinderShapeX (const btVector3& halfExtents)
27:btCylinderShape(halfExtents)
28{
29        m_upAxis = 0;
30        recalcLocalAabb();
31}
32
33
34btCylinderShapeZ::btCylinderShapeZ (const btVector3& halfExtents)
35:btCylinderShape(halfExtents)
36{
37        m_upAxis = 2;
38        recalcLocalAabb();
39}
40
41void btCylinderShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
42{
43        //skip the box 'getAabb'
44        btPolyhedralConvexShape::getAabb(t,aabbMin,aabbMax);
45}
46
47
48SIMD_FORCE_INLINE btVector3 CylinderLocalSupportX(const btVector3& halfExtents,const btVector3& v) 
49{
50const int cylinderUpAxis = 0;
51const int XX = 1;
52const int YY = 0;
53const int ZZ = 2;
54
55        //mapping depends on how cylinder local orientation is
56        // extents of the cylinder is: X,Y is for radius, and Z for height
57
58
59        btScalar radius = halfExtents[XX];
60        btScalar halfHeight = halfExtents[cylinderUpAxis];
61
62
63    btVector3 tmp;
64        btScalar d ;
65
66    btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
67    if (s != btScalar(0.0))
68        {
69        d = radius / s; 
70                tmp[XX] = v[XX] * d;
71                tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
72                tmp[ZZ] = v[ZZ] * d;
73                return tmp;
74        }
75    else
76        {
77            tmp[XX] = radius;
78                tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
79                tmp[ZZ] = btScalar(0.0);
80                return tmp;
81    }
82
83
84}
85
86
87
88
89
90
91inline  btVector3 CylinderLocalSupportY(const btVector3& halfExtents,const btVector3& v) 
92{
93
94const int cylinderUpAxis = 1;
95const int XX = 0;
96const int YY = 1;
97const int ZZ = 2;
98
99
100        btScalar radius = halfExtents[XX];
101        btScalar halfHeight = halfExtents[cylinderUpAxis];
102
103
104    btVector3 tmp;
105        btScalar d ;
106
107    btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
108    if (s != btScalar(0.0))
109        {
110        d = radius / s; 
111                tmp[XX] = v[XX] * d;
112                tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
113                tmp[ZZ] = v[ZZ] * d;
114                return tmp;
115        }
116    else
117        {
118            tmp[XX] = radius;
119                tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
120                tmp[ZZ] = btScalar(0.0);
121                return tmp;
122    }
123
124}
125
126inline btVector3 CylinderLocalSupportZ(const btVector3& halfExtents,const btVector3& v) 
127{
128const int cylinderUpAxis = 2;
129const int XX = 0;
130const int YY = 2;
131const int ZZ = 1;
132
133        //mapping depends on how cylinder local orientation is
134        // extents of the cylinder is: X,Y is for radius, and Z for height
135
136
137        btScalar radius = halfExtents[XX];
138        btScalar halfHeight = halfExtents[cylinderUpAxis];
139
140
141    btVector3 tmp;
142        btScalar d ;
143
144    btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
145    if (s != btScalar(0.0))
146        {
147        d = radius / s; 
148                tmp[XX] = v[XX] * d;
149                tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
150                tmp[ZZ] = v[ZZ] * d;
151                return tmp;
152        }
153    else
154        {
155            tmp[XX] = radius;
156                tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
157                tmp[ZZ] = btScalar(0.0);
158                return tmp;
159    }
160
161
162}
163
164btVector3       btCylinderShapeX::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
165{
166        return CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vec);
167}
168
169
170btVector3       btCylinderShapeZ::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
171{
172        return CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vec);
173}
174btVector3       btCylinderShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
175{
176        return CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vec);
177}
178
179void    btCylinderShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
180{
181        for (int i=0;i<numVectors;i++)
182        {
183                supportVerticesOut[i] = CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vectors[i]);
184        }
185}
186
187void    btCylinderShapeZ::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
188{
189        for (int i=0;i<numVectors;i++)
190        {
191                supportVerticesOut[i] = CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vectors[i]);
192        }
193}
194
195
196
197
198void    btCylinderShapeX::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
199{
200        for (int i=0;i<numVectors;i++)
201        {
202                supportVerticesOut[i] = CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vectors[i]);
203        }
204}
205
206
Note: See TracBrowser for help on using the repository browser.