~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to extern/bullet/Bullet/CollisionShapes/ConvexHullShape.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Bullet Continuous Collision Detection and Physics Library
3
 
Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
 
 
5
 
This software is provided 'as-is', without any express or implied warranty.
6
 
In no event will the authors be held liable for any damages arising from the use of this software.
7
 
Permission is granted to anyone to use this software for any purpose, 
8
 
including commercial applications, and to alter it and redistribute it freely, 
9
 
subject to the following restrictions:
10
 
 
11
 
1. 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.
12
 
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
 
3. This notice may not be removed or altered from any source distribution.
14
 
*/
15
 
#include "ConvexHullShape.h"
16
 
#include "CollisionShapes/CollisionMargin.h"
17
 
 
18
 
#include "SimdQuaternion.h"
19
 
 
20
 
 
21
 
ConvexHullShape ::ConvexHullShape (SimdPoint3* points,int numPoints)
22
 
{
23
 
        m_points.resize(numPoints);
24
 
        for (int i=0;i<numPoints;i++)
25
 
                m_points[i] = points[i];
26
 
}
27
 
 
28
 
SimdVector3     ConvexHullShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec0)const
29
 
{
30
 
        SimdVector3 supVec(0.f,0.f,0.f);
31
 
        SimdScalar newDot,maxDot = -1e30f;
32
 
 
33
 
        SimdVector3 vec = vec0;
34
 
        SimdScalar lenSqr = vec.length2();
35
 
        if (lenSqr < 0.0001f)
36
 
        {
37
 
                vec.setValue(1,0,0);
38
 
        } else
39
 
        {
40
 
                float rlen = 1.f / SimdSqrt(lenSqr );
41
 
                vec *= rlen;
42
 
        }
43
 
 
44
 
 
45
 
        for (size_t i=0;i<m_points.size();i++)
46
 
        {
47
 
                SimdPoint3 vtx = m_points[i] * m_localScaling;
48
 
 
49
 
                newDot = vec.dot(vtx);
50
 
                if (newDot > maxDot)
51
 
                {
52
 
                        maxDot = newDot;
53
 
                        supVec = vtx;
54
 
                }
55
 
        }
56
 
        return supVec;
57
 
}
58
 
 
59
 
void    ConvexHullShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
60
 
{
61
 
        SimdScalar newDot;
62
 
        //use 'w' component of supportVerticesOut?
63
 
        {
64
 
                for (int i=0;i<numVectors;i++)
65
 
                {
66
 
                        supportVerticesOut[i][3] = -1e30f;
67
 
                }
68
 
        }
69
 
        for (size_t i=0;i<m_points.size();i++)
70
 
        {
71
 
                SimdPoint3 vtx = m_points[i] * m_localScaling;
72
 
 
73
 
                for (int j=0;j<numVectors;j++)
74
 
                {
75
 
                        const SimdVector3& vec = vectors[j];
76
 
                        
77
 
                        newDot = vec.dot(vtx);
78
 
                        if (newDot > supportVerticesOut[j][3])
79
 
                        {
80
 
                                //WARNING: don't swap next lines, the w component would get overwritten!
81
 
                                supportVerticesOut[j] = vtx;
82
 
                                supportVerticesOut[j][3] = newDot;
83
 
                        }
84
 
                }
85
 
        }
86
 
 
87
 
 
88
 
 
89
 
}
90
 
        
91
 
 
92
 
 
93
 
SimdVector3     ConvexHullShape::LocalGetSupportingVertex(const SimdVector3& vec)const
94
 
{
95
 
        SimdVector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec);
96
 
 
97
 
        if ( GetMargin()!=0.f )
98
 
        {
99
 
                SimdVector3 vecnorm = vec;
100
 
                if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
101
 
                {
102
 
                        vecnorm.setValue(-1.f,-1.f,-1.f);
103
 
                } 
104
 
                vecnorm.normalize();
105
 
                supVertex+= GetMargin() * vecnorm;
106
 
        }
107
 
        return supVertex;
108
 
}
109
 
 
110
 
 
111
 
 
112
 
 
113
 
 
114
 
 
115
 
 
116
 
 
117
 
 
118
 
//currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
119
 
//Please note that you can debug-draw ConvexHullShape with the Raytracer Demo
120
 
int     ConvexHullShape::GetNumVertices() const
121
 
{
122
 
        return m_points.size();
123
 
}
124
 
 
125
 
int ConvexHullShape::GetNumEdges() const
126
 
{
127
 
        return m_points.size()*m_points.size();
128
 
}
129
 
 
130
 
void ConvexHullShape::GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const
131
 
{
132
 
 
133
 
        int index0 = i%m_points.size();
134
 
        int index1 = i/m_points.size();
135
 
        pa = m_points[index0]*m_localScaling;
136
 
        pb = m_points[index1]*m_localScaling;
137
 
}
138
 
 
139
 
void ConvexHullShape::GetVertex(int i,SimdPoint3& vtx) const
140
 
{
141
 
        vtx = m_points[i]*m_localScaling;
142
 
}
143
 
 
144
 
int     ConvexHullShape::GetNumPlanes() const
145
 
{
146
 
        return 0;
147
 
}
148
 
 
149
 
void ConvexHullShape::GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i ) const
150
 
{
151
 
        assert(0);
152
 
}
153
 
 
154
 
//not yet
155
 
bool ConvexHullShape::IsInside(const SimdPoint3& pt,SimdScalar tolerance) const
156
 
{
157
 
        assert(0);
158
 
        return false;
159
 
}
160