more bt* to b3*
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
#ifndef BT_CONTACT4_H
|
||||
#define BT_CONTACT4_H
|
||||
|
||||
#include "BulletCommon/btVector3.h"
|
||||
#include "BulletCommon/b3Vector3.h"
|
||||
|
||||
|
||||
ATTRIBUTE_ALIGNED16(struct) b3Contact4
|
||||
{
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
btVector3 m_worldPos[4];
|
||||
btVector3 m_worldNormal;
|
||||
b3Vector3 m_worldPos[4];
|
||||
b3Vector3 m_worldNormal;
|
||||
// float m_restituitionCoeff;
|
||||
// float m_frictionCoeff;
|
||||
unsigned short m_restituitionCoeffCmp;
|
||||
|
||||
@@ -25,8 +25,8 @@ subject to the following restrictions:
|
||||
#include "b3ConvexPolyhedronCL.h"
|
||||
|
||||
|
||||
typedef btAlignedObjectArray<btVector3> btVertexArray;
|
||||
#include "BulletCommon/btQuickprof.h"
|
||||
typedef b3AlignedObjectArray<b3Vector3> btVertexArray;
|
||||
#include "BulletCommon/b3Quickprof.h"
|
||||
|
||||
#include <float.h> //for FLT_MAX
|
||||
#include "basic_initialize/b3OpenCLUtils.h"
|
||||
@@ -219,7 +219,7 @@ struct MyTriangleCallback : public btNodeOverlapCallback
|
||||
};
|
||||
|
||||
|
||||
#define float4 btVector3
|
||||
#define float4 b3Vector3
|
||||
#define make_float4(x,y,z,w) btVector4(x,y,z,w)
|
||||
|
||||
float signedDistanceFromPointToPlane(const float4& point, const float4& planeEqn, float4* closestPointOnFace)
|
||||
@@ -234,14 +234,14 @@ float signedDistanceFromPointToPlane(const float4& point, const float4& planeEqn
|
||||
|
||||
|
||||
#define cross3(a,b) (a.cross(b))
|
||||
btVector3 transform(btVector3* v, const btVector3* pos, const btVector3* orn)
|
||||
b3Vector3 transform(b3Vector3* v, const b3Vector3* pos, const b3Vector3* orn)
|
||||
{
|
||||
btTransform tr;
|
||||
b3Transform tr;
|
||||
tr.setIdentity();
|
||||
tr.setOrigin(*pos);
|
||||
btQuaternion* o = (btQuaternion*) orn;
|
||||
b3Quaternion* o = (b3Quaternion*) orn;
|
||||
tr.setRotation(*o);
|
||||
btVector3 res = tr(*v);
|
||||
b3Vector3 res = tr(*v);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ void computeContactPlaneConvex(int pairIndex,
|
||||
const b3RigidBodyCL* rigidBodies,
|
||||
const b3Collidable* collidables,
|
||||
const b3ConvexPolyhedronCL* convexShapes,
|
||||
const btVector3* convexVertices,
|
||||
const b3Vector3* convexVertices,
|
||||
const int* convexIndices,
|
||||
const btGpuFace* faces,
|
||||
b3Contact4* globalContactsOut,
|
||||
@@ -422,40 +422,40 @@ void computeContactPlaneConvex(int pairIndex,
|
||||
int shapeIndex = collidables[collidableIndexB].m_shapeIndex;
|
||||
const b3ConvexPolyhedronCL* hullB = &convexShapes[shapeIndex];
|
||||
|
||||
btVector3 posB = rigidBodies[bodyIndexB].m_pos;
|
||||
btQuaternion ornB = rigidBodies[bodyIndexB].m_quat;
|
||||
btVector3 posA = rigidBodies[bodyIndexA].m_pos;
|
||||
btQuaternion ornA = rigidBodies[bodyIndexA].m_quat;
|
||||
b3Vector3 posB = rigidBodies[bodyIndexB].m_pos;
|
||||
b3Quaternion ornB = rigidBodies[bodyIndexB].m_quat;
|
||||
b3Vector3 posA = rigidBodies[bodyIndexA].m_pos;
|
||||
b3Quaternion ornA = rigidBodies[bodyIndexA].m_quat;
|
||||
|
||||
int numContactsOut = 0;
|
||||
int numWorldVertsB1= 0;
|
||||
|
||||
btVector3 planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane;
|
||||
btVector3 planeNormal(planeEq.x,planeEq.y,planeEq.z);
|
||||
btVector3 planeNormalWorld = quatRotate(ornA,planeNormal);
|
||||
b3Vector3 planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane;
|
||||
b3Vector3 planeNormal(planeEq.x,planeEq.y,planeEq.z);
|
||||
b3Vector3 planeNormalWorld = quatRotate(ornA,planeNormal);
|
||||
float planeConstant = planeEq.w;
|
||||
btTransform convexWorldTransform;
|
||||
b3Transform convexWorldTransform;
|
||||
convexWorldTransform.setIdentity();
|
||||
convexWorldTransform.setOrigin(posB);
|
||||
convexWorldTransform.setRotation(ornB);
|
||||
btTransform planeTransform;
|
||||
b3Transform planeTransform;
|
||||
planeTransform.setIdentity();
|
||||
planeTransform.setOrigin(posA);
|
||||
planeTransform.setRotation(ornA);
|
||||
|
||||
btTransform planeInConvex;
|
||||
b3Transform planeInConvex;
|
||||
planeInConvex= convexWorldTransform.inverse() * planeTransform;
|
||||
btTransform convexInPlane;
|
||||
b3Transform convexInPlane;
|
||||
convexInPlane = planeTransform.inverse() * convexWorldTransform;
|
||||
|
||||
btVector3 planeNormalInConvex = planeInConvex.getBasis()*-planeNormal;
|
||||
b3Vector3 planeNormalInConvex = planeInConvex.getBasis()*-planeNormal;
|
||||
float maxDot = -1e30;
|
||||
int hitVertex=-1;
|
||||
btVector3 hitVtx;
|
||||
b3Vector3 hitVtx;
|
||||
|
||||
#define MAX_PLANE_CONVEX_POINTS 64
|
||||
|
||||
btVector3 contactPoints[MAX_PLANE_CONVEX_POINTS];
|
||||
b3Vector3 contactPoints[MAX_PLANE_CONVEX_POINTS];
|
||||
int numPoints = 0;
|
||||
|
||||
btInt4 contactIdx;
|
||||
@@ -466,7 +466,7 @@ void computeContactPlaneConvex(int pairIndex,
|
||||
|
||||
for (int i=0;i<hullB->m_numVertices;i++)
|
||||
{
|
||||
btVector3 vtx = convexVertices[hullB->m_vertexOffset+i];
|
||||
b3Vector3 vtx = convexVertices[hullB->m_vertexOffset+i];
|
||||
float curDot = vtx.dot(planeNormalInConvex);
|
||||
|
||||
|
||||
@@ -482,8 +482,8 @@ void computeContactPlaneConvex(int pairIndex,
|
||||
|
||||
if (numPoints<MAX_PLANE_CONVEX_POINTS)
|
||||
{
|
||||
btVector3 vtxWorld = convexWorldTransform*vtx;
|
||||
btVector3 vtxInPlane = planeTransform.inverse()*vtxWorld;
|
||||
b3Vector3 vtxWorld = convexWorldTransform*vtx;
|
||||
b3Vector3 vtxInPlane = planeTransform.inverse()*vtxWorld;
|
||||
float dist = planeNormal.dot(vtxInPlane)-planeConstant;
|
||||
if (dist<0.f)
|
||||
{
|
||||
@@ -523,7 +523,7 @@ void computeContactPlaneConvex(int pairIndex,
|
||||
c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;
|
||||
for (int i=0;i<numReducedPoints;i++)
|
||||
{
|
||||
btVector3 pOnB1 = contactPoints[contactIdx.s[i]];
|
||||
b3Vector3 pOnB1 = contactPoints[contactIdx.s[i]];
|
||||
c->m_worldPos[i] = pOnB1;
|
||||
}
|
||||
c->m_worldNormal[3] = numReducedPoints;
|
||||
@@ -544,7 +544,7 @@ void computeContactPlaneCompound(int pairIndex,
|
||||
const b3RigidBodyCL* rigidBodies,
|
||||
const b3Collidable* collidables,
|
||||
const b3ConvexPolyhedronCL* convexShapes,
|
||||
const btVector3* convexVertices,
|
||||
const b3Vector3* convexVertices,
|
||||
const int* convexIndices,
|
||||
const btGpuFace* faces,
|
||||
b3Contact4* globalContactsOut,
|
||||
@@ -560,40 +560,40 @@ void computeContactPlaneCompound(int pairIndex,
|
||||
int shapeIndex = collidables[collidableIndexB].m_shapeIndex;
|
||||
const b3ConvexPolyhedronCL* hullB = &convexShapes[shapeIndex];
|
||||
|
||||
btVector3 posB = rigidBodies[bodyIndexB].m_pos;
|
||||
btQuaternion ornB = rigidBodies[bodyIndexB].m_quat;
|
||||
btVector3 posA = rigidBodies[bodyIndexA].m_pos;
|
||||
btQuaternion ornA = rigidBodies[bodyIndexA].m_quat;
|
||||
b3Vector3 posB = rigidBodies[bodyIndexB].m_pos;
|
||||
b3Quaternion ornB = rigidBodies[bodyIndexB].m_quat;
|
||||
b3Vector3 posA = rigidBodies[bodyIndexA].m_pos;
|
||||
b3Quaternion ornA = rigidBodies[bodyIndexA].m_quat;
|
||||
|
||||
int numContactsOut = 0;
|
||||
int numWorldVertsB1= 0;
|
||||
|
||||
btVector3 planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane;
|
||||
btVector3 planeNormal(planeEq.x,planeEq.y,planeEq.z);
|
||||
btVector3 planeNormalWorld = quatRotate(ornA,planeNormal);
|
||||
b3Vector3 planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane;
|
||||
b3Vector3 planeNormal(planeEq.x,planeEq.y,planeEq.z);
|
||||
b3Vector3 planeNormalWorld = quatRotate(ornA,planeNormal);
|
||||
float planeConstant = planeEq.w;
|
||||
btTransform convexWorldTransform;
|
||||
b3Transform convexWorldTransform;
|
||||
convexWorldTransform.setIdentity();
|
||||
convexWorldTransform.setOrigin(posB);
|
||||
convexWorldTransform.setRotation(ornB);
|
||||
btTransform planeTransform;
|
||||
b3Transform planeTransform;
|
||||
planeTransform.setIdentity();
|
||||
planeTransform.setOrigin(posA);
|
||||
planeTransform.setRotation(ornA);
|
||||
|
||||
btTransform planeInConvex;
|
||||
b3Transform planeInConvex;
|
||||
planeInConvex= convexWorldTransform.inverse() * planeTransform;
|
||||
btTransform convexInPlane;
|
||||
b3Transform convexInPlane;
|
||||
convexInPlane = planeTransform.inverse() * convexWorldTransform;
|
||||
|
||||
btVector3 planeNormalInConvex = planeInConvex.getBasis()*-planeNormal;
|
||||
b3Vector3 planeNormalInConvex = planeInConvex.getBasis()*-planeNormal;
|
||||
float maxDot = -1e30;
|
||||
int hitVertex=-1;
|
||||
btVector3 hitVtx;
|
||||
b3Vector3 hitVtx;
|
||||
|
||||
#define MAX_PLANE_CONVEX_POINTS 64
|
||||
|
||||
btVector3 contactPoints[MAX_PLANE_CONVEX_POINTS];
|
||||
b3Vector3 contactPoints[MAX_PLANE_CONVEX_POINTS];
|
||||
int numPoints = 0;
|
||||
|
||||
btInt4 contactIdx;
|
||||
@@ -604,7 +604,7 @@ void computeContactPlaneCompound(int pairIndex,
|
||||
|
||||
for (int i=0;i<hullB->m_numVertices;i++)
|
||||
{
|
||||
btVector3 vtx = convexVertices[hullB->m_vertexOffset+i];
|
||||
b3Vector3 vtx = convexVertices[hullB->m_vertexOffset+i];
|
||||
float curDot = vtx.dot(planeNormalInConvex);
|
||||
|
||||
|
||||
@@ -620,8 +620,8 @@ void computeContactPlaneCompound(int pairIndex,
|
||||
|
||||
if (numPoints<MAX_PLANE_CONVEX_POINTS)
|
||||
{
|
||||
btVector3 vtxWorld = convexWorldTransform*vtx;
|
||||
btVector3 vtxInPlane = planeTransform.inverse()*vtxWorld;
|
||||
b3Vector3 vtxWorld = convexWorldTransform*vtx;
|
||||
b3Vector3 vtxInPlane = planeTransform.inverse()*vtxWorld;
|
||||
float dist = planeNormal.dot(vtxInPlane)-planeConstant;
|
||||
if (dist<0.f)
|
||||
{
|
||||
@@ -661,7 +661,7 @@ void computeContactPlaneCompound(int pairIndex,
|
||||
c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;
|
||||
for (int i=0;i<numReducedPoints;i++)
|
||||
{
|
||||
btVector3 pOnB1 = contactPoints[contactIdx.s[i]];
|
||||
b3Vector3 pOnB1 = contactPoints[contactIdx.s[i]];
|
||||
c->m_worldPos[i] = pOnB1;
|
||||
}
|
||||
c->m_worldNormal[3] = numReducedPoints;
|
||||
@@ -683,7 +683,7 @@ void computeContactSphereConvex(int pairIndex,
|
||||
const b3RigidBodyCL* rigidBodies,
|
||||
const b3Collidable* collidables,
|
||||
const b3ConvexPolyhedronCL* convexShapes,
|
||||
const btVector3* convexVertices,
|
||||
const b3Vector3* convexVertices,
|
||||
const int* convexIndices,
|
||||
const btGpuFace* faces,
|
||||
b3Contact4* globalContactsOut,
|
||||
@@ -693,20 +693,20 @@ void computeContactSphereConvex(int pairIndex,
|
||||
|
||||
float radius = collidables[collidableIndexA].m_radius;
|
||||
float4 spherePos1 = rigidBodies[bodyIndexA].m_pos;
|
||||
btQuaternion sphereOrn = rigidBodies[bodyIndexA].m_quat;
|
||||
b3Quaternion sphereOrn = rigidBodies[bodyIndexA].m_quat;
|
||||
|
||||
|
||||
|
||||
float4 pos = rigidBodies[bodyIndexB].m_pos;
|
||||
|
||||
|
||||
btQuaternion quat = rigidBodies[bodyIndexB].m_quat;
|
||||
b3Quaternion quat = rigidBodies[bodyIndexB].m_quat;
|
||||
|
||||
btTransform tr;
|
||||
b3Transform tr;
|
||||
tr.setIdentity();
|
||||
tr.setOrigin(pos);
|
||||
tr.setRotation(quat);
|
||||
btTransform trInv = tr.inverse();
|
||||
b3Transform trInv = tr.inverse();
|
||||
|
||||
float4 spherePos = trInv(spherePos1);
|
||||
|
||||
@@ -740,7 +740,7 @@ void computeContactSphereConvex(int pairIndex,
|
||||
if ( dist > 0 )
|
||||
{
|
||||
//might hit an edge or vertex
|
||||
btVector3 out;
|
||||
b3Vector3 out;
|
||||
|
||||
bool isInPoly = IsPointInPolygon(spherePos,
|
||||
&face,
|
||||
@@ -758,8 +758,8 @@ void computeContactSphereConvex(int pairIndex,
|
||||
}
|
||||
} else
|
||||
{
|
||||
btVector3 tmp = spherePos-out;
|
||||
btScalar l2 = tmp.length2();
|
||||
b3Vector3 tmp = spherePos-out;
|
||||
b3Scalar l2 = tmp.length2();
|
||||
if (l2<radius*radius)
|
||||
{
|
||||
dist = btSqrt(l2);
|
||||
@@ -837,20 +837,20 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
|
||||
btOpenCLArray<b3Contact4>* contactOut, int& nContacts,
|
||||
int maxContactCapacity,
|
||||
const btOpenCLArray<b3ConvexPolyhedronCL>& convexData,
|
||||
const btOpenCLArray<btVector3>& gpuVertices,
|
||||
const btOpenCLArray<btVector3>& gpuUniqueEdges,
|
||||
const btOpenCLArray<b3Vector3>& gpuVertices,
|
||||
const btOpenCLArray<b3Vector3>& gpuUniqueEdges,
|
||||
const btOpenCLArray<btGpuFace>& gpuFaces,
|
||||
const btOpenCLArray<int>& gpuIndices,
|
||||
const btOpenCLArray<b3Collidable>& gpuCollidables,
|
||||
const btOpenCLArray<btGpuChildShape>& gpuChildShapes,
|
||||
|
||||
const btOpenCLArray<btYetAnotherAabb>& clAabbsWS,
|
||||
btOpenCLArray<btVector3>& worldVertsB1GPU,
|
||||
btOpenCLArray<b3Vector3>& worldVertsB1GPU,
|
||||
btOpenCLArray<btInt4>& clippingFacesOutGPU,
|
||||
btOpenCLArray<btVector3>& worldNormalsAGPU,
|
||||
btOpenCLArray<btVector3>& worldVertsA1GPU,
|
||||
btOpenCLArray<btVector3>& worldVertsB2GPU,
|
||||
btAlignedObjectArray<class b3OptimizedBvh*>& bvhData,
|
||||
btOpenCLArray<b3Vector3>& worldNormalsAGPU,
|
||||
btOpenCLArray<b3Vector3>& worldVertsA1GPU,
|
||||
btOpenCLArray<b3Vector3>& worldVertsB2GPU,
|
||||
b3AlignedObjectArray<class b3OptimizedBvh*>& bvhData,
|
||||
btOpenCLArray<btQuantizedBvhNode>* treeNodesGPU,
|
||||
btOpenCLArray<btBvhSubtreeInfo>* subTreesGPU,
|
||||
int numObjects,
|
||||
@@ -865,38 +865,38 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
|
||||
|
||||
//#define CHECK_ON_HOST
|
||||
#ifdef CHECK_ON_HOST
|
||||
btAlignedObjectArray<btYetAnotherAabb> hostAabbs;
|
||||
b3AlignedObjectArray<btYetAnotherAabb> hostAabbs;
|
||||
clAabbsWS.copyToHost(hostAabbs);
|
||||
btAlignedObjectArray<btInt2> hostPairs;
|
||||
b3AlignedObjectArray<btInt2> hostPairs;
|
||||
pairs->copyToHost(hostPairs);
|
||||
|
||||
btAlignedObjectArray<b3RigidBodyCL> hostBodyBuf;
|
||||
b3AlignedObjectArray<b3RigidBodyCL> hostBodyBuf;
|
||||
bodyBuf->copyToHost(hostBodyBuf);
|
||||
|
||||
|
||||
|
||||
btAlignedObjectArray<b3ConvexPolyhedronCL> hostConvexData;
|
||||
b3AlignedObjectArray<b3ConvexPolyhedronCL> hostConvexData;
|
||||
convexData.copyToHost(hostConvexData);
|
||||
|
||||
btAlignedObjectArray<btVector3> hostVertices;
|
||||
b3AlignedObjectArray<b3Vector3> hostVertices;
|
||||
gpuVertices.copyToHost(hostVertices);
|
||||
|
||||
btAlignedObjectArray<btVector3> hostUniqueEdges;
|
||||
b3AlignedObjectArray<b3Vector3> hostUniqueEdges;
|
||||
gpuUniqueEdges.copyToHost(hostUniqueEdges);
|
||||
btAlignedObjectArray<btGpuFace> hostFaces;
|
||||
b3AlignedObjectArray<btGpuFace> hostFaces;
|
||||
gpuFaces.copyToHost(hostFaces);
|
||||
btAlignedObjectArray<int> hostIndices;
|
||||
b3AlignedObjectArray<int> hostIndices;
|
||||
gpuIndices.copyToHost(hostIndices);
|
||||
btAlignedObjectArray<b3Collidable> hostCollidables;
|
||||
b3AlignedObjectArray<b3Collidable> hostCollidables;
|
||||
gpuCollidables.copyToHost(hostCollidables);
|
||||
|
||||
btAlignedObjectArray<btGpuChildShape> cpuChildShapes;
|
||||
b3AlignedObjectArray<btGpuChildShape> cpuChildShapes;
|
||||
gpuChildShapes.copyToHost(cpuChildShapes);
|
||||
|
||||
|
||||
btAlignedObjectArray<btInt4> hostTriangleConvexPairs;
|
||||
b3AlignedObjectArray<btInt4> hostTriangleConvexPairs;
|
||||
|
||||
btAlignedObjectArray<b3Contact4> hostContacts;
|
||||
b3AlignedObjectArray<b3Contact4> hostContacts;
|
||||
if (nContacts)
|
||||
{
|
||||
contactOut->copyToHost(hostContacts);
|
||||
@@ -1013,13 +1013,13 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
|
||||
BT_PROFILE("computeConvexConvexContactsGPUSAT");
|
||||
// printf("nContacts = %d\n",nContacts);
|
||||
|
||||
btOpenCLArray<btVector3> sepNormals(m_context,m_queue);
|
||||
btOpenCLArray<b3Vector3> sepNormals(m_context,m_queue);
|
||||
sepNormals.resize(nPairs);
|
||||
btOpenCLArray<int> hasSeparatingNormals(m_context,m_queue);
|
||||
hasSeparatingNormals.resize(nPairs);
|
||||
|
||||
int concaveCapacity=maxTriConvexPairCapacity;
|
||||
btOpenCLArray<btVector3> concaveSepNormals(m_context,m_queue);
|
||||
btOpenCLArray<b3Vector3> concaveSepNormals(m_context,m_queue);
|
||||
concaveSepNormals.resize(concaveCapacity);
|
||||
|
||||
btOpenCLArray<int> numConcavePairsOut(m_context,m_queue);
|
||||
@@ -1029,7 +1029,7 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
|
||||
btOpenCLArray<btCompoundOverlappingPair> gpuCompoundPairs(m_context,m_queue);
|
||||
gpuCompoundPairs.resize(compoundPairCapacity);
|
||||
|
||||
btOpenCLArray<btVector3> gpuCompoundSepNormals(m_context,m_queue);
|
||||
btOpenCLArray<b3Vector3> gpuCompoundSepNormals(m_context,m_queue);
|
||||
gpuCompoundSepNormals.resize(compoundPairCapacity);
|
||||
|
||||
|
||||
@@ -1081,9 +1081,9 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
|
||||
if (numNodes)
|
||||
{
|
||||
int numSubTrees = subTreesGPU->size();
|
||||
btVector3 bvhAabbMin = bvhData[0]->m_bvhAabbMin;
|
||||
btVector3 bvhAabbMax = bvhData[0]->m_bvhAabbMax;
|
||||
btVector3 bvhQuantization = bvhData[0]->m_bvhQuantization;
|
||||
b3Vector3 bvhAabbMin = bvhData[0]->m_bvhAabbMin;
|
||||
b3Vector3 bvhAabbMax = bvhData[0]->m_bvhAabbMax;
|
||||
b3Vector3 bvhQuantization = bvhData[0]->m_bvhQuantization;
|
||||
{
|
||||
BT_PROFILE("m_bvhTraversalKernel");
|
||||
numConcavePairs = numConcavePairsOut.at(0);
|
||||
@@ -1142,9 +1142,9 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
|
||||
launcher.launch1D( num);
|
||||
clFinish(m_queue);
|
||||
|
||||
// btAlignedObjectArray<btVector3> cpuCompoundSepNormals;
|
||||
// b3AlignedObjectArray<b3Vector3> cpuCompoundSepNormals;
|
||||
// concaveSepNormals.copyToHost(cpuCompoundSepNormals);
|
||||
// btAlignedObjectArray<btInt4> cpuConcavePairs;
|
||||
// b3AlignedObjectArray<btInt4> cpuConcavePairs;
|
||||
// triangleConvexPairsOut.copyToHost(cpuConcavePairs);
|
||||
|
||||
|
||||
@@ -1355,7 +1355,7 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
|
||||
clFinish(m_queue);
|
||||
nContacts = m_totalContactsOut.at(0);
|
||||
contactOut->resize(nContacts);
|
||||
btAlignedObjectArray<b3Contact4> cpuContacts;
|
||||
b3AlignedObjectArray<b3Contact4> cpuContacts;
|
||||
contactOut->copyToHost(cpuContacts);
|
||||
// printf("nContacts after = %d\n", nContacts);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "parallel_primitives/host/btOpenCLArray.h"
|
||||
#include "b3RigidBodyCL.h"
|
||||
#include "BulletCommon/btAlignedObjectArray.h"
|
||||
#include "BulletCommon/b3AlignedObjectArray.h"
|
||||
#include "b3ConvexUtility.h"
|
||||
#include "b3ConvexPolyhedronCL.h"
|
||||
#include "b3Collidable.h"
|
||||
@@ -69,20 +69,20 @@ struct GpuSatCollision
|
||||
btOpenCLArray<b3Contact4>* contactOut, int& nContacts,
|
||||
int maxContactCapacity,
|
||||
const btOpenCLArray<b3ConvexPolyhedronCL>& hostConvexData,
|
||||
const btOpenCLArray<btVector3>& vertices,
|
||||
const btOpenCLArray<btVector3>& uniqueEdges,
|
||||
const btOpenCLArray<b3Vector3>& vertices,
|
||||
const btOpenCLArray<b3Vector3>& uniqueEdges,
|
||||
const btOpenCLArray<btGpuFace>& faces,
|
||||
const btOpenCLArray<int>& indices,
|
||||
const btOpenCLArray<b3Collidable>& gpuCollidables,
|
||||
const btOpenCLArray<btGpuChildShape>& gpuChildShapes,
|
||||
|
||||
const btOpenCLArray<btYetAnotherAabb>& clAabbs,
|
||||
btOpenCLArray<btVector3>& worldVertsB1GPU,
|
||||
btOpenCLArray<b3Vector3>& worldVertsB1GPU,
|
||||
btOpenCLArray<btInt4>& clippingFacesOutGPU,
|
||||
btOpenCLArray<btVector3>& worldNormalsAGPU,
|
||||
btOpenCLArray<btVector3>& worldVertsA1GPU,
|
||||
btOpenCLArray<btVector3>& worldVertsB2GPU,
|
||||
btAlignedObjectArray<class b3OptimizedBvh*>& bvhData,
|
||||
btOpenCLArray<b3Vector3>& worldNormalsAGPU,
|
||||
btOpenCLArray<b3Vector3>& worldVertsA1GPU,
|
||||
btOpenCLArray<b3Vector3>& worldVertsB2GPU,
|
||||
b3AlignedObjectArray<class b3OptimizedBvh*>& bvhData,
|
||||
btOpenCLArray<btQuantizedBvhNode>* treeNodesGPU,
|
||||
btOpenCLArray<btBvhSubtreeInfo>* subTreesGPU,
|
||||
int numObjects,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef CONVEX_POLYHEDRON_CL
|
||||
#define CONVEX_POLYHEDRON_CL
|
||||
|
||||
#include "BulletCommon/btTransform.h"
|
||||
#include "BulletCommon/b3Transform.h"
|
||||
|
||||
struct btGpuFace
|
||||
{
|
||||
@@ -12,12 +12,12 @@ struct btGpuFace
|
||||
|
||||
ATTRIBUTE_ALIGNED16(struct) b3ConvexPolyhedronCL
|
||||
{
|
||||
btVector3 m_localCenter;
|
||||
btVector3 m_extents;
|
||||
btVector3 mC;
|
||||
btVector3 mE;
|
||||
b3Vector3 m_localCenter;
|
||||
b3Vector3 m_extents;
|
||||
b3Vector3 mC;
|
||||
b3Vector3 mE;
|
||||
|
||||
btScalar m_radius;
|
||||
b3Scalar m_radius;
|
||||
int m_faceOffset;
|
||||
int m_numFaces;
|
||||
int m_numVertices;
|
||||
@@ -29,29 +29,29 @@ ATTRIBUTE_ALIGNED16(struct) b3ConvexPolyhedronCL
|
||||
|
||||
|
||||
|
||||
inline void project(const btTransform& trans, const btVector3& dir, const btAlignedObjectArray<btVector3>& vertices, btScalar& min, btScalar& max) const
|
||||
inline void project(const b3Transform& trans, const b3Vector3& dir, const b3AlignedObjectArray<b3Vector3>& vertices, b3Scalar& min, b3Scalar& max) const
|
||||
{
|
||||
min = FLT_MAX;
|
||||
max = -FLT_MAX;
|
||||
int numVerts = m_numVertices;
|
||||
|
||||
const btVector3 localDir = trans.getBasis().transpose()*dir;
|
||||
const btVector3 localDi2 = quatRotate(trans.getRotation().inverse(),dir);
|
||||
const b3Vector3 localDir = trans.getBasis().transpose()*dir;
|
||||
const b3Vector3 localDi2 = quatRotate(trans.getRotation().inverse(),dir);
|
||||
|
||||
btScalar offset = trans.getOrigin().dot(dir);
|
||||
b3Scalar offset = trans.getOrigin().dot(dir);
|
||||
|
||||
for(int i=0;i<numVerts;i++)
|
||||
{
|
||||
//btVector3 pt = trans * vertices[m_vertexOffset+i];
|
||||
//btScalar dp = pt.dot(dir);
|
||||
btScalar dp = vertices[m_vertexOffset+i].dot(localDir);
|
||||
//b3Vector3 pt = trans * vertices[m_vertexOffset+i];
|
||||
//b3Scalar dp = pt.dot(dir);
|
||||
b3Scalar dp = vertices[m_vertexOffset+i].dot(localDir);
|
||||
//btAssert(dp==dpL);
|
||||
if(dp < min) min = dp;
|
||||
if(dp > max) max = dp;
|
||||
}
|
||||
if(min>max)
|
||||
{
|
||||
btScalar tmp = min;
|
||||
b3Scalar tmp = min;
|
||||
min = max;
|
||||
max = tmp;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ subject to the following restrictions:
|
||||
#include "b3ConvexUtility.h"
|
||||
#include "BulletGeometry/btConvexHullComputer.h"
|
||||
#include "BulletGeometry/btGrahamScan2dConvexHull.h"
|
||||
#include "BulletCommon/btQuaternion.h"
|
||||
#include "BulletCommon/btHashMap.h"
|
||||
#include "BulletCommon/b3Quaternion.h"
|
||||
#include "BulletCommon/b3HashMap.h"
|
||||
|
||||
#include "b3ConvexPolyhedronCL.h"
|
||||
|
||||
@@ -28,21 +28,21 @@ b3ConvexUtility::~b3ConvexUtility()
|
||||
{
|
||||
}
|
||||
|
||||
bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices, int numPoints, bool mergeCoplanarTriangles)
|
||||
bool b3ConvexUtility::initializePolyhedralFeatures(const b3Vector3* orgVertices, int numPoints, bool mergeCoplanarTriangles)
|
||||
{
|
||||
|
||||
|
||||
|
||||
btConvexHullComputer conv;
|
||||
conv.compute(&orgVertices[0].getX(), sizeof(btVector3),numPoints,0.f,0.f);
|
||||
conv.compute(&orgVertices[0].getX(), sizeof(b3Vector3),numPoints,0.f,0.f);
|
||||
|
||||
btAlignedObjectArray<btVector3> faceNormals;
|
||||
b3AlignedObjectArray<b3Vector3> faceNormals;
|
||||
int numFaces = conv.faces.size();
|
||||
faceNormals.resize(numFaces);
|
||||
btConvexHullComputer* convexUtil = &conv;
|
||||
|
||||
|
||||
btAlignedObjectArray<btMyFace> tmpFaces;
|
||||
b3AlignedObjectArray<btMyFace> tmpFaces;
|
||||
tmpFaces.resize(numFaces);
|
||||
|
||||
int numVertices = convexUtil->vertices.size();
|
||||
@@ -60,7 +60,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
|
||||
const btConvexHullComputer::Edge* firstEdge = &convexUtil->edges[face];
|
||||
const btConvexHullComputer::Edge* edge = firstEdge;
|
||||
|
||||
btVector3 edges[3];
|
||||
b3Vector3 edges[3];
|
||||
int numEdges = 0;
|
||||
//compute face normals
|
||||
|
||||
@@ -70,10 +70,10 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
|
||||
int src = edge->getSourceVertex();
|
||||
tmpFaces[i].m_indices.push_back(src);
|
||||
int targ = edge->getTargetVertex();
|
||||
btVector3 wa = convexUtil->vertices[src];
|
||||
b3Vector3 wa = convexUtil->vertices[src];
|
||||
|
||||
btVector3 wb = convexUtil->vertices[targ];
|
||||
btVector3 newEdge = wb-wa;
|
||||
b3Vector3 wb = convexUtil->vertices[targ];
|
||||
b3Vector3 newEdge = wb-wa;
|
||||
newEdge.normalize();
|
||||
if (numEdges<2)
|
||||
edges[numEdges++] = newEdge;
|
||||
@@ -81,7 +81,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
|
||||
edge = edge->getNextEdgeOfFace();
|
||||
} while (edge!=firstEdge);
|
||||
|
||||
btScalar planeEq = 1e30f;
|
||||
b3Scalar planeEq = 1e30f;
|
||||
|
||||
|
||||
if (numEdges==2)
|
||||
@@ -102,7 +102,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
|
||||
|
||||
for (int v=0;v<tmpFaces[i].m_indices.size();v++)
|
||||
{
|
||||
btScalar eq = m_vertices[tmpFaces[i].m_indices[v]].dot(faceNormals[i]);
|
||||
b3Scalar eq = m_vertices[tmpFaces[i].m_indices[v]].dot(faceNormals[i]);
|
||||
if (planeEq>eq)
|
||||
{
|
||||
planeEq=eq;
|
||||
@@ -113,26 +113,26 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
|
||||
|
||||
//merge coplanar faces and copy them to m_polyhedron
|
||||
|
||||
btScalar faceWeldThreshold= 0.999f;
|
||||
btAlignedObjectArray<int> todoFaces;
|
||||
b3Scalar faceWeldThreshold= 0.999f;
|
||||
b3AlignedObjectArray<int> todoFaces;
|
||||
for (int i=0;i<tmpFaces.size();i++)
|
||||
todoFaces.push_back(i);
|
||||
|
||||
while (todoFaces.size())
|
||||
{
|
||||
btAlignedObjectArray<int> coplanarFaceGroup;
|
||||
b3AlignedObjectArray<int> coplanarFaceGroup;
|
||||
int refFace = todoFaces[todoFaces.size()-1];
|
||||
|
||||
coplanarFaceGroup.push_back(refFace);
|
||||
btMyFace& faceA = tmpFaces[refFace];
|
||||
todoFaces.pop_back();
|
||||
|
||||
btVector3 faceNormalA(faceA.m_plane[0],faceA.m_plane[1],faceA.m_plane[2]);
|
||||
b3Vector3 faceNormalA(faceA.m_plane[0],faceA.m_plane[1],faceA.m_plane[2]);
|
||||
for (int j=todoFaces.size()-1;j>=0;j--)
|
||||
{
|
||||
int i = todoFaces[j];
|
||||
btMyFace& faceB = tmpFaces[i];
|
||||
btVector3 faceNormalB(faceB.m_plane[0],faceB.m_plane[1],faceB.m_plane[2]);
|
||||
b3Vector3 faceNormalB(faceB.m_plane[0],faceB.m_plane[1],faceB.m_plane[2]);
|
||||
if (faceNormalA.dot(faceNormalB)>faceWeldThreshold)
|
||||
{
|
||||
coplanarFaceGroup.push_back(i);
|
||||
@@ -146,20 +146,20 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
|
||||
{
|
||||
//do the merge: use Graham Scan 2d convex hull
|
||||
|
||||
btAlignedObjectArray<GrahamVector3> orgpoints;
|
||||
btVector3 averageFaceNormal(0,0,0);
|
||||
b3AlignedObjectArray<GrahamVector3> orgpoints;
|
||||
b3Vector3 averageFaceNormal(0,0,0);
|
||||
|
||||
for (int i=0;i<coplanarFaceGroup.size();i++)
|
||||
{
|
||||
// m_polyhedron->m_faces.push_back(tmpFaces[coplanarFaceGroup[i]]);
|
||||
|
||||
btMyFace& face = tmpFaces[coplanarFaceGroup[i]];
|
||||
btVector3 faceNormal(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
|
||||
b3Vector3 faceNormal(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
|
||||
averageFaceNormal+=faceNormal;
|
||||
for (int f=0;f<face.m_indices.size();f++)
|
||||
{
|
||||
int orgIndex = face.m_indices[f];
|
||||
btVector3 pt = m_vertices[orgIndex];
|
||||
b3Vector3 pt = m_vertices[orgIndex];
|
||||
|
||||
bool found = false;
|
||||
|
||||
@@ -183,7 +183,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
|
||||
for (int i=0;i<4;i++)
|
||||
combinedFace.m_plane[i] = tmpFaces[coplanarFaceGroup[0]].m_plane[i];
|
||||
|
||||
btAlignedObjectArray<GrahamVector3> hull;
|
||||
b3AlignedObjectArray<GrahamVector3> hull;
|
||||
|
||||
averageFaceNormal.normalize();
|
||||
GrahamScanConvexHull2D(orgpoints,hull,averageFaceNormal);
|
||||
@@ -269,7 +269,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
|
||||
|
||||
|
||||
|
||||
inline bool IsAlmostZero(const btVector3& v)
|
||||
inline bool IsAlmostZero(const b3Vector3& v)
|
||||
{
|
||||
if(fabsf(v.getX())>1e-6 || fabsf(v.getY())>1e-6 || fabsf(v.getZ())>1e-6) return false;
|
||||
return true;
|
||||
@@ -314,20 +314,20 @@ bool b3ConvexUtility::testContainment() const
|
||||
{
|
||||
for(int p=0;p<8;p++)
|
||||
{
|
||||
btVector3 LocalPt;
|
||||
if(p==0) LocalPt = m_localCenter + btVector3(m_extents[0], m_extents[1], m_extents[2]);
|
||||
else if(p==1) LocalPt = m_localCenter + btVector3(m_extents[0], m_extents[1], -m_extents[2]);
|
||||
else if(p==2) LocalPt = m_localCenter + btVector3(m_extents[0], -m_extents[1], m_extents[2]);
|
||||
else if(p==3) LocalPt = m_localCenter + btVector3(m_extents[0], -m_extents[1], -m_extents[2]);
|
||||
else if(p==4) LocalPt = m_localCenter + btVector3(-m_extents[0], m_extents[1], m_extents[2]);
|
||||
else if(p==5) LocalPt = m_localCenter + btVector3(-m_extents[0], m_extents[1], -m_extents[2]);
|
||||
else if(p==6) LocalPt = m_localCenter + btVector3(-m_extents[0], -m_extents[1], m_extents[2]);
|
||||
else if(p==7) LocalPt = m_localCenter + btVector3(-m_extents[0], -m_extents[1], -m_extents[2]);
|
||||
b3Vector3 LocalPt;
|
||||
if(p==0) LocalPt = m_localCenter + b3Vector3(m_extents[0], m_extents[1], m_extents[2]);
|
||||
else if(p==1) LocalPt = m_localCenter + b3Vector3(m_extents[0], m_extents[1], -m_extents[2]);
|
||||
else if(p==2) LocalPt = m_localCenter + b3Vector3(m_extents[0], -m_extents[1], m_extents[2]);
|
||||
else if(p==3) LocalPt = m_localCenter + b3Vector3(m_extents[0], -m_extents[1], -m_extents[2]);
|
||||
else if(p==4) LocalPt = m_localCenter + b3Vector3(-m_extents[0], m_extents[1], m_extents[2]);
|
||||
else if(p==5) LocalPt = m_localCenter + b3Vector3(-m_extents[0], m_extents[1], -m_extents[2]);
|
||||
else if(p==6) LocalPt = m_localCenter + b3Vector3(-m_extents[0], -m_extents[1], m_extents[2]);
|
||||
else if(p==7) LocalPt = m_localCenter + b3Vector3(-m_extents[0], -m_extents[1], -m_extents[2]);
|
||||
|
||||
for(int i=0;i<m_faces.size();i++)
|
||||
{
|
||||
const btVector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]);
|
||||
const btScalar d = LocalPt.dot(Normal) + m_faces[i].m_plane[3];
|
||||
const b3Vector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]);
|
||||
const b3Scalar d = LocalPt.dot(Normal) + m_faces[i].m_plane[3];
|
||||
if(d>0.0f)
|
||||
return false;
|
||||
}
|
||||
@@ -339,9 +339,9 @@ bool b3ConvexUtility::testContainment() const
|
||||
void b3ConvexUtility::initialize()
|
||||
{
|
||||
|
||||
btHashMap<btInternalVertexPair,btInternalEdge> edges;
|
||||
b3HashMap<btInternalVertexPair,btInternalEdge> edges;
|
||||
|
||||
btScalar TotalArea = 0.0f;
|
||||
b3Scalar TotalArea = 0.0f;
|
||||
|
||||
m_localCenter.setValue(0, 0, 0);
|
||||
for(int i=0;i<m_faces.size();i++)
|
||||
@@ -353,11 +353,11 @@ void b3ConvexUtility::initialize()
|
||||
int k = (j+1)%numVertices;
|
||||
btInternalVertexPair vp(m_faces[i].m_indices[j],m_faces[i].m_indices[k]);
|
||||
btInternalEdge* edptr = edges.find(vp);
|
||||
btVector3 edge = m_vertices[vp.m_v1]-m_vertices[vp.m_v0];
|
||||
b3Vector3 edge = m_vertices[vp.m_v1]-m_vertices[vp.m_v0];
|
||||
edge.normalize();
|
||||
|
||||
bool found = false;
|
||||
btVector3 diff,diff2;
|
||||
b3Vector3 diff,diff2;
|
||||
|
||||
for (int p=0;p<m_uniqueEdges.size();p++)
|
||||
{
|
||||
@@ -421,14 +421,14 @@ void b3ConvexUtility::initialize()
|
||||
int numVertices = m_faces[i].m_indices.size();
|
||||
int NbTris = numVertices-2;
|
||||
|
||||
const btVector3& p0 = m_vertices[m_faces[i].m_indices[0]];
|
||||
const b3Vector3& p0 = m_vertices[m_faces[i].m_indices[0]];
|
||||
for(int j=1;j<=NbTris;j++)
|
||||
{
|
||||
int k = (j+1)%numVertices;
|
||||
const btVector3& p1 = m_vertices[m_faces[i].m_indices[j]];
|
||||
const btVector3& p2 = m_vertices[m_faces[i].m_indices[k]];
|
||||
btScalar Area = ((p0 - p1).cross(p0 - p2)).length() * 0.5f;
|
||||
btVector3 Center = (p0+p1+p2)/3.0f;
|
||||
const b3Vector3& p1 = m_vertices[m_faces[i].m_indices[j]];
|
||||
const b3Vector3& p2 = m_vertices[m_faces[i].m_indices[k]];
|
||||
b3Scalar Area = ((p0 - p1).cross(p0 - p2)).length() * 0.5f;
|
||||
b3Vector3 Center = (p0+p1+p2)/3.0f;
|
||||
m_localCenter += Area * Center;
|
||||
TotalArea += Area;
|
||||
}
|
||||
@@ -444,22 +444,22 @@ void b3ConvexUtility::initialize()
|
||||
m_radius = FLT_MAX;
|
||||
for(int i=0;i<m_faces.size();i++)
|
||||
{
|
||||
const btVector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]);
|
||||
const btScalar dist = btFabs(m_localCenter.dot(Normal) + m_faces[i].m_plane[3]);
|
||||
const b3Vector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]);
|
||||
const b3Scalar dist = btFabs(m_localCenter.dot(Normal) + m_faces[i].m_plane[3]);
|
||||
if(dist<m_radius)
|
||||
m_radius = dist;
|
||||
}
|
||||
|
||||
|
||||
btScalar MinX = FLT_MAX;
|
||||
btScalar MinY = FLT_MAX;
|
||||
btScalar MinZ = FLT_MAX;
|
||||
btScalar MaxX = -FLT_MAX;
|
||||
btScalar MaxY = -FLT_MAX;
|
||||
btScalar MaxZ = -FLT_MAX;
|
||||
b3Scalar MinX = FLT_MAX;
|
||||
b3Scalar MinY = FLT_MAX;
|
||||
b3Scalar MinZ = FLT_MAX;
|
||||
b3Scalar MaxX = -FLT_MAX;
|
||||
b3Scalar MaxY = -FLT_MAX;
|
||||
b3Scalar MaxZ = -FLT_MAX;
|
||||
for(int i=0; i<m_vertices.size(); i++)
|
||||
{
|
||||
const btVector3& pt = m_vertices[i];
|
||||
const b3Vector3& pt = m_vertices[i];
|
||||
if(pt.getX()<MinX) MinX = pt.getX();
|
||||
if(pt.getX()>MaxX) MaxX = pt.getX();
|
||||
if(pt.getY()<MinY) MinY = pt.getY();
|
||||
@@ -472,10 +472,10 @@ void b3ConvexUtility::initialize()
|
||||
|
||||
|
||||
|
||||
// const btScalar r = m_radius / sqrtf(2.0f);
|
||||
const btScalar r = m_radius / sqrtf(3.0f);
|
||||
// const b3Scalar r = m_radius / sqrtf(2.0f);
|
||||
const b3Scalar r = m_radius / sqrtf(3.0f);
|
||||
const int LargestExtent = mE.maxAxis();
|
||||
const btScalar Step = (mE[LargestExtent]*0.5f - r)/1024.0f;
|
||||
const b3Scalar Step = (mE[LargestExtent]*0.5f - r)/1024.0f;
|
||||
m_extents[0] = m_extents[1] = m_extents[2] = r;
|
||||
m_extents[LargestExtent] = mE[LargestExtent]*0.5f;
|
||||
bool FoundBox = false;
|
||||
@@ -496,14 +496,14 @@ void b3ConvexUtility::initialize()
|
||||
else
|
||||
{
|
||||
// Refine the box
|
||||
const btScalar Step = (m_radius - r)/1024.0f;
|
||||
const b3Scalar Step = (m_radius - r)/1024.0f;
|
||||
const int e0 = (1<<LargestExtent) & 3;
|
||||
const int e1 = (1<<e0) & 3;
|
||||
|
||||
for(int j=0;j<1024;j++)
|
||||
{
|
||||
const btScalar Saved0 = m_extents[e0];
|
||||
const btScalar Saved1 = m_extents[e1];
|
||||
const b3Scalar Saved0 = m_extents[e0];
|
||||
const b3Scalar Saved1 = m_extents[e1];
|
||||
m_extents[e0] += Step;
|
||||
m_extents[e1] += Step;
|
||||
|
||||
|
||||
@@ -17,16 +17,16 @@ subject to the following restrictions:
|
||||
#ifndef _BT_CONVEX_UTILITY_H
|
||||
#define _BT_CONVEX_UTILITY_H
|
||||
|
||||
#include "BulletCommon/btAlignedObjectArray.h"
|
||||
#include "BulletCommon/btTransform.h"
|
||||
#include "BulletCommon/b3AlignedObjectArray.h"
|
||||
#include "BulletCommon/b3Transform.h"
|
||||
|
||||
#include "b3ConvexPolyhedronCL.h"
|
||||
|
||||
|
||||
struct btMyFace
|
||||
{
|
||||
btAlignedObjectArray<int> m_indices;
|
||||
btScalar m_plane[4];
|
||||
b3AlignedObjectArray<int> m_indices;
|
||||
b3Scalar m_plane[4];
|
||||
};
|
||||
|
||||
ATTRIBUTE_ALIGNED16(class) b3ConvexUtility
|
||||
@@ -34,15 +34,15 @@ ATTRIBUTE_ALIGNED16(class) b3ConvexUtility
|
||||
public:
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
btVector3 m_localCenter;
|
||||
btVector3 m_extents;
|
||||
btVector3 mC;
|
||||
btVector3 mE;
|
||||
btScalar m_radius;
|
||||
b3Vector3 m_localCenter;
|
||||
b3Vector3 m_extents;
|
||||
b3Vector3 mC;
|
||||
b3Vector3 mE;
|
||||
b3Scalar m_radius;
|
||||
|
||||
btAlignedObjectArray<btVector3> m_vertices;
|
||||
btAlignedObjectArray<btMyFace> m_faces;
|
||||
btAlignedObjectArray<btVector3> m_uniqueEdges;
|
||||
b3AlignedObjectArray<b3Vector3> m_vertices;
|
||||
b3AlignedObjectArray<btMyFace> m_faces;
|
||||
b3AlignedObjectArray<b3Vector3> m_uniqueEdges;
|
||||
|
||||
|
||||
b3ConvexUtility()
|
||||
@@ -50,7 +50,7 @@ ATTRIBUTE_ALIGNED16(class) b3ConvexUtility
|
||||
}
|
||||
virtual ~b3ConvexUtility();
|
||||
|
||||
bool initializePolyhedralFeatures(const btVector3* orgVertices, int numVertices, bool mergeCoplanarTriangles=true);
|
||||
bool initializePolyhedralFeatures(const b3Vector3* orgVertices, int numVertices, bool mergeCoplanarTriangles=true);
|
||||
|
||||
void initialize();
|
||||
bool testContainment() const;
|
||||
|
||||
@@ -17,7 +17,6 @@ subject to the following restrictions:
|
||||
#include "b3OptimizedBvh.h"
|
||||
#include "b3StridingMeshInterface.h"
|
||||
#include "BulletGeometry/btAabbUtil2.h"
|
||||
#include "BulletCommon/btIDebugDraw.h"
|
||||
|
||||
|
||||
b3OptimizedBvh::b3OptimizedBvh()
|
||||
@@ -29,7 +28,7 @@ b3OptimizedBvh::~b3OptimizedBvh()
|
||||
}
|
||||
|
||||
|
||||
void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantizedAabbCompression, const btVector3& bvhAabbMin, const btVector3& bvhAabbMax)
|
||||
void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantizedAabbCompression, const b3Vector3& bvhAabbMin, const b3Vector3& bvhAabbMax)
|
||||
{
|
||||
m_useQuantization = useQuantizedAabbCompression;
|
||||
|
||||
@@ -52,12 +51,12 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
|
||||
{
|
||||
}
|
||||
|
||||
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)
|
||||
virtual void internalProcessTriangleIndex(b3Vector3* triangle,int partId,int triangleIndex)
|
||||
{
|
||||
btOptimizedBvhNode node;
|
||||
btVector3 aabbMin,aabbMax;
|
||||
aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
|
||||
aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
|
||||
b3Vector3 aabbMin,aabbMax;
|
||||
aabbMin.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
|
||||
aabbMax.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
|
||||
aabbMin.setMin(triangle[0]);
|
||||
aabbMax.setMax(triangle[0]);
|
||||
aabbMin.setMin(triangle[1]);
|
||||
@@ -94,7 +93,7 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
|
||||
{
|
||||
}
|
||||
|
||||
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)
|
||||
virtual void internalProcessTriangleIndex(b3Vector3* triangle,int partId,int triangleIndex)
|
||||
{
|
||||
// The partId and triangle index must fit in the same (positive) integer
|
||||
btAssert(partId < (1<<MAX_NUM_PARTS_IN_BITS));
|
||||
@@ -103,9 +102,9 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
|
||||
btAssert(triangleIndex>=0);
|
||||
|
||||
btQuantizedBvhNode node;
|
||||
btVector3 aabbMin,aabbMax;
|
||||
aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
|
||||
aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
|
||||
b3Vector3 aabbMin,aabbMax;
|
||||
aabbMin.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
|
||||
aabbMax.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
|
||||
aabbMin.setMin(triangle[0]);
|
||||
aabbMax.setMax(triangle[0]);
|
||||
aabbMin.setMin(triangle[1]);
|
||||
@@ -114,8 +113,8 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
|
||||
aabbMax.setMax(triangle[2]);
|
||||
|
||||
//PCK: add these checks for zero dimensions of aabb
|
||||
const btScalar MIN_AABB_DIMENSION = btScalar(0.002);
|
||||
const btScalar MIN_AABB_HALF_DIMENSION = btScalar(0.001);
|
||||
const b3Scalar MIN_AABB_DIMENSION = b3Scalar(0.002);
|
||||
const b3Scalar MIN_AABB_HALF_DIMENSION = b3Scalar(0.001);
|
||||
if (aabbMax.getX() - aabbMin.getX() < MIN_AABB_DIMENSION)
|
||||
{
|
||||
aabbMax.setX(aabbMax.getX() + MIN_AABB_HALF_DIMENSION);
|
||||
@@ -168,8 +167,8 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
|
||||
{
|
||||
NodeTriangleCallback callback(m_leafNodes);
|
||||
|
||||
btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
|
||||
btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
|
||||
b3Vector3 aabbMin(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
|
||||
b3Vector3 aabbMax(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
|
||||
|
||||
triangles->InternalProcessAllTriangles(&callback,aabbMin,aabbMax);
|
||||
|
||||
@@ -203,7 +202,7 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
|
||||
|
||||
|
||||
|
||||
void b3OptimizedBvh::refit(b3StridingMeshInterface* meshInterface,const btVector3& aabbMin,const btVector3& aabbMax)
|
||||
void b3OptimizedBvh::refit(b3StridingMeshInterface* meshInterface,const b3Vector3& aabbMin,const b3Vector3& aabbMax)
|
||||
{
|
||||
if (m_useQuantization)
|
||||
{
|
||||
@@ -230,7 +229,7 @@ void b3OptimizedBvh::refit(b3StridingMeshInterface* meshInterface,const btVector
|
||||
|
||||
|
||||
|
||||
void b3OptimizedBvh::refitPartial(b3StridingMeshInterface* meshInterface,const btVector3& aabbMin,const btVector3& aabbMax)
|
||||
void b3OptimizedBvh::refitPartial(b3StridingMeshInterface* meshInterface,const b3Vector3& aabbMin,const b3Vector3& aabbMax)
|
||||
{
|
||||
//incrementally initialize quantization values
|
||||
btAssert(m_useQuantization);
|
||||
@@ -287,9 +286,9 @@ void b3OptimizedBvh::updateBvhNodes(b3StridingMeshInterface* meshInterface,int f
|
||||
int numfaces = 0;
|
||||
PHY_ScalarType indicestype = PHY_INTEGER;
|
||||
|
||||
btVector3 triangleVerts[3];
|
||||
btVector3 aabbMin,aabbMax;
|
||||
const btVector3& meshScaling = meshInterface->getScaling();
|
||||
b3Vector3 triangleVerts[3];
|
||||
b3Vector3 aabbMin,aabbMax;
|
||||
const b3Vector3& meshScaling = meshInterface->getScaling();
|
||||
|
||||
int i;
|
||||
for (i=endNode-1;i>=firstNode;i--)
|
||||
@@ -323,7 +322,7 @@ void b3OptimizedBvh::updateBvhNodes(b3StridingMeshInterface* meshInterface,int f
|
||||
if (type == PHY_FLOAT)
|
||||
{
|
||||
float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
|
||||
triangleVerts[j] = btVector3(
|
||||
triangleVerts[j] = b3Vector3(
|
||||
graphicsbase[0]*meshScaling.getX(),
|
||||
graphicsbase[1]*meshScaling.getY(),
|
||||
graphicsbase[2]*meshScaling.getZ());
|
||||
@@ -331,14 +330,14 @@ void b3OptimizedBvh::updateBvhNodes(b3StridingMeshInterface* meshInterface,int f
|
||||
else
|
||||
{
|
||||
double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
|
||||
triangleVerts[j] = btVector3( btScalar(graphicsbase[0]*meshScaling.getX()), btScalar(graphicsbase[1]*meshScaling.getY()), btScalar(graphicsbase[2]*meshScaling.getZ()));
|
||||
triangleVerts[j] = b3Vector3( b3Scalar(graphicsbase[0]*meshScaling.getX()), b3Scalar(graphicsbase[1]*meshScaling.getY()), b3Scalar(graphicsbase[2]*meshScaling.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
|
||||
aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
|
||||
aabbMin.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
|
||||
aabbMax.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
|
||||
aabbMin.setMin(triangleVerts[0]);
|
||||
aabbMax.setMax(triangleVerts[0]);
|
||||
aabbMin.setMin(triangleVerts[1]);
|
||||
|
||||
@@ -38,11 +38,11 @@ public:
|
||||
|
||||
virtual ~b3OptimizedBvh();
|
||||
|
||||
void build(b3StridingMeshInterface* triangles,bool useQuantizedAabbCompression, const btVector3& bvhAabbMin, const btVector3& bvhAabbMax);
|
||||
void build(b3StridingMeshInterface* triangles,bool useQuantizedAabbCompression, const b3Vector3& bvhAabbMin, const b3Vector3& bvhAabbMax);
|
||||
|
||||
void refit(b3StridingMeshInterface* triangles,const btVector3& aabbMin,const btVector3& aabbMax);
|
||||
void refit(b3StridingMeshInterface* triangles,const b3Vector3& aabbMin,const b3Vector3& aabbMax);
|
||||
|
||||
void refitPartial(b3StridingMeshInterface* triangles,const btVector3& aabbMin, const btVector3& aabbMax);
|
||||
void refitPartial(b3StridingMeshInterface* triangles,const b3Vector3& aabbMin, const b3Vector3& aabbMax);
|
||||
|
||||
void updateBvhNodes(b3StridingMeshInterface* meshInterface,int firstNode,int endNode,int index);
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ subject to the following restrictions:
|
||||
#include "b3QuantizedBvh.h"
|
||||
|
||||
#include "BulletGeometry/btAabbUtil2.h"
|
||||
#include "BulletCommon/btIDebugDraw.h"
|
||||
|
||||
|
||||
#define RAYAABB2
|
||||
@@ -77,25 +76,25 @@ void b3QuantizedBvh::buildInternal()
|
||||
|
||||
///just for debugging, to visualize the individual patches/subtrees
|
||||
#ifdef DEBUG_PATCH_COLORS
|
||||
btVector3 color[4]=
|
||||
b3Vector3 color[4]=
|
||||
{
|
||||
btVector3(1,0,0),
|
||||
btVector3(0,1,0),
|
||||
btVector3(0,0,1),
|
||||
btVector3(0,1,1)
|
||||
b3Vector3(1,0,0),
|
||||
b3Vector3(0,1,0),
|
||||
b3Vector3(0,0,1),
|
||||
b3Vector3(0,1,1)
|
||||
};
|
||||
#endif //DEBUG_PATCH_COLORS
|
||||
|
||||
|
||||
|
||||
void b3QuantizedBvh::setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin)
|
||||
void b3QuantizedBvh::setQuantizationValues(const b3Vector3& bvhAabbMin,const b3Vector3& bvhAabbMax,b3Scalar quantizationMargin)
|
||||
{
|
||||
//enlarge the AABB to avoid division by zero when initializing the quantization values
|
||||
btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
|
||||
b3Vector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
|
||||
m_bvhAabbMin = bvhAabbMin - clampValue;
|
||||
m_bvhAabbMax = bvhAabbMax + clampValue;
|
||||
btVector3 aabbSize = m_bvhAabbMax - m_bvhAabbMin;
|
||||
m_bvhQuantization = btVector3(btScalar(65533.0),btScalar(65533.0),btScalar(65533.0)) / aabbSize;
|
||||
b3Vector3 aabbSize = m_bvhAabbMax - m_bvhAabbMin;
|
||||
m_bvhQuantization = b3Vector3(b3Scalar(65533.0),b3Scalar(65533.0),b3Scalar(65533.0)) / aabbSize;
|
||||
m_useQuantization = true;
|
||||
}
|
||||
|
||||
@@ -147,8 +146,8 @@ void b3QuantizedBvh::buildTree (int startIndex,int endIndex)
|
||||
|
||||
//set the min aabb to 'inf' or a max value, and set the max aabb to a -inf/minimum value.
|
||||
//the aabb will be expanded during buildTree/mergeInternalNodeAabb with actual node values
|
||||
setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax);//can't use btVector3(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY)) because of quantization
|
||||
setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin);//can't use btVector3(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY)) because of quantization
|
||||
setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax);//can't use b3Vector3(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY)) because of quantization
|
||||
setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin);//can't use b3Vector3(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY)) because of quantization
|
||||
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
@@ -232,22 +231,22 @@ int b3QuantizedBvh::sortAndCalcSplittingIndex(int startIndex,int endIndex,int sp
|
||||
int i;
|
||||
int splitIndex =startIndex;
|
||||
int numIndices = endIndex - startIndex;
|
||||
btScalar splitValue;
|
||||
b3Scalar splitValue;
|
||||
|
||||
btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
b3Vector3 means(b3Scalar(0.),b3Scalar(0.),b3Scalar(0.));
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i));
|
||||
b3Vector3 center = b3Scalar(0.5)*(getAabbMax(i)+getAabbMin(i));
|
||||
means+=center;
|
||||
}
|
||||
means *= (btScalar(1.)/(btScalar)numIndices);
|
||||
means *= (b3Scalar(1.)/(b3Scalar)numIndices);
|
||||
|
||||
splitValue = means[splitAxis];
|
||||
|
||||
//sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'.
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i));
|
||||
b3Vector3 center = b3Scalar(0.5)*(getAabbMax(i)+getAabbMin(i));
|
||||
if (center[splitAxis] > splitValue)
|
||||
{
|
||||
//swap
|
||||
@@ -285,32 +284,32 @@ int b3QuantizedBvh::calcSplittingAxis(int startIndex,int endIndex)
|
||||
{
|
||||
int i;
|
||||
|
||||
btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
btVector3 variance(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
b3Vector3 means(b3Scalar(0.),b3Scalar(0.),b3Scalar(0.));
|
||||
b3Vector3 variance(b3Scalar(0.),b3Scalar(0.),b3Scalar(0.));
|
||||
int numIndices = endIndex-startIndex;
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i));
|
||||
b3Vector3 center = b3Scalar(0.5)*(getAabbMax(i)+getAabbMin(i));
|
||||
means+=center;
|
||||
}
|
||||
means *= (btScalar(1.)/(btScalar)numIndices);
|
||||
means *= (b3Scalar(1.)/(b3Scalar)numIndices);
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i));
|
||||
btVector3 diff2 = center-means;
|
||||
b3Vector3 center = b3Scalar(0.5)*(getAabbMax(i)+getAabbMin(i));
|
||||
b3Vector3 diff2 = center-means;
|
||||
diff2 = diff2 * diff2;
|
||||
variance += diff2;
|
||||
}
|
||||
variance *= (btScalar(1.)/ ((btScalar)numIndices-1) );
|
||||
variance *= (b3Scalar(1.)/ ((b3Scalar)numIndices-1) );
|
||||
|
||||
return variance.maxAxis();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void b3QuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
void b3QuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
|
||||
{
|
||||
//either choose recursive traversal (walkTree) or stackless (walkStacklessTree)
|
||||
|
||||
@@ -350,7 +349,7 @@ void b3QuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallb
|
||||
int maxIterations = 0;
|
||||
|
||||
|
||||
void b3QuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
void b3QuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
|
||||
{
|
||||
btAssert(!m_useQuantization);
|
||||
|
||||
@@ -395,7 +394,7 @@ void b3QuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const
|
||||
|
||||
/*
|
||||
///this was the original recursive traversal, before we optimized towards stackless traversal
|
||||
void b3QuantizedBvh::walkTree(btOptimizedBvhNode* rootNode,btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
void b3QuantizedBvh::walkTree(btOptimizedBvhNode* rootNode,btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
|
||||
{
|
||||
bool isLeafNode, aabbOverlap = TestAabbAgainstAabb2(aabbMin,aabbMax,rootNode->m_aabbMin,rootNode->m_aabbMax);
|
||||
if (aabbOverlap)
|
||||
@@ -446,7 +445,7 @@ void b3QuantizedBvh::walkRecursiveQuantizedTreeAgainstQueryAabb(const btQuantize
|
||||
|
||||
|
||||
|
||||
void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const
|
||||
void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin, const b3Vector3& aabbMax, int startNodeIndex,int endNodeIndex) const
|
||||
{
|
||||
btAssert(!m_useQuantization);
|
||||
|
||||
@@ -457,11 +456,11 @@ void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
|
||||
//PCK: unsigned instead of bool
|
||||
unsigned aabbOverlap=0;
|
||||
unsigned rayBoxOverlap=0;
|
||||
btScalar lambda_max = 1.0;
|
||||
b3Scalar lambda_max = 1.0;
|
||||
|
||||
/* Quick pruning by quantized box */
|
||||
btVector3 rayAabbMin = raySource;
|
||||
btVector3 rayAabbMax = raySource;
|
||||
b3Vector3 rayAabbMin = raySource;
|
||||
b3Vector3 rayAabbMax = raySource;
|
||||
rayAabbMin.setMin(rayTarget);
|
||||
rayAabbMax.setMax(rayTarget);
|
||||
|
||||
@@ -470,22 +469,22 @@ void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
|
||||
rayAabbMax += aabbMax;
|
||||
|
||||
#ifdef RAYAABB2
|
||||
btVector3 rayDir = (rayTarget-raySource);
|
||||
b3Vector3 rayDir = (rayTarget-raySource);
|
||||
rayDir.normalize ();
|
||||
lambda_max = rayDir.dot(rayTarget-raySource);
|
||||
///what about division by zero? --> just set rayDirection[i] to 1.0
|
||||
btVector3 rayDirectionInverse;
|
||||
rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0];
|
||||
rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1];
|
||||
rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2];
|
||||
b3Vector3 rayDirectionInverse;
|
||||
rayDirectionInverse[0] = rayDir[0] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDir[0];
|
||||
rayDirectionInverse[1] = rayDir[1] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDir[1];
|
||||
rayDirectionInverse[2] = rayDir[2] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDir[2];
|
||||
unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
|
||||
#endif
|
||||
|
||||
btVector3 bounds[2];
|
||||
b3Vector3 bounds[2];
|
||||
|
||||
while (curIndex < m_curNodeIndex)
|
||||
{
|
||||
btScalar param = 1.0;
|
||||
b3Scalar param = 1.0;
|
||||
//catch bugs in tree data
|
||||
btAssert (walkIterations < m_curNodeIndex);
|
||||
|
||||
@@ -507,7 +506,7 @@ void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
|
||||
rayBoxOverlap = aabbOverlap ? btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) : false;
|
||||
|
||||
#else
|
||||
btVector3 normal;
|
||||
b3Vector3 normal;
|
||||
rayBoxOverlap = btRayAabb(raySource, rayTarget,bounds[0],bounds[1],param, normal);
|
||||
#endif
|
||||
|
||||
@@ -538,7 +537,7 @@ void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
|
||||
|
||||
|
||||
|
||||
void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const
|
||||
void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin, const b3Vector3& aabbMax, int startNodeIndex,int endNodeIndex) const
|
||||
{
|
||||
btAssert(m_useQuantization);
|
||||
|
||||
@@ -555,22 +554,22 @@ void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
|
||||
unsigned boxBoxOverlap = 0;
|
||||
unsigned rayBoxOverlap = 0;
|
||||
|
||||
btScalar lambda_max = 1.0;
|
||||
b3Scalar lambda_max = 1.0;
|
||||
|
||||
#ifdef RAYAABB2
|
||||
btVector3 rayDirection = (rayTarget-raySource);
|
||||
b3Vector3 rayDirection = (rayTarget-raySource);
|
||||
rayDirection.normalize ();
|
||||
lambda_max = rayDirection.dot(rayTarget-raySource);
|
||||
///what about division by zero? --> just set rayDirection[i] to 1.0
|
||||
rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[0];
|
||||
rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[1];
|
||||
rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[2];
|
||||
rayDirection[0] = rayDirection[0] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDirection[0];
|
||||
rayDirection[1] = rayDirection[1] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDirection[1];
|
||||
rayDirection[2] = rayDirection[2] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDirection[2];
|
||||
unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0};
|
||||
#endif
|
||||
|
||||
/* Quick pruning by quantized box */
|
||||
btVector3 rayAabbMin = raySource;
|
||||
btVector3 rayAabbMax = raySource;
|
||||
b3Vector3 rayAabbMin = raySource;
|
||||
b3Vector3 rayAabbMax = raySource;
|
||||
rayAabbMin.setMin(rayTarget);
|
||||
rayAabbMax.setMax(rayTarget);
|
||||
|
||||
@@ -594,10 +593,10 @@ void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
|
||||
extern btIDebugDraw* debugDrawerPtr;
|
||||
if (curIndex==drawPatch)
|
||||
{
|
||||
btVector3 aabbMin,aabbMax;
|
||||
b3Vector3 aabbMin,aabbMax;
|
||||
aabbMin = unQuantize(rootNode->m_quantizedAabbMin);
|
||||
aabbMax = unQuantize(rootNode->m_quantizedAabbMax);
|
||||
btVector3 color(1,0,0);
|
||||
b3Vector3 color(1,0,0);
|
||||
debugDrawerPtr->drawAabb(aabbMin,aabbMax,color);
|
||||
}
|
||||
#endif//VISUALLY_ANALYZE_BVH
|
||||
@@ -608,19 +607,19 @@ void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
|
||||
walkIterations++;
|
||||
//PCK: unsigned instead of bool
|
||||
// only interested if this is closer than any previous hit
|
||||
btScalar param = 1.0;
|
||||
b3Scalar param = 1.0;
|
||||
rayBoxOverlap = 0;
|
||||
boxBoxOverlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,rootNode->m_quantizedAabbMin,rootNode->m_quantizedAabbMax);
|
||||
isLeafNode = rootNode->isLeafNode();
|
||||
if (boxBoxOverlap)
|
||||
{
|
||||
btVector3 bounds[2];
|
||||
b3Vector3 bounds[2];
|
||||
bounds[0] = unQuantize(rootNode->m_quantizedAabbMin);
|
||||
bounds[1] = unQuantize(rootNode->m_quantizedAabbMax);
|
||||
/* Add box cast extents */
|
||||
bounds[0] -= aabbMax;
|
||||
bounds[1] -= aabbMin;
|
||||
btVector3 normal;
|
||||
b3Vector3 normal;
|
||||
#if 0
|
||||
bool ra2 = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max);
|
||||
bool ra = btRayAabb (raySource, rayTarget, bounds[0], bounds[1], param, normal);
|
||||
@@ -691,10 +690,10 @@ void b3QuantizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallb
|
||||
extern btIDebugDraw* debugDrawerPtr;
|
||||
if (curIndex==drawPatch)
|
||||
{
|
||||
btVector3 aabbMin,aabbMax;
|
||||
b3Vector3 aabbMin,aabbMax;
|
||||
aabbMin = unQuantize(rootNode->m_quantizedAabbMin);
|
||||
aabbMax = unQuantize(rootNode->m_quantizedAabbMax);
|
||||
btVector3 color(1,0,0);
|
||||
b3Vector3 color(1,0,0);
|
||||
debugDrawerPtr->drawAabb(aabbMin,aabbMax,color);
|
||||
}
|
||||
#endif//VISUALLY_ANALYZE_BVH
|
||||
@@ -753,13 +752,13 @@ void b3QuantizedBvh::walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallba
|
||||
}
|
||||
|
||||
|
||||
void b3QuantizedBvh::reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const
|
||||
void b3QuantizedBvh::reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget) const
|
||||
{
|
||||
reportBoxCastOverlappingNodex(nodeCallback,raySource,rayTarget,btVector3(0,0,0),btVector3(0,0,0));
|
||||
reportBoxCastOverlappingNodex(nodeCallback,raySource,rayTarget,b3Vector3(0,0,0),b3Vector3(0,0,0));
|
||||
}
|
||||
|
||||
|
||||
void b3QuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
void b3QuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
|
||||
{
|
||||
//always use stackless
|
||||
|
||||
@@ -774,8 +773,8 @@ void b3QuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCa
|
||||
/*
|
||||
{
|
||||
//recursive traversal
|
||||
btVector3 qaabbMin = raySource;
|
||||
btVector3 qaabbMax = raySource;
|
||||
b3Vector3 qaabbMin = raySource;
|
||||
b3Vector3 qaabbMax = raySource;
|
||||
qaabbMin.setMin(rayTarget);
|
||||
qaabbMax.setMax(rayTarget);
|
||||
qaabbMin += aabbMin;
|
||||
@@ -1134,7 +1133,7 @@ b3QuantizedBvh *b3QuantizedBvh::deSerializeInPlace(void *i_alignedDataBuffer, un
|
||||
return bvh;
|
||||
}
|
||||
|
||||
// Constructor that prevents btVector3's default constructor from being called
|
||||
// Constructor that prevents b3Vector3's default constructor from being called
|
||||
b3QuantizedBvh::b3QuantizedBvh(b3QuantizedBvh &self, bool /* ownsMemory */) :
|
||||
m_bvhAabbMin(self.m_bvhAabbMin),
|
||||
m_bvhAabbMax(self.m_bvhAabbMax),
|
||||
|
||||
@@ -28,8 +28,8 @@ class btSerializer;
|
||||
#include <stdlib.h>
|
||||
#endif //DEBUG_CHECK_DEQUANTIZATION
|
||||
|
||||
#include "BulletCommon/btVector3.h"
|
||||
#include "BulletCommon/btAlignedAllocator.h"
|
||||
#include "BulletCommon/b3Vector3.h"
|
||||
#include "BulletCommon/b3AlignedAllocator.h"
|
||||
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
#define btQuantizedBvhData btQuantizedBvhDoubleData
|
||||
@@ -99,8 +99,8 @@ ATTRIBUTE_ALIGNED16 (struct) btOptimizedBvhNode
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
//32 bytes
|
||||
btVector3 m_aabbMinOrg;
|
||||
btVector3 m_aabbMaxOrg;
|
||||
b3Vector3 m_aabbMinOrg;
|
||||
b3Vector3 m_aabbMaxOrg;
|
||||
|
||||
//4
|
||||
int m_escapeIndex;
|
||||
@@ -157,15 +157,15 @@ public:
|
||||
virtual void processNode(int subPart, int triangleIndex) = 0;
|
||||
};
|
||||
|
||||
#include "BulletCommon/btAlignedAllocator.h"
|
||||
#include "BulletCommon/btAlignedObjectArray.h"
|
||||
#include "BulletCommon/b3AlignedAllocator.h"
|
||||
#include "BulletCommon/b3AlignedObjectArray.h"
|
||||
|
||||
|
||||
|
||||
///for code readability:
|
||||
typedef btAlignedObjectArray<btOptimizedBvhNode> NodeArray;
|
||||
typedef btAlignedObjectArray<btQuantizedBvhNode> QuantizedNodeArray;
|
||||
typedef btAlignedObjectArray<btBvhSubtreeInfo> BvhSubtreeInfoArray;
|
||||
typedef b3AlignedObjectArray<btOptimizedBvhNode> NodeArray;
|
||||
typedef b3AlignedObjectArray<btQuantizedBvhNode> QuantizedNodeArray;
|
||||
typedef b3AlignedObjectArray<btBvhSubtreeInfo> BvhSubtreeInfoArray;
|
||||
|
||||
|
||||
///The b3QuantizedBvh class stores an AABB tree that can be quickly traversed on CPU and Cell SPU.
|
||||
@@ -184,9 +184,9 @@ public:
|
||||
|
||||
|
||||
|
||||
btVector3 m_bvhAabbMin;
|
||||
btVector3 m_bvhAabbMax;
|
||||
btVector3 m_bvhQuantization;
|
||||
b3Vector3 m_bvhAabbMin;
|
||||
b3Vector3 m_bvhAabbMax;
|
||||
b3Vector3 m_bvhQuantization;
|
||||
|
||||
protected:
|
||||
int m_bulletVersion; //for serialization versioning. It could also be used to detect endianess.
|
||||
@@ -205,7 +205,7 @@ protected:
|
||||
btTraversalMode m_traversalMode;
|
||||
BvhSubtreeInfoArray m_SubtreeHeaders;
|
||||
|
||||
//This is only used for serialization so we don't have to add serialization directly to btAlignedObjectArray
|
||||
//This is only used for serialization so we don't have to add serialization directly to b3AlignedObjectArray
|
||||
mutable int m_subtreeHeaderCount;
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ protected:
|
||||
|
||||
///two versions, one for quantized and normal nodes. This allows code-reuse while maintaining readability (no template/macro!)
|
||||
///this might be refactored into a virtual, it is usually not calculated at run-time
|
||||
void setInternalNodeAabbMin(int nodeIndex, const btVector3& aabbMin)
|
||||
void setInternalNodeAabbMin(int nodeIndex, const b3Vector3& aabbMin)
|
||||
{
|
||||
if (m_useQuantization)
|
||||
{
|
||||
@@ -225,7 +225,7 @@ protected:
|
||||
|
||||
}
|
||||
}
|
||||
void setInternalNodeAabbMax(int nodeIndex,const btVector3& aabbMax)
|
||||
void setInternalNodeAabbMax(int nodeIndex,const b3Vector3& aabbMax)
|
||||
{
|
||||
if (m_useQuantization)
|
||||
{
|
||||
@@ -236,7 +236,7 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
btVector3 getAabbMin(int nodeIndex) const
|
||||
b3Vector3 getAabbMin(int nodeIndex) const
|
||||
{
|
||||
if (m_useQuantization)
|
||||
{
|
||||
@@ -246,7 +246,7 @@ protected:
|
||||
return m_leafNodes[nodeIndex].m_aabbMinOrg;
|
||||
|
||||
}
|
||||
btVector3 getAabbMax(int nodeIndex) const
|
||||
b3Vector3 getAabbMax(int nodeIndex) const
|
||||
{
|
||||
if (m_useQuantization)
|
||||
{
|
||||
@@ -271,7 +271,7 @@ protected:
|
||||
|
||||
}
|
||||
|
||||
void mergeInternalNodeAabb(int nodeIndex,const btVector3& newAabbMin,const btVector3& newAabbMax)
|
||||
void mergeInternalNodeAabb(int nodeIndex,const b3Vector3& newAabbMin,const b3Vector3& newAabbMax)
|
||||
{
|
||||
if (m_useQuantization)
|
||||
{
|
||||
@@ -310,11 +310,11 @@ protected:
|
||||
|
||||
int sortAndCalcSplittingIndex(int startIndex,int endIndex,int splitAxis);
|
||||
|
||||
void walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const;
|
||||
void walkStacklessTree(btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const;
|
||||
|
||||
void walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
|
||||
void walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin, const b3Vector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
|
||||
void walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,int startNodeIndex,int endNodeIndex) const;
|
||||
void walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
|
||||
void walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin, const b3Vector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
|
||||
|
||||
///tree traversal designed for small-memory processors like PS3 SPU
|
||||
void walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const;
|
||||
@@ -340,17 +340,17 @@ public:
|
||||
|
||||
|
||||
///***************************************** expert/internal use only *************************
|
||||
void setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin=btScalar(1.0));
|
||||
void setQuantizationValues(const b3Vector3& bvhAabbMin,const b3Vector3& bvhAabbMax,b3Scalar quantizationMargin=b3Scalar(1.0));
|
||||
QuantizedNodeArray& getLeafNodeArray() { return m_quantizedLeafNodes; }
|
||||
///buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialized
|
||||
void buildInternal();
|
||||
///***************************************** expert/internal use only *************************
|
||||
|
||||
void reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const;
|
||||
void reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const;
|
||||
void reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const;
|
||||
void reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const;
|
||||
void reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget) const;
|
||||
void reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin,const b3Vector3& aabbMax) const;
|
||||
|
||||
SIMD_FORCE_INLINE void quantize(unsigned short* out, const btVector3& point,int isMax) const
|
||||
SIMD_FORCE_INLINE void quantize(unsigned short* out, const b3Vector3& point,int isMax) const
|
||||
{
|
||||
|
||||
btAssert(m_useQuantization);
|
||||
@@ -363,15 +363,15 @@ public:
|
||||
btAssert(point.getY() >= m_bvhAabbMin.getY());
|
||||
btAssert(point.getZ() >= m_bvhAabbMin.getZ());
|
||||
|
||||
btVector3 v = (point - m_bvhAabbMin) * m_bvhQuantization;
|
||||
b3Vector3 v = (point - m_bvhAabbMin) * m_bvhQuantization;
|
||||
///Make sure rounding is done in a way that unQuantize(quantizeWithClamp(...)) is conservative
|
||||
///end-points always set the first bit, so that they are sorted properly (so that neighbouring AABBs overlap properly)
|
||||
///@todo: double-check this
|
||||
if (isMax)
|
||||
{
|
||||
out[0] = (unsigned short) (((unsigned short)(v.getX()+btScalar(1.)) | 1));
|
||||
out[1] = (unsigned short) (((unsigned short)(v.getY()+btScalar(1.)) | 1));
|
||||
out[2] = (unsigned short) (((unsigned short)(v.getZ()+btScalar(1.)) | 1));
|
||||
out[0] = (unsigned short) (((unsigned short)(v.getX()+b3Scalar(1.)) | 1));
|
||||
out[1] = (unsigned short) (((unsigned short)(v.getY()+b3Scalar(1.)) | 1));
|
||||
out[2] = (unsigned short) (((unsigned short)(v.getZ()+b3Scalar(1.)) | 1));
|
||||
} else
|
||||
{
|
||||
out[0] = (unsigned short) (((unsigned short)(v.getX()) & 0xfffe));
|
||||
@@ -381,7 +381,7 @@ public:
|
||||
|
||||
|
||||
#ifdef DEBUG_CHECK_DEQUANTIZATION
|
||||
btVector3 newPoint = unQuantize(out);
|
||||
b3Vector3 newPoint = unQuantize(out);
|
||||
if (isMax)
|
||||
{
|
||||
if (newPoint.getX() < point.getX())
|
||||
@@ -417,12 +417,12 @@ public:
|
||||
}
|
||||
|
||||
|
||||
SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const btVector3& point2,int isMax) const
|
||||
SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const b3Vector3& point2,int isMax) const
|
||||
{
|
||||
|
||||
btAssert(m_useQuantization);
|
||||
|
||||
btVector3 clampedPoint(point2);
|
||||
b3Vector3 clampedPoint(point2);
|
||||
clampedPoint.setMax(m_bvhAabbMin);
|
||||
clampedPoint.setMin(m_bvhAabbMax);
|
||||
|
||||
@@ -430,13 +430,13 @@ public:
|
||||
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btVector3 unQuantize(const unsigned short* vecIn) const
|
||||
SIMD_FORCE_INLINE b3Vector3 unQuantize(const unsigned short* vecIn) const
|
||||
{
|
||||
btVector3 vecOut;
|
||||
b3Vector3 vecOut;
|
||||
vecOut.setValue(
|
||||
(btScalar)(vecIn[0]) / (m_bvhQuantization.getX()),
|
||||
(btScalar)(vecIn[1]) / (m_bvhQuantization.getY()),
|
||||
(btScalar)(vecIn[2]) / (m_bvhQuantization.getZ()));
|
||||
(b3Scalar)(vecIn[0]) / (m_bvhQuantization.getX()),
|
||||
(b3Scalar)(vecIn[1]) / (m_bvhQuantization.getY()),
|
||||
(b3Scalar)(vecIn[2]) / (m_bvhQuantization.getZ()));
|
||||
vecOut += m_bvhAabbMin;
|
||||
return vecOut;
|
||||
}
|
||||
@@ -493,7 +493,7 @@ public:
|
||||
|
||||
private:
|
||||
// Special "copy" constructor that allows for in-place deserialization
|
||||
// Prevents btVector3's default constructor from being called, but doesn't inialize much else
|
||||
// Prevents b3Vector3's default constructor from being called, but doesn't inialize much else
|
||||
// ownsMemory should most likely be false if deserializing, and if you are not, don't call this (it also changes the function signature, which we need)
|
||||
b3QuantizedBvh(b3QuantizedBvh &other, bool ownsMemory);
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#ifndef BT_RIGID_BODY_CL
|
||||
#define BT_RIGID_BODY_CL
|
||||
|
||||
#include "BulletCommon/btScalar.h"
|
||||
#include "BulletCommon/btMatrix3x3.h"
|
||||
#include "BulletCommon/b3Scalar.h"
|
||||
#include "BulletCommon/b3Matrix3x3.h"
|
||||
|
||||
ATTRIBUTE_ALIGNED16(struct) b3RigidBodyCL
|
||||
{
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
btVector3 m_pos;
|
||||
btQuaternion m_quat;
|
||||
btVector3 m_linVel;
|
||||
btVector3 m_angVel;
|
||||
b3Vector3 m_pos;
|
||||
b3Quaternion m_quat;
|
||||
b3Vector3 m_linVel;
|
||||
b3Vector3 m_angVel;
|
||||
|
||||
int m_collidableIdx;
|
||||
float m_invMass;
|
||||
@@ -27,8 +27,8 @@ ATTRIBUTE_ALIGNED16(struct) b3RigidBodyCL
|
||||
|
||||
struct btInertiaCL
|
||||
{
|
||||
btMatrix3x3 m_invInertiaWorld;
|
||||
btMatrix3x3 m_initInvInertia;
|
||||
b3Matrix3x3 m_invInertiaWorld;
|
||||
b3Matrix3x3 m_initInvInertia;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ b3StridingMeshInterface::~b3StridingMeshInterface()
|
||||
}
|
||||
|
||||
|
||||
void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
|
||||
{
|
||||
(void)aabbMin;
|
||||
(void)aabbMax;
|
||||
@@ -35,9 +35,9 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
|
||||
PHY_ScalarType gfxindextype;
|
||||
int stride,numverts,numtriangles;
|
||||
int gfxindex;
|
||||
btVector3 triangle[3];
|
||||
b3Vector3 triangle[3];
|
||||
|
||||
btVector3 meshScaling = getScaling();
|
||||
b3Vector3 meshScaling = getScaling();
|
||||
|
||||
///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
|
||||
for (part=0;part<graphicssubparts ;part++)
|
||||
@@ -121,11 +121,11 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
|
||||
{
|
||||
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
|
||||
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
|
||||
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||
triangle[0].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(),(b3Scalar)graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
|
||||
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||
triangle[1].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
|
||||
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||
triangle[2].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
|
||||
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
||||
}
|
||||
break;
|
||||
@@ -136,11 +136,11 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
|
||||
{
|
||||
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
|
||||
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
|
||||
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||
triangle[0].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(),(b3Scalar)graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
|
||||
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||
triangle[1].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
|
||||
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||
triangle[2].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
|
||||
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
||||
}
|
||||
break;
|
||||
@@ -151,11 +151,11 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
|
||||
{
|
||||
unsigned char* tri_indices= (unsigned char*)(indexbase+gfxindex*indexstride);
|
||||
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
|
||||
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||
triangle[0].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(),(b3Scalar)graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
|
||||
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||
triangle[1].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
|
||||
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||
triangle[2].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
|
||||
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
||||
}
|
||||
break;
|
||||
@@ -173,21 +173,21 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
|
||||
}
|
||||
}
|
||||
|
||||
void b3StridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax)
|
||||
void b3StridingMeshInterface::calculateAabbBruteForce(b3Vector3& aabbMin,b3Vector3& aabbMax)
|
||||
{
|
||||
|
||||
struct AabbCalculationCallback : public btInternalTriangleIndexCallback
|
||||
{
|
||||
btVector3 m_aabbMin;
|
||||
btVector3 m_aabbMax;
|
||||
b3Vector3 m_aabbMin;
|
||||
b3Vector3 m_aabbMax;
|
||||
|
||||
AabbCalculationCallback()
|
||||
{
|
||||
m_aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
|
||||
m_aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
|
||||
m_aabbMin.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
|
||||
m_aabbMax.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
|
||||
}
|
||||
|
||||
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)
|
||||
virtual void internalProcessTriangleIndex(b3Vector3* triangle,int partId,int triangleIndex)
|
||||
{
|
||||
(void)partId;
|
||||
(void)triangleIndex;
|
||||
@@ -203,8 +203,8 @@ void b3StridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVecto
|
||||
|
||||
//first calculate the total aabb for all triangles
|
||||
AabbCalculationCallback aabbCallback;
|
||||
aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
|
||||
aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
|
||||
aabbMin.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
|
||||
aabbMax.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
|
||||
InternalProcessAllTriangles(&aabbCallback,aabbMin,aabbMax);
|
||||
|
||||
aabbMin = aabbCallback.m_aabbMin;
|
||||
|
||||
@@ -16,7 +16,7 @@ subject to the following restrictions:
|
||||
#ifndef BT_STRIDING_MESHINTERFACE_H
|
||||
#define BT_STRIDING_MESHINTERFACE_H
|
||||
|
||||
#include "BulletCommon/btVector3.h"
|
||||
#include "BulletCommon/b3Vector3.h"
|
||||
#include "b3TriangleCallback.h"
|
||||
//#include "btConcaveShape.h"
|
||||
|
||||
@@ -34,12 +34,12 @@ ATTRIBUTE_ALIGNED16(class ) b3StridingMeshInterface
|
||||
{
|
||||
protected:
|
||||
|
||||
btVector3 m_scaling;
|
||||
b3Vector3 m_scaling;
|
||||
|
||||
public:
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
b3StridingMeshInterface() :m_scaling(btScalar(1.),btScalar(1.),btScalar(1.))
|
||||
b3StridingMeshInterface() :m_scaling(b3Scalar(1.),b3Scalar(1.),b3Scalar(1.))
|
||||
{
|
||||
|
||||
}
|
||||
@@ -48,10 +48,10 @@ ATTRIBUTE_ALIGNED16(class ) b3StridingMeshInterface
|
||||
|
||||
|
||||
|
||||
virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
|
||||
virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const;
|
||||
|
||||
///brute force method to calculate aabb
|
||||
void calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax);
|
||||
void calculateAabbBruteForce(b3Vector3& aabbMin,b3Vector3& aabbMax);
|
||||
|
||||
/// get read and write access to a subpart of a triangle mesh
|
||||
/// this subpart has a continuous array of vertices and indices
|
||||
@@ -77,21 +77,21 @@ ATTRIBUTE_ALIGNED16(class ) b3StridingMeshInterface
|
||||
virtual void preallocateIndices(int numindices)=0;
|
||||
|
||||
virtual bool hasPremadeAabb() const { return false; }
|
||||
virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const
|
||||
virtual void setPremadeAabb(const b3Vector3& aabbMin, const b3Vector3& aabbMax ) const
|
||||
{
|
||||
(void) aabbMin;
|
||||
(void) aabbMax;
|
||||
}
|
||||
virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const
|
||||
virtual void getPremadeAabb(b3Vector3* aabbMin, b3Vector3* aabbMax ) const
|
||||
{
|
||||
(void) aabbMin;
|
||||
(void) aabbMax;
|
||||
}
|
||||
|
||||
const btVector3& getScaling() const {
|
||||
const b3Vector3& getScaling() const {
|
||||
return m_scaling;
|
||||
}
|
||||
void setScaling(const btVector3& scaling)
|
||||
void setScaling(const b3Vector3& scaling)
|
||||
{
|
||||
m_scaling = scaling;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ subject to the following restrictions:
|
||||
#ifndef BT_TRIANGLE_CALLBACK_H
|
||||
#define BT_TRIANGLE_CALLBACK_H
|
||||
|
||||
#include "BulletCommon/btVector3.h"
|
||||
#include "BulletCommon/b3Vector3.h"
|
||||
|
||||
|
||||
///The b3TriangleCallback provides a callback for each overlapping triangle when calling processAllTriangles.
|
||||
@@ -26,7 +26,7 @@ class b3TriangleCallback
|
||||
public:
|
||||
|
||||
virtual ~b3TriangleCallback();
|
||||
virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex) = 0;
|
||||
virtual void processTriangle(b3Vector3* triangle, int partId, int triangleIndex) = 0;
|
||||
};
|
||||
|
||||
class btInternalTriangleIndexCallback
|
||||
@@ -34,7 +34,7 @@ class btInternalTriangleIndexCallback
|
||||
public:
|
||||
|
||||
virtual ~btInternalTriangleIndexCallback();
|
||||
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex) = 0;
|
||||
virtual void internalProcessTriangleIndex(b3Vector3* triangle,int partId,int triangleIndex) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ subject to the following restrictions:
|
||||
|
||||
#include "b3TriangleIndexVertexArray.h"
|
||||
|
||||
b3TriangleIndexVertexArray::b3TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride)
|
||||
b3TriangleIndexVertexArray::b3TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,b3Scalar* vertexBase,int vertexStride)
|
||||
: m_hasAabb(0)
|
||||
{
|
||||
btIndexedMesh mesh;
|
||||
@@ -79,14 +79,14 @@ bool b3TriangleIndexVertexArray::hasPremadeAabb() const
|
||||
}
|
||||
|
||||
|
||||
void b3TriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const
|
||||
void b3TriangleIndexVertexArray::setPremadeAabb(const b3Vector3& aabbMin, const b3Vector3& aabbMax ) const
|
||||
{
|
||||
m_aabbMin = aabbMin;
|
||||
m_aabbMax = aabbMax;
|
||||
m_hasAabb = 1; // this is intentionally an int see notes in header
|
||||
}
|
||||
|
||||
void b3TriangleIndexVertexArray::getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const
|
||||
void b3TriangleIndexVertexArray::getPremadeAabb(b3Vector3* aabbMin, b3Vector3* aabbMax ) const
|
||||
{
|
||||
*aabbMin = m_aabbMin;
|
||||
*aabbMax = m_aabbMax;
|
||||
|
||||
@@ -17,8 +17,8 @@ subject to the following restrictions:
|
||||
#define BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
|
||||
|
||||
#include "b3StridingMeshInterface.h"
|
||||
#include "BulletCommon/btAlignedObjectArray.h"
|
||||
#include "BulletCommon/btScalar.h"
|
||||
#include "BulletCommon/b3AlignedObjectArray.h"
|
||||
#include "BulletCommon/b3Scalar.h"
|
||||
|
||||
|
||||
///The btIndexedMesh indexes a single vertex and index array. Multiple btIndexedMesh objects can be passed into a b3TriangleIndexVertexArray using addIndexedMesh.
|
||||
@@ -59,7 +59,7 @@ ATTRIBUTE_ALIGNED16( struct) btIndexedMesh
|
||||
;
|
||||
|
||||
|
||||
typedef btAlignedObjectArray<btIndexedMesh> IndexedMeshArray;
|
||||
typedef b3AlignedObjectArray<btIndexedMesh> IndexedMeshArray;
|
||||
|
||||
///The b3TriangleIndexVertexArray allows to access multiple triangle meshes, by indexing into existing triangle/index arrays.
|
||||
///Additional meshes can be added using addIndexedMesh
|
||||
@@ -71,8 +71,8 @@ protected:
|
||||
IndexedMeshArray m_indexedMeshes;
|
||||
int m_pad[2];
|
||||
mutable int m_hasAabb; // using int instead of bool to maintain alignment
|
||||
mutable btVector3 m_aabbMin;
|
||||
mutable btVector3 m_aabbMax;
|
||||
mutable b3Vector3 m_aabbMin;
|
||||
mutable b3Vector3 m_aabbMax;
|
||||
|
||||
public:
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
virtual ~b3TriangleIndexVertexArray();
|
||||
|
||||
//just to be backwards compatible
|
||||
b3TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride);
|
||||
b3TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,b3Scalar* vertexBase,int vertexStride);
|
||||
|
||||
void addIndexedMesh(const btIndexedMesh& mesh, PHY_ScalarType indexType = PHY_INTEGER)
|
||||
{
|
||||
@@ -124,8 +124,8 @@ public:
|
||||
virtual void preallocateIndices(int numindices){(void) numindices;}
|
||||
|
||||
virtual bool hasPremadeAabb() const;
|
||||
virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const;
|
||||
virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const;
|
||||
virtual void setPremadeAabb(const b3Vector3& aabbMin, const b3Vector3& aabbMax ) const;
|
||||
virtual void getPremadeAabb(b3Vector3* aabbMin, b3Vector3* aabbMax ) const;
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user