Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/environment/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.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: 6.0 KB
Line 
1/*
2btbtShapeHull implemented by John McCutchan.
3
4Bullet Continuous Collision Detection and Physics Library
5Copyright (c) 2003-2008 Erwin Coumans  http://bulletphysics.com
6
7This software is provided 'as-is', without any express or implied warranty.
8In no event will the authors be held liable for any damages arising from the use of this software.
9Permission is granted to anyone to use this software for any purpose,
10including commercial applications, and to alter it and redistribute it freely,
11subject to the following restrictions:
12
131. 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.
142. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
153. This notice may not be removed or altered from any source distribution.
16*/
17
18#include "btShapeHull.h"
19#include "LinearMath/btConvexHull.h"
20
21#define NUM_UNITSPHERE_POINTS 42
22
23static btVector3 btUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] = 
24{
25        btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),
26        btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),
27        btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),
28        btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),
29        btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),
30        btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),
31        btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),
32        btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),
33        btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),
34        btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),
35        btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),
36        btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),
37        btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),
38        btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),
39        btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),
40        btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),
41        btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),
42        btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),
43        btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),
44        btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),
45        btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),
46        btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),
47        btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),
48        btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),
49        btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),
50        btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),
51        btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),
52        btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),
53        btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),
54        btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),
55        btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),
56        btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),
57        btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),
58        btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),
59        btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),
60        btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),
61        btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),
62        btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),
63        btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),
64        btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),
65        btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
66        btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
67};
68
69btShapeHull::btShapeHull (const btConvexShape* shape)
70{
71        m_shape = shape;
72        m_vertices.clear ();
73        m_indices.clear();
74        m_numIndices = 0;
75}
76
77btShapeHull::~btShapeHull ()
78{
79        m_indices.clear();     
80        m_vertices.clear ();
81}
82
83bool
84btShapeHull::buildHull (btScalar /*margin*/)
85{
86        int numSampleDirections = NUM_UNITSPHERE_POINTS;
87        {
88                int numPDA = m_shape->getNumPreferredPenetrationDirections();
89                if (numPDA)
90                {
91                        for (int i=0;i<numPDA;i++)
92                        {
93                                btVector3 norm;
94                                m_shape->getPreferredPenetrationDirection(i,norm);
95                                btUnitSpherePoints[numSampleDirections] = norm;
96                                numSampleDirections++;
97                        }
98                }
99        }
100
101        btVector3 supportPoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
102        int i;
103        for (i = 0; i < numSampleDirections; i++)
104        {
105                supportPoints[i] = m_shape->localGetSupportingVertex(btUnitSpherePoints[i]);
106        }
107
108        HullDesc hd;
109        hd.mFlags = QF_TRIANGLES;
110        hd.mVcount = static_cast<unsigned int>(numSampleDirections);
111
112#ifdef BT_USE_DOUBLE_PRECISION
113        hd.mVertices = &supportPoints[0];
114        hd.mVertexStride = sizeof(btVector3);
115#else
116        hd.mVertices = &supportPoints[0];
117        hd.mVertexStride = sizeof (btVector3);
118#endif
119
120        HullLibrary hl;
121        HullResult hr;
122        if (hl.CreateConvexHull (hd, hr) == QE_FAIL)
123        {
124                return false;
125        }
126
127        m_vertices.resize (static_cast<int>(hr.mNumOutputVertices));
128
129
130        for (i = 0; i < static_cast<int>(hr.mNumOutputVertices); i++)
131        {
132                m_vertices[i] = hr.m_OutputVertices[i];
133        }
134        m_numIndices = hr.mNumIndices;
135        m_indices.resize(static_cast<int>(m_numIndices));
136        for (i = 0; i < static_cast<int>(m_numIndices); i++)
137        {
138                m_indices[i] = hr.m_Indices[i];
139        }
140
141        // free temporary hull result that we just copied
142        hl.ReleaseResult (hr);
143
144        return true;
145}
146
147int
148btShapeHull::numTriangles () const
149{
150        return static_cast<int>(m_numIndices / 3);
151}
152
153int
154btShapeHull::numVertices () const
155{
156        return m_vertices.size ();
157}
158
159int
160btShapeHull::numIndices () const
161{
162        return static_cast<int>(m_numIndices);
163}
164
Note: See TracBrowser for help on using the repository browser.