Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Downgraded Bullet to latest tagged version: 2.72
That should give us more stability.

  • Property svn:eol-style set to native
File size: 4.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 "btConvexPointCloudShape.h"
16#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
17
18#include "LinearMath/btQuaternion.h"
19
20btConvexPointCloudShape::btConvexPointCloudShape (btVector3* points,int numPoints) : btPolyhedralConvexShape ()
21{
22        m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
23        m_points = points;
24        m_numPoints = numPoints;
25
26        recalcLocalAabb();
27}
28
29void btConvexPointCloudShape::setPoints (btVector3* points, int numPoints)
30{
31        m_points = points;
32        m_numPoints = numPoints;
33
34        recalcLocalAabb();
35}
36
37
38void btConvexPointCloudShape::setLocalScaling(const btVector3& scaling)
39{
40        m_localScaling = scaling;
41        recalcLocalAabb();
42}
43
44btVector3       btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
45{
46        btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
47        btScalar newDot,maxDot = btScalar(-1e30);
48
49        btVector3 vec = vec0;
50        btScalar lenSqr = vec.length2();
51        if (lenSqr < btScalar(0.0001))
52        {
53                vec.setValue(1,0,0);
54        } else
55        {
56                btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
57                vec *= rlen;
58        }
59
60
61        for (int i=0;i<m_numPoints;i++)
62        {
63                btPoint3 vtx = m_points[i] * m_localScaling;
64
65                newDot = vec.dot(vtx);
66                if (newDot > maxDot)
67                {
68                        maxDot = newDot;
69                        supVec = vtx;
70                }
71        }
72        return supVec;
73}
74
75void    btConvexPointCloudShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
76{
77        btScalar newDot;
78        //use 'w' component of supportVerticesOut?
79        {
80                for (int i=0;i<numVectors;i++)
81                {
82                        supportVerticesOut[i][3] = btScalar(-1e30);
83                }
84        }
85        for (int i=0;i<m_numPoints;i++)
86        {
87                btPoint3 vtx = m_points[i] * m_localScaling;
88
89                for (int j=0;j<numVectors;j++)
90                {
91                        const btVector3& vec = vectors[j];
92                       
93                        newDot = vec.dot(vtx);
94                        if (newDot > supportVerticesOut[j][3])
95                        {
96                                //WARNING: don't swap next lines, the w component would get overwritten!
97                                supportVerticesOut[j] = vtx;
98                                supportVerticesOut[j][3] = newDot;
99                        }
100                }
101        }
102
103
104
105}
106       
107
108
109btVector3       btConvexPointCloudShape::localGetSupportingVertex(const btVector3& vec)const
110{
111        btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
112
113        if ( getMargin()!=btScalar(0.) )
114        {
115                btVector3 vecnorm = vec;
116                if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
117                {
118                        vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
119                } 
120                vecnorm.normalize();
121                supVertex+= getMargin() * vecnorm;
122        }
123        return supVertex;
124}
125
126
127
128
129
130
131
132
133
134//currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
135//Please note that you can debug-draw btConvexHullShape with the Raytracer Demo
136int     btConvexPointCloudShape::getNumVertices() const
137{
138        return m_numPoints;
139}
140
141int btConvexPointCloudShape::getNumEdges() const
142{
143        return 0;
144}
145
146void btConvexPointCloudShape::getEdge(int i,btPoint3& pa,btPoint3& pb) const
147{
148        btAssert (0);
149}
150
151void btConvexPointCloudShape::getVertex(int i,btPoint3& vtx) const
152{
153        vtx = m_points[i]*m_localScaling;
154}
155
156int     btConvexPointCloudShape::getNumPlanes() const
157{
158        return 0;
159}
160
161void btConvexPointCloudShape::getPlane(btVector3& ,btPoint3& ,int ) const
162{
163
164        btAssert(0);
165}
166
167//not yet
168bool btConvexPointCloudShape::isInside(const btPoint3& ,btScalar ) const
169{
170        assert(0);
171        return false;
172}
173
Note: See TracBrowser for help on using the repository browser.