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

« back to all changes in this revision

Viewing changes to extern/bullet/Bullet/CollisionShapes/ConeShape.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
 
#include "ConeShape.h"
17
 
#include "SimdPoint3.h"
18
 
 
19
 
#ifdef WIN32
20
 
static int coneindices[3] = {1,2,0};
21
 
#else
22
 
static int coneindices[3] = {2,1,0};
23
 
#endif
24
 
 
25
 
ConeShape::ConeShape (SimdScalar radius,SimdScalar height):
26
 
m_radius (radius),
27
 
m_height(height)
28
 
{
29
 
        SimdVector3 halfExtents;
30
 
        m_sinAngle = (m_radius / sqrt(m_radius * m_radius + m_height * m_height));
31
 
}
32
 
 
33
 
 
34
 
SimdVector3 ConeShape::ConeLocalSupport(const SimdVector3& v) const
35
 
{
36
 
        
37
 
        float halfHeight = m_height * 0.5f;
38
 
 
39
 
 if (v[coneindices[1]] > v.length() * m_sinAngle)
40
 
 {
41
 
        SimdVector3 tmp;
42
 
 
43
 
        tmp[coneindices[0]] = 0.f;
44
 
        tmp[coneindices[1]] = halfHeight;
45
 
        tmp[coneindices[2]] = 0.f;
46
 
        return tmp;
47
 
 }
48
 
  else {
49
 
    SimdScalar s = SimdSqrt(v[coneindices[0]] * v[coneindices[0]] + v[coneindices[2]] * v[coneindices[2]]);
50
 
    if (s > SIMD_EPSILON) {
51
 
      SimdScalar d = m_radius / s;
52
 
          SimdVector3 tmp;
53
 
          tmp[coneindices[0]] = v[coneindices[0]] * d;
54
 
          tmp[coneindices[1]] = -halfHeight;
55
 
          tmp[coneindices[2]] = v[coneindices[2]] * d;
56
 
          return tmp;
57
 
    }
58
 
    else  {
59
 
                SimdVector3 tmp;
60
 
                tmp[coneindices[0]] = 0.f;
61
 
                tmp[coneindices[1]] = -halfHeight;
62
 
                tmp[coneindices[2]] = 0.f;
63
 
                return tmp;
64
 
        }
65
 
  }
66
 
 
67
 
}
68
 
 
69
 
SimdVector3     ConeShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec) const
70
 
{
71
 
                return ConeLocalSupport(vec);
72
 
}
73
 
 
74
 
void    ConeShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
75
 
{
76
 
        for (int i=0;i<numVectors;i++)
77
 
        {
78
 
                const SimdVector3& vec = vectors[i];
79
 
                supportVerticesOut[i] = ConeLocalSupport(vec);
80
 
        }
81
 
}
82
 
 
83
 
 
84
 
SimdVector3     ConeShape::LocalGetSupportingVertex(const SimdVector3& vec)  const
85
 
{
86
 
        SimdVector3 supVertex = ConeLocalSupport(vec);
87
 
        if ( GetMargin()!=0.f )
88
 
        {
89
 
                SimdVector3 vecnorm = vec;
90
 
                if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
91
 
                {
92
 
                        vecnorm.setValue(-1.f,-1.f,-1.f);
93
 
                } 
94
 
                vecnorm.normalize();
95
 
                supVertex+= GetMargin() * vecnorm;
96
 
        }
97
 
        return supVertex;
98
 
}
99
 
 
100