Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/consolecommands2/src/external/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp @ 7691

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