Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp @ 8577

Last change on this file since 8577 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: 6.0 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
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 "btConvexPlaneCollisionAlgorithm.h"
17
18#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
19#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
20#include "BulletCollision/CollisionShapes/btConvexShape.h"
21#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
22
23//#include <stdio.h>
24
25btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold)
26: btCollisionAlgorithm(ci),
27m_ownManifold(false),
28m_manifoldPtr(mf),
29m_isSwapped(isSwapped),
30m_numPerturbationIterations(numPerturbationIterations),
31m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
32{
33        btCollisionObject* convexObj = m_isSwapped? col1 : col0;
34        btCollisionObject* planeObj = m_isSwapped? col0 : col1;
35
36        if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObj,planeObj))
37        {
38                m_manifoldPtr = m_dispatcher->getNewManifold(convexObj,planeObj);
39                m_ownManifold = true;
40        }
41}
42
43
44btConvexPlaneCollisionAlgorithm::~btConvexPlaneCollisionAlgorithm()
45{
46        if (m_ownManifold)
47        {
48                if (m_manifoldPtr)
49                        m_dispatcher->releaseManifold(m_manifoldPtr);
50        }
51}
52
53void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
54{
55    btCollisionObject* convexObj = m_isSwapped? body1 : body0;
56        btCollisionObject* planeObj = m_isSwapped? body0: body1;
57
58        btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape();
59        btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape();
60
61    bool hasCollision = false;
62        const btVector3& planeNormal = planeShape->getPlaneNormal();
63        const btScalar& planeConstant = planeShape->getPlaneConstant();
64       
65        btTransform convexWorldTransform = convexObj->getWorldTransform();
66        btTransform convexInPlaneTrans;
67        convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexWorldTransform;
68        //now perturbe the convex-world transform
69        convexWorldTransform.getBasis()*=btMatrix3x3(perturbeRot);
70        btTransform planeInConvex;
71        planeInConvex= convexWorldTransform.inverse() * planeObj->getWorldTransform();
72       
73        btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
74
75        btVector3 vtxInPlane = convexInPlaneTrans(vtx);
76        btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
77
78        btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
79        btVector3 vtxInPlaneWorld = planeObj->getWorldTransform() * vtxInPlaneProjected;
80
81        hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
82        resultOut->setPersistentManifold(m_manifoldPtr);
83        if (hasCollision)
84        {
85                /// report a contact. internally this will be kept persistent, and contact reduction is done
86                btVector3 normalOnSurfaceB = planeObj->getWorldTransform().getBasis() * planeNormal;
87                btVector3 pOnB = vtxInPlaneWorld;
88                resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance);
89        }
90}
91
92
93void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
94{
95        (void)dispatchInfo;
96        if (!m_manifoldPtr)
97                return;
98
99    btCollisionObject* convexObj = m_isSwapped? body1 : body0;
100        btCollisionObject* planeObj = m_isSwapped? body0: body1;
101
102        btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape();
103        btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape();
104
105   
106        const btVector3& planeNormal = planeShape->getPlaneNormal();
107        //const btScalar& planeConstant = planeShape->getPlaneConstant();
108
109        //first perform a collision query with the non-perturbated collision objects
110        {
111                btQuaternion rotq(0,0,0,1);
112                collideSingleContact(rotq,body0,body1,dispatchInfo,resultOut);
113        }
114
115        if (resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPerturbationThreshold)
116        {
117                btVector3 v0,v1;
118                btPlaneSpace1(planeNormal,v0,v1);
119                //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects
120
121                const btScalar angleLimit = 0.125f * SIMD_PI;
122                btScalar perturbeAngle;
123                btScalar radius = convexShape->getAngularMotionDisc();
124                perturbeAngle = gContactBreakingThreshold / radius;
125                if ( perturbeAngle > angleLimit ) 
126                                perturbeAngle = angleLimit;
127
128                btQuaternion perturbeRot(v0,perturbeAngle);
129                for (int i=0;i<m_numPerturbationIterations;i++)
130                {
131                        btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));
132                        btQuaternion rotq(planeNormal,iterationAngle);
133                        collideSingleContact(rotq.inverse()*perturbeRot*rotq,body0,body1,dispatchInfo,resultOut);
134                }
135        }
136
137        if (m_ownManifold)
138        {
139                if (m_manifoldPtr->getNumContacts())
140                {
141                        resultOut->refreshContactPoints();
142                }
143        }
144}
145
146btScalar btConvexPlaneCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
147{
148        (void)resultOut;
149        (void)dispatchInfo;
150        (void)col0;
151        (void)col1;
152
153        //not yet
154        return btScalar(1.);
155}
Note: See TracBrowser for help on using the repository browser.