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

« back to all changes in this revision

Viewing changes to extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.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
 
 
16
 
 
17
#include "btCapsuleShape.h"
 
18
 
 
19
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
 
20
#include "LinearMath/btQuaternion.h"
 
21
 
 
22
btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
 
23
{
 
24
        m_implicitShapeDimensions.setValue(radius,0.5f*height,radius);
 
25
}
 
26
 
 
27
 
 
28
 btVector3      btCapsuleShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
 
29
{
 
30
 
 
31
        btVector3 supVec(0,0,0);
 
32
 
 
33
        btScalar maxDot(btScalar(-1e30));
 
34
 
 
35
        btVector3 vec = vec0;
 
36
        btScalar lenSqr = vec.length2();
 
37
        if (lenSqr < btScalar(0.0001))
 
38
        {
 
39
                vec.setValue(1,0,0);
 
40
        } else
 
41
        {
 
42
                btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
 
43
                vec *= rlen;
 
44
        }
 
45
 
 
46
        btVector3 vtx;
 
47
        btScalar newDot;
 
48
        
 
49
        btScalar radius = getRadius();
 
50
 
 
51
 
 
52
        {
 
53
                btVector3 pos(0,getHalfHeight(),0);
 
54
                vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
 
55
                newDot = vec.dot(vtx);
 
56
                if (newDot > maxDot)
 
57
                {
 
58
                        maxDot = newDot;
 
59
                        supVec = vtx;
 
60
                }
 
61
        }
 
62
        {
 
63
                btVector3 pos(0,-getHalfHeight(),0);
 
64
                vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
 
65
                newDot = vec.dot(vtx);
 
66
                if (newDot > maxDot)
 
67
                {
 
68
                        maxDot = newDot;
 
69
                        supVec = vtx;
 
70
                }
 
71
        }
 
72
 
 
73
        return supVec;
 
74
 
 
75
}
 
76
 
 
77
 void   btCapsuleShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
 
78
{
 
79
 
 
80
        
 
81
        btScalar radius = getRadius();
 
82
 
 
83
        for (int j=0;j<numVectors;j++)
 
84
        {
 
85
                btScalar maxDot(btScalar(-1e30));
 
86
                const btVector3& vec = vectors[j];
 
87
 
 
88
                btVector3 vtx;
 
89
                btScalar newDot;
 
90
                {
 
91
                        btVector3 pos(0,getHalfHeight(),0);
 
92
                        vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
 
93
                        newDot = vec.dot(vtx);
 
94
                        if (newDot > maxDot)
 
95
                        {
 
96
                                maxDot = newDot;
 
97
                                supportVerticesOut[j] = vtx;
 
98
                        }
 
99
                }
 
100
                {
 
101
                        btVector3 pos(0,-getHalfHeight(),0);
 
102
                        vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
 
103
                        newDot = vec.dot(vtx);
 
104
                        if (newDot > maxDot)
 
105
                        {
 
106
                                maxDot = newDot;
 
107
                                supportVerticesOut[j] = vtx;
 
108
                        }
 
109
                }
 
110
                
 
111
        }
 
112
}
 
113
 
 
114
 
 
115
void    btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
 
116
{
 
117
        //as an approximation, take the inertia of the box that bounds the spheres
 
118
 
 
119
        btTransform ident;
 
120
        ident.setIdentity();
 
121
 
 
122
        
 
123
        btScalar radius = getRadius();
 
124
 
 
125
        btVector3 halfExtents(radius,radius+getHalfHeight(),radius);
 
126
 
 
127
        btScalar margin = CONVEX_DISTANCE_MARGIN;
 
128
 
 
129
        btScalar lx=btScalar(2.)*(halfExtents[0]+margin);
 
130
        btScalar ly=btScalar(2.)*(halfExtents[1]+margin);
 
131
        btScalar lz=btScalar(2.)*(halfExtents[2]+margin);
 
132
        const btScalar x2 = lx*lx;
 
133
        const btScalar y2 = ly*ly;
 
134
        const btScalar z2 = lz*lz;
 
135
        const btScalar scaledmass = mass * btScalar(.08333333);
 
136
 
 
137
        inertia[0] = scaledmass * (y2+z2);
 
138
        inertia[1] = scaledmass * (x2+z2);
 
139
        inertia[2] = scaledmass * (x2+y2);
 
140
 
 
141
}
 
142
 
 
143
 
 
144
 
 
145
 
 
146