Made the move from sourceforge to googlecode (no svn sync any longer)

Fixed BulletColladaConverter load/save
Removed btTypedUserInfo
Added btHashMap
Fixed btCapsuleShape
This commit is contained in:
erwin.coumans
2008-03-13 05:16:42 +00:00
parent 2f80e7f814
commit fe5386a5c8
20 changed files with 771 additions and 269 deletions

View File

@@ -99,9 +99,9 @@ BT_DECLARE_ALIGNED_ALLOCATOR();
int m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
int m_unusedPadding; //making the structure 16 bytes, better for alignment etc.
SIMD_FORCE_INLINE int getUid()
SIMD_FORCE_INLINE int getUid() const
{
return m_uniqueId;//(int)this;
return m_uniqueId;
}
//used for memory pools

View File

@@ -138,6 +138,11 @@ btBroadphasePair* btOverlappingPairCache::findPair(btBroadphaseProxy* proxy0, bt
int hash = getHash(proxyId1, proxyId2) & (m_overlappingPairArray.capacity()-1);
if (hash >= m_hashTable.size())
{
return NULL;
}
int index = m_hashTable[hash];
while (index != BT_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyId1, proxyId2) == false)
{

View File

@@ -26,7 +26,6 @@ btCollisionObject::btCollisionObject()
m_deactivationTime(btScalar(0.)),
m_friction(btScalar(0.5)),
m_restitution(btScalar(0.)),
m_typedUserInfo (NULL),
m_userObjectPointer(0),
m_internalOwner(0),
m_hitFraction(btScalar(1.)),

View File

@@ -27,7 +27,6 @@ subject to the following restrictions:
struct btBroadphaseProxy;
class btCollisionShape;
class btTypedUserInfo;
#include "LinearMath/btMotionState.h"
#include "LinearMath/btAlignedAllocator.h"
@@ -70,8 +69,6 @@ protected:
///m_internalOwner is reserved to point to Bullet's btRigidBody. Don't use this, use m_userObjectPointer instead.
void* m_internalOwner;
btTypedUserInfo* m_typedUserInfo;
///time of impact calculation
btScalar m_hitFraction;
@@ -337,15 +334,6 @@ public:
m_userObjectPointer = userPointer;
}
btTypedUserInfo* getTypedUserInfo () const
{
return m_typedUserInfo;
}
void setTypedUserInfo (btTypedUserInfo* typedUserInfo)
{
m_typedUserInfo = typedUserInfo;
}
inline bool checkCollideWith(btCollisionObject* co)
{

View File

@@ -112,7 +112,6 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i
btCollisionShape* tmpShape = ob->getCollisionShape();
//copy over user pointers to temporary shape
tm.setTypedUserInfo(tmpShape->getTypedUserInfo());
tm.setUserPointer(tmpShape->getUserPointer());
ob->setCollisionShape( &tm );

View File

@@ -48,7 +48,7 @@ public:
virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
{
btVector3 halfExtents(getRadius(),getRadius(),getRadius());
halfExtents[m_upAxis] = getRadius()*btScalar(2.0) + btScalar(0.5)*getHalfHeight();
halfExtents[m_upAxis] = getRadius() + getHalfHeight();
btMatrix3x3 abs_b = t.getBasis().absolute();
btPoint3 center = t.getOrigin();
btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));

View File

@@ -16,7 +16,6 @@ subject to the following restrictions:
#ifndef COLLISION_SHAPE_H
#define COLLISION_SHAPE_H
class btTypedUserInfo;
#include "LinearMath/btTransform.h"
#include "LinearMath/btVector3.h"
#include "LinearMath/btMatrix3x3.h"
@@ -28,11 +27,10 @@ class btCollisionShape
{
void* m_userPointer;
btTypedUserInfo* m_typedUserInfo;
public:
btCollisionShape() : m_userPointer(0), m_typedUserInfo (0)
btCollisionShape() : m_userPointer(0)
{
}
virtual ~btCollisionShape()
@@ -105,15 +103,6 @@ public:
return m_userPointer;
}
btTypedUserInfo* getTypedUserInfo () const
{
return m_typedUserInfo;
}
void setTypedUserInfo (btTypedUserInfo* typedUserInfo)
{
m_typedUserInfo = typedUserInfo;
}
};
#endif //COLLISION_SHAPE_H

View File

@@ -83,6 +83,7 @@ class btStridingMeshInterface
m_scaling = scaling;
}
};

View File

