Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp @ 1997

Last change on this file since 1997 was 1963, checked in by rgrieder, 16 years ago

Added Bullet physics engine.

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