Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.cpp @ 9380

Last change on this file since 9380 was 8351, checked in by rgrieder, 14 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: 4.6 KB
RevLine 
[1963]1/*
2Bullet Continuous Collision Detection and Physics Library
[8351]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
[8351]16
17
[1963]18#include "btMultiSphereShape.h"
19#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
20#include "LinearMath/btQuaternion.h"
[8351]21#include "LinearMath/btSerializer.h"
[1963]22
[8351]23btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres)
24:btConvexInternalAabbCachingShape ()
[1963]25{
26        m_shapeType = MULTI_SPHERE_SHAPE_PROXYTYPE;
[8351]27        //btScalar startMargin = btScalar(BT_LARGE_FLOAT);
[1963]28
[8351]29        m_localPositionArray.resize(numSpheres);
30        m_radiArray.resize(numSpheres);
31        for (int i=0;i<numSpheres;i++)
[1963]32        {
[8351]33                m_localPositionArray[i] = positions[i];
34                m_radiArray[i] = radi[i];
35               
[1963]36        }
37
[8351]38        recalcLocalAabb();
39
[1963]40}
41
42 
43 btVector3      btMultiSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
44{
45        int i;
46        btVector3 supVec(0,0,0);
47
[8351]48        btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
[1963]49
50
51        btVector3 vec = vec0;
52        btScalar lenSqr = vec.length2();
53        if (lenSqr < (SIMD_EPSILON*SIMD_EPSILON))
54        {
55                vec.setValue(1,0,0);
56        } else
57        {
58                btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
59                vec *= rlen;
60        }
61
62        btVector3 vtx;
63        btScalar newDot;
64
[8351]65        const btVector3* pos = &m_localPositionArray[0];
66        const btScalar* rad = &m_radiArray[0];
67        int numSpheres = m_localPositionArray.size();
[1963]68
[8351]69        for (i=0;i<numSpheres;i++)
[1963]70        {
71                vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
72                pos++;
73                rad++;
74                newDot = vec.dot(vtx);
75                if (newDot > maxDot)
76                {
77                        maxDot = newDot;
78                        supVec = vtx;
79                }
80        }
81
82        return supVec;
83
84}
85
86 void   btMultiSphereShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
87{
88
89        for (int j=0;j<numVectors;j++)
90        {
[8351]91                btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
[1963]92
93                const btVector3& vec = vectors[j];
94
95                btVector3 vtx;
96                btScalar newDot;
97
[8351]98                const btVector3* pos = &m_localPositionArray[0];
99                const btScalar* rad = &m_radiArray[0];
100                int numSpheres = m_localPositionArray.size();
101                for (int i=0;i<numSpheres;i++)
[1963]102                {
103                        vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
104                        pos++;
105                        rad++;
106                        newDot = vec.dot(vtx);
107                        if (newDot > maxDot)
108                        {
109                                maxDot = newDot;
110                                supportVerticesOut[j] = vtx;
111                        }
112                }
113        }
114}
115
116
117
118
119
120
121
122
123void    btMultiSphereShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
124{
125        //as an approximation, take the inertia of the box that bounds the spheres
126
[8351]127        btVector3 localAabbMin,localAabbMax;
128        getCachedLocalAabb(localAabbMin,localAabbMax);
129        btVector3 halfExtents = (localAabbMax-localAabbMin)*btScalar(0.5);
[1963]130
[8351]131        btScalar lx=btScalar(2.)*(halfExtents.x());
132        btScalar ly=btScalar(2.)*(halfExtents.y());
133        btScalar lz=btScalar(2.)*(halfExtents.z());
[1963]134
[8351]135        inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz),
136                                        mass/(btScalar(12.0)) * (lx*lx + lz*lz),
137                                        mass/(btScalar(12.0)) * (lx*lx + ly*ly));
[1963]138
[8351]139}
[1963]140
141
[8351]142///fills the dataBuffer and returns the struct name (and 0 on failure)
143const char*     btMultiSphereShape::serialize(void* dataBuffer, btSerializer* serializer) const
144{
145        btMultiSphereShapeData* shapeData = (btMultiSphereShapeData*) dataBuffer;
146        btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer);
[1963]147
[8351]148        int numElem = m_localPositionArray.size();
149        shapeData->m_localPositionArrayPtr = numElem ? (btPositionAndRadius*)serializer->getUniquePointer((void*)&m_localPositionArray[0]):  0;
150       
151        shapeData->m_localPositionArraySize = numElem;
152        if (numElem)
153        {
154                btChunk* chunk = serializer->allocate(sizeof(btPositionAndRadius),numElem);
155                btPositionAndRadius* memPtr = (btPositionAndRadius*)chunk->m_oldPtr;
156                for (int i=0;i<numElem;i++,memPtr++)
157                {
158                        m_localPositionArray[i].serializeFloat(memPtr->m_pos);
159                        memPtr->m_radius = float(m_radiArray[i]);
160                }
161                serializer->finalizeChunk(chunk,"btPositionAndRadius",BT_ARRAY_CODE,(void*)&m_localPositionArray[0]);
162        }
163       
164        return "btMultiSphereShapeData";
[1963]165}
166
167
Note: See TracBrowser for help on using the repository browser.