Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/environment/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.cpp @ 8206

Last change on this file since 8206 was 5781, checked in by rgrieder, 15 years ago

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

  • Property svn:eol-style set to native
File size: 3.5 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
16#include "btConeShape.h"
17
18
19
20btConeShape::btConeShape (btScalar radius,btScalar height): btConvexInternalShape (),
21m_radius (radius),
22m_height(height)
23{
24        m_shapeType = CONE_SHAPE_PROXYTYPE;
25        setConeUpIndex(1);
26        btVector3 halfExtents;
27        m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height));
28}
29
30btConeShapeZ::btConeShapeZ (btScalar radius,btScalar height):
31btConeShape(radius,height)
32{
33        setConeUpIndex(2);
34}
35
36btConeShapeX::btConeShapeX (btScalar radius,btScalar height):
37btConeShape(radius,height)
38{
39        setConeUpIndex(0);
40}
41
42///choose upAxis index
43void    btConeShape::setConeUpIndex(int upIndex)
44{
45        switch (upIndex)
46        {
47        case 0:
48                        m_coneIndices[0] = 1;
49                        m_coneIndices[1] = 0;
50                        m_coneIndices[2] = 2;
51                break;
52        case 1:
53                        m_coneIndices[0] = 0;
54                        m_coneIndices[1] = 1;
55                        m_coneIndices[2] = 2;
56                break;
57        case 2:
58                        m_coneIndices[0] = 0;
59                        m_coneIndices[1] = 2;
60                        m_coneIndices[2] = 1;
61                break;
62        default:
63                btAssert(0);
64        };
65}
66
67btVector3 btConeShape::coneLocalSupport(const btVector3& v) const
68{
69       
70        btScalar halfHeight = m_height * btScalar(0.5);
71
72 if (v[m_coneIndices[1]] > v.length() * m_sinAngle)
73 {
74        btVector3 tmp;
75
76        tmp[m_coneIndices[0]] = btScalar(0.);
77        tmp[m_coneIndices[1]] = halfHeight;
78        tmp[m_coneIndices[2]] = btScalar(0.);
79        return tmp;
80 }
81  else {
82    btScalar s = btSqrt(v[m_coneIndices[0]] * v[m_coneIndices[0]] + v[m_coneIndices[2]] * v[m_coneIndices[2]]);
83    if (s > SIMD_EPSILON) {
84      btScalar d = m_radius / s;
85          btVector3 tmp;
86          tmp[m_coneIndices[0]] = v[m_coneIndices[0]] * d;
87          tmp[m_coneIndices[1]] = -halfHeight;
88          tmp[m_coneIndices[2]] = v[m_coneIndices[2]] * d;
89          return tmp;
90    }
91    else  {
92                btVector3 tmp;
93                tmp[m_coneIndices[0]] = btScalar(0.);
94                tmp[m_coneIndices[1]] = -halfHeight;
95                tmp[m_coneIndices[2]] = btScalar(0.);
96                return tmp;
97        }
98  }
99
100}
101
102btVector3       btConeShape::localGetSupportingVertexWithoutMargin(const btVector3& vec) const
103{
104                return coneLocalSupport(vec);
105}
106
107void    btConeShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
108{
109        for (int i=0;i<numVectors;i++)
110        {
111                const btVector3& vec = vectors[i];
112                supportVerticesOut[i] = coneLocalSupport(vec);
113        }
114}
115
116
117btVector3       btConeShape::localGetSupportingVertex(const btVector3& vec)  const
118{
119        btVector3 supVertex = coneLocalSupport(vec);
120        if ( getMargin()!=btScalar(0.) )
121        {
122                btVector3 vecnorm = vec;
123                if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
124                {
125                        vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
126                } 
127                vecnorm.normalize();
128                supVertex+= getMargin() * vecnorm;
129        }
130        return supVertex;
131}
132
133
Note: See TracBrowser for help on using the repository browser.