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
00037
00038 struct SpuConvexPolyhedronVertexData
00039 {
00040 void* gSpuConvexShapePtr;
00041 btVector3* gConvexPoints;
00042 int gNumConvexPoints;
00043 int unused;
00044 ATTRIBUTE_ALIGNED16(btVector3 g_convexPointBuffer[MAX_NUM_SPU_CONVEX_POINTS]);
00045 };
00046
00047 #define MAX_SHAPE_SIZE 256
00048
00049 struct CollisionShape_LocalStoreMemory
00050 {
00051 ATTRIBUTE_ALIGNED16(char collisionShape[MAX_SHAPE_SIZE]);
00052 };
00053
00054 struct CompoundShape_LocalStoreMemory
00055 {
00056
00057 #define MAX_SPU_COMPOUND_SUBSHAPES 16
00058 ATTRIBUTE_ALIGNED16(btCompoundShapeChild gSubshapes[MAX_SPU_COMPOUND_SUBSHAPES]);
00059 ATTRIBUTE_ALIGNED16(char gSubshapeShape[MAX_SPU_COMPOUND_SUBSHAPES][MAX_SHAPE_SIZE]);
00060 };
00061
00062 struct bvhMeshShape_LocalStoreMemory
00063 {
00064
00065 ATTRIBUTE_ALIGNED16(char gOptimizedBvh[sizeof(btOptimizedBvh)+16]);
00066 btOptimizedBvh* getOptimizedBvh()
00067 {
00068 return (btOptimizedBvh*) gOptimizedBvh;
00069 }
00070
00071 ATTRIBUTE_ALIGNED16(btTriangleIndexVertexArray gTriangleMeshInterfaceStorage);
00072 btTriangleIndexVertexArray* gTriangleMeshInterfacePtr;
00074 ATTRIBUTE_ALIGNED16(btIndexedMesh gIndexMesh);
00075 #define MAX_SPU_SUBTREE_HEADERS 32
00076
00077 ATTRIBUTE_ALIGNED16(btBvhSubtreeInfo gSubtreeHeaders[MAX_SPU_SUBTREE_HEADERS]);
00078 ATTRIBUTE_ALIGNED16(btQuantizedBvhNode gSubtreeNodes[MAX_SUBTREE_SIZE_IN_BYTES/sizeof(btQuantizedBvhNode)]);
00079 };
00080
00081
00082 void computeAabb (btVector3& aabbMin, btVector3& aabbMax, btConvexInternalShape* convexShape, ppu_address_t convexShapePtr, int shapeType, const btTransform& xform);
00083 void dmaBvhShapeData (bvhMeshShape_LocalStoreMemory* bvhMeshShape, btBvhTriangleMeshShape* triMeshShape);
00084 void dmaBvhIndexedMesh (btIndexedMesh* IndexMesh, IndexedMeshArray& indexArray, int index, uint32_t dmaTag);
00085 void dmaBvhSubTreeHeaders (btBvhSubtreeInfo* subTreeHeaders, ppu_address_t subTreePtr, int batchSize, uint32_t dmaTag);
00086 void dmaBvhSubTreeNodes (btQuantizedBvhNode* nodes, const btBvhSubtreeInfo& subtree, QuantizedNodeArray& nodeArray, int dmaTag);
00087
00088 int getShapeTypeSize(int shapeType);
00089 void dmaConvexVertexData (SpuConvexPolyhedronVertexData* convexVertexData, btConvexHullShape* convexShapeSPU);
00090 void dmaCollisionShape (void* collisionShapeLocation, ppu_address_t collisionShapePtr, uint32_t dmaTag, int shapeType);
00091 void dmaCompoundShapeInfo (CompoundShape_LocalStoreMemory* compoundShapeLocation, btCompoundShape* spuCompoundShape, uint32_t dmaTag);
00092 void dmaCompoundSubShapes (CompoundShape_LocalStoreMemory* compoundShapeLocation, btCompoundShape* spuCompoundShape, uint32_t dmaTag);
00093
00094
00095 #define USE_BRANCHFREE_TEST 1
00096 #ifdef USE_BRANCHFREE_TEST
00097 SIMD_FORCE_INLINE unsigned int spuTestQuantizedAabbAgainstQuantizedAabb(unsigned short int* aabbMin1,unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2)
00098 {
00099 #if defined(__CELLOS_LV2__) && defined (__SPU__)
00100 vec_ushort8 vecMin = {aabbMin1[0],aabbMin2[0],aabbMin1[2],aabbMin2[2],aabbMin1[1],aabbMin2[1],0,0};
00101 vec_ushort8 vecMax = {aabbMax2[0],aabbMax1[0],aabbMax2[2],aabbMax1[2],aabbMax2[1],aabbMax1[1],0,0};
00102 vec_ushort8 isGt = spu_cmpgt(vecMin,vecMax);
00103 return spu_extract(spu_gather(isGt),0)==0;
00104
00105 #else
00106 return btSelect((unsigned)((aabbMin1[0] <= aabbMax2[0]) & (aabbMax1[0] >= aabbMin2[0])
00107 & (aabbMin1[2] <= aabbMax2[2]) & (aabbMax1[2] >= aabbMin2[2])
00108 & (aabbMin1[1] <= aabbMax2[1]) & (aabbMax1[1] >= aabbMin2[1])),
00109 1, 0);
00110 #endif
00111 }
00112 #else
00113
00114 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)
00115 {
00116 unsigned int overlap = 1;
00117 overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? 0 : overlap;
00118 overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? 0 : overlap;
00119 overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? 0 : overlap;
00120 return overlap;
00121 }
00122 #endif
00123
00124 void spuWalkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,const btQuantizedBvhNode* rootNode,int startNodeIndex,int endNodeIndex);
00125
00126 #endif