@@ -23,7 +23,6 @@ btTypedConstraint::btTypedConstraint(btTypedConstraintType type)
:m_userConstraintType(-1),
m_userConstraintId(-1),
m_constraintType (type),
m_typedUserInfo(0),
m_rbA(s_fixed),
m_rbB(s_fixed),
m_appliedImpulse(btScalar(0.))
@@ -33,7 +32,6 @@ m_appliedImpulse(btScalar(0.))
btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA)
:m_userConstraintType(-1),
m_userConstraintId(-1),
m_typedUserInfo(0),
m_constraintType (type),
m_rbA(rbA),
m_rbB(s_fixed),
@@ -47,7 +45,6 @@ m_appliedImpulse(btScalar(0.))
btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA,btRigidBody& rbB)
:m_userConstraintType(-1),
m_userConstraintId(-1),
m_typedUserInfo(0),
m_constraintType (type),
m_rbA(rbA),
m_rbB(rbB),

View File

@@ -17,7 +17,6 @@ subject to the following restrictions:
#define TYPED_CONSTRAINT_H
class btRigidBody;
class btTypedUserInfo;
#include "LinearMath/btScalar.h"
enum btTypedConstraintType
@@ -34,7 +33,6 @@ class btTypedConstraint
{
int m_userConstraintType;
int m_userConstraintId;
btTypedUserInfo* m_typedUserInfo;
btTypedConstraintType m_constraintType;
@@ -100,6 +98,13 @@ public:
{
return m_userConstraintId;
}
///unique id is needed by the btHashMap during serialization
int getUid() const
{
return m_userConstraintId;
}
btScalar getAppliedImpulse() const
{
return m_appliedImpulse;
@@ -110,15 +115,6 @@ public:
return m_constraintType;
}
btTypedUserInfo* getTypedUserInfo () const
{
return m_typedUserInfo;
}
void setTypedUserInfo (btTypedUserInfo* typedUserInfo)
{
m_typedUserInfo = typedUserInfo;
}
};
#endif //TYPED_CONSTRAINT_H

301
src/LinearMath/btHashMap.h Normal file
View File

