Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp @ 8474

Last change on this file since 8474 was 8284, checked in by rgrieder, 14 years ago

Merged revisions 7978 - 8096 from kicklib to kicklib2.

  • Property svn:eol-style set to native
File size: 4.6 KB
RevLine 
[1963]1/*
2Bullet Continuous Collision Detection and Physics Library
[8284]3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
[1963]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
16#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
17
[8284]18btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape()
[1963]19{
20
21}
22
23
24btVector3       btPolyhedralConvexShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
25{
[8284]26
27
28        btVector3 supVec(0,0,0);
29#ifndef __SPU__
[1963]30        int i;
[8284]31        btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
[1963]32
33        btVector3 vec = vec0;
34        btScalar lenSqr = vec.length2();
35        if (lenSqr < btScalar(0.0001))
36        {
37                vec.setValue(1,0,0);
38        } else
39        {
40                btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
41                vec *= rlen;
42        }
43
44        btVector3 vtx;
45        btScalar newDot;
46
47        for (i=0;i<getNumVertices();i++)
48        {
49                getVertex(i,vtx);
50                newDot = vec.dot(vtx);
51                if (newDot > maxDot)
52                {
53                        maxDot = newDot;
54                        supVec = vtx;
55                }
56        }
57
[8284]58       
59#endif //__SPU__
[1963]60        return supVec;
61}
62
[8284]63
64
[1963]65void    btPolyhedralConvexShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
66{
[8284]67#ifndef __SPU__
[1963]68        int i;
69
70        btVector3 vtx;
71        btScalar newDot;
72
73        for (i=0;i<numVectors;i++)
74        {
[8284]75                supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT);
[1963]76        }
77
78        for (int j=0;j<numVectors;j++)
79        {
80       
81                const btVector3& vec = vectors[j];
82
83                for (i=0;i<getNumVertices();i++)
84                {
85                        getVertex(i,vtx);
86                        newDot = vec.dot(vtx);
87                        if (newDot > supportVerticesOut[j][3])
88                        {
89                                //WARNING: don't swap next lines, the w component would get overwritten!
90                                supportVerticesOut[j] = vtx;
91                                supportVerticesOut[j][3] = newDot;
92                        }
93                }
94        }
[8284]95#endif //__SPU__
[1963]96}
97
98
99
100void    btPolyhedralConvexShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
101{
[8284]102#ifndef __SPU__
[1963]103        //not yet, return box inertia
104
105        btScalar margin = getMargin();
106
107        btTransform ident;
108        ident.setIdentity();
109        btVector3 aabbMin,aabbMax;
110        getAabb(ident,aabbMin,aabbMax);
111        btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5);
112
113        btScalar lx=btScalar(2.)*(halfExtents.x()+margin);
114        btScalar ly=btScalar(2.)*(halfExtents.y()+margin);
115        btScalar lz=btScalar(2.)*(halfExtents.z()+margin);
116        const btScalar x2 = lx*lx;
117        const btScalar y2 = ly*ly;
118        const btScalar z2 = lz*lz;
119        const btScalar scaledmass = mass * btScalar(0.08333333);
120
121        inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
[8284]122#endif //__SPU__
[1963]123}
124
125
126
[8284]127void    btPolyhedralConvexAabbCachingShape::setLocalScaling(const btVector3& scaling)
[1963]128{
[8284]129        btConvexInternalShape::setLocalScaling(scaling);
130        recalcLocalAabb();
[1963]131}
132
[8284]133btPolyhedralConvexAabbCachingShape::btPolyhedralConvexAabbCachingShape()
134:btPolyhedralConvexShape(),
135m_localAabbMin(1,1,1),
136m_localAabbMax(-1,-1,-1),
137m_isLocalAabbValid(false)
138{
139}
[1963]140
[8284]141void btPolyhedralConvexAabbCachingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
[1963]142{
[8284]143        getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin());
[1963]144}
145
[8284]146void    btPolyhedralConvexAabbCachingShape::recalcLocalAabb()
[1963]147{
148        m_isLocalAabbValid = true;
149       
150        #if 1
151        static const btVector3 _directions[] =
152        {
153                btVector3( 1.,  0.,  0.),
154                btVector3( 0.,  1.,  0.),
155                btVector3( 0.,  0.,  1.),
156                btVector3( -1., 0.,  0.),
157                btVector3( 0., -1.,  0.),
158                btVector3( 0.,  0., -1.)
159        };
160       
161        btVector3 _supporting[] =
162        {
163                btVector3( 0., 0., 0.),
164                btVector3( 0., 0., 0.),
165                btVector3( 0., 0., 0.),
166                btVector3( 0., 0., 0.),
167                btVector3( 0., 0., 0.),
168                btVector3( 0., 0., 0.)
169        };
170       
171        batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
172       
173        for ( int i = 0; i < 3; ++i )
174        {
175                m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
176                m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
177        }
178       
179        #else
180
181        for (int i=0;i<3;i++)
182        {
183                btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
184                vec[i] = btScalar(1.);
185                btVector3 tmp = localGetSupportingVertex(vec);
186                m_localAabbMax[i] = tmp[i]+m_collisionMargin;
187                vec[i] = btScalar(-1.);
188                tmp = localGetSupportingVertex(vec);
189                m_localAabbMin[i] = tmp[i]-m_collisionMargin;
190        }
191        #endif
192}
193
Note: See TracBrowser for help on using the repository browser.