Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/src/external/bullet/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp @ 9352

Last change on this file since 9352 was 5781, checked in by rgrieder, 15 years ago

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

  • Property svn:eol-style set to native
File size: 3.5 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 "btSphereSphereCollisionAlgorithm.h"
17#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
18#include "BulletCollision/CollisionShapes/btSphereShape.h"
19#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
20
21btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1)
22: btActivatingCollisionAlgorithm(ci,col0,col1),
23m_ownManifold(false),
24m_manifoldPtr(mf)
25{
26        if (!m_manifoldPtr)
27        {
28                m_manifoldPtr = m_dispatcher->getNewManifold(col0,col1);
29                m_ownManifold = true;
30        }
31}
32
33btSphereSphereCollisionAlgorithm::~btSphereSphereCollisionAlgorithm()
34{
35        if (m_ownManifold)
36        {
37                if (m_manifoldPtr)
38                        m_dispatcher->releaseManifold(m_manifoldPtr);
39        }
40}
41
42void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
43{
44        (void)dispatchInfo;
45
46        if (!m_manifoldPtr)
47                return;
48
49        resultOut->setPersistentManifold(m_manifoldPtr);
50
51        btSphereShape* sphere0 = (btSphereShape*)col0->getCollisionShape();
52        btSphereShape* sphere1 = (btSphereShape*)col1->getCollisionShape();
53
54        btVector3 diff = col0->getWorldTransform().getOrigin()-  col1->getWorldTransform().getOrigin();
55        btScalar len = diff.length();
56        btScalar radius0 = sphere0->getRadius();
57        btScalar radius1 = sphere1->getRadius();
58
59#ifdef CLEAR_MANIFOLD
60        m_manifoldPtr->clearManifold(); //don't do this, it disables warmstarting
61#endif
62
63        ///iff distance positive, don't generate a new contact
64        if ( len > (radius0+radius1))
65        {
66#ifndef CLEAR_MANIFOLD
67                resultOut->refreshContactPoints();
68#endif //CLEAR_MANIFOLD
69                return;
70        }
71        ///distance (negative means penetration)
72        btScalar dist = len - (radius0+radius1);
73
74        btVector3 normalOnSurfaceB(1,0,0);
75        if (len > SIMD_EPSILON)
76        {
77                normalOnSurfaceB = diff / len;
78        }
79
80        ///point on A (worldspace)
81        ///btVector3 pos0 = col0->getWorldTransform().getOrigin() - radius0 * normalOnSurfaceB;
82        ///point on B (worldspace)
83        btVector3 pos1 = col1->getWorldTransform().getOrigin() + radius1* normalOnSurfaceB;
84
85        /// report a contact. internally this will be kept persistent, and contact reduction is done
86       
87       
88        resultOut->addContactPoint(normalOnSurfaceB,pos1,dist);
89
90#ifndef CLEAR_MANIFOLD
91        resultOut->refreshContactPoints();
92#endif //CLEAR_MANIFOLD
93
94}
95
96btScalar btSphereSphereCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
97{
98        (void)col0;
99        (void)col1;
100        (void)dispatchInfo;
101        (void)resultOut;
102
103        //not yet
104        return btScalar(1.);
105}
Note: See TracBrowser for help on using the repository browser.