Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp @ 8351

Last change on this file since 8351 was 8351, checked in by rgrieder, 13 years ago

Merged kicklib2 branch back to trunk (includes former branches ois_update, mac_osx and kicklib).

Notes for updating

Linux:
You don't need an extra package for CEGUILua and Tolua, it's already shipped with CEGUI.
However you do need to make sure that the OgreRenderer is installed too with CEGUI 0.7 (may be a separate package).
Also, Orxonox now recognises if you install the CgProgramManager (a separate package available on newer Ubuntu on Debian systems).

Windows:
Download the new dependency packages versioned 6.0 and use these. If you have problems with that or if you don't like the in game console problem mentioned below, you can download the new 4.3 version of the packages (only available for Visual Studio 2005/2008).

Key new features:

  • *Support for Mac OS X*
  • Visual Studio 2010 support
  • Bullet library update to 2.77
  • OIS library update to 1.3
  • Support for CEGUI 0.7 —> Support for Arch Linux and even SuSE
  • Improved install target
  • Compiles now with GCC 4.6
  • Ogre Cg Shader plugin activated for Linux if available
  • And of course lots of bug fixes

There are also some regressions:

  • No support for CEGUI 0.5, Ogre 1.4 and boost 1.35 - 1.39 any more
  • In game console is not working in main menu for CEGUI 0.7
  • Tolua (just the C lib, not the application) and CEGUILua libraries are no longer in our repository. —> You will need to get these as well when compiling Orxonox
  • And of course lots of new bugs we don't yet know about
  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
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 "btTriangleMeshShape.h"
17#include "LinearMath/btVector3.h"
18#include "LinearMath/btQuaternion.h"
19#include "btStridingMeshInterface.h"
20#include "LinearMath/btAabbUtil2.h"
21#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
22
23
24btTriangleMeshShape::btTriangleMeshShape(btStridingMeshInterface* meshInterface)
25: btConcaveShape (), m_meshInterface(meshInterface)
26{
27        m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
28        if(meshInterface->hasPremadeAabb())
29        {
30                meshInterface->getPremadeAabb(&m_localAabbMin, &m_localAabbMax);
31        }
32        else
33        {
34                recalcLocalAabb();
35        }
36}
37
38
39btTriangleMeshShape::~btTriangleMeshShape()
40{
41               
42}
43
44
45
46
47void btTriangleMeshShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
48{
49
50        btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
51        localHalfExtents += btVector3(getMargin(),getMargin(),getMargin());
52        btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
53       
54        btMatrix3x3 abs_b = trans.getBasis().absolute(); 
55
56        btVector3 center = trans(localCenter);
57
58        btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
59                   abs_b[1].dot(localHalfExtents),
60                  abs_b[2].dot(localHalfExtents));
61        aabbMin = center - extent;
62        aabbMax = center + extent;
63
64
65}
66
67void    btTriangleMeshShape::recalcLocalAabb()
68{
69        for (int i=0;i<3;i++)
70        {
71                btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
72                vec[i] = btScalar(1.);
73                btVector3 tmp = localGetSupportingVertex(vec);
74                m_localAabbMax[i] = tmp[i]+m_collisionMargin;
75                vec[i] = btScalar(-1.);
76                tmp = localGetSupportingVertex(vec);
77                m_localAabbMin[i] = tmp[i]-m_collisionMargin;
78        }
79}
80
81
82
83class SupportVertexCallback : public btTriangleCallback
84{
85
86        btVector3 m_supportVertexLocal;
87public:
88
89        btTransform     m_worldTrans;
90        btScalar m_maxDot;
91        btVector3 m_supportVecLocal;
92
93        SupportVertexCallback(const btVector3& supportVecWorld,const btTransform& trans)
94                : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)), m_worldTrans(trans) ,m_maxDot(btScalar(-BT_LARGE_FLOAT))
95               
96        {
97                m_supportVecLocal = supportVecWorld * m_worldTrans.getBasis();
98        }
99
100        virtual void processTriangle( btVector3* triangle,int partId, int triangleIndex)
101        {
102                (void)partId;
103                (void)triangleIndex;
104                for (int i=0;i<3;i++)
105                {
106                        btScalar dot = m_supportVecLocal.dot(triangle[i]);
107                        if (dot > m_maxDot)
108                        {
109                                m_maxDot = dot;
110                                m_supportVertexLocal = triangle[i];
111                        }
112                }
113        }
114
115        btVector3 GetSupportVertexWorldSpace()
116        {
117                return m_worldTrans(m_supportVertexLocal);
118        }
119
120        btVector3       GetSupportVertexLocal()
121        {
122                return m_supportVertexLocal;
123        }
124
125};
126
127       
128void btTriangleMeshShape::setLocalScaling(const btVector3& scaling)
129{
130        m_meshInterface->setScaling(scaling);
131        recalcLocalAabb();
132}
133
134const btVector3& btTriangleMeshShape::getLocalScaling() const
135{
136        return m_meshInterface->getScaling();
137}
138
139
140
141
142
143
144//#define DEBUG_TRIANGLE_MESH
145
146
147
148void    btTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
149{
150                struct FilteredCallback : public btInternalTriangleIndexCallback
151        {
152                btTriangleCallback* m_callback;
153                btVector3 m_aabbMin;
154                btVector3 m_aabbMax;
155
156                FilteredCallback(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax)
157                        :m_callback(callback),
158                        m_aabbMin(aabbMin),
159                        m_aabbMax(aabbMax)
160                {
161                }
162
163                virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)
164                {
165                        if (TestTriangleAgainstAabb2(&triangle[0],m_aabbMin,m_aabbMax))
166                        {
167                                //check aabb in triangle-space, before doing this
168                                m_callback->processTriangle(triangle,partId,triangleIndex);
169                        }
170                       
171                }
172
173        };
174
175        FilteredCallback filterCallback(callback,aabbMin,aabbMax);
176
177        m_meshInterface->InternalProcessAllTriangles(&filterCallback,aabbMin,aabbMax);
178}
179
180
181
182
183
184void    btTriangleMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
185{
186        (void)mass;
187        //moving concave objects not supported
188        btAssert(0);
189        inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
190}
191
192
193btVector3 btTriangleMeshShape::localGetSupportingVertex(const btVector3& vec) const
194{
195        btVector3 supportVertex;
196
197        btTransform ident;
198        ident.setIdentity();
199
200        SupportVertexCallback supportCallback(vec,ident);
201
202        btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
203       
204        processAllTriangles(&supportCallback,-aabbMax,aabbMax);
205               
206        supportVertex = supportCallback.GetSupportVertexLocal();
207
208        return supportVertex;
209}
210
211
Note: See TracBrowser for help on using the repository browser.