@@ -0,0 +1,301 @@
#ifndef BT_HASH_MAP_H
#define BT_HASH_MAP_H
#include "btAlignedObjectArray.h"
const int BT_HASH_NULL=0xffffffff;
template <class Value>
class btHashKey
{
int m_uid;
public:
btHashKey(int uid)
:m_uid(uid)
{
}
int getUid() const
{
return m_uid;
}
//to our success
SIMD_FORCE_INLINE unsigned int getHash()const
{
int key = m_uid;
// Thomas Wang's hash
key += ~(key << 15);
key ^= (key >> 10);
key += (key << 3);
key ^= (key >> 6);
key += ~(key << 11);
key ^= (key >> 16);
return key;
}
btHashKey getKey(const Value& value) const
{
return btHashKey(value.getUid());
}
};
template <class Value>
class btHashKeyPtr
{
int m_uid;
public:
btHashKeyPtr(int uid)
:m_uid(uid)
{
}
int getUid() const
{
return m_uid;
}
//to our success
SIMD_FORCE_INLINE unsigned int getHash()const
{
int key = m_uid;
// Thomas Wang's hash
key += ~(key << 15);
key ^= (key >> 10);
key += (key << 3);
key ^= (key >> 6);
key += ~(key << 11);
key ^= (key >> 16);
return key;
}
btHashKeyPtr getKey(const Value& value) const
{
return btHashKeyPtr(value->getUid());
}
};
template <class Key, class Value>
class btHashMap
{
btAlignedObjectArray<int> m_hashTable;
btAlignedObjectArray<int> m_next;
btAlignedObjectArray<Value> m_valueArray;
void growTables(const Key& key)
{
int newCapacity = m_valueArray.capacity();
if (m_hashTable.size() < newCapacity)
{
//grow hashtable and next table
int curHashtableSize = m_hashTable.size();
m_hashTable.resize(newCapacity);
m_next.resize(newCapacity);
int i;
for (i= 0; i < newCapacity; ++i)
{
m_hashTable[i] = BT_HASH_NULL;
}
for (i = 0; i < newCapacity; ++i)
{
m_next[i] = BT_HASH_NULL;
}
for(i=0;i<curHashtableSize;i++)
{
const Value& value = m_valueArray[i];
int hashValue = key.getKey(value).getHash() & (m_valueArray.capacity()-1); // New hash value with new mask
m_next[i] = m_hashTable[hashValue];
m_hashTable[hashValue] = i;
}
}
}
public:
void insert(const Key& key, const Value& value) {
int hash = key.getHash() & (m_valueArray.capacity()-1);
//don't add it if it is already there
if (find(key))
{
return;
}
int count = m_valueArray.size();
int oldCapacity = m_valueArray.capacity();
m_valueArray.push_back(value);
int newCapacity = m_valueArray.capacity();
if (oldCapacity < newCapacity)
{
growTables(key);
//hash with new capacity
hash = key.getHash() & (m_valueArray.capacity()-1);
}
m_next[count] = m_hashTable[hash];
m_hashTable[hash] = count;
}
void remove(const Key& key) {
int hash = key.getHash() & (m_valueArray.capacity()-1);
int pairIndex = findIndex(key);
if (pairIndex ==BT_HASH_NULL)
{
return;
}
// Remove the pair from the hash table.
int index = m_hashTable[hash];
btAssert(index != BT_HASH_NULL);
int previous = BT_HASH_NULL;
while (index != pairIndex)
{
previous = index;
index = m_next[index];
}
if (previous != BT_HASH_NULL)
{
btAssert(m_next[previous] == pairIndex);
m_next[previous] = m_next[pairIndex];
}
else
{
m_hashTable[hash] = m_next[pairIndex];
}
// We now move the last pair into spot of the
// pair being removed. We need to fix the hash
// table indices to support the move.
int lastPairIndex = m_valueArray.size() - 1;
// If the removed pair is the last pair, we are done.
if (lastPairIndex == pairIndex)
{
m_valueArray.pop_back();
return;
}
// Remove the last pair from the hash table.
const Value* lastValue = &m_valueArray[lastPairIndex];
int lastHash = key.getKey(*lastValue).getHash() & (m_valueArray.capacity()-1);
index = m_hashTable[lastHash];
btAssert(index != BT_HASH_NULL);
previous = BT_HASH_NULL;
while (index != lastPairIndex)
{
previous = index;
index = m_next[index];
}
if (previous != BT_HASH_NULL)
{
btAssert(m_next[previous] == lastPairIndex);
m_next[previous] = m_next[lastPairIndex];
}
else
{
m_hashTable[lastHash] = m_next[lastPairIndex];
}
// Copy the last pair into the remove pair's spot.
m_valueArray[pairIndex] = m_valueArray[lastPairIndex];
// Insert the last pair into the hash table
m_next[pairIndex] = m_hashTable[lastHash];
m_hashTable[lastHash] = pairIndex;
m_valueArray.pop_back();
}
int size() const
{
return m_valueArray.size();
}
const Value* getAtIndex(int index) const
{
btAssert(index < m_valueArray.size());
return &m_valueArray[index];
}
Value* getAtIndex(int index)
{
btAssert(index < m_valueArray.size());
return &m_valueArray[index];
}
Value* operator[](const Key& key) {
return find(key);
}
const Value* find(const Key& key) const
{
int index = findIndex(key);
if (index == BT_HASH_NULL)
{
return NULL;
}
return &m_valueArray[index];
}
Value* find(const Key& key)
{
int index = findIndex(key);
if (index == BT_HASH_NULL)
{
return NULL;
}
return &m_valueArray[index];
}
int findIndex(const Key& key) const
{
int hash = key.getHash() & (m_valueArray.capacity()-1);
if (hash >= m_hashTable.size())
{
return BT_HASH_NULL;
}
int index = m_hashTable[hash];
while ((index != BT_HASH_NULL) && (key.getUid() == key.getKey(m_valueArray[index]).getUid()) == false)
{
index = m_next[index];
}
return index;
}
void clear()
{
m_hashTable.clear();
m_next.clear();
m_valueArray.clear();
}
};
#endif //BT_HASH_MAP_H

View File

@@ -1,54 +0,0 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. 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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BT_TYPE_USER_INFO_H
#define BT_TYPE_USER_INFO_H
class btTypedUserInfo
{
protected:
int m_type;
char* m_name;
void* m_userPointer;
/* Only systems internal to Bullet are allowed
* to use this pointer
*/
void* m_privatePointer;
public:
btTypedUserInfo ()
{
m_type = 0;
m_name = 0;
m_userPointer = 0;
m_privatePointer = 0;
}
virtual ~btTypedUserInfo () {};
int getType () { return m_type; }
void setType (int type) { m_type = type; }
char* getName () { return m_name; }
void setName (char* name) { m_name = name; }
void* getUserPointer () { return m_userPointer; }
void setUserPointer (void* userPointer) { m_userPointer = userPointer; }
void* getPrivatePointer () { return m_privatePointer; }
void setPrivatePointer (void* privatePointer) { m_privatePointer = privatePointer; }
};
#endif //BT_TYPE_USER_INFO_H