~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp

  • Committer: theeth
  • Date: 2008-10-14 16:52:04 UTC
  • Revision ID: vcs-imports@canonical.com-20081014165204-r32w2gm6s0osvdhn
copy back trunk

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 "btStaticPlaneShape.h"
 
17
 
 
18
#include "LinearMath/btTransformUtil.h"
 
19
 
 
20
 
 
21
btStaticPlaneShape::btStaticPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
 
22
:m_planeNormal(planeNormal.normalized()),
 
23
m_planeConstant(planeConstant),
 
24
m_localScaling(btScalar(0.),btScalar(0.),btScalar(0.))
 
25
{
 
26
        //      btAssert( btFuzzyZero(m_planeNormal.length() - btScalar(1.)) );
 
27
}
 
28
 
 
29
 
 
30
btStaticPlaneShape::~btStaticPlaneShape()
 
31
{
 
32
}
 
33
 
 
34
 
 
35
 
 
36
void btStaticPlaneShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
 
37
{
 
38
        (void)t;
 
39
        /*
 
40
        btVector3 infvec (btScalar(1e30),btScalar(1e30),btScalar(1e30));
 
41
 
 
42
        btVector3 center = m_planeNormal*m_planeConstant;
 
43
        aabbMin = center + infvec*m_planeNormal;
 
44
        aabbMax = aabbMin;
 
45
        aabbMin.setMin(center - infvec*m_planeNormal);
 
46
        aabbMax.setMax(center - infvec*m_planeNormal); 
 
47
        */
 
48
 
 
49
        aabbMin.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
 
50
        aabbMax.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
 
51
 
 
52
}
 
53
 
 
54
 
 
55
 
 
56
 
 
57
void    btStaticPlaneShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
 
58
{
 
59
 
 
60
        btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
 
61
        btScalar radius = halfExtents.length();
 
62
        btVector3 center = (aabbMax + aabbMin) * btScalar(0.5);
 
63
        
 
64
        //this is where the triangles are generated, given AABB and plane equation (normal/constant)
 
65
 
 
66
        btVector3 tangentDir0,tangentDir1;
 
67
 
 
68
        //tangentDir0/tangentDir1 can be precalculated
 
69
        btPlaneSpace1(m_planeNormal,tangentDir0,tangentDir1);
 
70
 
 
71
        btVector3 supVertex0,supVertex1;
 
72
 
 
73
        btVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant)*m_planeNormal;
 
74
        
 
75
        btVector3 triangle[3];
 
76
        triangle[0] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
 
77
        triangle[1] = projectedCenter + tangentDir0*radius - tangentDir1*radius;
 
78
        triangle[2] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
 
79
 
 
80
        callback->processTriangle(triangle,0,0);
 
81
 
 
82
        triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
 
83
        triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius;
 
84
        triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
 
85
 
 
86
        callback->processTriangle(triangle,0,1);
 
87
 
 
88
}
 
89
 
 
90
void    btStaticPlaneShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
 
91
{
 
92
        (void)mass;
 
93
 
 
94
        //moving concave objects not supported
 
95
        
 
96
        inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
 
97
}
 
98
 
 
99
void    btStaticPlaneShape::setLocalScaling(const btVector3& scaling)
 
100
{
 
101
        m_localScaling = scaling;
 
102
}
 
103
const btVector3& btStaticPlaneShape::getLocalScaling() const
 
104
{
 
105
        return m_localScaling;
 
106
}