00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __SPU_COLLISION_SHAPES_H
00016 #define __SPU_COLLISION_SHAPES_H
00017
00018 #include "../SpuDoubleBuffer.h"
00019
00020 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
00021 #include "BulletCollision/CollisionShapes/btConvexInternalShape.h"
00022 #include "BulletCollision/CollisionShapes/btCylinderShape.h"
00023 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
00024
00025 #include "BulletCollision/CollisionShapes/btOptimizedBvh.h"
00026 #include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
00027 #include "BulletCollision/CollisionShapes/btSphereShape.h"
00028
00029 #include "BulletCollision/CollisionShapes/btCapsuleShape.h"
00030
00031 #include "BulletCollision/CollisionShapes/btConvexShape.h"
00032 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
00033 #include "BulletCollision/CollisionShapes/btConvexHullShape.h"
00034 #include "BulletCollision/CollisionShapes/btCompoundShape.h"
00035
00036 #define MAX_NUM_SPU_CONVEX_POINTS 128 //@fallback to PPU if a btConvexHullShape has more than MAX_NUM_SPU_CONVEX_POINTS points
00037 #define MAX_SPU_COMPOUND_SUBSHAPES 16 //@fallback on PPU if compound has more than MAX_SPU_COMPOUND_SUBSHAPES child shapes
00038 #define MAX_SHAPE_SIZE 256 //@todo: assert on this
00039
00040 ATTRIBUTE_ALIGNED16(struct) SpuConvexPolyhedronVertexData
00041 {
00042 void* gSpuConvexShapePtr;
00043 btVector3* gConvexPoints;
00044 int gNumConvexPoints;
00045 int unused;
00046 ATTRIBUTE_ALIGNED16(btVector3 g_convexPointBuffer[MAX_NUM_SPU_CONVEX_POINTS]);
00047 };
00048
00049
00050
00051 ATTRIBUTE_ALIGNED16(struct) CollisionShape_LocalStoreMemory
00052 {
00053 ATTRIBUTE_ALIGNED16(char collisionShape[MAX_SHAPE_SIZE]);
00054 };
00055
00056 ATTRIBUTE_ALIGNED16(struct) CompoundShape_LocalStoreMemory
00057 {
00058
00059
00060 ATTRIBUTE_ALIGNED16(btCompoundShapeChild gSubshapes[MAX_SPU_COMPOUND_SUBSHAPES]);
00061 ATTRIBUTE_ALIGNED16(char gSubshapeShape[MAX_SPU_COMPOUND_SUBSHAPES][MAX_SHAPE_SIZE]);
00062 };
00063
00064 ATTRIBUTE_ALIGNED16(struct) bvhMeshShape_LocalStoreMemory
00065 {
00066
00067 ATTRIBUTE_ALIGNED16(char gOptimizedBvh[sizeof(btOptimizedBvh)+16]);
00068 btOptimizedBvh* getOptimizedBvh()
00069 {
00070 return (btOptimizedBvh*) gOptimizedBvh;
00071 }
00072
00073 ATTRIBUTE_ALIGNED16(btTriangleIndexVertexArray gTriangleMeshInterfaceStorage);
00074 btTriangleIndexVertexArray* gTriangleMeshInterfacePtr;
00076 ATTRIBUTE_ALIGNED16(btIndexedMesh gIndexMesh);
00077 #define MAX_SPU_SUBTREE_HEADERS 32
00078
00079 ATTRIBUTE_ALIGNED16(btBvhSubtreeInfo gSubtreeHeaders[MAX_SPU_SUBTREE_HEADERS]);
00080 ATTRIBUTE_ALIGNED16(btQuantizedBvhNode gSubtreeNodes[MAX_SUBTREE_SIZE_IN_BYTES/sizeof(btQuantizedBvhNode)]);
00081 };
00082
00083
00084 void computeAabb (btVector3& aabbMin, btVector3& aabbMax, btConvexInternalShape* convexShape, ppu_address_t convexShapePtr, int shapeType, const btTransform& xform);
00085 void dmaBvhShapeData (bvhMeshShape_LocalStoreMemory* bvhMeshShape, btBvhTriangleMeshShape* triMeshShape);
00086 void dmaBvhIndexedMesh (btIndexedMesh* IndexMesh, IndexedMeshArray& indexArray, int index, uint32_t dmaTag);
00087 void dmaBvhSubTreeHeaders (btBvhSubtreeInfo* subTreeHeaders, ppu_address_t subTreePtr, int batchSize, uint32_t dmaTag);
00088 void dmaBvhSubTreeNodes (btQuantizedBvhNode* nodes, const btBvhSubtreeInfo& subtree, QuantizedNodeArray& nodeArray, int dmaTag);
00089
00090 int getShapeTypeSize(int shapeType);
00091 void dmaConvexVertexData (SpuConvexPolyhedronVertexData* convexVertexData, btConvexHullShape* convexShapeSPU);
00092 void dmaCollisionShape (void* collisionShapeLocation, ppu_address_t collisionShapePtr, uint32_t dmaTag, int shapeType);
00093 void dmaCompoundShapeInfo (CompoundShape_LocalStoreMemory* compoundShapeLocation, btCompoundShape* spuCompoundShape, uint32_t dmaTag);
00094 void dmaCompoundSubShapes (CompoundShape_LocalStoreMemory* compoundShapeLocation, btCompoundShape* spuCompoundShape, uint32_t dmaTag);
00095
00096
00097 #define USE_BRANCHFREE_TEST 1
00098 #ifdef USE_BRANCHFREE_TEST
00099 SIMD_FORCE_INLINE unsigned int spuTestQuantizedAabbAgainstQuantizedAabb(unsigned short int* aabbMin1,unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2)
00100 {
00101 #if defined(__CELLOS_LV2__) && defined (__SPU__)
00102 vec_ushort8 vecMin = {aabbMin1[0],aabbMin2[0],aabbMin1[2],aabbMin2[2],aabbMin1[1],aabbMin2[1],0,0};
00103 vec_ushort8 vecMax = {aabbMax2[0],aabbMax1[0],aabbMax2[2],aabbMax1[2],aabbMax2[1],aabbMax1[1],0,0};
00104 vec_ushort8 isGt = spu_cmpgt(vecMin,vecMax);
00105 return spu_extract(spu_gather(isGt),0)==0;
00106
00107 #else
00108 return btSelect((unsigned)((aabbMin1[0] <= aabbMax2[0]) & (aabbMax1[0] >= aabbMin2[0])
00109 & (aabbMin1[2] <= aabbMax2[2]) & (aabbMax1[2] >= aabbMin2[2])
00110 & (aabbMin1[1] <= aabbMax2[1]) & (aabbMax1[1] >= aabbMin2[1])),
00111 1, 0);
00112 #endif
00113 }
00114 #else
00115
00116 SIMD_FORCE_INLINE unsigned int spuTestQuantizedAabbAgainstQuantizedAabb(const unsigned short int* aabbMin1,const unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2)
00117 {
00118 unsigned int overlap = 1;
00119 overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? 0 : overlap;
00120 overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? 0 : overlap;
00121 overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? 0 : overlap;
00122 return overlap;
00123 }
00124 #endif
00125
00126 void spuWalkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,const btQuantizedBvhNode* rootNode,int startNodeIndex,int endNodeIndex);
00127
00128 #endif