diff --git a/Demos/ConcaveDemo/CMakeLists.txt b/Demos/ConcaveDemo/CMakeLists.txt index f520050f1..4de3e42dc 100644 --- a/Demos/ConcaveDemo/CMakeLists.txt +++ b/Demos/ConcaveDemo/CMakeLists.txt @@ -6,16 +6,19 @@ + # You shouldn't have to modify anything below this line ######################################################## IF (USE_GLUT) INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter ) LINK_LIBRARIES( - OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision BulletFileLoader LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) IF (WIN32) @@ -51,10 +54,12 @@ ELSE (USE_GLUT) INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter ) LINK_LIBRARIES( - OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision BulletFileLoader LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) ADD_EXECUTABLE(AppConcaveDemo diff --git a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp index 049f04dc9..296af478b 100644 --- a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp +++ b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp @@ -20,6 +20,18 @@ subject to the following restrictions: #include "GL_ShapeDrawer.h" #include "GlutStuff.h" +#include "btBulletWorldImporter.h" + +#define SERIALIZE_TO_DISK 1 + +//by default, the sample only (de)serializes the BVH to disk. +//If you enable the SERIALIZE_SHAPE define then it will serialize the entire collision shape +//then the animation will not play, because it is using the deserialized vertices +//#define SERIALIZE_SHAPE + + + + //#define USE_PARALLEL_DISPATCHER 1 #ifdef USE_PARALLEL_DISPATCHER #include "../../Extras/BulletMultiThreaded/SpuGatheringCollisionDispatcher.h" @@ -186,55 +198,60 @@ void ConcaveDemo::initPhysics() bool useQuantizedAabbCompression = true; //comment out the next line to read the BVH from disk (first run the demo once to create the BVH) -#define SERIALIZE_TO_DISK 1 + #ifdef SERIALIZE_TO_DISK + + btVector3 aabbMin(-1000,-1000,-1000),aabbMax(1000,1000,1000); trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax); m_collisionShapes.push_back(trimeshShape); - - - ///we can serialize the BVH data - void* buffer = 0; - int numBytes = trimeshShape->getOptimizedBvh()->calculateSerializeBufferSize(); - buffer = btAlignedAlloc(numBytes,16); - bool swapEndian = false; - trimeshShape->getOptimizedBvh()->serialize(buffer,numBytes,swapEndian); - FILE* file = fopen("bvh.bin","wb"); - fwrite(buffer,1,numBytes,file); - fclose(file); - btAlignedFree(buffer); - + int maxSerializeBufferSize = 1024*1024*5; + btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize); + //serializer->setSerializationFlags(BT_SERIALIZE_NO_BVH);// or BT_SERIALIZE_NO_TRIANGLEINFOMAP + serializer->startSerialization(); + //registering a name is optional, it allows you to retrieve the shape by name + //serializer->registerNameForPointer(trimeshShape,"mymesh"); +#ifdef SERIALIZE_SHAPE + trimeshShape->serializeSingleShape(serializer); +#else + trimeshShape->serializeSingleBvh(serializer); +#endif + serializer->finishSerialization(); + FILE* f2 = fopen("myShape.bullet","wb"); + fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2); + fclose(f2); #else - - trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,false); - - char* fileName = "bvh.bin"; - - FILE* file = fopen(fileName,"rb"); - int size=0; - btOptimizedBvh* bvh = 0; - - if (fseek(file, 0, SEEK_END) || (size = ftell(file)) == EOF || fseek(file, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */ - printf("Error: cannot get filesize from %s\n", fileName); - exit(0); - } else + btBulletWorldImporter import(0);//don't store info into the world + if (import.loadFile("myShape.bullet")) { - - fseek(file, 0, SEEK_SET); - - int buffersize = size+btOptimizedBvh::getAlignmentSerializationPadding(); - - void* buffer = btAlignedAlloc(buffersize,16); - int read = fread(buffer,1,size,file); - fclose(file); - bool swapEndian = false; - bvh = btOptimizedBvh::deSerializeInPlace(buffer,buffersize,swapEndian); + int numBvh = import.getNumBvhs(); + if (numBvh) + { + btOptimizedBvh* bvh = import.getBvhByIndex(0); + btVector3 aabbMin(-1000,-1000,-1000),aabbMax(1000,1000,1000); + + trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax,false); + trimeshShape->setOptimizedBvh(bvh); + //trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax); + //trimeshShape->setOptimizedBvh(bvh); + + } + int numShape = import.getNumCollisionShapes(); + if (numShape) + { + trimeshShape = (btBvhTriangleMeshShape*)import.getCollisionShapeByIndex(0); + + //if you know the name, you can also try to get the shape by name: + const char* meshName = import.getNameForPointer(trimeshShape); + if (meshName) + trimeshShape = (btBvhTriangleMeshShape*)import.getCollisionShapeByName(meshName); + + } } - trimeshShape->setOptimizedBvh(bvh); #endif diff --git a/Demos/OpenGL/DemoApplication.cpp b/Demos/OpenGL/DemoApplication.cpp index 6209cf0d7..7eb06348e 100644 --- a/Demos/OpenGL/DemoApplication.cpp +++ b/Demos/OpenGL/DemoApplication.cpp @@ -377,6 +377,7 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y) { int maxSerializeBufferSize = 1024*1024*5; btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize); + //serializer->setSerializationFlags(BT_SERIALIZE_NO_DUPLICATE_ASSERT); m_dynamicsWorld->serialize(serializer); FILE* f2 = fopen("testFile.bullet","wb"); fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2); diff --git a/Demos/SerializeDemo/CMakeLists.txt b/Demos/SerializeDemo/CMakeLists.txt index 8aef1c73a..c19521c72 100644 --- a/Demos/SerializeDemo/CMakeLists.txt +++ b/Demos/SerializeDemo/CMakeLists.txt @@ -21,7 +21,7 @@ ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter IF (USE_GLUT) LINK_LIBRARIES( - OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision LinearMath BulletFileLoader ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision BulletFileLoader LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) IF (WIN32) @@ -59,7 +59,7 @@ IF (USE_GLUT) ELSE (USE_GLUT) LINK_LIBRARIES( - OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision LinearMath BulletFileLoader ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision BulletFileLoader LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) ADD_EXECUTABLE(AppSerializeDemo diff --git a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp index 061f0ac0d..7a4c04b80 100644 --- a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp +++ b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp @@ -18,13 +18,54 @@ m_verboseDumpAllTypes(false) btBulletWorldImporter::~btBulletWorldImporter() { - for (int i=0;im_planeNormal); localScaling.deSerializeFloat(planeData->m_localScaling); - shape = new btStaticPlaneShape(planeNormal,btScalar(planeData->m_planeConstant)); + shape = createPlaneShape(planeNormal,planeData->m_planeConstant); shape->setLocalScaling(localScaling); break; @@ -305,13 +346,27 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap if (trimesh->m_quantizedFloatBvh) { - bvh = createOptimizedBvh(); - bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh); + btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh); + if (bvhPtr && *bvhPtr) + { + bvh = *bvhPtr; + } else + { + bvh = createOptimizedBvh(); + bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh); + } } if (trimesh->m_quantizedDoubleBvh) { - bvh = createOptimizedBvh(); - bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh); + btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedDoubleBvh); + if (bvhPtr && *bvhPtr) + { + bvh = *bvhPtr; + } else + { + bvh = createOptimizedBvh(); + bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh); + } } @@ -369,12 +424,25 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap } +char* btBulletWorldImporter::duplicateName(const char* name) +{ + if (name) + { + int l = strlen(name); + char* newName = new char[l+1]; + memcpy(newName,name,l); + newName[l] = 0; + m_allocatedNames.push_back(newName); + return newName; + } + return 0; +} bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFile2) { - + int i; bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0; if (ok) @@ -387,7 +455,24 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil bulletFile2->dumpChunks(bulletFile2->getFileDNA()); } - int i; + for (i=0;im_bvhs.size();i++) + { + btOptimizedBvh* bvh = createOptimizedBvh(); + + if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) + { + btQuantizedBvhDoubleData* bvhData = (btQuantizedBvhDoubleData*)bulletFile2->m_bvhs[i]; + bvh->deSerializeDouble(*bvhData); + } else + { + btQuantizedBvhFloatData* bvhData = (btQuantizedBvhFloatData*)bulletFile2->m_bvhs[i]; + bvh->deSerializeFloat(*bvhData); + } + m_bvhMap.insert(bulletFile2->m_bvhs[i],bvh); + } + + + btHashMap shapeMap; for (i=0;im_collisionShapes.size();i++) @@ -396,11 +481,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil btCollisionShape* shape = convertCollisionShape(shapeData); if (shape) shapeMap.insert(shapeData,shape); + + if (shape&& shapeData->m_name) + { + char* newname = duplicateName(shapeData->m_name); + m_objectNameMap.insert(shape,newname); + m_nameShapeMap.insert(newname,shape); + } } btHashMap bodyMap; - for (i=0;im_rigidBodies.size();i++) { if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) @@ -559,12 +650,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil rbB = &getFixedBody(); } + btTypedConstraint* constraint = 0; + switch (constraintData->m_objectType) { case POINT2POINT_CONSTRAINT_TYPE: { - btPoint2PointConstraint* constraint = 0; - if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) { btPoint2PointConstraintDoubleData* p2pData = (btPoint2PointConstraintDoubleData*)constraintData; @@ -573,12 +664,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil btVector3 pivotInA,pivotInB; pivotInA.deSerializeDouble(p2pData->m_pivotInA); pivotInB.deSerializeDouble(p2pData->m_pivotInB); - constraint = new btPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); + constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); } else { btVector3 pivotInA; pivotInA.deSerializeDouble(p2pData->m_pivotInA); - constraint = new btPoint2PointConstraint(*rbA,pivotInA); + constraint = createPoint2PointConstraint(*rbA,pivotInA); } } else { @@ -588,19 +679,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil btVector3 pivotInA,pivotInB; pivotInA.deSerializeFloat(p2pData->m_pivotInA); pivotInB.deSerializeFloat(p2pData->m_pivotInB); - constraint = new btPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); + constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); } else { btVector3 pivotInA; pivotInA.deSerializeFloat(p2pData->m_pivotInA); - constraint = new btPoint2PointConstraint(*rbA,pivotInA); + constraint = createPoint2PointConstraint(*rbA,pivotInA); } } - m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); - constraint->setDbgDrawSize(constraintData->m_dbgDrawSize); break; } case HINGE_CONSTRAINT_TYPE: @@ -615,12 +704,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil btTransform rbAFrame,rbBFrame; rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); rbBFrame.deSerializeDouble(hingeData->m_rbBFrame); - hinge = new btHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); + hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); } else { btTransform rbAFrame; rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); - hinge = new btHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); + hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); } if (hingeData->m_enableAngularMotor) { @@ -636,12 +725,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil btTransform rbAFrame,rbBFrame; rbAFrame.deSerializeFloat(hingeData->m_rbAFrame); rbBFrame.deSerializeFloat(hingeData->m_rbBFrame); - hinge = new btHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); + hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); } else { btTransform rbAFrame; rbAFrame.deSerializeFloat(hingeData->m_rbAFrame); - hinge = new btHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); + hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); } if (hingeData->m_enableAngularMotor) { @@ -650,10 +739,8 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil hinge->setAngularOnly(hingeData->m_angularOnly!=0); hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor)); } - m_dynamicsWorld->addConstraint(hinge,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); - hinge->setDbgDrawSize(constraintData->m_dbgDrawSize); - - + + constraint = hinge; break; } @@ -667,19 +754,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil btTransform rbAFrame,rbBFrame; rbAFrame.deSerializeFloat(coneData->m_rbAFrame); rbBFrame.deSerializeFloat(coneData->m_rbBFrame); - coneTwist = new btConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame); + coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame); } else { btTransform rbAFrame; rbAFrame.deSerializeFloat(coneData->m_rbAFrame); - coneTwist = new btConeTwistConstraint(*rbA,rbAFrame); + coneTwist = createConeTwistConstraint(*rbA,rbAFrame); } coneTwist->setLimit(coneData->m_swingSpan1,coneData->m_swingSpan2,coneData->m_twistSpan,coneData->m_limitSoftness,coneData->m_biasFactor,coneData->m_relaxationFactor); coneTwist->setDamping(coneData->m_damping); - m_dynamicsWorld->addConstraint(coneTwist,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); - coneTwist->setDbgDrawSize(constraintData->m_dbgDrawSize); - - + + constraint = coneTwist; break; } @@ -693,12 +778,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil btTransform rbAFrame,rbBFrame; rbAFrame.deSerializeFloat(dofData->m_rbAFrame); rbBFrame.deSerializeFloat(dofData->m_rbBFrame); - dof = new btGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); } else { btTransform rbBFrame; rbBFrame.deSerializeFloat(dofData->m_rbBFrame); - dof = new btGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); } btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit); @@ -711,8 +796,7 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil dof->setLinearLowerLimit(linLowerLimit); dof->setLinearUpperLimit(linUpperlimit); - m_dynamicsWorld->addConstraint(dof,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); - dof->setDbgDrawSize(constraintData->m_dbgDrawSize); + constraint = dof; break; } case SLIDER_CONSTRAINT_TYPE: @@ -724,22 +808,19 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil btTransform rbAFrame,rbBFrame; rbAFrame.deSerializeFloat(sliderData->m_rbAFrame); rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); - slider = new btSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); } else { btTransform rbBFrame; rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); - slider = new btSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); } slider->setLowerLinLimit(sliderData->m_linearLowerLimit); slider->setUpperLinLimit(sliderData->m_linearUpperLimit); slider->setLowerAngLimit(sliderData->m_angularLowerLimit); slider->setUpperAngLimit(sliderData->m_angularUpperLimit); slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0); - - m_dynamicsWorld->addConstraint(slider,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); - slider->setDbgDrawSize(constraintData->m_dbgDrawSize); - + constraint = slider; break; } @@ -748,23 +829,26 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil printf("unknown constraint type\n"); } }; + + if (constraint) + { + constraint->setDbgDrawSize(constraintData->m_dbgDrawSize); + if (constraintData->m_name) + { + char* newname = duplicateName(constraintData->m_name); + m_nameConstraintMap.insert(newname,constraint); + m_objectNameMap.insert(constraint,newname); + } + if(m_dynamicsWorld) + m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); + } } return true; } -btTypedConstraint* btBulletWorldImporter::createUniversalD6Constraint(class btRigidBody* body0,class btRigidBody* otherBody, - btTransform& localAttachmentFrameRef, - btTransform& localAttachmentOther, - const btVector3& linearMinLimits, - const btVector3& linearMaxLimits, - const btVector3& angularMinLimits, - const btVector3& angularMaxLimits, - bool disableCollisionsBetweenLinkedBodies) -{ - return 0; -} + btCollisionObject* btBulletWorldImporter::createCollisionObject(const btTransform& startTransform,btCollisionShape* shape, const char* bodyName) { @@ -784,69 +868,102 @@ btRigidBody* btBulletWorldImporter::createRigidBody(bool isDynamic, btScalar ma btRigidBody* body = new btRigidBody(mass,0,shape,localInertia); body->setWorldTransform(startTransform); - m_dynamicsWorld->addRigidBody(body); + if (m_dynamicsWorld) + m_dynamicsWorld->addRigidBody(body); + if (bodyName) + { + char* newname = duplicateName(bodyName); + m_objectNameMap.insert(body,newname); + m_nameBodyMap.insert(newname,body); + } + m_allocatedRigidBodies.push_back(body); return body; + } btCollisionShape* btBulletWorldImporter::createPlaneShape(const btVector3& planeNormal,btScalar planeConstant) { - return 0; + btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal,planeConstant); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btCollisionShape* btBulletWorldImporter::createBoxShape(const btVector3& halfExtents) { - return new btBoxShape(halfExtents); + btBoxShape* shape = new btBoxShape(halfExtents); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btCollisionShape* btBulletWorldImporter::createSphereShape(btScalar radius) { - return new btSphereShape(radius); + btSphereShape* shape = new btSphereShape(radius); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btCollisionShape* btBulletWorldImporter::createCapsuleShapeX(btScalar radius, btScalar height) { - return new btCapsuleShapeX(radius,height); + btCapsuleShapeX* shape = new btCapsuleShapeX(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btCollisionShape* btBulletWorldImporter::createCapsuleShapeY(btScalar radius, btScalar height) { - return new btCapsuleShape(radius,height); + btCapsuleShape* shape = new btCapsuleShape(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btCollisionShape* btBulletWorldImporter::createCapsuleShapeZ(btScalar radius, btScalar height) { - return new btCapsuleShapeZ(radius,height); + btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btCollisionShape* btBulletWorldImporter::createCylinderShapeX(btScalar radius,btScalar height) { - return new btCylinderShapeX(btVector3(height,radius,radius)); + btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height,radius,radius)); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btCollisionShape* btBulletWorldImporter::createCylinderShapeY(btScalar radius,btScalar height) { - return new btCylinderShape(btVector3(radius,height,radius)); + btCylinderShape* shape = new btCylinderShape(btVector3(radius,height,radius)); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btCollisionShape* btBulletWorldImporter::createCylinderShapeZ(btScalar radius,btScalar height) { - return new btCylinderShapeZ(btVector3(radius,radius,height)); + btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius,radius,height)); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btTriangleIndexVertexArray* btBulletWorldImporter::createTriangleMeshContainer() { - return new btTriangleIndexVertexArray(); + btTriangleIndexVertexArray* in = new btTriangleIndexVertexArray(); + m_allocatedTriangleIndexArrays.push_back(in); + return in; } btOptimizedBvh* btBulletWorldImporter::createOptimizedBvh() { - return new btOptimizedBvh(); + btOptimizedBvh* bvh = new btOptimizedBvh(); + m_allocatedBvhs.push_back(bvh); + return bvh; } btTriangleInfoMap* btBulletWorldImporter::createTriangleInfoMap() { - return new btTriangleInfoMap(); + btTriangleInfoMap* tim = new btTriangleInfoMap(); + m_allocatedTriangleInfoMaps.push_back(tim); + return tim; } btBvhTriangleMeshShape* btBulletWorldImporter::createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh) @@ -855,9 +972,14 @@ btBvhTriangleMeshShape* btBulletWorldImporter::createBvhTriangleMeshShape(btStri { btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false); bvhTriMesh->setOptimizedBvh(bvh); + m_allocatedCollisionShapes.push_back(bvhTriMesh); return bvhTriMesh; } - return new btBvhTriangleMeshShape(trimesh,true); + + btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh,true); + m_allocatedCollisionShapes.push_back(ts); + return ts; + } btCollisionShape* btBulletWorldImporter::createConvexTriangleMeshShape(btStridingMeshInterface* trimesh) { @@ -865,16 +987,23 @@ btCollisionShape* btBulletWorldImporter::createConvexTriangleMeshShape(btStridin } btGImpactMeshShape* btBulletWorldImporter::createGimpactShape(btStridingMeshInterface* trimesh) { - return new btGImpactMeshShape(trimesh); + btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh); + m_allocatedCollisionShapes.push_back(shape); + return shape; + } btConvexHullShape* btBulletWorldImporter::createConvexHullShape() { - return new btConvexHullShape(); + btConvexHullShape* shape = new btConvexHullShape(); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btCompoundShape* btBulletWorldImporter::createCompoundShape() { - return new btCompoundShape(); + btCompoundShape* shape = new btCompoundShape(); + m_allocatedCollisionShapes.push_back(shape); + return shape; } btRigidBody& btBulletWorldImporter::getFixedBody() @@ -884,3 +1013,163 @@ btRigidBody& btBulletWorldImporter::getFixedBody() return s_fixed; } +btPoint2PointConstraint* btBulletWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB) +{ + btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,rbB,pivotInA,pivotInB); + m_allocatedConstraints.push_back(p2p); + return p2p; +} + +btPoint2PointConstraint* btBulletWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA) +{ + btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,pivotInA); + m_allocatedConstraints.push_back(p2p); + return p2p; +} + + +btHingeConstraint* btBulletWorldImporter::createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA) +{ + btHingeConstraint* hinge = new btHingeConstraint(rbA,rbB,rbAFrame,rbBFrame,useReferenceFrameA); + m_allocatedConstraints.push_back(hinge); + return hinge; +} + +btHingeConstraint* btBulletWorldImporter::createHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA) +{ + btHingeConstraint* hinge = new btHingeConstraint(rbA,rbAFrame,useReferenceFrameA); + m_allocatedConstraints.push_back(hinge); + return hinge; +} + +btConeTwistConstraint* btBulletWorldImporter::createConeTwistConstraint(btRigidBody& rbA,btRigidBody& rbB,const btTransform& rbAFrame, const btTransform& rbBFrame) +{ + btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbB,rbAFrame,rbBFrame); + m_allocatedConstraints.push_back(cone); + return cone; +} + +btConeTwistConstraint* btBulletWorldImporter::createConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame) +{ + btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbAFrame); + m_allocatedConstraints.push_back(cone); + return cone; +} + + +btGeneric6DofConstraint* btBulletWorldImporter::createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA) +{ + btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(dof); + return dof; +} + +btGeneric6DofConstraint* btBulletWorldImporter::createGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB) +{ + btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbB,frameInB,useLinearReferenceFrameB); + m_allocatedConstraints.push_back(dof); + return dof; +} +btSliderConstraint* btBulletWorldImporter::createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA) +{ + btSliderConstraint* slider = new btSliderConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(slider); + return slider; +} + +btSliderConstraint* btBulletWorldImporter::createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA) +{ + btSliderConstraint* slider = new btSliderConstraint(rbB,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(slider); + return slider; +} + + + // query for data +int btBulletWorldImporter::getNumCollisionShapes() const +{ + return m_allocatedCollisionShapes.size(); +} + +btCollisionShape* btBulletWorldImporter::getCollisionShapeByIndex(int index) +{ + return m_allocatedCollisionShapes[index]; +} + +btCollisionShape* btBulletWorldImporter::getCollisionShapeByName(const char* name) +{ + btCollisionShape** shapePtr = m_nameShapeMap.find(name); + if (shapePtr&& *shapePtr) + { + return *shapePtr; + } + return 0; +} + +btRigidBody* btBulletWorldImporter::getRigidBodyByName(const char* name) +{ + btRigidBody** bodyPtr = m_nameBodyMap.find(name); + if (bodyPtr && *bodyPtr) + { + *bodyPtr; + } + return 0; +} + +btTypedConstraint* btBulletWorldImporter::getConstraintByName(const char* name) +{ + btTypedConstraint** constraintPtr = m_nameConstraintMap.find(name); + if (constraintPtr && *constraintPtr) + { + return *constraintPtr; + } + return 0; +} + +const char* btBulletWorldImporter::getNameForPointer(const void* ptr) const +{ + const char*const * namePtr = m_objectNameMap.find(ptr); + if (namePtr && *namePtr) + return *namePtr; + return 0; +} + + +int btBulletWorldImporter::getNumRigidBodies() const +{ + return m_allocatedRigidBodies.size(); +} + +btCollisionObject* btBulletWorldImporter::getRigidBodyByIndex(int index) const +{ + return m_allocatedRigidBodies[index]; +} +int btBulletWorldImporter::getNumConstraints() const +{ + return m_allocatedConstraints.size(); +} + +btTypedConstraint* btBulletWorldImporter::getConstraintByIndex(int index) const +{ + return m_allocatedConstraints[index]; +} + +int btBulletWorldImporter::getNumBvhs() const +{ + return m_allocatedBvhs.size(); +} + btOptimizedBvh* btBulletWorldImporter::getBvhByIndex(int index) const +{ + return m_allocatedBvhs[index]; +} + +int btBulletWorldImporter::getNumTriangleInfoMaps() const +{ + return m_allocatedTriangleInfoMaps.size(); +} + +btTriangleInfoMap* btBulletWorldImporter::getTriangleInfoMapByIndex(int index) const +{ + return m_allocatedTriangleInfoMaps[index]; +} + diff --git a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h index 798cca395..88535d266 100644 --- a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h +++ b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h @@ -39,6 +39,12 @@ class btGImpactMeshShape; class btOptimizedBvh; struct btTriangleInfoMap; class btBvhTriangleMeshShape; +class btPoint2PointConstraint; +class btHingeConstraint; +class btConeTwistConstraint; +class btGeneric6DofConstraint; +class btSliderConstraint; + namespace bParse @@ -58,18 +64,40 @@ protected: btCollisionShape* convertCollisionShape( btCollisionShapeData* shapeData ); - btAlignedObjectArray m_allocatedCollisionShapes; + btAlignedObjectArray m_allocatedCollisionShapes; + btAlignedObjectArray m_allocatedRigidBodies; + btAlignedObjectArray m_allocatedConstraints; + btAlignedObjectArray m_allocatedBvhs; + btAlignedObjectArray m_allocatedTriangleInfoMaps; + btAlignedObjectArray m_allocatedTriangleIndexArrays; + btAlignedObjectArray m_allocatedNames; + + btHashMap m_bvhMap; + btHashMap m_timMap; + + btHashMap m_nameShapeMap; + btHashMap m_nameBodyMap; + btHashMap m_nameConstraintMap; + btHashMap m_objectNameMap; + + //methods btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData); static btRigidBody& getFixedBody(); - + + char* duplicateName(const char* name); + public: - btBulletWorldImporter(btDynamicsWorld* world); + btBulletWorldImporter(btDynamicsWorld* world=0); virtual ~btBulletWorldImporter(); + ///delete all memory collision shapes, rigid bodies, constraints etc. allocated during the load. + ///make sure you don't use the dynamics world containing objects after you call this method + void deleteAllData(); + bool loadFile(const char* fileName); ///the memoryBuffer might be modified (for example if endian swaps are necessary) @@ -86,26 +114,32 @@ public: { return m_verboseDumpAllTypes; } - - ///those virtuals are called by load - virtual btTypedConstraint* createUniversalD6Constraint( - class btRigidBody* body0,class btRigidBody* otherBody, - btTransform& localAttachmentFrameRef, - btTransform& localAttachmentOther, - const btVector3& linearMinLimits, - const btVector3& linearMaxLimits, - const btVector3& angularMinLimits, - const btVector3& angularMaxLimits, - bool disableCollisionsBetweenLinkedBodies - ); - - virtual btRigidBody* createRigidBody(bool isDynamic, - btScalar mass, - const btTransform& startTransform, - btCollisionShape* shape,const char* bodyName); + // query for data + int getNumCollisionShapes() const; + btCollisionShape* getCollisionShapeByIndex(int index); + int getNumRigidBodies() const; + btCollisionObject* getRigidBodyByIndex(int index) const; + int getNumConstraints() const; + btTypedConstraint* getConstraintByIndex(int index) const; + int getNumBvhs() const; + btOptimizedBvh* getBvhByIndex(int index) const; + int getNumTriangleInfoMaps() const; + btTriangleInfoMap* getTriangleInfoMapByIndex(int index) const; + + // queris involving named objects + btCollisionShape* getCollisionShapeByName(const char* name); + btRigidBody* getRigidBodyByName(const char* name); + btTypedConstraint* getConstraintByName(const char* name); + const char* getNameForPointer(const void* ptr) const; + + ///those virtuals are called by load and can be overridden by the user + + //bodies + virtual btRigidBody* createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform, btCollisionShape* shape,const char* bodyName); virtual btCollisionObject* createCollisionObject( const btTransform& startTransform, btCollisionShape* shape,const char* bodyName); + ///shapes virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant); virtual btCollisionShape* createBoxShape(const btVector3& halfExtents); @@ -119,13 +153,27 @@ public: virtual btCollisionShape* createCylinderShapeZ(btScalar radius,btScalar height); virtual class btTriangleIndexVertexArray* createTriangleMeshContainer(); virtual btBvhTriangleMeshShape* createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh); - virtual btOptimizedBvh* createOptimizedBvh(); - virtual btTriangleInfoMap* createTriangleInfoMap(); virtual btCollisionShape* createConvexTriangleMeshShape(btStridingMeshInterface* trimesh); virtual btGImpactMeshShape* createGimpactShape(btStridingMeshInterface* trimesh); virtual class btConvexHullShape* createConvexHullShape(); virtual class btCompoundShape* createCompoundShape(); + ///acceleration and connectivity structures + virtual btOptimizedBvh* createOptimizedBvh(); + virtual btTriangleInfoMap* createTriangleInfoMap(); + + ///constraints + virtual btPoint2PointConstraint* createPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB); + virtual btPoint2PointConstraint* createPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA); + virtual btHingeConstraint* createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA=false); + virtual btHingeConstraint* createHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA=false); + virtual btConeTwistConstraint* createConeTwistConstraint(btRigidBody& rbA,btRigidBody& rbB,const btTransform& rbAFrame, const btTransform& rbBFrame); + virtual btConeTwistConstraint* createConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame); + virtual btGeneric6DofConstraint* createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); + virtual btGeneric6DofConstraint* createGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB); + virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); + virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA); + }; #endif //BULLET_WORLD_IMPORTER_H diff --git a/Extras/Serialize/CMakeLists.txt b/Extras/Serialize/CMakeLists.txt index 50a436f8d..acf8619ed 100644 --- a/Extras/Serialize/CMakeLists.txt +++ b/Extras/Serialize/CMakeLists.txt @@ -1,8 +1,9 @@ -IF (BUILD_BLEND_DEMO) +IF (BUILD_BLEND_DEMO OR INTERNAL_UPDATE_SERIALIZATION_STRUCTURES) SUBDIRS(BlenderSerialize ) ENDIF() + IF(INTERNAL_UPDATE_SERIALIZATION_STRUCTURES) # makesdna and HeaderGenerator are for advanced use only diff --git a/Extras/obsolete/AlgebraicCCD/BU_AlgebraicPolynomialSolver.cpp b/Extras/obsolete/AlgebraicCCD/BU_AlgebraicPolynomialSolver.cpp deleted file mode 100644 index e547079cb..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_AlgebraicPolynomialSolver.cpp +++ /dev/null @@ -1,360 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#include "BU_AlgebraicPolynomialSolver.h" -#include -#include - -int BU_AlgebraicPolynomialSolver::Solve2Quadratic(btScalar p, btScalar q) -{ - - btScalar basic_h_local; - btScalar basic_h_local_delta; - - basic_h_local = p * 0.5f; - basic_h_local_delta = basic_h_local * basic_h_local - q; - if (basic_h_local_delta > 0.0f) { - basic_h_local_delta = btSqrt(basic_h_local_delta); - m_roots[0] = - basic_h_local + basic_h_local_delta; - m_roots[1] = - basic_h_local - basic_h_local_delta; - return 2; - } - else if (btGreaterEqual(basic_h_local_delta, SIMD_EPSILON)) { - m_roots[0] = - basic_h_local; - return 1; - } - else { - return 0; - } - } - - -int BU_AlgebraicPolynomialSolver::Solve2QuadraticFull(btScalar a,btScalar b, btScalar c) -{ - btScalar radical = b * b - 4.0f * a * c; - if(radical >= 0.f) - { - btScalar sqrtRadical = btSqrt(radical); - btScalar idenom = 1.0f/(2.0f * a); - m_roots[0]=(-b + sqrtRadical) * idenom; - m_roots[1]=(-b - sqrtRadical) * idenom; - return 2; - } - return 0; -} - - -#define cubic_rt(x) \ - ((x) > 0.0f ? btPow((btScalar)(x), 0.333333333333333333333333f) : \ - ((x) < 0.0f ? -btPow((btScalar)-(x), 0.333333333333333333333333f) : 0.0f)) - - - -/* */ -/* this function solves the following cubic equation: */ -/* */ -/* 3 2 */ -/* lead * x + a * x + b * x + c = 0. */ -/* */ -/* it returns the number of different roots found, and stores the roots in */ -/* roots[0,2]. it returns -1 for a degenerate equation 0 = 0. */ -/* */ -int BU_AlgebraicPolynomialSolver::Solve3Cubic(btScalar lead, btScalar a, btScalar b, btScalar c) -{ - btScalar p, q, r; - btScalar delta, u, phi; - btScalar dummy; - - if (lead != 1.0) { - /* */ - /* transform into normal form: x^3 + a x^2 + b x + c = 0 */ - /* */ - if (btEqual(lead, SIMD_EPSILON)) { - /* */ - /* we have a x^2 + b x + c = 0 */ - /* */ - if (btEqual(a, SIMD_EPSILON)) { - /* */ - /* we have b x + c = 0 */ - /* */ - if (btEqual(b, SIMD_EPSILON)) { - if (btEqual(c, SIMD_EPSILON)) { - return -1; - } - else { - return 0; - } - } - else { - m_roots[0] = -c / b; - return 1; - } - } - else { - p = c / a; - q = b / a; - return Solve2QuadraticFull(a,b,c); - } - } - else { - a = a / lead; - b = b / lead; - c = c / lead; - } - } - - /* */ - /* we substitute x = y - a / 3 in order to eliminate the quadric term. */ - /* we get x^3 + p x + q = 0 */ - /* */ - a /= 3.0f; - u = a * a; - p = b / 3.0f - u; - q = a * (2.0f * u - b) + c; - - /* */ - /* now use Cardano's formula */ - /* */ - if (btEqual(p, SIMD_EPSILON)) { - if (btEqual(q, SIMD_EPSILON)) { - /* */ - /* one triple root */ - /* */ - m_roots[0] = -a; - return 1; - } - else { - /* */ - /* one real and two complex roots */ - /* */ - m_roots[0] = cubic_rt(-q) - a; - return 1; - } - } - - q /= 2.0f; - delta = p * p * p + q * q; - if (delta > 0.0f) { - /* */ - /* one real and two complex roots. note that v = -p / u. */ - /* */ - u = -q + btSqrt(delta); - u = cubic_rt(u); - m_roots[0] = u - p / u - a; - return 1; - } - else if (delta < 0.0) { - /* */ - /* Casus irreducibilis: we have three real roots */ - /* */ - r = btSqrt(-p); - p *= -r; - r *= 2.0; - phi = btAcos(-q / p) / 3.0f; - dummy = SIMD_2_PI / 3.0f; - m_roots[0] = r * btCos(phi) - a; - m_roots[1] = r * btCos(phi + dummy) - a; - m_roots[2] = r * btCos(phi - dummy) - a; - return 3; - } - else { - /* */ - /* one single and one btScalar root */ - /* */ - r = cubic_rt(-q); - m_roots[0] = 2.0f * r - a; - m_roots[1] = -r - a; - return 2; - } -} - - -/* */ -/* this function solves the following quartic equation: */ -/* */ -/* 4 3 2 */ -/* lead * x + a * x + b * x + c * x + d = 0. */ -/* */ -/* it returns the number of different roots found, and stores the roots in */ -/* roots[0,3]. it returns -1 for a degenerate equation 0 = 0. */ -/* */ -int BU_AlgebraicPolynomialSolver::Solve4Quartic(btScalar lead, btScalar a, btScalar b, btScalar c, btScalar d) -{ - btScalar p, q ,r; - btScalar u, v, w; - int i, num_roots, num_tmp; - //btScalar tmp[2]; - - if (lead != 1.0) { - /* */ - /* transform into normal form: x^4 + a x^3 + b x^2 + c x + d = 0 */ - /* */ - if (btEqual(lead, SIMD_EPSILON)) { - /* */ - /* we have a x^3 + b x^2 + c x + d = 0 */ - /* */ - if (btEqual(a, SIMD_EPSILON)) { - /* */ - /* we have b x^2 + c x + d = 0 */ - /* */ - if (btEqual(b, SIMD_EPSILON)) { - /* */ - /* we have c x + d = 0 */ - /* */ - if (btEqual(c, SIMD_EPSILON)) { - if (btEqual(d, SIMD_EPSILON)) { - return -1; - } - else { - return 0; - } - } - else { - m_roots[0] = -d / c; - return 1; - } - } - else { - p = c / b; - q = d / b; - return Solve2QuadraticFull(b,c,d); - - } - } - else { - return Solve3Cubic(1.0, b / a, c / a, d / a); - } - } - else { - a = a / lead; - b = b / lead; - c = c / lead; - d = d / lead; - } - } - - /* */ - /* we substitute x = y - a / 4 in order to eliminate the cubic term. */ - /* we get: y^4 + p y^2 + q y + r = 0. */ - /* */ - a /= 4.0f; - p = b - 6.0f * a * a; - q = a * (8.0f * a * a - 2.0f * b) + c; - r = a * (a * (b - 3.f * a * a) - c) + d; - if (btEqual(q, SIMD_EPSILON)) { - /* */ - /* biquadratic equation: y^4 + p y^2 + r = 0. */ - /* */ - num_roots = Solve2Quadratic(p, r); - if (num_roots > 0) { - if (m_roots[0] > 0.0f) { - if (num_roots > 1) { - if ((m_roots[1] > 0.0f) && (m_roots[1] != m_roots[0])) { - u = btSqrt(m_roots[1]); - m_roots[2] = u - a; - m_roots[3] = -u - a; - u = btSqrt(m_roots[0]); - m_roots[0] = u - a; - m_roots[1] = -u - a; - return 4; - } - else { - u = btSqrt(m_roots[0]); - m_roots[0] = u - a; - m_roots[1] = -u - a; - return 2; - } - } - else { - u = btSqrt(m_roots[0]); - m_roots[0] = u - a; - m_roots[1] = -u - a; - return 2; - } - } - } - return 0; - } - else if (btEqual(r, SIMD_EPSILON)) { - /* */ - /* no absolute term: y (y^3 + p y + q) = 0. */ - /* */ - num_roots = Solve3Cubic(1.0, 0.0, p, q); - for (i = 0; i < num_roots; ++i) m_roots[i] -= a; - if (num_roots != -1) { - m_roots[num_roots] = -a; - ++num_roots; - } - else { - m_roots[0] = -a; - num_roots = 1;; - } - return num_roots; - } - else { - /* */ - /* we solve the resolvent cubic equation */ - /* */ - num_roots = Solve3Cubic(1.0f, -0.5f * p, -r, 0.5f * r * p - 0.125f * q * q); - if (num_roots == -1) { - num_roots = 1; - m_roots[0] = 0.0f; - } - - /* */ - /* build two quadric equations */ - /* */ - w = m_roots[0]; - u = w * w - r; - v = 2.0f * w - p; - - if (btEqual(u, SIMD_EPSILON)) - u = 0.0; - else if (u > 0.0f) - u = btSqrt(u); - else - return 0; - - if (btEqual(v, SIMD_EPSILON)) - v = 0.0; - else if (v > 0.0f) - v = btSqrt(v); - else - return 0; - - if (q < 0.0f) v = -v; - w -= u; - num_roots=Solve2Quadratic(v, w); - for (i = 0; i < num_roots; ++i) - { - m_roots[i] -= a; - } - w += 2.0f *u; - btScalar tmp[2]; - tmp[0] = m_roots[0]; - tmp[1] = m_roots[1]; - - num_tmp = Solve2Quadratic(-v, w); - for (i = 0; i < num_tmp; ++i) - { - m_roots[i + num_roots] = tmp[i] - a; - m_roots[i]=tmp[i]; - } - - return (num_tmp + num_roots); - } -} - diff --git a/Extras/obsolete/AlgebraicCCD/BU_AlgebraicPolynomialSolver.h b/Extras/obsolete/AlgebraicCCD/BU_AlgebraicPolynomialSolver.h deleted file mode 100644 index 52d21a0f5..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_AlgebraicPolynomialSolver.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#ifndef BU_ALGEBRAIC_POLYNOMIAL_SOLVER_H -#define BU_ALGEBRAIC_POLYNOMIAL_SOLVER_H - -#include "BU_PolynomialSolverInterface.h" - -/// BU_AlgebraicPolynomialSolver implements polynomial root finding by analytically solving algebraic equations. -/// Polynomials up to 4rd degree are supported, Cardano's formula is used for 3rd degree -class BU_AlgebraicPolynomialSolver : public BUM_PolynomialSolverInterface -{ -public: - BU_AlgebraicPolynomialSolver() {}; - - int Solve2Quadratic(btScalar p, btScalar q); - int Solve2QuadraticFull(btScalar a,btScalar b, btScalar c); - int Solve3Cubic(btScalar lead, btScalar a, btScalar b, btScalar c); - int Solve4Quartic(btScalar lead, btScalar a, btScalar b, btScalar c, btScalar d); - - - btScalar GetRoot(int i) const - { - return m_roots[i]; - } - -private: - btScalar m_roots[4]; - -}; - -#endif //BU_ALGEBRAIC_POLYNOMIAL_SOLVER_H diff --git a/Extras/obsolete/AlgebraicCCD/BU_Collidable.cpp b/Extras/obsolete/AlgebraicCCD/BU_Collidable.cpp deleted file mode 100644 index f88928098..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_Collidable.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#include "BU_Collidable.h" -#include "BulletCollision/CollisionShapes/btCollisionShape.h" -#include -#include "BU_MotionStateInterface.h" - -BU_Collidable::BU_Collidable(BU_MotionStateInterface& motion,btPolyhedralConvexShape& shape,void* userPointer ) -:m_motionState(motion),m_shape(shape),m_userPointer(userPointer) -{ -} diff --git a/Extras/obsolete/AlgebraicCCD/BU_Collidable.h b/Extras/obsolete/AlgebraicCCD/BU_Collidable.h deleted file mode 100644 index 513acbde1..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_Collidable.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#ifndef BU_COLLIDABLE -#define BU_COLLIDABLE - - -class btPolyhedralConvexShape; -class BU_MotionStateInterface; -#include - -class BU_Collidable -{ -public: - BU_Collidable(BU_MotionStateInterface& motion,btPolyhedralConvexShape& shape, void* userPointer); - - void* GetUserPointer() const - { - return m_userPointer; - } - - BU_MotionStateInterface& GetMotionState() - { - return m_motionState; - } - inline const BU_MotionStateInterface& GetMotionState() const - { - return m_motionState; - } - - inline const btPolyhedralConvexShape& GetShape() const - { - return m_shape; - }; - - -private: - BU_MotionStateInterface& m_motionState; - btPolyhedralConvexShape& m_shape; - void* m_userPointer; - -}; - -#endif //BU_COLLIDABLE diff --git a/Extras/obsolete/AlgebraicCCD/BU_CollisionPair.cpp b/Extras/obsolete/AlgebraicCCD/BU_CollisionPair.cpp deleted file mode 100644 index 84dc6cd2b..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_CollisionPair.cpp +++ /dev/null @@ -1,581 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - - -#include "BU_CollisionPair.h" -#include "NarrowPhaseCollision/BU_VertexPoly.h" -#include "NarrowPhaseCollision/BU_EdgeEdge.h" -#include "BU_Collidable.h" - - -#include "BU_MotionStateInterface.h" -#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" -#include -#include "LinearMath/btTransformUtil.h" - - - -BU_CollisionPair::BU_CollisionPair(const btPolyhedralConvexShape* convexA,const btPolyhedralConvexShape* convexB,btScalar tolerance) -: m_convexA(convexA),m_convexB(convexB),m_screwing(btVector3(0,0,0),btVector3(0,0,0)), -m_tolerance(tolerance) -{ - -} - -// if there exists a time-of-impact between any feature_pair (edgeA,edgeB), -// (vertexA,faceB) or (vertexB,faceA) in [0..1], report true and smallest time - - -/* -bool BU_CollisionPair::GetTimeOfImpact(const btVector3& linearMotionA,const btQuaternion& angularMotionA,const btVector3& linearMotionB,const btQuaternion& angularMotionB, btScalar& toi,btTransform& impactTransA,btTransform& impactTransB) - -*/ - -bool BU_CollisionPair::calcTimeOfImpact( - const btTransform& fromA, - const btTransform& toA, - const btTransform& fromB, - const btTransform& toB, - CastResult& result) -{ - - - - - btVector3 linvelA,angvelA; - btVector3 linvelB,angvelB; - - btTransformUtil::calculateVelocity(fromA,toA,1.f,linvelA,angvelA); - btTransformUtil::calculateVelocity(fromB,toB,1.f,linvelB,angvelB); - - - btVector3 linearMotionA = toA.getOrigin() - fromA.getOrigin(); - btQuaternion angularMotionA(0,0,0,1.f); - btVector3 linearMotionB = toB.getOrigin() - fromB.getOrigin(); - btQuaternion angularMotionB(0,0,0,1); - - - - result.m_fraction = 1.f; - - btTransform impactTransA; - btTransform impactTransB; - - int index=0; - - btScalar toiUnscaled=result.m_fraction; - const btScalar toiUnscaledLimit = result.m_fraction; - - btTransform a2w; - a2w = fromA; - btTransform b2w = fromB; - -/* debugging code - { - const int numvertsB = m_convexB->getNumVertices(); - for (int v=0;vgetVertex(v,pt); - pt = b2w * pt; - char buf[1000]; - - if (pt.y() < 0.) - { - sprintf(buf,"PRE ERROR (%d) %.20E %.20E %.20E!!!!!!!!!\n",v,pt.x(),pt.y(),pt.z()); - if (debugFile) - fwrite(buf,1,strlen(buf),debugFile); - } else - { - sprintf(buf,"PRE %d = %.20E,%.20E,%.20E\n",v,pt.x(),pt.y(),pt.z()); - if (debugFile) - fwrite(buf,1,strlen(buf),debugFile); - - } - } - } -*/ - - - btTransform b2wp = b2w; - - b2wp.setOrigin(b2w.getOrigin() + linearMotionB); - b2wp.setRotation( b2w.getRotation() + angularMotionB); - - impactTransB = b2wp; - - btTransform a2wp; - a2wp.setOrigin(a2w.getOrigin()+ linearMotionA); - a2wp.setRotation(a2w.getRotation()+angularMotionA); - - impactTransA = a2wp; - - btTransform a2winv; - a2winv = a2w.inverse(); - - btTransform b2wpinv; - b2wpinv = b2wp.inverse(); - - btTransform b2winv; - b2winv = b2w.inverse(); - - btTransform a2wpinv; - a2wpinv = a2wp.inverse(); - - //Redon's version with concatenated transforms - - btTransform relative; - - relative = b2w * b2wpinv * a2wp * a2winv; - - //relative = a2winv * a2wp * b2wpinv * b2w; - - btQuaternion qrel; - relative.getBasis().getRotation(qrel); - - btVector3 linvel = relative.getOrigin(); - - if (linvel.length() < SCREWEPSILON) - { - linvel.setValue(0.,0.,0.); - } - btVector3 angvel; - angvel[0] = 2.f * btAsin (qrel[0]); - angvel[1] = 2.f * btAsin (qrel[1]); - angvel[2] = 2.f * btAsin (qrel[2]); - - if (angvel.length() < SCREWEPSILON) - { - angvel.setValue(0.f,0.f,0.f); - } - - //Redon's version with concatenated transforms - m_screwing = BU_Screwing(linvel,angvel); - - btTransform w2s; - m_screwing.LocalMatrix(w2s); - - btTransform s2w; - s2w = w2s.inverse(); - - //impactTransA = a2w; - //impactTransB = b2w; - - bool hit = false; - - if (btFuzzyZero(m_screwing.GetS()) && btFuzzyZero(m_screwing.GetW())) - { - //W = 0 , S = 0 , no collision - //toi = 0; - /* - { - const int numvertsB = m_convexB->getNumVertices(); - for (int v=0;vgetVertex(v,pt); - pt = impactTransB * pt; - char buf[1000]; - - if (pt.y() < 0.) - { - sprintf(buf,"EARLY POST ERROR (%d) %.20E,%.20E,%.20E!!!!!!!!!\n",v,pt.x(),pt.y(),pt.z()); - if (debugFile) - fwrite(buf,1,strlen(buf),debugFile); - } - else - { - sprintf(buf,"EARLY POST %d = %.20E,%.20E,%.20E\n",v,pt.x(),pt.y(),pt.z()); - if (debugFile) - fwrite(buf,1,strlen(buf),debugFile); - } - } - } - */ - - return false;//don't continue moving within epsilon - } - -#define EDGEEDGE -#ifdef EDGEEDGE - - BU_EdgeEdge edgeEdge; - - //for all edged in A check agains all edges in B - for (int ea = 0;ea < m_convexA->getNumEdges();ea++) - { - btPoint3 pA0,pA1; - - m_convexA->getEdge(ea,pA0,pA1); - - pA0= a2w * pA0;//in world space - pA0 = w2s * pA0;//in screwing space - - pA1= a2w * pA1;//in world space - pA1 = w2s * pA1;//in screwing space - - int numedgesB = m_convexB->getNumEdges(); - for (int eb = 0; eb < numedgesB;eb++) - { - { - btPoint3 pB0,pB1; - m_convexB->getEdge(eb,pB0,pB1); - - pB0= b2w * pB0;//in world space - pB0 = w2s * pB0;//in screwing space - - pB1= b2w * pB1;//in world space - pB1 = w2s * pB1;//in screwing space - - - btScalar lambda,mu; - - toiUnscaled = 1.; - - btVector3 edgeDirA(pA1-pA0); - btVector3 edgeDirB(pB1-pB0); - - if (edgeEdge.GetTimeOfImpact(m_screwing,pA0,edgeDirA,pB0,edgeDirB,toiUnscaled,lambda,mu)) - { - //printf("edgeedge potential hit\n"); - if (toiUnscaled>=0) - { - if (toiUnscaled < toiUnscaledLimit) - { - - //inside check is already done by checking the mu and gamma ! - - btPoint3 vtx = pA0+lambda * (pA1-pA0); - btPoint3 hitpt = m_screwing.InBetweenPosition(vtx,toiUnscaled); - - btPoint3 hitptWorld = s2w * hitpt; - { - - if (toiUnscaled < result.m_fraction) - result.m_fraction = toiUnscaled; - - hit = true; - - btVector3 hitNormal = edgeDirB.cross(edgeDirA); - - hitNormal = m_screwing.InBetweenVector(hitNormal,toiUnscaled); - - - hitNormal.normalize(); - - //an approximated normal can be calculated by taking the cross product of both edges - //take care of the sign ! - - btVector3 hitNormalWorld = s2w.getBasis() * hitNormal ; - - btScalar dist = m_screwing.GetU().dot(hitNormalWorld); - if (dist > 0) - hitNormalWorld *= -1; - - //todo: this is the wrong point, because b2winv is still at begin of motion - // not at time-of-impact location! - //bhitpt = b2winv * hitptWorld; - -// m_manifold.SetContactPoint(BUM_FeatureEdgeEdge,index,ea,eb,hitptWorld,hitNormalWorld); - } - - } - } - } - } - - index++; - } - }; -#endif //EDGEEDGE - -#define VERTEXFACE -#ifdef VERTEXFACE - - // for all vertices in A, for each face in B,do vertex-face - { - const int numvertsA = m_convexA->getNumVertices(); - for (int v=0;vgetVertex(v,vtx); - - vtx = a2w * vtx;//in world space - vtx = w2s * vtx;//in screwing space - - const int numplanesB = m_convexB->getNumPlanes(); - - for (int p = 0 ; p < numplanesB; p++) - //int p=2; - { - - { - - btVector3 planeNorm; - btPoint3 planeSupport; - - m_convexB->getPlane(planeNorm,planeSupport,p); - - - planeSupport = b2w * planeSupport;//transform to world space - btVector3 planeNormWorld = b2w.getBasis() * planeNorm; - - planeSupport = w2s * planeSupport ; //transform to screwing space - planeNorm = w2s.getBasis() * planeNormWorld; - - planeNorm.normalize(); - - btScalar d = planeSupport.dot(planeNorm); - - btVector4 planeEq(planeNorm[0],planeNorm[1],planeNorm[2],d); - - BU_VertexPoly vtxApolyB; - - toiUnscaled = 1.; - - if ((p==2) && (v==6)) - { -// printf("%f toiUnscaled\n",toiUnscaled); - - } - if (vtxApolyB.GetTimeOfImpact(m_screwing,vtx,planeEq,toiUnscaled,false)) - { - - - - - if (toiUnscaled >= 0. ) - { - //not only collect the first point, get every contactpoint, later we have to check the - //manifold properly! - - if (toiUnscaled <= toiUnscaledLimit) - { - // printf("toiUnscaled %f\n",toiUnscaled ); - - btPoint3 hitpt = m_screwing.InBetweenPosition(vtx,toiUnscaled); - btVector3 hitNormal = m_screwing.InBetweenVector(planeNorm ,toiUnscaled); - - btVector3 hitNormalWorld = s2w.getBasis() * hitNormal ; - btPoint3 hitptWorld = s2w * hitpt; - - - hitpt = b2winv * hitptWorld; - //vertex has to be 'within' the facet's boundary - if (m_convexB->isInside(hitpt,m_tolerance)) - { -// m_manifold.SetContactPoint(BUM_FeatureVertexFace, index,v,p,hitptWorld,hitNormalWorld); - - if (toiUnscaled < result.m_fraction) - result.m_fraction= toiUnscaled; - hit = true; - - } - } - } - } - - } - - index++; - } - } - } - - // - // for all vertices in B, for each face in A,do vertex-face - //copy and pasted from all verts A -> all planes B so potential typos! - //todo: make this into one method with a kind of 'swapped' logic - // - { - const int numvertsB = m_convexB->getNumVertices(); - for (int v=0;vgetVertex(v,vtx); - - vtx = b2w * vtx;//in world space -/* - - char buf[1000]; - - if (vtx.y() < 0.) - { - sprintf(buf,"ERROR !!!!!!!!!\n",v,vtx.x(),vtx.y(),vtx.z()); - if (debugFile) - fwrite(buf,1,strlen(buf),debugFile); - } - sprintf(buf,"vertexWorld(%d) = (%.20E,%.20E,%.20E)\n",v,vtx.x(),vtx.y(),vtx.z()); - if (debugFile) - fwrite(buf,1,strlen(buf),debugFile); - -*/ - vtx = w2s * vtx;//in screwing space - - const int numplanesA = m_convexA->getNumPlanes(); - - for (int p = 0 ; p < numplanesA; p++) - //int p=2; - { - - { - btVector3 planeNorm; - btPoint3 planeSupport; - - m_convexA->getPlane(planeNorm,planeSupport,p); - - - planeSupport = a2w * planeSupport;//transform to world space - btVector3 planeNormWorld = a2w.getBasis() * planeNorm; - - planeSupport = w2s * planeSupport ; //transform to screwing space - planeNorm = w2s.getBasis() * planeNormWorld; - - planeNorm.normalize(); - - btScalar d = planeSupport.dot(planeNorm); - - btVector4 planeEq(planeNorm[0],planeNorm[1],planeNorm[2],d); - - BU_VertexPoly vtxBpolyA; - - toiUnscaled = 1.; - - if (vtxBpolyA.GetTimeOfImpact(m_screwing,vtx,planeEq,toiUnscaled,true)) - { - if (toiUnscaled>=0.) - { - if (toiUnscaled < toiUnscaledLimit) - { - btPoint3 hitpt = m_screwing.InBetweenPosition( vtx , -toiUnscaled); - btVector3 hitNormal = m_screwing.InBetweenVector(-planeNorm ,-toiUnscaled); - //btScalar len = hitNormal.length()-1; - - //assert( btFuzzyZero(len) ); - - - btVector3 hitNormalWorld = s2w.getBasis() * hitNormal ; - btPoint3 hitptWorld = s2w * hitpt; - hitpt = a2winv * hitptWorld; - - - //vertex has to be 'within' the facet's boundary - if (m_convexA->isInside(hitpt,m_tolerance)) - { - -// m_manifold.SetContactPoint(BUM_FeatureFaceVertex,index,p,v,hitptWorld,hitNormalWorld); - if (toiUnscaled getNumVertices(); - for (int v=0;vgetVertex(v,pt); - pt = impactTransB * pt; - char buf[1000]; - - if (pt.y() < 0.) - { - sprintf(buf,"POST ERROR (%d) %.20E,%.20E,%.20E!!!!!!!!!\n",v,pt.x(),pt.y(),pt.z()); - if (debugFile) - fwrite(buf,1,strlen(buf),debugFile); - } - else - { - sprintf(buf,"POST %d = %.20E,%.20E,%.20E\n",v,pt.x(),pt.y(),pt.z()); - if (debugFile) - fwrite(buf,1,strlen(buf),debugFile); - } - } - } -*/ - return hit; -} - - diff --git a/Extras/obsolete/AlgebraicCCD/BU_CollisionPair.h b/Extras/obsolete/AlgebraicCCD/BU_CollisionPair.h deleted file mode 100644 index 69ca15225..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_CollisionPair.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#ifndef BU_COLLISIONPAIR -#define BU_COLLISIONPAIR - -#include -#include - - -#include - -class btPolyhedralConvexShape; - - -///BU_CollisionPair implements collision algorithm for algebraic time of impact calculation of feature based shapes. -class BU_CollisionPair : public btConvexCast -{ - -public: - BU_CollisionPair(const btPolyhedralConvexShape* convexA,const btPolyhedralConvexShape* convexB,btScalar tolerance=0.2f); - //toi - - virtual bool calcTimeOfImpact( - const btTransform& fromA, - const btTransform& toA, - const btTransform& fromB, - const btTransform& toB, - CastResult& result); - - - - -private: - const btPolyhedralConvexShape* m_convexA; - const btPolyhedralConvexShape* m_convexB; - BU_Screwing m_screwing; - btScalar m_tolerance; - -}; -#endif //BU_COLLISIONPAIR diff --git a/Extras/obsolete/AlgebraicCCD/BU_EdgeEdge.cpp b/Extras/obsolete/AlgebraicCCD/BU_EdgeEdge.cpp deleted file mode 100644 index 8df4c0d91..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_EdgeEdge.cpp +++ /dev/null @@ -1,578 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#include "BU_EdgeEdge.h" -#include "BU_Screwing.h" -#include -#include - -//#include "BU_IntervalArithmeticPolynomialSolver.h" -#include "BU_AlgebraicPolynomialSolver.h" - -#define USE_ALGEBRAIC -#ifdef USE_ALGEBRAIC -#define BU_Polynomial BU_AlgebraicPolynomialSolver -#else -#define BU_Polynomial BU_IntervalArithmeticPolynomialSolver -#endif - -BU_EdgeEdge::BU_EdgeEdge() -{ -} - - -bool BU_EdgeEdge::GetTimeOfImpact( - const BU_Screwing& screwAB, - const btPoint3& a,//edge in object A - const btVector3& u, - const btPoint3& c,//edge in object B - const btVector3& v, - btScalar &minTime, - btScalar &lambda1, - btScalar& mu1 - - ) -{ - bool hit=false; - - btScalar lambda; - btScalar mu; - - const btScalar w=screwAB.GetW(); - const btScalar s=screwAB.GetS(); - - if (btFuzzyZero(s) && - btFuzzyZero(w)) - { - //no motion, no collision - return false; - } - - if (btFuzzyZero(w) ) - { - //pure translation W=0, S <> 0 - //no trig, f(t)=t - btScalar det = u.y()*v.x()-u.x()*v.y(); - if (!btFuzzyZero(det)) - { - lambda = (a.x()*v.y() - c.x() * v.y() - v.x() * a.y() + v.x() * c.y()) / det; - mu = (u.y() * a.x() - u.y() * c.x() - u.x() * a.y() + u.x() * c.y()) / det; - - if (mu >=0 && mu <= 1 && lambda >= 0 && lambda <= 1) - { - // single potential collision is - btScalar t = (c.z()-a.z()+mu*v.z()-lambda*u.z())/s; - //if this is on the edge, and time t within [0..1] report hit - if (t>=0 && t <= minTime) - { - hit = true; - lambda1 = lambda; - mu1 = mu; - minTime=t; - } - } - - } else - { - //parallel case, not yet - } - } else - { - if (btFuzzyZero(s) ) - { - if (btFuzzyZero(u.z()) ) - { - if (btFuzzyZero(v.z()) ) - { - //u.z()=0,v.z()=0 - if (btFuzzyZero(a.z()-c.z())) - { - //printf("NOT YET planar problem, 4 vertex=edge cases\n"); - - } else - { - //printf("parallel but distinct planes, no collision\n"); - return false; - } - - } else - { - btScalar mu = (a.z() - c.z())/v.z(); - if (0<=mu && mu <= 1) - { - // printf("NOT YET//u.z()=0,v.z()<>0\n"); - } else - { - return false; - } - - } - } else - { - //u.z()<>0 - - if (btFuzzyZero(v.z()) ) - { - //printf("u.z()<>0,v.z()=0\n"); - lambda = (c.z() - a.z())/u.z(); - if (0<=lambda && lambda <= 1) - { - //printf("u.z()<>0,v.z()=0\n"); - btPoint3 rotPt(a.x()+lambda * u.x(), a.y()+lambda * u.y(),0.f); - btScalar r2 = rotPt.length2();//px*px + py*py; - - //either y=a*x+b, or x = a*x+b... - //depends on whether value v.x() is zero or not - btScalar aa; - btScalar bb; - - if (btFuzzyZero(v.x())) - { - aa = v.x()/v.y(); - bb= c.x()+ (-c.y() /v.y()) *v.x(); - } else - { - //line is c+mu*v; - //x = c.x()+mu*v.x(); - //mu = ((x-c.x())/v.x()); - //y = c.y()+((x-c.x())/v.x())*v.y(); - //y = c.y()+ (-c.x() /v.x()) *v.y() + (x /v.x()) *v.y(); - //y = a*x+b,where a = v.y()/v.x(), b= c.y()+ (-c.x() /v.x()) *v.y(); - aa = v.y()/v.x(); - bb= c.y()+ (-c.x() /v.x()) *v.y(); - } - - btScalar disc = aa*aa*r2 + r2 - bb*bb; - if (disc <0) - { - //edge doesn't intersect the circle (motion of the vertex) - return false; - } - btScalar rad = btSqrt(r2); - - if (btFuzzyZero(disc)) - { - btPoint3 intersectPt; - - btScalar mu; - //intersectionPoint edge with circle; - if (btFuzzyZero(v.x())) - { - intersectPt.setY( (-2*aa*bb)/(2*(aa*aa+1))); - intersectPt.setX( aa*intersectPt.y()+bb ); - mu = ((intersectPt.y()-c.y())/v.y()); - } else - { - intersectPt.setX((-2*aa*bb)/(2*(aa*aa+1))); - intersectPt.setY(aa*intersectPt.x()+bb); - mu = ((intersectPt.getX()-c.getX())/v.getX()); - - } - - if (0 <= mu && mu <= 1) - { - hit = Calc2DRotationPointPoint(rotPt,rad,screwAB.GetW(),intersectPt,minTime); - } - //only one solution - } else - { - //two points... - //intersectionPoint edge with circle; - btPoint3 intersectPt; - //intersectionPoint edge with circle; - if (btFuzzyZero(v.x())) - { - btScalar mu; - - intersectPt.setY((-2.f*aa*bb+2.f*btSqrt(disc))/(2.f*(aa*aa+1.f))); - intersectPt.setX(aa*intersectPt.y()+bb); - mu = ((intersectPt.getY()-c.getY())/v.getY()); - if (0.f <= mu && mu <= 1.f) - { - hit = Calc2DRotationPointPoint(rotPt,rad,screwAB.GetW(),intersectPt,minTime); - } - intersectPt.setY((-2.f*aa*bb-2.f*btSqrt(disc))/(2.f*(aa*aa+1.f))); - intersectPt.setX(aa*intersectPt.y()+bb); - mu = ((intersectPt.getY()-c.getY())/v.getY()); - if (0 <= mu && mu <= 1) - { - hit = hit || Calc2DRotationPointPoint(rotPt,rad,screwAB.GetW(),intersectPt,minTime); - } - - } else - { - btScalar mu; - - intersectPt.setX((-2.f*aa*bb+2.f*btSqrt(disc))/(2*(aa*aa+1.f))); - intersectPt.setY(aa*intersectPt.x()+bb); - mu = ((intersectPt.getX()-c.getX())/v.getX()); - if (0 <= mu && mu <= 1) - { - hit = Calc2DRotationPointPoint(rotPt,rad,screwAB.GetW(),intersectPt,minTime); - } - intersectPt.setX((-2.f*aa*bb-2.f*btSqrt(disc))/(2.f*(aa*aa+1.f))); - intersectPt.setY(aa*intersectPt.x()+bb); - mu = ((intersectPt.getX()-c.getX())/v.getX()); - if (0.f <= mu && mu <= 1.f) - { - hit = hit || Calc2DRotationPointPoint(rotPt,rad,screwAB.GetW(),intersectPt,minTime); - } - } - } - - - - //int k=0; - - } else - { - return false; - } - - - } else - { - //u.z()<>0,v.z()<>0 - //printf("general case with s=0\n"); - hit = GetTimeOfImpactbteralCase(screwAB,a,u,c,v,minTime,lambda,mu); - if (hit) - { - lambda1 = lambda; - mu1 = mu; - - } - } - } - - } else - { - //printf("general case, W<>0,S<>0\n"); - hit = GetTimeOfImpactbteralCase(screwAB,a,u,c,v,minTime,lambda,mu); - if (hit) - { - lambda1 = lambda; - mu1 = mu; - } - - } - - - //W <> 0,pure rotation - } - - return hit; -} - - -bool BU_EdgeEdge::GetTimeOfImpactbteralCase( - const BU_Screwing& screwAB, - const btPoint3& a,//edge in object A - const btVector3& u, - const btPoint3& c,//edge in object B - const btVector3& v, - btScalar &minTime, - btScalar &lambda, - btScalar& mu - - ) -{ - bool hit = false; - - btScalar coefs[4]={0.f,0.f,0.f,0.f}; - BU_Polynomial polynomialSolver; - int numroots = 0; - - //btScalar eps=1e-15f; - //btScalar eps2=1e-20f; - btScalar s=screwAB.GetS(); - btScalar w = screwAB.GetW(); - - btScalar ax = a.x(); - btScalar ay = a.y(); - btScalar az = a.z(); - btScalar cx = c.x(); - btScalar cy = c.y(); - btScalar cz = c.z(); - btScalar vx = v.x(); - btScalar vy = v.y(); - btScalar vz = v.z(); - btScalar ux = u.x(); - btScalar uy = u.y(); - btScalar uz = u.z(); - - - if (!btFuzzyZero(v.z())) - { - - //Maple Autogenerated C code - btScalar t1,t2,t3,t4,t7,t8,t10; - btScalar t13,t14,t15,t16,t17,t18,t19,t20; - btScalar t21,t22,t23,t24,t25,t26,t27,t28,t29,t30; - btScalar t31,t32,t33,t34,t35,t36,t39,t40; - btScalar t41,t43,t48; - btScalar t63; - - btScalar aa,bb,cc,dd;//the coefficients - - t1 = v.y()*s; t2 = t1*u.x(); - t3 = v.x()*s; - t4 = t3*u.y(); - t7 = btTan(w/2.0f); - t8 = 1.0f/t7; - t10 = 1.0f/v.z(); - aa = (t2-t4)*t8*t10; - t13 = a.x()*t7; - t14 = u.z()*v.y(); - t15 = t13*t14; - t16 = u.x()*v.z(); - t17 = a.y()*t7; - t18 = t16*t17; - t19 = u.y()*v.z(); - t20 = t13*t19; - t21 = v.y()*u.x(); - t22 = c.z()*t7; - t23 = t21*t22; - t24 = v.x()*a.z(); - t25 = t7*u.y(); - t26 = t24*t25; - t27 = c.y()*t7; - t28 = t16*t27; - t29 = a.z()*t7; - t30 = t21*t29; - t31 = u.z()*v.x(); - t32 = t31*t27; - t33 = t31*t17; - t34 = c.x()*t7; - t35 = t34*t19; - t36 = t34*t14; - t39 = v.x()*c.z(); - t40 = t39*t25; - t41 = 2.0f*t1*u.y()-t15+t18-t20-t23-t26+t28+t30+t32+t33-t35-t36+2.0f*t3*u.x()+t40; - bb = t41*t8*t10; - t43 = t7*u.x(); - t48 = u.y()*v.y(); - cc = (-2.0f*t39*t43+2.0f*t24*t43+t4-2.0f*t48*t22+2.0f*t34*t16-2.0f*t31*t13-t2 - -2.0f*t17*t14+2.0f*t19*t27+2.0f*t48*t29)*t8*t10; - t63 = -t36+t26+t32-t40+t23+t35-t20+t18-t28-t33+t15-t30; - dd = t63*t8*t10; - - coefs[0]=aa; - coefs[1]=bb; - coefs[2]=cc; - coefs[3]=dd; - - } else - { - - btScalar t1,t2,t3,t4,t7,t8,t10; - btScalar t13,t14,t15,t16,t17,t18,t19,t20; - btScalar t21,t22,t23,t24,t25,t26,t27,t28,t29,t30; - btScalar t31,t32,t33,t34,t35,t36,t37,t38,t57; - btScalar p1,p2,p3,p4; - - t1 = uy*s; - t2 = t1*vx; - t3 = ux*s; - t4 = t3*vy; - t7 = btTan(w/2.0f); - t8 = 1/t7; - t10 = 1/uz; - t13 = ux*az; - t14 = t7*vy; - t15 = t13*t14; - t16 = ax*t7; - t17 = uy*vz; - t18 = t16*t17; - t19 = cx*t7; - t20 = t19*t17; - t21 = vy*uz; - t22 = t19*t21; - t23 = ay*t7; - t24 = vx*uz; - t25 = t23*t24; - t26 = uy*cz; - t27 = t7*vx; - t28 = t26*t27; - t29 = t16*t21; - t30 = cy*t7; - t31 = ux*vz; - t32 = t30*t31; - t33 = ux*cz; - t34 = t33*t14; - t35 = t23*t31; - t36 = t30*t24; - t37 = uy*az; - t38 = t37*t27; - - p4 = (-t2+t4)*t8*t10; - p3 = 2.0f*t1*vy+t15-t18-t20-t22+t25+t28-t29+t32-t34+t35+t36-t38+2.0f*t3*vx; - p2 = -2.0f*t33*t27-2.0f*t26*t14-2.0f*t23*t21+2.0f*t37*t14+2.0f*t30*t17+2.0f*t13 -*t27+t2-t4+2.0f*t19*t31-2.0f*t16*t24; - t57 = -t22+t29+t36-t25-t32+t34+t35-t28-t15+t20-t18+t38; - p1 = t57*t8*t10; - - coefs[0] = p4; - coefs[1] = p3; - coefs[2] = p2; - coefs[1] = p1; - - } - - numroots = polynomialSolver.Solve3Cubic(coefs[0],coefs[1],coefs[2],coefs[3]); - - for (int i=0;i=0.f && t= -0.001); - - //if (hit) - { - // minTime = 0; - //calculate the time of impact, using the fact of - //toi = alpha / screwAB.getW(); - // cos (alpha) = adjacent/hypothenuse; - //adjacent = dotproduct(ipedge,point); - //hypothenuse = sqrt(r2); - btScalar adjacent = intersectPt.dot(rotPt)/rotRadius; - btScalar hypo = rotRadius; - btScalar alpha = btAcos(adjacent/hypo); - btScalar t = alpha / rotW; - if (t >= 0 && t < minTime) - { - hit = true; - minTime = t; - } else - { - hit = false; - } - - } - return hit; -} - -bool BU_EdgeEdge::GetTimeOfImpactVertexEdge( - const BU_Screwing& screwAB, - const btPoint3& a,//edge in object A - const btVector3& u, - const btPoint3& c,//edge in object B - const btVector3& v, - btScalar &minTime, - btScalar &lamda, - btScalar& mu - - ) -{ - return false; -} diff --git a/Extras/obsolete/AlgebraicCCD/BU_EdgeEdge.h b/Extras/obsolete/AlgebraicCCD/BU_EdgeEdge.h deleted file mode 100644 index c8c5768a6..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_EdgeEdge.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#ifndef BU_EDGEEDGE -#define BU_EDGEEDGE - -class BU_Screwing; -#include -#include -#include - -//class BUM_Point2; - -#include - -///BU_EdgeEdge implements algebraic time of impact calculation between two (angular + linear) moving edges. -class BU_EdgeEdge -{ -public: - - - BU_EdgeEdge(); - bool GetTimeOfImpact( - const BU_Screwing& screwAB, - const btPoint3& a,//edge in object A - const btVector3& u, - const btPoint3& c,//edge in object B - const btVector3& v, - btScalar &minTime, - btScalar &lamda, - btScalar& mu - ); -private: - - bool Calc2DRotationPointPoint(const btPoint3& rotPt, btScalar rotRadius, btScalar rotW,const btPoint3& intersectPt,btScalar& minTime); - bool GetTimeOfImpactbteralCase( - const BU_Screwing& screwAB, - const btPoint3& a,//edge in object A - const btVector3& u, - const btPoint3& c,//edge in object B - const btVector3& v, - btScalar &minTime, - btScalar &lamda, - btScalar& mu - - ); - - - bool GetTimeOfImpactVertexEdge( - const BU_Screwing& screwAB, - const btPoint3& a,//edge in object A - const btVector3& u, - const btPoint3& c,//edge in object B - const btVector3& v, - btScalar &minTime, - btScalar &lamda, - btScalar& mu - - ); - -}; - -#endif //BU_EDGEEDGE diff --git a/Extras/obsolete/AlgebraicCCD/BU_MotionStateInterface.h b/Extras/obsolete/AlgebraicCCD/BU_MotionStateInterface.h deleted file mode 100644 index 513675622..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_MotionStateInterface.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#ifndef BU_MOTIONSTATE -#define BU_MOTIONSTATE - - -#include -#include -#include - -class BU_MotionStateInterface -{ -public: - virtual ~BU_MotionStateInterface(){}; - - virtual void SetTransform(const btTransform& trans) = 0; - virtual void GetTransform(btTransform& trans) const = 0; - - virtual void SetPosition(const btPoint3& position) = 0; - virtual void GetPosition(btPoint3& position) const = 0; - - virtual void SetOrientation(const btQuaternion& orientation) = 0; - virtual void GetOrientation(btQuaternion& orientation) const = 0; - - virtual void SetBasis(const btMatrix3x3& basis) = 0; - virtual void GetBasis(btMatrix3x3& basis) const = 0; - - virtual void SetLinearVelocity(const btVector3& linvel) = 0; - virtual void GetLinearVelocity(btVector3& linvel) const = 0; - - virtual void GetAngularVelocity(btVector3& angvel) const = 0; - virtual void SetAngularVelocity(const btVector3& angvel) = 0; - -}; - -#endif //BU_MOTIONSTATE diff --git a/Extras/obsolete/AlgebraicCCD/BU_PolynomialSolverInterface.h b/Extras/obsolete/AlgebraicCCD/BU_PolynomialSolverInterface.h deleted file mode 100644 index 00e3e1294..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_PolynomialSolverInterface.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef BUM_POLYNOMIAL_SOLVER_INTERFACE -#define BUM_POLYNOMIAL_SOLVER_INTERFACE - -#include -// -//BUM_PolynomialSolverInterface is interface class for polynomial root finding. -//The number of roots is returned as a result, query GetRoot to get the actual solution. -// -class BUM_PolynomialSolverInterface -{ -public: - virtual ~BUM_PolynomialSolverInterface() {}; - - -// virtual int Solve2QuadraticFull(btScalar a,btScalar b, btScalar c) = 0; - - virtual int Solve3Cubic(btScalar lead, btScalar a, btScalar b, btScalar c) = 0; - - virtual int Solve4Quartic(btScalar lead, btScalar a, btScalar b, btScalar c, btScalar d) = 0; - - virtual btScalar GetRoot(int i) const = 0; - -}; - -#endif //BUM_POLYNOMIAL_SOLVER_INTERFACE diff --git a/Extras/obsolete/AlgebraicCCD/BU_Screwing.cpp b/Extras/obsolete/AlgebraicCCD/BU_Screwing.cpp deleted file mode 100644 index 1f5915740..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_Screwing.cpp +++ /dev/null @@ -1,200 +0,0 @@ - -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Stephane Redon / Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#include "BU_Screwing.h" - - -BU_Screwing::BU_Screwing(const btVector3& relLinVel,const btVector3& relAngVel) { - - - const btScalar dx=relLinVel[0]; - const btScalar dy=relLinVel[1]; - const btScalar dz=relLinVel[2]; - const btScalar wx=relAngVel[0]; - const btScalar wy=relAngVel[1]; - const btScalar wz=relAngVel[2]; - - // Compute the screwing parameters : - // w : total amount of rotation - // s : total amount of translation - // u : vector along the screwing axis (||u||=1) - // o : point on the screwing axis - - m_w=btSqrt(wx*wx+wy*wy+wz*wz); - //if (!w) { - if (fabs(m_w)= BUM_EPSILON2) { - if (n1[0] || n1[1] || n1[2]) { // n1 is not the zero vector - n1.normalize(); - btVector3 n1orth=m_u.cross(n1); - - float n2x=btCos(0.5f*m_w); - float n2y=btSin(0.5f*m_w); - - m_o=0.5f*t.dot(n1)*(n1+n2x/n2y*n1orth); - } - else - { - m_o=btPoint3(0.f,0.f,0.f); - } - - } - -} - -//Then, I need to compute Pa, the matrix from the reference (global) frame to -//the screwing frame : - - -void BU_Screwing::LocalMatrix(btTransform &t) const { -//So the whole computations do this : align the Oz axis along the -// screwing axis (thanks to u), and then find two others orthogonal axes to -// complete the basis. - - if ((m_u[0]>SCREWEPSILON)||(m_u[0]<-SCREWEPSILON)||(m_u[1]>SCREWEPSILON)||(m_u[1]<-SCREWEPSILON)) - { - // to avoid numerical problems - float n=btSqrt(m_u[0]*m_u[0]+m_u[1]*m_u[1]); - float invn=1.0f/n; - btMatrix3x3 mat; - - mat[0][0]=-m_u[1]*invn; - mat[0][1]=m_u[0]*invn; - mat[0][2]=0.f; - - mat[1][0]=-m_u[0]*invn*m_u[2]; - mat[1][1]=-m_u[1]*invn*m_u[2]; - mat[1][2]=n; - - mat[2][0]=m_u[0]; - mat[2][1]=m_u[1]; - mat[2][2]=m_u[2]; - - t.setOrigin(btPoint3( - m_o[0]*m_u[1]*invn-m_o[1]*m_u[0]*invn, - -(m_o[0]*mat[1][0]+m_o[1]*mat[1][1]+m_o[2]*n), - -(m_o[0]*m_u[0]+m_o[1]*m_u[1]+m_o[2]*m_u[2]))); - - t.setBasis(mat); - - } - else { - - btMatrix3x3 m; - - m[0][0]=1.; - m[1][0]=0.; - m[2][0]=0.; - - m[0][1]=0.f; - m[1][1]=float(btSign(m_u[2])); - m[2][1]=0.f; - - m[0][2]=0.f; - m[1][2]=0.f; - m[2][2]=float(btSign(m_u[2])); - - t.setOrigin(btPoint3( - -m_o[0], - -btSign(m_u[2])*m_o[1], - -btSign(m_u[2])*m_o[2] - )); - t.setBasis(m); - - } -} - -//gives interpolated transform for time in [0..1] in screwing frame -btTransform BU_Screwing::InBetweenTransform(const btTransform& tr,btScalar t) const -{ - btPoint3 org = tr.getOrigin(); - - btPoint3 neworg ( - org.x()*btCos(m_w*t)-org.y()*btSin(m_w*t), - org.x()*btSin(m_w*t)+org.y()*btCos(m_w*t), - org.z()+m_s*CalculateF(t)); - - btTransform newtr; - newtr.setOrigin(neworg); - btMatrix3x3 basis = tr.getBasis(); - btMatrix3x3 basisorg = tr.getBasis(); - - btQuaternion rot(btVector3(0.,0.,1.),m_w*t); - btQuaternion tmpOrn; - tr.getBasis().getRotation(tmpOrn); - rot = rot * tmpOrn; - - //to avoid numerical drift, normalize quaternion - rot.normalize(); - newtr.setBasis(btMatrix3x3(rot)); - return newtr; - -} - - -btScalar BU_Screwing::CalculateF(btScalar t) const -{ - btScalar result; - if (!m_w) - { - result = t; - } else - { - result = ( btTan((m_w*t)/2.f) / btTan(m_w/2.f)); - } - return result; -} - diff --git a/Extras/obsolete/AlgebraicCCD/BU_Screwing.h b/Extras/obsolete/AlgebraicCCD/BU_Screwing.h deleted file mode 100644 index f5efa890e..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_Screwing.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#ifndef B_SCREWING_H -#define B_SCREWING_H - - -#include -#include -#include - - -#define SCREWEPSILON 0.00001f - -///BU_Screwing implements screwing motion interpolation. -class BU_Screwing -{ -public: - - - BU_Screwing(const btVector3& relLinVel,const btVector3& relAngVel); - - ~BU_Screwing() { - }; - - btScalar CalculateF(btScalar t) const; - //gives interpolated position for time in [0..1] in screwing frame - - inline btPoint3 InBetweenPosition(const btPoint3& pt,btScalar t) const - { - return btPoint3( - pt.x()*btCos(m_w*t)-pt.y()*btSin(m_w*t), - pt.x()*btSin(m_w*t)+pt.y()*btCos(m_w*t), - pt.z()+m_s*CalculateF(t)); - } - - inline btVector3 InBetweenVector(const btVector3& vec,btScalar t) const - { - return btVector3( - vec.x()*btCos(m_w*t)-vec.y()*btSin(m_w*t), - vec.x()*btSin(m_w*t)+vec.y()*btCos(m_w*t), - vec.z()); - } - - //gives interpolated transform for time in [0..1] in screwing frame - btTransform InBetweenTransform(const btTransform& tr,btScalar t) const; - - - //gives matrix from global frame into screwing frame - void LocalMatrix(btTransform &t) const; - - inline const btVector3& GetU() const { return m_u;} - inline const btVector3& GetO() const {return m_o;} - inline const btScalar GetS() const{ return m_s;} - inline const btScalar GetW() const { return m_w;} - -private: - float m_w; - float m_s; - btVector3 m_u; - btVector3 m_o; -}; - -#endif //B_SCREWING_H diff --git a/Extras/obsolete/AlgebraicCCD/BU_StaticMotionState.h b/Extras/obsolete/AlgebraicCCD/BU_StaticMotionState.h deleted file mode 100644 index 86fcbcc94..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_StaticMotionState.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#ifndef BU_STATIC_MOTIONSTATE -#define BU_STATIC_MOTIONSTATE - - -#include - -class BU_StaticMotionState :public BU_MotionStateInterface -{ -public: - virtual ~BU_StaticMotionState(){}; - - virtual void SetTransform(const btTransform& trans) - { - m_trans = trans; - } - virtual void GetTransform(btTransform& trans) const - { - trans = m_trans; - } - virtual void SetPosition(const btPoint3& position) - { - m_trans.setOrigin( position ); - } - virtual void GetPosition(btPoint3& position) const - { - position = m_trans.getOrigin(); - } - - virtual void SetOrientation(const btQuaternion& orientation) - { - m_trans.setRotation( orientation); - } - virtual void GetOrientation(btQuaternion& orientation) const - { - orientation = m_trans.getRotation(); - } - - virtual void SetBasis(const btMatrix3x3& basis) - { - m_trans.setBasis( basis); - } - virtual void GetBasis(btMatrix3x3& basis) const - { - basis = m_trans.getBasis(); - } - - virtual void SetLinearVelocity(const btVector3& linvel) - { - m_linearVelocity = linvel; - } - virtual void GetLinearVelocity(btVector3& linvel) const - { - linvel = m_linearVelocity; - } - - virtual void SetAngularVelocity(const btVector3& angvel) - { - m_angularVelocity = angvel; - } - virtual void GetAngularVelocity(btVector3& angvel) const - { - angvel = m_angularVelocity; - } - - - -protected: - - btTransform m_trans; - btVector3 m_angularVelocity; - btVector3 m_linearVelocity; - -}; - -#endif //BU_STATIC_MOTIONSTATE diff --git a/Extras/obsolete/AlgebraicCCD/BU_VertexPoly.cpp b/Extras/obsolete/AlgebraicCCD/BU_VertexPoly.cpp deleted file mode 100644 index 2f5fb0edc..000000000 --- a/Extras/obsolete/AlgebraicCCD/BU_VertexPoly.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - - -#include "BU_VertexPoly.h" -#include "BU_Screwing.h" -#include -#include -#include - -#define USE_ALGEBRAIC -#ifdef USE_ALGEBRAIC - #include "BU_AlgebraicPolynomialSolver.h" - #define BU_Polynomial BU_AlgebraicPolynomialSolver -#else - #include "BU_IntervalArithmeticPolynomialSolver.h" - #define BU_Polynomial BU_IntervalArithmeticPolynomialSolver -#endif - -inline bool TestFuzzyZero(btScalar x) { return btFabs(x) < 0.0001f; } - - -BU_VertexPoly::BU_VertexPoly() -{ - -} -//return true if a collision will occur between [0..1] -//false otherwise. If true, minTime contains the time of impact -bool BU_VertexPoly::GetTimeOfImpact( - const BU_Screwing& screwAB, - const btPoint3& a, - const btVector4& planeEq, - btScalar &minTime,bool swapAB) -{ - - bool hit = false; - - // precondition: s=0 and w= 0 is catched by caller! - if (TestFuzzyZero(screwAB.GetS()) && - TestFuzzyZero(screwAB.GetW())) - { - return false; - } - - - //case w<>0 and s<> 0 - const btScalar w=screwAB.GetW(); - const btScalar s=screwAB.GetS(); - - btScalar coefs[4]; - const btScalar p=planeEq[0]; - const btScalar q=planeEq[1]; - const btScalar r=planeEq[2]; - const btScalar d=planeEq[3]; - - const btVector3 norm(p,q,r); - BU_Polynomial polynomialSolver; - int numroots = 0; - - //btScalar eps=1e-80f; - //btScalar eps2=1e-100f; - - if (TestFuzzyZero(screwAB.GetS()) ) - { - //S = 0 , W <> 0 - - //ax^3+bx^2+cx+d=0 - coefs[0]=0.; - coefs[1]=(-p*a.x()-q*a.y()+r*a.z()-d); - coefs[2]=-2*p*a.y()+2*q*a.x(); - coefs[3]=p*a.x()+q*a.y()+r*a.z()-d; - -// numroots = polynomialSolver.Solve3Cubic(coefs[0],coefs[1],coefs[2],coefs[3]); - numroots = polynomialSolver.Solve2QuadraticFull(coefs[1],coefs[2],coefs[3]); - - } else - { - if (TestFuzzyZero(screwAB.GetW())) - { - // W = 0 , S <> 0 - //pax+qay+r(az+st)=d - - btScalar dist = (d - a.dot(norm)); - - if (TestFuzzyZero(r)) - { - if (TestFuzzyZero(dist)) - { - // no hit - } else - { - // todo a a' might hit sides of polygon T - //printf("unhandled case, w=0,s<>0,r<>0, a a' might hit sides of polygon T \n"); - } - - } else - { - btScalar etoi = (dist)/(r*screwAB.GetS()); - if (swapAB) - etoi *= -1; - - if (etoi >= 0. && etoi <= minTime) - { - minTime = etoi; - hit = true; - } - } - - } else - { - //ax^3+bx^2+cx+d=0 - - //degenerate coefficients mess things up :( - btScalar ietsje = (r*s)/btTan(w/2.f); - if (ietsje*ietsje < 0.01f) - ietsje = 0.f; - - coefs[0]=ietsje;//(r*s)/tan(w/2.); - coefs[1]=(-p*a.x()-q*a.y()+r*a.z()-d); - coefs[2]=-2.f*p*a.y()+2.f*q*a.x()+ietsje;//((r*s)/(tan(w/2.))); - coefs[3]=p*a.x()+q*a.y()+r*a.z()-d; - - numroots = polynomialSolver.Solve3Cubic(coefs[0],coefs[1],coefs[2],coefs[3]); - } - } - - - for (int i=0;i=0 && t -#include -#include - -///BU_VertexPoly implements algebraic time of impact calculation between vertex and a plane. -class BU_VertexPoly -{ -public: - BU_VertexPoly(); - bool GetTimeOfImpact( - const BU_Screwing& screwAB, - const btPoint3& vtx, - const btVector4& planeEq, - btScalar &minTime, - bool swapAB); - -private: - - //cached data (frame coherency etc.) here - -}; -#endif //VERTEX_POLY_H diff --git a/Extras/obsolete/BulletX/Keys/BulletX.snk b/Extras/obsolete/BulletX/Keys/BulletX.snk deleted file mode 100644 index 4ce590752..000000000 Binary files a/Extras/obsolete/BulletX/Keys/BulletX.snk and /dev/null differ diff --git a/Extras/obsolete/BulletX/Keys/BulletXDemos.snk b/Extras/obsolete/BulletX/Keys/BulletXDemos.snk deleted file mode 100644 index b64d5796b..000000000 Binary files a/Extras/obsolete/BulletX/Keys/BulletXDemos.snk and /dev/null differ diff --git a/Extras/obsolete/BulletX/Keys/Demos.snk b/Extras/obsolete/BulletX/Keys/Demos.snk deleted file mode 100644 index 2d6c672ff..000000000 Binary files a/Extras/obsolete/BulletX/Keys/Demos.snk and /dev/null differ diff --git a/Extras/obsolete/BulletX/Source/SharedContent/Models/box.x b/Extras/obsolete/BulletX/Source/SharedContent/Models/box.x deleted file mode 100644 index c923cff4e..000000000 --- a/Extras/obsolete/BulletX/Source/SharedContent/Models/box.x +++ /dev/null @@ -1,228 +0,0 @@ -xof 0303txt 0032 -template Frame { - <3d82ab46-62da-11cf-ab39-0020af71e433> - [...] -} - -template Matrix4x4 { - - array FLOAT matrix[16]; -} - -template FrameTransformMatrix { - - Matrix4x4 frameMatrix; -} - -template Vector { - <3d82ab5e-62da-11cf-ab39-0020af71e433> - FLOAT x; - FLOAT y; - FLOAT z; -} - -template MeshFace { - <3d82ab5f-62da-11cf-ab39-0020af71e433> - DWORD nFaceVertexIndices; - array DWORD faceVertexIndices[nFaceVertexIndices]; -} - -template Mesh { - <3d82ab44-62da-11cf-ab39-0020af71e433> - DWORD nVertices; - array Vector vertices[nVertices]; - DWORD nFaces; - array MeshFace faces[nFaces]; - [...] -} - -template MeshNormals { - - DWORD nNormals; - array Vector normals[nNormals]; - DWORD nFaceNormals; - array MeshFace faceNormals[nFaceNormals]; -} - -template ColorRGBA { - <35ff44e0-6c7c-11cf-8f52-0040333594a3> - FLOAT red; - FLOAT green; - FLOAT blue; - FLOAT alpha; -} - -template ColorRGB { - - FLOAT red; - FLOAT green; - FLOAT blue; -} - -template Material { - <3d82ab4d-62da-11cf-ab39-0020af71e433> - ColorRGBA faceColor; - FLOAT power; - ColorRGB specularColor; - ColorRGB emissiveColor; - [...] -} - -template MeshMaterialList { - - DWORD nMaterials; - DWORD nFaceIndexes; - array DWORD faceIndexes[nFaceIndexes]; - [Material <3d82ab4d-62da-11cf-ab39-0020af71e433>] -} - -template VertexDuplicationIndices { - - DWORD nIndices; - DWORD nOriginalVertices; - array DWORD indices[nIndices]; -} - - -Frame { - - - FrameTransformMatrix { - 1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000;; - } - - Mesh { - 24; - -0.500000;-0.500000;-0.500000;, - -0.500000;-0.500000;0.500000;, - -0.500000;0.500000;0.500000;, - -0.500000;0.500000;-0.500000;, - -0.500000;0.500000;-0.500000;, - -0.500000;0.500000;0.500000;, - 0.500000;0.500000;0.500000;, - 0.500000;0.500000;-0.500000;, - 0.500000;0.500000;-0.500000;, - 0.500000;0.500000;0.500000;, - 0.500000;-0.500000;0.500000;, - 0.500000;-0.500000;-0.500000;, - -0.500000;-0.500000;0.500000;, - -0.500000;-0.500000;-0.500000;, - 0.500000;-0.500000;-0.500000;, - 0.500000;-0.500000;0.500000;, - -0.500000;-0.500000;0.500000;, - 0.500000;-0.500000;0.500000;, - 0.500000;0.500000;0.500000;, - -0.500000;0.500000;0.500000;, - -0.500000;-0.500000;-0.500000;, - -0.500000;0.500000;-0.500000;, - 0.500000;0.500000;-0.500000;, - 0.500000;-0.500000;-0.500000;; - 12; - 3;0,1,2;, - 3;2,3,0;, - 3;4,5,6;, - 3;6,7,4;, - 3;8,9,10;, - 3;10,11,8;, - 3;12,13,14;, - 3;14,15,12;, - 3;16,17,18;, - 3;18,19,16;, - 3;20,21,22;, - 3;22,23,20;; - - MeshNormals { - 24; - -1.000000;0.000000;0.000000;, - -1.000000;0.000000;0.000000;, - -1.000000;0.000000;0.000000;, - -1.000000;0.000000;0.000000;, - 0.000000;1.000000;0.000000;, - 0.000000;1.000000;0.000000;, - 0.000000;1.000000;0.000000;, - 0.000000;1.000000;0.000000;, - 1.000000;0.000000;0.000000;, - 1.000000;0.000000;0.000000;, - 1.000000;0.000000;0.000000;, - 1.000000;0.000000;0.000000;, - 0.000000;-1.000000;0.000000;, - 0.000000;-1.000000;0.000000;, - 0.000000;-1.000000;0.000000;, - 0.000000;-1.000000;0.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;; - 12; - 3;0,1,2;, - 3;2,3,0;, - 3;4,5,6;, - 3;6,7,4;, - 3;8,9,10;, - 3;10,11,8;, - 3;12,13,14;, - 3;14,15,12;, - 3;16,17,18;, - 3;18,19,16;, - 3;20,21,22;, - 3;22,23,20;; - } - - MeshMaterialList { - 1; - 12; - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0; - - Material { - 0.500000;0.500000;0.500000;0.000000;; - 0.000000; - 0.500000;0.500000;0.500000;; - 0.000000;0.000000;0.000000;; - } - } - - VertexDuplicationIndices { - 24; - 8; - 0, - 1, - 2, - 3, - 3, - 2, - 6, - 7, - 7, - 6, - 10, - 11, - 1, - 0, - 11, - 10, - 1, - 10, - 6, - 2, - 0, - 3, - 7, - 11; - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/SharedContent/Models/cylinder.x b/Extras/obsolete/BulletX/Source/SharedContent/Models/cylinder.x deleted file mode 100644 index 9ca60ef3c..000000000 --- a/Extras/obsolete/BulletX/Source/SharedContent/Models/cylinder.x +++ /dev/null @@ -1,786 +0,0 @@ -xof 0303txt 0032 -template Frame { - <3d82ab46-62da-11cf-ab39-0020af71e433> - [...] -} - -template Matrix4x4 { - - array FLOAT matrix[16]; -} - -template FrameTransformMatrix { - - Matrix4x4 frameMatrix; -} - -template Vector { - <3d82ab5e-62da-11cf-ab39-0020af71e433> - FLOAT x; - FLOAT y; - FLOAT z; -} - -template MeshFace { - <3d82ab5f-62da-11cf-ab39-0020af71e433> - DWORD nFaceVertexIndices; - array DWORD faceVertexIndices[nFaceVertexIndices]; -} - -template Mesh { - <3d82ab44-62da-11cf-ab39-0020af71e433> - DWORD nVertices; - array Vector vertices[nVertices]; - DWORD nFaces; - array MeshFace faces[nFaces]; - [...] -} - -template MeshNormals { - - DWORD nNormals; - array Vector normals[nNormals]; - DWORD nFaceNormals; - array MeshFace faceNormals[nFaceNormals]; -} - -template ColorRGBA { - <35ff44e0-6c7c-11cf-8f52-0040333594a3> - FLOAT red; - FLOAT green; - FLOAT blue; - FLOAT alpha; -} - -template ColorRGB { - - FLOAT red; - FLOAT green; - FLOAT blue; -} - -template Material { - <3d82ab4d-62da-11cf-ab39-0020af71e433> - ColorRGBA faceColor; - FLOAT power; - ColorRGB specularColor; - ColorRGB emissiveColor; - [...] -} - -template MeshMaterialList { - - DWORD nMaterials; - DWORD nFaceIndexes; - array DWORD faceIndexes[nFaceIndexes]; - [Material <3d82ab4d-62da-11cf-ab39-0020af71e433>] -} - -template VertexDuplicationIndices { - - DWORD nIndices; - DWORD nOriginalVertices; - array DWORD indices[nIndices]; -} - - -Frame { - - - FrameTransformMatrix { - 1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000;; - } - - Mesh { - 102; - 0.000000;0.000000;-1.500000;, - 0.000000;1.000000;-1.500000;, - 0.309017;0.951057;-1.500000;, - 0.587785;0.809017;-1.500000;, - 0.809017;0.587785;-1.500000;, - 0.951057;0.309017;-1.500000;, - 1.000000;-0.000000;-1.500000;, - 0.951057;-0.309017;-1.500000;, - 0.809017;-0.587785;-1.500000;, - 0.587785;-0.809017;-1.500000;, - 0.309017;-0.951057;-1.500000;, - -0.000000;-1.000000;-1.500000;, - -0.309017;-0.951056;-1.500000;, - -0.587785;-0.809017;-1.500000;, - -0.809017;-0.587785;-1.500000;, - -0.951057;-0.309017;-1.500000;, - -1.000000;0.000000;-1.500000;, - -0.951057;0.309017;-1.500000;, - -0.809017;0.587786;-1.500000;, - -0.587785;0.809017;-1.500000;, - -0.309017;0.951057;-1.500000;, - 0.000000;1.000000;-1.500000;, - 0.309017;0.951057;-1.500000;, - 0.587785;0.809017;-1.500000;, - 0.809017;0.587785;-1.500000;, - 0.951057;0.309017;-1.500000;, - 1.000000;-0.000000;-1.500000;, - 0.951057;-0.309017;-1.500000;, - 0.809017;-0.587785;-1.500000;, - 0.587785;-0.809017;-1.500000;, - 0.309017;-0.951057;-1.500000;, - -0.000000;-1.000000;-1.500000;, - -0.309017;-0.951056;-1.500000;, - -0.587785;-0.809017;-1.500000;, - -0.809017;-0.587785;-1.500000;, - -0.951057;-0.309017;-1.500000;, - -1.000000;0.000000;-1.500000;, - -0.951057;0.309017;-1.500000;, - -0.809017;0.587786;-1.500000;, - -0.587785;0.809017;-1.500000;, - -0.309017;0.951057;-1.500000;, - 0.000000;1.000000;0.000000;, - 0.309017;0.951057;0.000000;, - 0.587785;0.809017;0.000000;, - 0.809017;0.587785;0.000000;, - 0.951057;0.309017;0.000000;, - 1.000000;-0.000000;0.000000;, - 0.951057;-0.309017;0.000000;, - 0.809017;-0.587785;0.000000;, - 0.587785;-0.809017;0.000000;, - 0.309017;-0.951057;0.000000;, - -0.000000;-1.000000;0.000000;, - -0.309017;-0.951056;0.000000;, - -0.587785;-0.809017;0.000000;, - -0.809017;-0.587785;0.000000;, - -0.951057;-0.309017;0.000000;, - -1.000000;0.000000;0.000000;, - -0.951057;0.309017;0.000000;, - -0.809017;0.587786;0.000000;, - -0.587785;0.809017;0.000000;, - -0.309017;0.951057;0.000000;, - 0.000000;1.000000;1.500000;, - 0.309017;0.951057;1.500000;, - 0.587785;0.809017;1.500000;, - 0.809017;0.587785;1.500000;, - 0.951057;0.309017;1.500000;, - 1.000000;-0.000000;1.500000;, - 0.951057;-0.309017;1.500000;, - 0.809017;-0.587785;1.500000;, - 0.587785;-0.809017;1.500000;, - 0.309017;-0.951057;1.500000;, - -0.000000;-1.000000;1.500000;, - -0.309017;-0.951056;1.500000;, - -0.587785;-0.809017;1.500000;, - -0.809017;-0.587785;1.500000;, - -0.951057;-0.309017;1.500000;, - -1.000000;0.000000;1.500000;, - -0.951057;0.309017;1.500000;, - -0.809017;0.587786;1.500000;, - -0.587785;0.809017;1.500000;, - -0.309017;0.951057;1.500000;, - 0.000000;1.000000;1.500000;, - 0.309017;0.951057;1.500000;, - 0.587785;0.809017;1.500000;, - 0.809017;0.587785;1.500000;, - 0.951057;0.309017;1.500000;, - 1.000000;-0.000000;1.500000;, - 0.951057;-0.309017;1.500000;, - 0.809017;-0.587785;1.500000;, - 0.587785;-0.809017;1.500000;, - 0.309017;-0.951057;1.500000;, - -0.000000;-1.000000;1.500000;, - -0.309017;-0.951056;1.500000;, - -0.587785;-0.809017;1.500000;, - -0.809017;-0.587785;1.500000;, - -0.951057;-0.309017;1.500000;, - -1.000000;0.000000;1.500000;, - -0.951057;0.309017;1.500000;, - -0.809017;0.587786;1.500000;, - -0.587785;0.809017;1.500000;, - -0.309017;0.951057;1.500000;, - 0.000000;0.000000;1.500000;; - 120; - 3;0,1,2;, - 3;0,2,3;, - 3;0,3,4;, - 3;0,4,5;, - 3;0,5,6;, - 3;0,6,7;, - 3;0,7,8;, - 3;0,8,9;, - 3;0,9,10;, - 3;0,10,11;, - 3;0,11,12;, - 3;0,12,13;, - 3;0,13,14;, - 3;0,14,15;, - 3;0,15,16;, - 3;0,16,17;, - 3;0,17,18;, - 3;0,18,19;, - 3;0,19,20;, - 3;0,20,1;, - 3;21,41,22;, - 3;22,41,42;, - 3;22,42,23;, - 3;23,42,43;, - 3;23,43,24;, - 3;24,43,44;, - 3;24,44,25;, - 3;25,44,45;, - 3;25,45,26;, - 3;26,45,46;, - 3;26,46,27;, - 3;27,46,47;, - 3;27,47,28;, - 3;28,47,48;, - 3;28,48,29;, - 3;29,48,49;, - 3;29,49,30;, - 3;30,49,50;, - 3;30,50,31;, - 3;31,50,51;, - 3;31,51,32;, - 3;32,51,52;, - 3;32,52,33;, - 3;33,52,53;, - 3;33,53,34;, - 3;34,53,54;, - 3;34,54,35;, - 3;35,54,55;, - 3;35,55,36;, - 3;36,55,56;, - 3;36,56,37;, - 3;37,56,57;, - 3;37,57,38;, - 3;38,57,58;, - 3;38,58,39;, - 3;39,58,59;, - 3;39,59,40;, - 3;40,59,60;, - 3;40,60,21;, - 3;21,60,41;, - 3;41,61,42;, - 3;42,61,62;, - 3;42,62,43;, - 3;43,62,63;, - 3;43,63,44;, - 3;44,63,64;, - 3;44,64,45;, - 3;45,64,65;, - 3;45,65,46;, - 3;46,65,66;, - 3;46,66,47;, - 3;47,66,67;, - 3;47,67,48;, - 3;48,67,68;, - 3;48,68,49;, - 3;49,68,69;, - 3;49,69,50;, - 3;50,69,70;, - 3;50,70,51;, - 3;51,70,71;, - 3;51,71,52;, - 3;52,71,72;, - 3;52,72,53;, - 3;53,72,73;, - 3;53,73,54;, - 3;54,73,74;, - 3;54,74,55;, - 3;55,74,75;, - 3;55,75,56;, - 3;56,75,76;, - 3;56,76,57;, - 3;57,76,77;, - 3;57,77,58;, - 3;58,77,78;, - 3;58,78,59;, - 3;59,78,79;, - 3;59,79,60;, - 3;60,79,80;, - 3;60,80,41;, - 3;41,80,61;, - 3;81,101,82;, - 3;82,101,83;, - 3;83,101,84;, - 3;84,101,85;, - 3;85,101,86;, - 3;86,101,87;, - 3;87,101,88;, - 3;88,101,89;, - 3;89,101,90;, - 3;90,101,91;, - 3;91,101,92;, - 3;92,101,93;, - 3;93,101,94;, - 3;94,101,95;, - 3;95,101,96;, - 3;96,101,97;, - 3;97,101,98;, - 3;98,101,99;, - 3;99,101,100;, - 3;100,101,81;; - - MeshNormals { - 102; - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;0.000000;-1.000000;, - 0.000000;1.000000;0.000000;, - 0.309017;0.951057;0.000000;, - 0.587785;0.809017;0.000000;, - 0.809017;0.587785;0.000000;, - 0.951057;0.309017;0.000000;, - 1.000000;-0.000000;0.000000;, - 0.951057;-0.309017;0.000000;, - 0.809017;-0.587785;0.000000;, - 0.587785;-0.809017;0.000000;, - 0.309017;-0.951057;0.000000;, - -0.000000;-1.000000;0.000000;, - -0.309017;-0.951056;0.000000;, - -0.587785;-0.809017;0.000000;, - -0.809017;-0.587785;0.000000;, - -0.951057;-0.309017;0.000000;, - -1.000000;0.000000;0.000000;, - -0.951057;0.309017;0.000000;, - -0.809017;0.587786;0.000000;, - -0.587785;0.809017;0.000000;, - -0.309017;0.951057;0.000000;, - 0.000000;1.000000;0.000000;, - 0.309017;0.951057;0.000000;, - 0.587785;0.809017;0.000000;, - 0.809017;0.587785;0.000000;, - 0.951057;0.309017;0.000000;, - 1.000000;-0.000000;0.000000;, - 0.951057;-0.309017;0.000000;, - 0.809017;-0.587785;0.000000;, - 0.587785;-0.809017;0.000000;, - 0.309017;-0.951057;0.000000;, - -0.000000;-1.000000;0.000000;, - -0.309017;-0.951056;0.000000;, - -0.587785;-0.809017;0.000000;, - -0.809017;-0.587785;0.000000;, - -0.951057;-0.309017;0.000000;, - -1.000000;0.000000;0.000000;, - -0.951057;0.309017;0.000000;, - -0.809017;0.587786;0.000000;, - -0.587785;0.809017;0.000000;, - -0.309017;0.951057;0.000000;, - 0.000000;1.000000;0.000000;, - 0.309017;0.951057;0.000000;, - 0.587785;0.809017;0.000000;, - 0.809017;0.587785;0.000000;, - 0.951057;0.309017;0.000000;, - 1.000000;-0.000000;0.000000;, - 0.951057;-0.309017;0.000000;, - 0.809017;-0.587785;0.000000;, - 0.587785;-0.809017;0.000000;, - 0.309017;-0.951057;0.000000;, - -0.000000;-1.000000;0.000000;, - -0.309017;-0.951056;0.000000;, - -0.587785;-0.809017;0.000000;, - -0.809017;-0.587785;0.000000;, - -0.951057;-0.309017;0.000000;, - -1.000000;0.000000;0.000000;, - -0.951057;0.309017;0.000000;, - -0.809017;0.587786;0.000000;, - -0.587785;0.809017;0.000000;, - -0.309017;0.951057;0.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;, - 0.000000;0.000000;1.000000;; - 120; - 3;0,1,2;, - 3;0,2,3;, - 3;0,3,4;, - 3;0,4,5;, - 3;0,5,6;, - 3;0,6,7;, - 3;0,7,8;, - 3;0,8,9;, - 3;0,9,10;, - 3;0,10,11;, - 3;0,11,12;, - 3;0,12,13;, - 3;0,13,14;, - 3;0,14,15;, - 3;0,15,16;, - 3;0,16,17;, - 3;0,17,18;, - 3;0,18,19;, - 3;0,19,20;, - 3;0,20,1;, - 3;21,41,22;, - 3;22,41,42;, - 3;22,42,23;, - 3;23,42,43;, - 3;23,43,24;, - 3;24,43,44;, - 3;24,44,25;, - 3;25,44,45;, - 3;25,45,26;, - 3;26,45,46;, - 3;26,46,27;, - 3;27,46,47;, - 3;27,47,28;, - 3;28,47,48;, - 3;28,48,29;, - 3;29,48,49;, - 3;29,49,30;, - 3;30,49,50;, - 3;30,50,31;, - 3;31,50,51;, - 3;31,51,32;, - 3;32,51,52;, - 3;32,52,33;, - 3;33,52,53;, - 3;33,53,34;, - 3;34,53,54;, - 3;34,54,35;, - 3;35,54,55;, - 3;35,55,36;, - 3;36,55,56;, - 3;36,56,37;, - 3;37,56,57;, - 3;37,57,38;, - 3;38,57,58;, - 3;38,58,39;, - 3;39,58,59;, - 3;39,59,40;, - 3;40,59,60;, - 3;40,60,21;, - 3;21,60,41;, - 3;41,61,42;, - 3;42,61,62;, - 3;42,62,43;, - 3;43,62,63;, - 3;43,63,44;, - 3;44,63,64;, - 3;44,64,45;, - 3;45,64,65;, - 3;45,65,46;, - 3;46,65,66;, - 3;46,66,47;, - 3;47,66,67;, - 3;47,67,48;, - 3;48,67,68;, - 3;48,68,49;, - 3;49,68,69;, - 3;49,69,50;, - 3;50,69,70;, - 3;50,70,51;, - 3;51,70,71;, - 3;51,71,52;, - 3;52,71,72;, - 3;52,72,53;, - 3;53,72,73;, - 3;53,73,54;, - 3;54,73,74;, - 3;54,74,55;, - 3;55,74,75;, - 3;55,75,56;, - 3;56,75,76;, - 3;56,76,57;, - 3;57,76,77;, - 3;57,77,58;, - 3;58,77,78;, - 3;58,78,59;, - 3;59,78,79;, - 3;59,79,60;, - 3;60,79,80;, - 3;60,80,41;, - 3;41,80,61;, - 3;81,101,82;, - 3;82,101,83;, - 3;83,101,84;, - 3;84,101,85;, - 3;85,101,86;, - 3;86,101,87;, - 3;87,101,88;, - 3;88,101,89;, - 3;89,101,90;, - 3;90,101,91;, - 3;91,101,92;, - 3;92,101,93;, - 3;93,101,94;, - 3;94,101,95;, - 3;95,101,96;, - 3;96,101,97;, - 3;97,101,98;, - 3;98,101,99;, - 3;99,101,100;, - 3;100,101,81;; - } - - MeshMaterialList { - 1; - 120; - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0; - - Material { - 0.500000;0.500000;0.500000;0.000000;; - 0.000000; - 0.500000;0.500000;0.500000;; - 0.000000;0.000000;0.000000;; - } - } - - VertexDuplicationIndices { - 102; - 62; - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 41, - 42, - 43, - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 59, - 60, - 61, - 62, - 63, - 64, - 65, - 66, - 67, - 68, - 69, - 70, - 71, - 72, - 73, - 74, - 75, - 76, - 77, - 78, - 79, - 80, - 61, - 62, - 63, - 64, - 65, - 66, - 67, - 68, - 69, - 70, - 71, - 72, - 73, - 74, - 75, - 76, - 77, - 78, - 79, - 80, - 101; - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/SharedContent/Models/sphere.x b/Extras/obsolete/BulletX/Source/SharedContent/Models/sphere.x deleted file mode 100644 index 515b80898..000000000 --- a/Extras/obsolete/BulletX/Source/SharedContent/Models/sphere.x +++ /dev/null @@ -1,936 +0,0 @@ -xof 0303txt 0032 -template Frame { - <3d82ab46-62da-11cf-ab39-0020af71e433> - [...] -} - -template Matrix4x4 { - - array FLOAT matrix[16]; -} - -template FrameTransformMatrix { - - Matrix4x4 frameMatrix; -} - -template Vector { - <3d82ab5e-62da-11cf-ab39-0020af71e433> - FLOAT x; - FLOAT y; - FLOAT z; -} - -template MeshFace { - <3d82ab5f-62da-11cf-ab39-0020af71e433> - DWORD nFaceVertexIndices; - array DWORD faceVertexIndices[nFaceVertexIndices]; -} - -template Mesh { - <3d82ab44-62da-11cf-ab39-0020af71e433> - DWORD nVertices; - array Vector vertices[nVertices]; - DWORD nFaces; - array MeshFace faces[nFaces]; - [...] -} - -template MeshNormals { - - DWORD nNormals; - array Vector normals[nNormals]; - DWORD nFaceNormals; - array MeshFace faceNormals[nFaceNormals]; -} - -template ColorRGBA { - <35ff44e0-6c7c-11cf-8f52-0040333594a3> - FLOAT red; - FLOAT green; - FLOAT blue; - FLOAT alpha; -} - -template ColorRGB { - - FLOAT red; - FLOAT green; - FLOAT blue; -} - -template Material { - <3d82ab4d-62da-11cf-ab39-0020af71e433> - ColorRGBA faceColor; - FLOAT power; - ColorRGB specularColor; - ColorRGB emissiveColor; - [...] -} - -template MeshMaterialList { - - DWORD nMaterials; - DWORD nFaceIndexes; - array DWORD faceIndexes[nFaceIndexes]; - [Material <3d82ab4d-62da-11cf-ab39-0020af71e433>] -} - -template VertexDuplicationIndices { - - DWORD nIndices; - DWORD nOriginalVertices; - array DWORD indices[nIndices]; -} - - -Frame { - - - FrameTransformMatrix { - 1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000;; - } - - Mesh { - 92; - 0.000000;0.000000;1.000000;, - 0.000000;0.309017;0.951057;, - 0.181636;0.250000;0.951057;, - 0.293893;0.095491;0.951057;, - 0.293893;-0.095492;0.951057;, - 0.181636;-0.250000;0.951057;, - -0.000000;-0.309017;0.951057;, - -0.181636;-0.250000;0.951057;, - -0.293893;-0.095491;0.951057;, - -0.293893;0.095492;0.951057;, - -0.181636;0.250000;0.951057;, - 0.000000;0.587785;0.809017;, - 0.345491;0.475528;0.809017;, - 0.559017;0.181636;0.809017;, - 0.559017;-0.181636;0.809017;, - 0.345491;-0.475528;0.809017;, - -0.000000;-0.587785;0.809017;, - -0.345492;-0.475528;0.809017;, - -0.559017;-0.181635;0.809017;, - -0.559017;0.181636;0.809017;, - -0.345492;0.475528;0.809017;, - 0.000000;0.809017;0.587785;, - 0.475528;0.654509;0.587785;, - 0.769421;0.250000;0.587785;, - 0.769421;-0.250000;0.587785;, - 0.475528;-0.654509;0.587785;, - -0.000000;-0.809017;0.587785;, - -0.475528;-0.654508;0.587785;, - -0.769421;-0.250000;0.587785;, - -0.769421;0.250000;0.587785;, - -0.475528;0.654508;0.587785;, - 0.000000;0.951057;0.309017;, - 0.559017;0.769421;0.309017;, - 0.904509;0.293893;0.309017;, - 0.904508;-0.293893;0.309017;, - 0.559017;-0.769421;0.309017;, - -0.000000;-0.951057;0.309017;, - -0.559017;-0.769421;0.309017;, - -0.904509;-0.293892;0.309017;, - -0.904508;0.293893;0.309017;, - -0.559017;0.769421;0.309017;, - 0.000000;1.000000;-0.000000;, - 0.587785;0.809017;-0.000000;, - 0.951057;0.309017;-0.000000;, - 0.951056;-0.309017;-0.000000;, - 0.587785;-0.809017;-0.000000;, - -0.000000;-1.000000;-0.000000;, - -0.587785;-0.809017;-0.000000;, - -0.951057;-0.309017;-0.000000;, - -0.951056;0.309017;-0.000000;, - -0.587785;0.809017;-0.000000;, - 0.000000;0.951056;-0.309017;, - 0.559017;0.769421;-0.309017;, - 0.904508;0.293893;-0.309017;, - 0.904508;-0.293893;-0.309017;, - 0.559017;-0.769421;-0.309017;, - -0.000000;-0.951056;-0.309017;, - -0.559017;-0.769421;-0.309017;, - -0.904509;-0.293892;-0.309017;, - -0.904508;0.293893;-0.309017;, - -0.559017;0.769421;-0.309017;, - 0.000000;0.809017;-0.587785;, - 0.475528;0.654508;-0.587785;, - 0.769421;0.250000;-0.587785;, - 0.769421;-0.250000;-0.587785;, - 0.475528;-0.654508;-0.587785;, - -0.000000;-0.809017;-0.587785;, - -0.475528;-0.654508;-0.587785;, - -0.769421;-0.250000;-0.587785;, - -0.769421;0.250000;-0.587785;, - -0.475528;0.654508;-0.587785;, - 0.000000;0.587785;-0.809017;, - 0.345491;0.475528;-0.809017;, - 0.559017;0.181636;-0.809017;, - 0.559017;-0.181636;-0.809017;, - 0.345491;-0.475528;-0.809017;, - -0.000000;-0.587785;-0.809017;, - -0.345492;-0.475528;-0.809017;, - -0.559017;-0.181635;-0.809017;, - -0.559017;0.181636;-0.809017;, - -0.345491;0.475528;-0.809017;, - 0.000000;0.309017;-0.951056;, - 0.181636;0.250000;-0.951056;, - 0.293893;0.095492;-0.951056;, - 0.293893;-0.095492;-0.951056;, - 0.181636;-0.250000;-0.951056;, - -0.000000;-0.309017;-0.951056;, - -0.181636;-0.250000;-0.951056;, - -0.293893;-0.095491;-0.951056;, - -0.293893;0.095492;-0.951056;, - -0.181636;0.250000;-0.951056;, - 0.000000;0.000000;-1.000000;; - 180; - 3;0,2,1;, - 3;0,3,2;, - 3;0,4,3;, - 3;0,5,4;, - 3;0,6,5;, - 3;0,7,6;, - 3;0,8,7;, - 3;0,9,8;, - 3;0,10,9;, - 3;0,1,10;, - 3;1,2,11;, - 3;2,12,11;, - 3;2,3,12;, - 3;3,13,12;, - 3;3,4,13;, - 3;4,14,13;, - 3;4,5,14;, - 3;5,15,14;, - 3;5,6,15;, - 3;6,16,15;, - 3;6,7,16;, - 3;7,17,16;, - 3;7,8,17;, - 3;8,18,17;, - 3;8,9,18;, - 3;9,19,18;, - 3;9,10,19;, - 3;10,20,19;, - 3;10,1,20;, - 3;1,11,20;, - 3;11,12,21;, - 3;12,22,21;, - 3;12,13,22;, - 3;13,23,22;, - 3;13,14,23;, - 3;14,24,23;, - 3;14,15,24;, - 3;15,25,24;, - 3;15,16,25;, - 3;16,26,25;, - 3;16,17,26;, - 3;17,27,26;, - 3;17,18,27;, - 3;18,28,27;, - 3;18,19,28;, - 3;19,29,28;, - 3;19,20,29;, - 3;20,30,29;, - 3;20,11,30;, - 3;11,21,30;, - 3;21,22,31;, - 3;22,32,31;, - 3;22,23,32;, - 3;23,33,32;, - 3;23,24,33;, - 3;24,34,33;, - 3;24,25,34;, - 3;25,35,34;, - 3;25,26,35;, - 3;26,36,35;, - 3;26,27,36;, - 3;27,37,36;, - 3;27,28,37;, - 3;28,38,37;, - 3;28,29,38;, - 3;29,39,38;, - 3;29,30,39;, - 3;30,40,39;, - 3;30,21,40;, - 3;21,31,40;, - 3;31,32,41;, - 3;32,42,41;, - 3;32,33,42;, - 3;33,43,42;, - 3;33,34,43;, - 3;34,44,43;, - 3;34,35,44;, - 3;35,45,44;, - 3;35,36,45;, - 3;36,46,45;, - 3;36,37,46;, - 3;37,47,46;, - 3;37,38,47;, - 3;38,48,47;, - 3;38,39,48;, - 3;39,49,48;, - 3;39,40,49;, - 3;40,50,49;, - 3;40,31,50;, - 3;31,41,50;, - 3;41,42,51;, - 3;42,52,51;, - 3;42,43,52;, - 3;43,53,52;, - 3;43,44,53;, - 3;44,54,53;, - 3;44,45,54;, - 3;45,55,54;, - 3;45,46,55;, - 3;46,56,55;, - 3;46,47,56;, - 3;47,57,56;, - 3;47,48,57;, - 3;48,58,57;, - 3;48,49,58;, - 3;49,59,58;, - 3;49,50,59;, - 3;50,60,59;, - 3;50,41,60;, - 3;41,51,60;, - 3;51,52,61;, - 3;52,62,61;, - 3;52,53,62;, - 3;53,63,62;, - 3;53,54,63;, - 3;54,64,63;, - 3;54,55,64;, - 3;55,65,64;, - 3;55,56,65;, - 3;56,66,65;, - 3;56,57,66;, - 3;57,67,66;, - 3;57,58,67;, - 3;58,68,67;, - 3;58,59,68;, - 3;59,69,68;, - 3;59,60,69;, - 3;60,70,69;, - 3;60,51,70;, - 3;51,61,70;, - 3;61,62,71;, - 3;62,72,71;, - 3;62,63,72;, - 3;63,73,72;, - 3;63,64,73;, - 3;64,74,73;, - 3;64,65,74;, - 3;65,75,74;, - 3;65,66,75;, - 3;66,76,75;, - 3;66,67,76;, - 3;67,77,76;, - 3;67,68,77;, - 3;68,78,77;, - 3;68,69,78;, - 3;69,79,78;, - 3;69,70,79;, - 3;70,80,79;, - 3;70,61,80;, - 3;61,71,80;, - 3;71,72,81;, - 3;72,82,81;, - 3;72,73,82;, - 3;73,83,82;, - 3;73,74,83;, - 3;74,84,83;, - 3;74,75,84;, - 3;75,85,84;, - 3;75,76,85;, - 3;76,86,85;, - 3;76,77,86;, - 3;77,87,86;, - 3;77,78,87;, - 3;78,88,87;, - 3;78,79,88;, - 3;79,89,88;, - 3;79,80,89;, - 3;80,90,89;, - 3;80,71,90;, - 3;71,81,90;, - 3;81,82,91;, - 3;82,83,91;, - 3;83,84,91;, - 3;84,85,91;, - 3;85,86,91;, - 3;86,87,91;, - 3;87,88,91;, - 3;88,89,91;, - 3;89,90,91;, - 3;90,81,91;; - - MeshNormals { - 92; - 0.000000;0.000000;1.000000;, - 0.000000;0.309017;0.951057;, - 0.181636;0.250000;0.951057;, - 0.293893;0.095491;0.951057;, - 0.293893;-0.095492;0.951057;, - 0.181636;-0.250000;0.951057;, - -0.000000;-0.309017;0.951057;, - -0.181636;-0.250000;0.951057;, - -0.293893;-0.095491;0.951057;, - -0.293893;0.095492;0.951057;, - -0.181636;0.250000;0.951057;, - 0.000000;0.587785;0.809017;, - 0.345491;0.475528;0.809017;, - 0.559017;0.181636;0.809017;, - 0.559017;-0.181636;0.809017;, - 0.345491;-0.475528;0.809017;, - -0.000000;-0.587785;0.809017;, - -0.345492;-0.475528;0.809017;, - -0.559017;-0.181635;0.809017;, - -0.559017;0.181636;0.809017;, - -0.345492;0.475528;0.809017;, - 0.000000;0.809017;0.587785;, - 0.475528;0.654509;0.587785;, - 0.769421;0.250000;0.587785;, - 0.769421;-0.250000;0.587785;, - 0.475528;-0.654509;0.587785;, - -0.000000;-0.809017;0.587785;, - -0.475528;-0.654508;0.587785;, - -0.769421;-0.250000;0.587785;, - -0.769421;0.250000;0.587785;, - -0.475528;0.654508;0.587785;, - 0.000000;0.951057;0.309017;, - 0.559017;0.769421;0.309017;, - 0.904509;0.293893;0.309017;, - 0.904508;-0.293893;0.309017;, - 0.559017;-0.769421;0.309017;, - -0.000000;-0.951057;0.309017;, - -0.559017;-0.769421;0.309017;, - -0.904509;-0.293892;0.309017;, - -0.904508;0.293893;0.309017;, - -0.559017;0.769421;0.309017;, - 0.000000;1.000000;-0.000000;, - 0.587785;0.809017;-0.000000;, - 0.951057;0.309017;-0.000000;, - 0.951056;-0.309017;-0.000000;, - 0.587785;-0.809017;-0.000000;, - -0.000000;-1.000000;-0.000000;, - -0.587785;-0.809017;-0.000000;, - -0.951057;-0.309017;-0.000000;, - -0.951056;0.309017;-0.000000;, - -0.587785;0.809017;-0.000000;, - 0.000000;0.951056;-0.309017;, - 0.559017;0.769421;-0.309017;, - 0.904508;0.293893;-0.309017;, - 0.904508;-0.293893;-0.309017;, - 0.559017;-0.769421;-0.309017;, - -0.000000;-0.951056;-0.309017;, - -0.559017;-0.769421;-0.309017;, - -0.904509;-0.293892;-0.309017;, - -0.904508;0.293893;-0.309017;, - -0.559017;0.769421;-0.309017;, - 0.000000;0.809017;-0.587785;, - 0.475528;0.654508;-0.587785;, - 0.769421;0.250000;-0.587785;, - 0.769421;-0.250000;-0.587785;, - 0.475528;-0.654508;-0.587785;, - -0.000000;-0.809017;-0.587785;, - -0.475528;-0.654508;-0.587785;, - -0.769421;-0.250000;-0.587785;, - -0.769421;0.250000;-0.587785;, - -0.475528;0.654508;-0.587785;, - 0.000000;0.587785;-0.809017;, - 0.345491;0.475528;-0.809017;, - 0.559017;0.181636;-0.809017;, - 0.559017;-0.181636;-0.809017;, - 0.345491;-0.475528;-0.809017;, - -0.000000;-0.587785;-0.809017;, - -0.345492;-0.475528;-0.809017;, - -0.559017;-0.181635;-0.809017;, - -0.559017;0.181636;-0.809017;, - -0.345491;0.475528;-0.809017;, - 0.000000;0.309017;-0.951056;, - 0.181636;0.250000;-0.951056;, - 0.293893;0.095492;-0.951056;, - 0.293893;-0.095492;-0.951056;, - 0.181636;-0.250000;-0.951056;, - -0.000000;-0.309017;-0.951056;, - -0.181636;-0.250000;-0.951056;, - -0.293893;-0.095491;-0.951056;, - -0.293893;0.095492;-0.951056;, - -0.181636;0.250000;-0.951056;, - 0.000000;0.000000;-1.000000;; - 180; - 3;0,2,1;, - 3;0,3,2;, - 3;0,4,3;, - 3;0,5,4;, - 3;0,6,5;, - 3;0,7,6;, - 3;0,8,7;, - 3;0,9,8;, - 3;0,10,9;, - 3;0,1,10;, - 3;1,2,11;, - 3;2,12,11;, - 3;2,3,12;, - 3;3,13,12;, - 3;3,4,13;, - 3;4,14,13;, - 3;4,5,14;, - 3;5,15,14;, - 3;5,6,15;, - 3;6,16,15;, - 3;6,7,16;, - 3;7,17,16;, - 3;7,8,17;, - 3;8,18,17;, - 3;8,9,18;, - 3;9,19,18;, - 3;9,10,19;, - 3;10,20,19;, - 3;10,1,20;, - 3;1,11,20;, - 3;11,12,21;, - 3;12,22,21;, - 3;12,13,22;, - 3;13,23,22;, - 3;13,14,23;, - 3;14,24,23;, - 3;14,15,24;, - 3;15,25,24;, - 3;15,16,25;, - 3;16,26,25;, - 3;16,17,26;, - 3;17,27,26;, - 3;17,18,27;, - 3;18,28,27;, - 3;18,19,28;, - 3;19,29,28;, - 3;19,20,29;, - 3;20,30,29;, - 3;20,11,30;, - 3;11,21,30;, - 3;21,22,31;, - 3;22,32,31;, - 3;22,23,32;, - 3;23,33,32;, - 3;23,24,33;, - 3;24,34,33;, - 3;24,25,34;, - 3;25,35,34;, - 3;25,26,35;, - 3;26,36,35;, - 3;26,27,36;, - 3;27,37,36;, - 3;27,28,37;, - 3;28,38,37;, - 3;28,29,38;, - 3;29,39,38;, - 3;29,30,39;, - 3;30,40,39;, - 3;30,21,40;, - 3;21,31,40;, - 3;31,32,41;, - 3;32,42,41;, - 3;32,33,42;, - 3;33,43,42;, - 3;33,34,43;, - 3;34,44,43;, - 3;34,35,44;, - 3;35,45,44;, - 3;35,36,45;, - 3;36,46,45;, - 3;36,37,46;, - 3;37,47,46;, - 3;37,38,47;, - 3;38,48,47;, - 3;38,39,48;, - 3;39,49,48;, - 3;39,40,49;, - 3;40,50,49;, - 3;40,31,50;, - 3;31,41,50;, - 3;41,42,51;, - 3;42,52,51;, - 3;42,43,52;, - 3;43,53,52;, - 3;43,44,53;, - 3;44,54,53;, - 3;44,45,54;, - 3;45,55,54;, - 3;45,46,55;, - 3;46,56,55;, - 3;46,47,56;, - 3;47,57,56;, - 3;47,48,57;, - 3;48,58,57;, - 3;48,49,58;, - 3;49,59,58;, - 3;49,50,59;, - 3;50,60,59;, - 3;50,41,60;, - 3;41,51,60;, - 3;51,52,61;, - 3;52,62,61;, - 3;52,53,62;, - 3;53,63,62;, - 3;53,54,63;, - 3;54,64,63;, - 3;54,55,64;, - 3;55,65,64;, - 3;55,56,65;, - 3;56,66,65;, - 3;56,57,66;, - 3;57,67,66;, - 3;57,58,67;, - 3;58,68,67;, - 3;58,59,68;, - 3;59,69,68;, - 3;59,60,69;, - 3;60,70,69;, - 3;60,51,70;, - 3;51,61,70;, - 3;61,62,71;, - 3;62,72,71;, - 3;62,63,72;, - 3;63,73,72;, - 3;63,64,73;, - 3;64,74,73;, - 3;64,65,74;, - 3;65,75,74;, - 3;65,66,75;, - 3;66,76,75;, - 3;66,67,76;, - 3;67,77,76;, - 3;67,68,77;, - 3;68,78,77;, - 3;68,69,78;, - 3;69,79,78;, - 3;69,70,79;, - 3;70,80,79;, - 3;70,61,80;, - 3;61,71,80;, - 3;71,72,81;, - 3;72,82,81;, - 3;72,73,82;, - 3;73,83,82;, - 3;73,74,83;, - 3;74,84,83;, - 3;74,75,84;, - 3;75,85,84;, - 3;75,76,85;, - 3;76,86,85;, - 3;76,77,86;, - 3;77,87,86;, - 3;77,78,87;, - 3;78,88,87;, - 3;78,79,88;, - 3;79,89,88;, - 3;79,80,89;, - 3;80,90,89;, - 3;80,71,90;, - 3;71,81,90;, - 3;81,82,91;, - 3;82,83,91;, - 3;83,84,91;, - 3;84,85,91;, - 3;85,86,91;, - 3;86,87,91;, - 3;87,88,91;, - 3;88,89,91;, - 3;89,90,91;, - 3;90,81,91;; - } - - MeshMaterialList { - 1; - 180; - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0; - - Material { - 0.500000;0.500000;0.500000;0.000000;; - 0.000000; - 0.500000;0.500000;0.500000;; - 0.000000;0.000000;0.000000;; - } - } - - VertexDuplicationIndices { - 92; - 92; - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28, - 29, - 30, - 31, - 32, - 33, - 34, - 35, - 36, - 37, - 38, - 39, - 40, - 41, - 42, - 43, - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 59, - 60, - 61, - 62, - 63, - 64, - 65, - 66, - 67, - 68, - 69, - 70, - 71, - 72, - 73, - 74, - 75, - 76, - 77, - 78, - 79, - 80, - 81, - 82, - 83, - 84, - 85, - 86, - 87, - 88, - 89, - 90, - 91; - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/SharedContent/bullet_ico.ico b/Extras/obsolete/BulletX/Source/SharedContent/bullet_ico.ico deleted file mode 100644 index b006325fd..000000000 Binary files a/Extras/obsolete/BulletX/Source/SharedContent/bullet_ico.ico and /dev/null differ diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/BasicDemo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/BasicDemo.cs deleted file mode 100644 index 786306795..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/BasicDemo.cs +++ /dev/null @@ -1,71 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#region Using Statements -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Audio; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using Microsoft.Xna.Framework.Storage; -#endregion -using XnaDevRu.BulletX; -using XnaDevRu.BulletX.Dynamics; - -namespace XnaDevRu.BulletX.Demos.Basic -{ - /// - /// This is the main type for your game - /// - public class BasicDemo : XnaDevRu.BulletX.Demos.DemoGame - { - public BasicDemo() - { - SphereBoxCollisionAlgorithm.CreateFunc boxAlgo = new SphereBoxCollisionAlgorithm.CreateFunc(); - boxAlgo.IsSwapped = true; - CollisionDispatcher.RegisterCollisionCreateFunc(BroadphaseNativeTypes.Sphere, BroadphaseNativeTypes.Sphere, new SphereSphereCollisionAlgorithm.CreateFunc()); - CollisionDispatcher.RegisterCollisionCreateFunc(BroadphaseNativeTypes.Sphere, BroadphaseNativeTypes.Box, new SphereBoxCollisionAlgorithm.CreateFunc()); - CollisionDispatcher.RegisterCollisionCreateFunc(BroadphaseNativeTypes.Box, BroadphaseNativeTypes.Sphere, boxAlgo); - - Shapes[0] = new SphereShape(50); - Shapes[2] = new SphereShape(HalfExtents - CollisionMargin); - - Matrix tr = Matrix.Identity; - tr.Translation = new Vector3(0, -50, 0); - CreateRigidBody(0, tr, Shapes[0]); - - for (int i = 0; i < NumObjects; i++) - { - Shapes[2].Margin = CollisionMargin; - int colsize = 2; - int row = (int)((i * HalfExtents * 2) / (colsize * 2 * HalfExtents)); - int row2 = row; - int col = i % colsize - colsize / 2; - tr.Translation = new Vector3(col * 2 * HalfExtents + (row2 % 2) * HalfExtents, - row * 2 * HalfExtents + HalfExtents, 0); - - CreateRigidBody(1, tr, Shapes[2]); - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/Program.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/Program.cs deleted file mode 100644 index 1ced98a66..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/Program.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; - -namespace XnaDevRu.BulletX.Demos.Basic -{ - static class Program - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - using (BasicDemo game = new BasicDemo()) - { - game.Run(); - } - } - } -} - diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/Properties/AssemblyInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/Properties/AssemblyInfo.cs deleted file mode 100644 index ee47cac13..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("XnaDevRu.BulletX.Demos.Basic")] -[assembly: AssemblyProduct("Bullet for XNA")] -[assembly: AssemblyDescription("Bullet for XNA Basic Demo")] -[assembly: AssemblyCompany("XNADev.ru")] - -[assembly: AssemblyCopyright("Copyright © 2007 XNADev.ru")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("dd847e80-8cf8-4c43-91cd-524301838768")] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.149.21894")] diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/XnaDevRu.BulletX.Demos.Basic.csproj b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/XnaDevRu.BulletX.Demos.Basic.csproj deleted file mode 100644 index 89073feb3..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Basic/XnaDevRu.BulletX.Demos.Basic.csproj +++ /dev/null @@ -1,97 +0,0 @@ - - - {72384342-889C-47B0-B98E-C855D1CE0F41} - {9F340DF3-2AED-4330-AC16-78AC2D9B4738};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - WinExe - Properties - XnaDevRu.BulletX.Demos.Basic - Basic - v1.0 - Windows - ..\..\..\SharedContent\bullet_ico.ico - Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll - - - - - true - full - false - ..\..\..\..\Build\x86\Debug\Demos\BulletX\ - DEBUG;TRACE - prompt - 4 - true - false - x86 - - - pdbonly - true - ..\..\..\..\Build\x86\Release\Demos\BulletX\ - TRACE - prompt - 4 - true - false - x86 - - - - False - - - False - - - False - - - False - - - - - - false - Program - - - false - BasicDemo - - - - - bullet_ico.ico - false - bullet_ico - - - - - {2DF77065-B2FF-4DBB-96BB-A28E09A4A23A} - XnaDevRu.BulletX.Demos - - - {5BEE189F-47A1-42A8-A297-1960221BE20D} - XnaDevRu.BulletX - - - - - - - - - - - \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/CcdDemo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/CcdDemo.cs deleted file mode 100644 index 9295d945d..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/CcdDemo.cs +++ /dev/null @@ -1,108 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#region Using Statements -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Audio; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using Microsoft.Xna.Framework.Storage; -#endregion -using XnaDevRu.BulletX; -using XnaDevRu.BulletX.Dynamics; - -namespace XnaDevRu.BulletX.Demos.Ccd -{ - /// - /// This is the main type for your game - /// - public class CcdDemo : XnaDevRu.BulletX.Demos.DemoGame - { - public CcdDemo() - { - NumObjects = 120; - - Shapes[0] = new BoxShape(new Vector3(200, 10, 200)); - - for (int i = 0; i < NumObjects; i++) - { - CollisionShape shape = Shapes[ShapeIndex[i]]; - shape.Margin = CollisionMargin; - - bool isDynamic = i > 0; - - Matrix trans = Matrix.Identity; - - if (i > 0) - { - //stack them - int colsize = 10; - int row = (i * HalfExtents * 2) / (colsize * 2 * HalfExtents); - int row2 = row; - int col = (i) % (colsize) - colsize / 2; - - if (col > 3) - { - col = 11; - row2 |= 1; - } - - Vector3 pos; - if (NumObjects > 2) - { - pos = new Vector3(col * 2 * HalfExtents + (row2 % 2) * HalfExtents, - row * 2 * HalfExtents + HalfExtents + ExtraHeight, 0); - } - else - { - pos = new Vector3(0, -30, 0); - } - - if (shape is BoxShape) - { - trans.Right = new Vector3(0, -1, 0); - trans.Up = new Vector3(1, 0, 0); - trans.Backward = new Vector3(0, 0, 1); - } - - trans *= Matrix.CreateRotationZ(Microsoft.Xna.Framework.MathHelper.PiOver2); - trans.Translation = pos; - } - else - { - trans.Translation = new Vector3(0, -30, 0); - } - - float mass = 1.0f; - if (!isDynamic) - mass = 0.0f; - - RigidBody body = CreateRigidBody(mass, trans, shape); - - body.CcdSquareMotionThreshold = HalfExtents; - body.CcdSweptSphereRadius = 0.2f * HalfExtents; - } - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/Program.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/Program.cs deleted file mode 100644 index 8cbc9ec37..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/Program.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; - -namespace XnaDevRu.BulletX.Demos.Ccd -{ - static class Program - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - using (CcdDemo game = new CcdDemo()) - { - game.Run(); - } - } - } -} - diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/Properties/AssemblyInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/Properties/AssemblyInfo.cs deleted file mode 100644 index d316594fb..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("XnaDevRu.BulletX.Demos.Ccd")] -[assembly: AssemblyProduct("Bullet for XNA")] -[assembly: AssemblyDescription("Bullet for XNA CCD Demo")] -[assembly: AssemblyCompany("XNADev.ru")] - -[assembly: AssemblyCopyright("Copyright © 2007 XNADev.ru")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("58969560-d588-4200-a57e-2f312cdf6a18")] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.149.21894")] diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/XnaDevRu.BulletX.Demos.Ccd.csproj b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/XnaDevRu.BulletX.Demos.Ccd.csproj deleted file mode 100644 index 1c3314a5c..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Ccd/XnaDevRu.BulletX.Demos.Ccd.csproj +++ /dev/null @@ -1,93 +0,0 @@ - - - {705FCCF1-44C8-430E-92A9-9987CD3D6A64} - {9F340DF3-2AED-4330-AC16-78AC2D9B4738};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - WinExe - Properties - XnaDevRu.BulletX.Demos.Ccd - Ccd - v1.0 - Windows - ..\..\..\SharedContent\bullet_ico.ico - Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll - - - - - true - full - false - ..\..\..\..\Build\x86\Debug\Demos\BulletX\ - DEBUG;TRACE - prompt - 4 - true - false - x86 - - - pdbonly - true - ..\..\..\..\Build\x86\Release\Demos\BulletX\ - TRACE - prompt - 4 - true - false - x86 - - - - False - - - False - - - False - - - False - - - - - false - CcdDemo - - - - false - Program - - - - - {2DF77065-B2FF-4DBB-96BB-A28E09A4A23A} - XnaDevRu.BulletX.Demos - - - {EBC5D108-65E5-4F8E-B3F2-BF7EE56C27F3} - XnaDevRu.BulletX - - - - - bullet_ico.ico - false - bullet_ico - - - - - - - \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/ConstraintDemo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/ConstraintDemo.cs deleted file mode 100644 index 0c56f3229..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/ConstraintDemo.cs +++ /dev/null @@ -1,121 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#region Using Statements -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Audio; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using Microsoft.Xna.Framework.Storage; -#endregion -using XnaDevRu.BulletX; -using XnaDevRu.BulletX.Dynamics; - -namespace XnaDevRu.BulletX.Demos.Constraints -{ - /// - /// This is the main type for your game - /// - public class ConstraintDemo : XnaDevRu.BulletX.Demos.DemoGame - { - Matrix _sliderTransform; - Vector3 _lowerSliderLimit = new Vector3(-10, 0, 0); - Vector3 _hiSliderLimit = new Vector3(10, 0, 0); - - RigidBody _d6BodyA = null; - - public ConstraintDemo() - { - CollisionShape shape = new BoxShape(new Vector3(HalfExtents, HalfExtents, HalfExtents)); - Matrix trans = Matrix.Identity; - trans.Translation = new Vector3(0, 20, 0); - - float mass = 1f; - //Point to Point constraint (ball socket) - { - RigidBody bodyA = CreateRigidBody(mass, trans, shape); - trans.Translation = new Vector3(2 * HalfExtents, 20, 0); - - mass = 1f; - RigidBody bodyB = null; - //RigidBody bodyB = CreateRigidBody(mass, trans, shape); - //bodyB.ActivationState = ActivationState.DisableDeactivation; - //bodyB.SetDamping(0.3f, 0.3f); - - Vector3 pivotInA = new Vector3(HalfExtents, -HalfExtents, -HalfExtents); - Vector3 axisInA = new Vector3(0, 0, 1); - - Vector3 pivotInB = bodyB != null ? MathHelper.MatrixToVector(MathHelper.InvertMatrix(bodyB.CenterOfMassTransform), MathHelper.MatrixToVector(bodyA.CenterOfMassTransform, pivotInA)) : pivotInA; - Vector3 axisInB = bodyB != null ? - Vector3.TransformNormal(Vector3.TransformNormal(axisInA, bodyB.CenterOfMassTransform), MathHelper.InvertMatrix(bodyB.CenterOfMassTransform)) : - Vector3.TransformNormal(axisInA, bodyA.CenterOfMassTransform); - - //TypedConstraint p2p = new Point2PointConstraint(bodyA, bodyB, pivotInA, pivotInB); - //TypedConstraint hinge = new HingeConstraint(bodyA, bodyB, pivotInA, pivotInB, axisInA, axisInB); - HingeConstraint hinge = new HingeConstraint(bodyA, pivotInA, axisInA); - - //use zero targetVelocity and a small maxMotorImpulse to simulate joint friction - //float targetVelocity = 0.0f; - //float maxMotorImpulse = 0.01; - float targetVelocity = 1.0f; - float maxMotorImpulse = 1.0f; - hinge.EnableAngularMotor(true, targetVelocity, maxMotorImpulse); - - PhysicsWorld.AddConstraint(hinge); - } - - // create a slider, using the generic D6 constraint - { - mass = 1f; - Vector3 sliderWorldPos = new Vector3(0, 10, 0); - Vector3 sliderAxis = new Vector3(1, 0, 0); - float angle = 0; - Matrix sliderOrientation = Matrix.CreateFromQuaternion(new Quaternion(sliderAxis, angle)); - - trans = Matrix.Identity; - trans.Translation = sliderWorldPos; - //trans.setBasis(sliderOrientation); - _sliderTransform = trans; - - _d6BodyA = CreateRigidBody(mass, trans, shape); - _d6BodyA.ActivationState = ActivationState.DisableDeactivation; - RigidBody fixedBody1 = CreateRigidBody(0, trans, null); - - Matrix frameInA, frameInB; - frameInA = Matrix.Identity; - frameInB = Matrix.Identity; - - Generic6DofConstraint slider = new Generic6DofConstraint(_d6BodyA, fixedBody1, frameInA, frameInB); - slider.SetLinearLowerLimit(_lowerSliderLimit); - slider.SetLinearUpperLimit(_hiSliderLimit); - - //range should be small, otherwise singularities will 'explode' the constraint - slider.SetAngularLowerLimit(new Vector3(10, 0, 0)); - slider.SetAngularUpperLimit(new Vector3(0, 0, 0)); - - PhysicsWorld.AddConstraint(slider); - } - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/Program.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/Program.cs deleted file mode 100644 index f361d99d6..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/Program.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; - -namespace XnaDevRu.BulletX.Demos.Constraints -{ - static class Program - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - using (ConstraintDemo game = new ConstraintDemo()) - { - game.Run(); - } - } - } -} - diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/Properties/AssemblyInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/Properties/AssemblyInfo.cs deleted file mode 100644 index d0e4f5b19..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("XnaDevRu.BulletX.Demos.Constraints")] -[assembly: AssemblyProduct("Bullet for XNA")] -[assembly: AssemblyDescription("Bullet for XNA Constraint Demo")] -[assembly: AssemblyCompany("XNADev.ru")] - -[assembly: AssemblyCopyright("Copyright © 2007 XNADev.ru")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("1c75580e-8bd8-47cd-8124-0e0054125840")] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.149.21894")] diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/XnaDevRu.BulletX.Demos.Constraints.csproj b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/XnaDevRu.BulletX.Demos.Constraints.csproj deleted file mode 100644 index bda112231..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos.Constraints/XnaDevRu.BulletX.Demos.Constraints.csproj +++ /dev/null @@ -1,93 +0,0 @@ - - - {77ABF9BD-E838-4EF0-BD76-C656C62BC517} - {9F340DF3-2AED-4330-AC16-78AC2D9B4738};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - WinExe - Properties - XnaDevRu.BulletX.Demos.Constraints - Constraints - v1.0 - Windows - ..\..\..\SharedContent\bullet_ico.ico - Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll - - - - - true - full - false - ..\..\..\..\Build\x86\Debug\Demos\BulletX\ - DEBUG;TRACE - prompt - 4 - true - false - x86 - - - pdbonly - true - ..\..\..\..\Build\x86\Release\Demos\BulletX\ - TRACE - prompt - 4 - true - false - x86 - - - - False - - - False - - - False - - - False - - - - - false - ConstraintDemo - - - - false - Program - - - - - {2DF77065-B2FF-4DBB-96BB-A28E09A4A23A} - XnaDevRu.BulletX.Demos - - - {EBC5D108-65E5-4F8E-B3F2-BF7EE56C27F3} - XnaDevRu.BulletX - - - - - bullet_ico.ico - false - bullet_ico - - - - - - - \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/BulletXDemos.snk b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/BulletXDemos.snk deleted file mode 100644 index b64d5796b..000000000 Binary files a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/BulletXDemos.snk and /dev/null differ diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/DemoGame.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/DemoGame.cs deleted file mode 100644 index a9ba227ef..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/DemoGame.cs +++ /dev/null @@ -1,589 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#region Using Statements -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Audio; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using Microsoft.Xna.Framework.Storage; -#endregion -using XnaDevRu.Demos; -using XnaDevRu.BulletX; -using XnaDevRu.BulletX.Dynamics; - -namespace XnaDevRu.BulletX.Demos -{ - /// - /// This is the main type for your BulletX Demo. - /// - public class DemoGame : Microsoft.Xna.Framework.Game - { - // Main elements - private GraphicsDeviceManager _graphics; - private ContentManager _content; - - // Components - private Camera _camera; - private Framerate _fps; - - private MouseState _prevMouseState; - - // Picking - private TypedConstraint _pickConstraint; - private Vector3 _oldPickingPos; - private float _oldPickingDist = 0f; - private RigidBody _pickedBody = null; //for deactivation state - - //Physics - private CollisionDispatcher _collisionDispatcher; - private OverlappingPairCache _broadphase; - private SequentialImpulseConstraintSolver _solver; - private DiscreteDynamicsWorld _world; - private CollisionShape[] _shapePtr; - - private const int _maxNumObjects = 32760; - private int _numObjects = 120; - private const int _cubeHalfExtent = 1; - private const int _extraHeight = -20; - private const float _collisionMargin = 0.05f; - private float _shootBoxInitialSpeed = 50f; - private int[] _shapeIndex; - private Model _modelBox; - private Model _modelSphere; - private Model _modelCylinder; - - private bool _useDebugDrawer; - private bool _useSweepAndPrune = true; - - /// - /// Initializes new Demo testbed. - /// - public DemoGame() - { - _graphics = new GraphicsDeviceManager(this); - _content = new ContentManager(Services); - //graphics.SynchronizeWithVerticalRetrace = false; - - IsMouseVisible = true; - _camera = new Camera(this); - _fps = new Framerate(this); - _fps.UpdateFrequency = 100; - Components.Add(_camera); - Components.Add(_fps); - - ResetPhysics(); - } - - /// - /// Gets graphics device manager associated with this demo. - /// - public GraphicsDeviceManager Graphics { get { return _graphics; } } - /// - /// Gets content manager associated with this demo. - /// - public ContentManager Content { get { return _content; } } - - /// - /// Gets camera component associated with this demo. - /// - public Camera Camera { get { return _camera; } } - /// - /// Gets framerate component associated with this demo. - /// - public Framerate Fps { get { return _fps; } } - - /// - /// Gets or sets current collision dispatcher. - /// - public CollisionDispatcher CollisionDispatcher { get { return _collisionDispatcher; } set { _collisionDispatcher = value; } } - /// - /// Gets or sets current overlapping pair cache. - /// - public OverlappingPairCache Broadphase { get { return _broadphase; } set { _broadphase = value; } } - /// - /// Gets or sets current sequential impulse constraint solver. - /// - public SequentialImpulseConstraintSolver Solver { get { return _solver; } set { _solver = value; } } - /// - /// Gets or sets current dynamics world. - /// - public DiscreteDynamicsWorld PhysicsWorld { get { return _world; } set { _world = value; } } - /// - /// Gets or sets predefined shape array. - /// - public CollisionShape[] Shapes { get { return _shapePtr; } set { _shapePtr = value; } } - - /// - /// Gets max number of objects in the simulation. - /// - public int MaxNumObjects { get { return _maxNumObjects; } } - /// - /// Gets or sets starting objects count in simulation. - /// - public int NumObjects { get { return _numObjects; } set { _numObjects = value; } } - /// - /// Gets half extents. - /// - public int HalfExtents { get { return _cubeHalfExtent; } } - /// - /// Gets extra height. - /// - public int ExtraHeight { get { return _extraHeight; } } - /// - /// Gets collision margin. - /// - public float CollisionMargin { get { return _collisionMargin; } } - /// - /// Gets or sets initial box speed when shot. - /// - public float ShootBoxInitialSpeed { get { return _shootBoxInitialSpeed; } set { _shootBoxInitialSpeed = value; } } - /// - /// Gets or sets predefined shape index reference for simulated objects. - /// - public int[] ShapeIndex { get { return _shapeIndex; } set { _shapeIndex = value; } } - /// - /// Gets or sets box model. - /// - public Model ModelBox { get { return _modelBox; } set { _modelBox = value; } } - /// - /// Gets or sets sphere model. - /// - public Model ModelSphere { get { return _modelSphere; } set { _modelSphere = value; } } - /// - /// Gets or sets cylinder model. - /// - public Model ModelCylinder { get { return _modelCylinder; } set { _modelCylinder = value; } } - - /// - /// Gets or sets the ability to draw debug information. - /// - public bool UseDebugDrawer { get { return _useDebugDrawer; } set { _useDebugDrawer = value; } } - /// - /// Gets or sets the sweep and prune for broadphase. - /// - public bool UseSweepAndPrune { get { return _useSweepAndPrune; } set { _useSweepAndPrune = value; } } - - /// - /// Reinitializes physics. - /// - public void ResetPhysics() - { - _collisionDispatcher = new CollisionDispatcher(); - - if (_useSweepAndPrune) - { - Vector3 worldAabbMin = new Vector3(-10000, -10000, -10000); - Vector3 worldAabbMax = new Vector3(10000, 10000, 10000); - const int maxProxies = 32766; - _broadphase = new AxisSweep3(worldAabbMin, worldAabbMax, maxProxies); - } - else - _broadphase = new SimpleBroadphase(); - - _solver = new SequentialImpulseConstraintSolver(); - _world = new DiscreteDynamicsWorld(_collisionDispatcher, _broadphase, _solver); - - //world.setConstraintSolver(solver); - _world.Gravity = new Vector3(0, -10, 0); - - _shapePtr = new CollisionShape[4]; - _shapePtr[0] = new BoxShape(new Vector3(50, 10, 50)); - _shapePtr[1] = new CylinderShape(new Vector3(_cubeHalfExtent - _collisionMargin, _cubeHalfExtent - _collisionMargin, _cubeHalfExtent - _collisionMargin)); - _shapePtr[2] = new SphereShape(_cubeHalfExtent); - _shapePtr[3] = new BoxShape(new Vector3(_cubeHalfExtent, _cubeHalfExtent, _cubeHalfExtent)); - - _shapeIndex = new int[_maxNumObjects]; - Matrix tr = Matrix.Identity; - - for (int i = 0; i < _numObjects; i++) - { - if (i > 0) - // set shape - _shapeIndex[i] = 1; - else - _shapeIndex[i] = 0; - } - - GC.Collect(); - } - - /// - /// Creates new rigid body and adds it to the world. - /// - /// Body mass, if 0 body is static. - /// Starting body transform. - /// Body shape. - /// Created rigid body. - public RigidBody CreateRigidBody(float mass, Matrix startTransform, CollisionShape shape) - { - //rigidbody is dynamic if and only if mass is non zero, otherwise static - bool isDynamic = (mass != 0.0f); - - Vector3 localInertia = new Vector3(); - if (isDynamic) - shape.CalculateLocalInertia(mass, out localInertia); - - //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects - - DefaultMotionState myMotionState = new DefaultMotionState(startTransform, Matrix.Identity); - RigidBody body = new RigidBody(mass, myMotionState, shape, localInertia, 0.0f, 0.0f, 0.5f, 0.0f); - - _world.AddRigidBody(body); - - return body; - } - - /// - /// Called after the Game and Graphics.GraphicsDevice are created, but before Game.LoadGraphicsContent. - /// - protected override void Initialize() - { - base.Initialize(); - - _camera.Position = new Vector3(0, 3, 75); - _camera.Target = new Vector3(0, 0, 0); - - if (_useDebugDrawer) - { - XnaDebugDraw dbg = new XnaDebugDraw(_graphics.GraphicsDevice); - dbg.DebugMode = DebugDrawModes.DrawAabb | DebugDrawModes.DrawContactPoints; - _world.DebugDrawer = dbg; - } - } - - /// - /// Loads graphics content needed by this demo. - /// - /// If need to reload all content. - protected override void LoadGraphicsContent(bool loadAllContent) - { - if (loadAllContent) - { - _modelBox = _content.Load("content\\box"); - _modelSphere = _content.Load("content\\sphere"); - _modelCylinder = _content.Load("content\\cylinder"); - } - } - - /// - /// Unloads graphics content needed by this demo. - /// - /// If need to unload all content. - protected override void UnloadGraphicsContent(bool unloadAllContent) - { - if (unloadAllContent == true) - { - _content.Unload(); - } - } - - /// - /// Called when the game has determined that game logic needs to be processed. - /// - /// Time passed since the last call to this function. - protected override void Update(GameTime gameTime) - { - MouseState mouseState = Mouse.GetState(); - Vector3 rayTo = getRayTo(mouseState.X, mouseState.Y); - - if (mouseState.LeftButton == ButtonState.Pressed && _prevMouseState.LeftButton == ButtonState.Released) - { - shootBox(rayTo); - } - if (mouseState.MiddleButton == ButtonState.Pressed && _prevMouseState.MiddleButton == ButtonState.Released) - { - if (_world != null) - { - CollisionWorld.ClosestRayResultCallback rayCallback = new CollisionWorld.ClosestRayResultCallback(_camera.Position, rayTo); - _world.RayTest(_camera.Position, rayTo, rayCallback); - if (rayCallback.HasHit) - { - RigidBody body = RigidBody.Upcast(rayCallback.CollisionObject); - if (body != null) - { - //other exclusions? - if (!(body.IsStaticObject || body.IsKinematicObject)) - { - _pickedBody = body; - _pickedBody.ActivationState = ActivationState.DisableDeactivation; - - Vector3 pickPos = rayCallback.HitPointWorld; - - Vector3 localPivot = Vector3.Transform(pickPos, XnaDevRu.BulletX.MathHelper.InvertMatrix(body.CenterOfMassTransform)); - - Point2PointConstraint p2p = new Point2PointConstraint(body, localPivot); - _world.AddConstraint(p2p); - _pickConstraint = p2p; - - //save mouse position for dragging - _oldPickingPos = rayTo; - - Vector3 eyePos = new Vector3(_camera.Position.X, _camera.Position.Y, _camera.Position.Z); - - _oldPickingDist = (eyePos - pickPos).Length(); - - //very weak constraint for picking - p2p.Settings.Tau = 1.1f; - } - } - } - } - } - else if (mouseState.MiddleButton == ButtonState.Released && _prevMouseState.MiddleButton == ButtonState.Pressed) - { - if (_pickConstraint != null && _world != null) - { - _world.RemoveConstraint(_pickConstraint); - _pickConstraint = null; - _pickedBody.ForceActivationState(ActivationState.Active); - _pickedBody.DeactivationTime = 0f; - _pickedBody = null; - } - } - - if (_pickConstraint != null) - { - //move the constraint pivot - Point2PointConstraint p2p = _pickConstraint as Point2PointConstraint; - if (p2p != null) - { - //keep it at the same picking distance - Vector3 dir = rayTo - _camera.Position; - dir.Normalize(); - dir *= _oldPickingDist; - - Vector3 newPos = _camera.Position + dir; - p2p.PivotInB = newPos; - } - } - - _prevMouseState = mouseState; - - if (Keyboard.GetState().IsKeyDown(Keys.Space)) - { - //world.stepSimulation(1.0f/60.0f,0); - int numObjects = _world.CollisionObjectsCount; - - for (int i = 0; i < numObjects; i++) - { - CollisionObject colObj = _world.CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - if (body.MotionState != null) - { - DefaultMotionState myMotionState = (DefaultMotionState)body.MotionState; - myMotionState.GraphicsWorldTransform = myMotionState.StartWorldTransform; - colObj.WorldTransform = myMotionState.GraphicsWorldTransform; - colObj.InterpolationWorldTransform = myMotionState.StartWorldTransform; - colObj.Activate(); - } - - //removed cached contact points - _world.Broadphase.CleanProxyFromPairs(colObj.Broadphase); - - if (body != null && !body.IsStaticObject) - { - RigidBody.Upcast(colObj).LinearVelocity = new Vector3(0, 0, 0); - RigidBody.Upcast(colObj).AngularVelocity = new Vector3(0, 0, 0); - } - } - } - } - else if (Keyboard.GetState().IsKeyDown(Keys.Escape) || GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) - { - Exit(); - } - else - { - //world.stepSimulation(1.0f / 60.0f, 1); - } - - base.Update(gameTime); - } - - /// - /// Called when the gamedetermines it is time to draw a frame. - /// - /// Time passed since the last call to this function. - protected override void Draw(GameTime gameTime) - { - _graphics.GraphicsDevice.Clear(Color.CornflowerBlue); - - if (_useDebugDrawer) - ((XnaDebugDraw)_world.DebugDrawer).Update(_camera.View, _camera.Projection); - - _world.StepSimulation(1.0f / 60.0f, 1); - - Matrix objMatrix; - - if (_world != null) - { - int numObjects = _world.CollisionObjectsCount; - Vector3 wireColor = Vector3.UnitX; - for (int i = 0; i < numObjects; i++) - { - CollisionObject colObj = _world.CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - - if (body != null && body.MotionState != null) - { - DefaultMotionState myMotionState = (DefaultMotionState)body.MotionState; - objMatrix = myMotionState.GraphicsWorldTransform; - } - else - { - objMatrix = colObj.WorldTransform; - } - - wireColor = new Vector3(1.0f, 1.0f, 0.5f); //wants deactivation - if ((i & 1) == 1) - { - wireColor = new Vector3(0.0f, 0.0f, 1.0f); - } - - //color differently for active, sleeping, wantsdeactivation states - if (colObj.ActivationState == ActivationState.Active) - { - if ((i & 1) == 1) - { - wireColor += new Vector3(1.0f, 0.0f, 0.0f); - } - else - { - wireColor += new Vector3(0.5f, 0.0f, 0.0f); - } - } - - if (colObj.ActivationState == ActivationState.IslandSleeping) - { - if ((i & 1) == 1) - { - wireColor += new Vector3(0.0f, 1.0f, 0.0f); - } - else - { - wireColor += new Vector3(0.0f, 0.5f, 0.0f); - } - } - - // draw box - objMatrix = XnaDevRu.BulletX.MathHelper.GetDisplayMatrix(objMatrix); - - if (i == 0) - wireColor = Vector3.Zero; - - DrawModel(objMatrix, wireColor, colObj); - } - } - - base.Draw(gameTime); - } - - private void DrawModel(Matrix modelTransform, Vector3 color, CollisionObject obj) - { - Model model = _modelBox; - Matrix scale = Matrix.Identity; - - if (obj.CollisionShape is CylinderShape) - { - CylinderShape cylinderShape = (CylinderShape)obj.CollisionShape; - Vector3 halfExtent = cylinderShape.HalfExtents; - scale = Matrix.CreateScale(halfExtent.X + _collisionMargin, halfExtent.Y + _collisionMargin, halfExtent.Z / 2 + _collisionMargin * 3.5f) * Matrix.CreateRotationX((float)Math.PI / 2); - model = _modelCylinder; - } - else if (obj.CollisionShape is BoxShape) - { - BoxShape boxShape = (BoxShape)obj.CollisionShape; - Vector3 halfExtent = boxShape.HalfExtents; - scale = Matrix.CreateScale(2 * halfExtent.X, 2 * halfExtent.Y, 2 * halfExtent.Z); - model = _modelBox; - } - else if (obj.CollisionShape is SphereShape) - { - SphereShape sphereShape = (SphereShape)obj.CollisionShape; - float radius = sphereShape.Radius; - scale = Matrix.CreateScale(radius, radius, radius); - model = _modelSphere; - } - - Matrix[] transforms = new Matrix[model.Bones.Count]; - model.CopyAbsoluteBoneTransformsTo(transforms); - - foreach (ModelMesh mesh in model.Meshes) - { - foreach (BasicEffect effect in mesh.Effects) - { - effect.EnableDefaultLighting(); - effect.PreferPerPixelLighting = true; - effect.AmbientLightColor = color; - - effect.View = _camera.View; - effect.Projection = _camera.Projection; - effect.World = transforms[mesh.ParentBone.Index] * scale * modelTransform; - } - mesh.Draw(); - } - } - - private void shootBox(Vector3 destination) - { - if (_world != null) - { - float mass = 1f; - Matrix startTransform = Matrix.Identity; - Vector3 camPos = _camera.Position; - startTransform.Translation = camPos; - //CollisionShape boxShape = new SphereShape(1); - CollisionShape boxShape = new BoxShape(Vector3.One); - RigidBody body = CreateRigidBody(mass, startTransform, boxShape); - - Vector3 linVel = new Vector3(destination.X - camPos.X, destination.Y - camPos.Y, destination.Z - camPos.Z); - linVel.Normalize(); - linVel *= _shootBoxInitialSpeed; - - //body.getWorldTransform().setOrigin(camPos); - //body.getWorldTransform().setRotation(btQuaternion(0, 0, 0, 1)); - body.LinearVelocity = linVel; - body.AngularVelocity = Vector3.Zero; - } - } - - private Vector3 getRayTo(int x, int y) - { - Vector3 nearSource = new Vector3(x, y, 0); - Vector3 farSource = new Vector3(x, y, 1); - - Matrix world = Matrix.CreateTranslation(0, 0, 0); - - Vector3 nearPoint = Graphics.GraphicsDevice.Viewport.Unproject(nearSource, Camera.Projection, Camera.View, world); - Vector3 farPoint = Graphics.GraphicsDevice.Viewport.Unproject(farSource, Camera.Projection, Camera.View, world); - - Vector3 direction = farPoint - nearPoint; - //direction.Normalize(); - return direction; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/Properties/AssemblyInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/Properties/AssemblyInfo.cs deleted file mode 100644 index 7ff74e5fe..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("XnaDevRu.BulletX.Demos")] -[assembly: AssemblyProduct("Bullet for XNA")] -[assembly: AssemblyDescription("BulletX Common Demo Code")] -[assembly: AssemblyCompany("XNADev.ru")] -[assembly: AssemblyCopyright("Copyright © 2007 XNADev.ru")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("49577e4d-b699-4933-972d-7734f73b02ba")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.149.21894")] diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/XnaDevRu.BulletX.Demos.csproj b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/XnaDevRu.BulletX.Demos.csproj deleted file mode 100644 index 8a97f7970..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX.Demos/XnaDevRu.BulletX.Demos.csproj +++ /dev/null @@ -1,115 +0,0 @@ - - - {2DF77065-B2FF-4DBB-96BB-A28E09A4A23A} - {9F340DF3-2AED-4330-AC16-78AC2D9B4738};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - Library - Properties - XnaDevRu.BulletX.Demos - XnaDevRu.BulletX.Demos - v1.0 - Windows - Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll - - - false - BulletXDemos.snk - true - - - true - full - false - ..\..\..\..\Build\x86\Debug\ - DEBUG;TRACE - prompt - 4 - true - false - x86 - ..\..\..\..\Build\x86\Debug\XnaDevRu.BulletX.Demos.XML - - - pdbonly - true - ..\..\..\..\Build\x86\Release\ - TRACE - prompt - 4 - true - false - x86 - ..\..\..\..\Build\x86\Release\XnaDevRu.BulletX.Demos.XML - - - - False - - - False - - - False - - - False - - - - - false - DemoGame - - - - - - {C54AF66D-0C55-4A84-9E7C-FC6346C78681} - XnaDevRu.Demos - - - {5BEE189F-47A1-42A8-A297-1960221BE20D} - XnaDevRu.BulletX - - - - - Content\box.x - true - XImporter - ModelProcessor - box - - - Content\cylinder.x - true - XImporter - ModelProcessor - cylinder - - - Content\sphere.x - true - XImporter - ModelProcessor - sphere - - - - - false - BulletXDemos - - - - - - - \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/BulletDebug.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/BulletDebug.cs deleted file mode 100644 index d0d58454a..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/BulletDebug.cs +++ /dev/null @@ -1,68 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using System.Diagnostics; - -namespace XnaDevRu.BulletX -{ - internal static class BulletDebug - { - [Conditional("DEBUG")] - public static void Assert(Boolean condition) - { - //if (!condition) - //{ - // Throw("No info available"); - //} - Debug.Assert(condition); - } - - [Conditional("DEBUG")] - public static void Assert(Boolean condition, String message) - { - //if (!condition) - //{ - // Throw(message); - //} - Debug.Assert(condition, message); - } - - [Conditional("DEBUG")] - public static void Assert(Boolean condition, String message, String detailMessage) - { - //if (!condition) - //{ - // Throw(message); - //} - Debug.Assert(condition, message, detailMessage); - } - - private static void Throw(String message) - { - String msg = String.Format("Assertion Error: {0}", message); - - throw new BulletException(msg); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/BulletX.snk b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/BulletX.snk deleted file mode 100644 index 4ce590752..000000000 Binary files a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/BulletX.snk and /dev/null differ diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/AxisSweep3.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/AxisSweep3.cs deleted file mode 100644 index 3c5980b50..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/AxisSweep3.cs +++ /dev/null @@ -1,623 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class AxisSweep3: OverlappingPairCache - { - Vector3 _worldAabbMin; - Vector3 _worldAabbMax; - - Vector3 _quantize; - - int _numHandles; - int _maxHandles; - - Handle[] _handles; - Edge[][] _edges = new Edge[3][]; - - ushort _firstFreeHandle; - - int _invalidPair; - - public AxisSweep3(Vector3 worldAabbMin, Vector3 worldAabbMax, int maxHandles) - : base() - { - BulletDebug.Assert(maxHandles > 1 && maxHandles < 32767); - - // init bounds - _worldAabbMin = worldAabbMin; - _worldAabbMax = worldAabbMax; - - Vector3 aabbSize = _worldAabbMax - _worldAabbMin; - _quantize = new Vector3(65535.0f, 65535.0f, 65535.0f) / aabbSize; - - // allocate handles buffer and put all handles on free list - _handles = new Handle[maxHandles]; - for (int i = 0; i < maxHandles; i++) - _handles[i] = new Handle(); - _maxHandles = maxHandles; - _numHandles = 0; - - // handle 0 is reserved as the null index, and is also used as the sentinel - _firstFreeHandle = 1; - { - for (int i = _firstFreeHandle; i < maxHandles; i++) - { - _handles[i].NextFree = (ushort)(i + 1); - } - _handles[maxHandles - 1].NextFree = 0; - } - - { - // allocate edge buffers - for (int i = 0; i < 3; i++) - { - _edges[i] = new Edge[maxHandles * 2]; - for (int j = 0; j < maxHandles * 2; j++) - { - _edges[i][j] = new Edge(); - } - } - } - //removed overlap management - - // make boundary sentinels - - _handles[0].ClientData = 0; - - for (int axis = 0; axis < 3; axis++) - { - _handles[0].MinEdges[axis] = 0; - _handles[0].MaxEdges[axis] = 1; - - _edges[axis][0].Position = 0; - _edges[axis][0].Handle = 0; - _edges[axis][1].Position = 0xffff; - _edges[axis][1].Handle = 0; - } - } - - public ushort AddHandle(Vector3 aabbMin, Vector3 aabbMax, object owner, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask) - { - ushort[] min = new ushort[3], max = new ushort[3]; - Quantize(out min, aabbMin, 0); - Quantize(out max, aabbMax, 1); - - ushort handle = AllocateHandle(); - Handle oHandle = GetHandle(handle); - - oHandle.HandleID = handle; - oHandle.ClientData = owner; - oHandle.CollisionFilterGroup = collisionFilterGroup; - oHandle.CollisionFilterMask = collisionFilterMask; - - int limit = _numHandles * 2; - - // (Gluk ) - // ( Inside ) - for (int axis = 0; axis < 3; axis++) - { - _handles[0].MaxEdges[axis] += 2; - - _edges[axis][limit + 1].Position = _edges[axis][limit - 1].Position; - _edges[axis][limit + 1].Handle = _edges[axis][limit - 1].Handle; - - _edges[axis][limit - 1].Position = min[axis]; - _edges[axis][limit - 1].Handle = handle; - - _edges[axis][limit].Position = max[axis]; - _edges[axis][limit].Handle = handle; - - oHandle.MinEdges[axis] = (ushort)(limit - 1); - oHandle.MaxEdges[axis] = (ushort)limit; - } - - SortMinDown(0, oHandle.MinEdges[0], false); - SortMaxDown(0, oHandle.MaxEdges[0], false); - SortMinDown(1, oHandle.MinEdges[1], false); - SortMaxDown(1, oHandle.MaxEdges[1], false); - SortMinDown(2, oHandle.MinEdges[2], true); - SortMaxDown(2, oHandle.MaxEdges[2], true); - - return handle; - } - - public void RemoveHandle(ushort handle) - { - Handle pHandle = GetHandle(handle); - - //explicitly remove the pairs containing the proxy - //we could do it also in the sortMinUp (passing true) - //todo: compare performance - RemoveOverlappingPairsContainingProxy(pHandle); - - - // compute current limit of edge arrays - int limit = _numHandles * 2; - int axis; - - for (axis = 0; axis < 3; axis++) - { - _handles[0].MaxEdges[axis] -= 2; - } - - // remove the edges by sorting them up to the end of the list - for (axis = 0; axis < 3; axis++) - { - Edge[] pEdges = _edges[axis]; - ushort max = pHandle.MaxEdges[axis]; - pEdges[max].Position = 0xffff; - - SortMaxUp(axis, max, false); - - ushort i = pHandle.MinEdges[axis]; - pEdges[i].Position = 0xffff; - - SortMinUp(axis, i, false); - - pEdges[limit - 1].Handle = 0; - pEdges[limit - 1].Position = 0xffff; - } - - // free the handle - FreeHandle(handle); - } - - public override void ProcessAllOverlappingPairs(IOverlapCallback callback) - { - OverlappingPairs.Sort(new Comparison(BroadphasePair.ComparisonSort)); - - if (_invalidPair != 0) - OverlappingPairs.RemoveRange(OverlappingPairs.Count - _invalidPair, _invalidPair); - _invalidPair = 0; - - BroadphasePair previousPair = new BroadphasePair(); - previousPair.ProxyA = null; - previousPair.ProxyB = null; - previousPair.CollisionAlgorithm = null; - - List removal = new List(); - - for (int i = 0; i < OverlappingPairs.Count; i++) - { - bool isDuplicate = (OverlappingPairs[i] == previousPair); - previousPair = OverlappingPairs[i]; - bool needsRemoval; - if (!isDuplicate) - { - bool hasOverlap = TestOverlap(previousPair.ProxyA, previousPair.ProxyB); - if (hasOverlap) - { - needsRemoval = callback.ProcessOverlap(ref previousPair); - } - else - { - needsRemoval = true; - } - } - else - { - needsRemoval = true; - BulletDebug.Assert(previousPair.CollisionAlgorithm == null); - } - - if (needsRemoval) - { - removal.Add(previousPair); - } - } - - for (int i = 0; i < removal.Count; i++) - { - BroadphasePair pair = removal[i]; - CleanOverlappingPair(ref pair); - pair.ProxyA = null; - pair.ProxyB = null; - _invalidPair++; - OverlappingPairCount--; - } - } - - private bool TestOverlap(BroadphaseProxy proxyA, BroadphaseProxy proxyB) - { - if (proxyA == null || proxyB == null) - return false; - - Handle handleA = proxyA as Handle; - Handle handleB = proxyB as Handle; - - for (int axis = 0; axis < 3; axis++) - { - if (handleA.MaxEdges[axis] < handleB.MinEdges[axis] || - handleB.MaxEdges[axis] < handleA.MinEdges[axis]) - { - return false; - } - } - return true; - } - - private bool TestOverlap(int ignoreAxis, Handle pHandleA, Handle pHandleB) - { - for (int axis = 0; axis < 3; axis++) - { - if (axis != ignoreAxis) - { - if (pHandleA.MaxEdges[axis] < pHandleB.MinEdges[axis] || - pHandleB.MaxEdges[axis] < pHandleA.MinEdges[axis]) - { - return false; - } - } - } - - return true; - } - - private ushort AllocateHandle() - { - ushort handle = _firstFreeHandle; - _firstFreeHandle = GetHandle(handle).NextFree; - _numHandles++; - - return handle; - } - - private void FreeHandle(ushort handle) - { - BulletDebug.Assert(handle > 0 && handle < _maxHandles); - - GetHandle(handle).NextFree = _firstFreeHandle; - _firstFreeHandle = handle; - - _numHandles--; - } - - private Handle GetHandle(ushort handle) - { - return _handles[handle]; - } - - private void UpdateHandle(ushort handle, Vector3 aabbMin, Vector3 aabbMax) - { - Handle pHandle = GetHandle(handle); - - // quantize the new bounds - ushort[] min = new ushort[3]; - ushort[] max = new ushort[3]; - Quantize(out min, aabbMin, 0); - Quantize(out max, aabbMax, 1); - - // update changed edges - for (int axis = 0; axis < 3; axis++) - { - ushort emin = pHandle.MinEdges[axis]; - ushort emax = pHandle.MaxEdges[axis]; - - int dmin = (int)min[axis] - (int)_edges[axis][emin].Position; - int dmax = (int)max[axis] - (int)_edges[axis][emax].Position; - - _edges[axis][emin].Position = min[axis]; - _edges[axis][emax].Position = max[axis]; - - // expand (only adds overlaps) - if (dmin < 0) - SortMinDown(axis, emin, true); - - if (dmax > 0) - SortMaxUp(axis, emax, true); - - // shrink (only removes overlaps) - if (dmin > 0) - SortMinUp(axis, emin, true); - - if (dmax < 0) - SortMaxDown(axis, emax, true); - } - } - - private void Quantize(out ushort[] result, Vector3 point, int isMax) - { - Vector3 clampedPoint = new Vector3( - point.X, - point.Y, - point.Z - ); - - MathHelper.SetMax(ref clampedPoint, _worldAabbMin); - MathHelper.SetMin(ref clampedPoint, _worldAabbMax); - - Vector3 v = (clampedPoint - _worldAabbMin) * _quantize; - - result = new ushort[3]; - result[0] = (ushort)(((int)v.X & 0xfffe) | isMax); - result[1] = (ushort)(((int)v.Y & 0xfffe) | isMax); - result[2] = (ushort)(((int)v.Z & 0xfffe) | isMax); - } - - private void SortMinDown(int axis, ushort edge, bool updateOverlaps) - { - Edge pEdge = _edges[axis][edge]; - Edge pPrev = _edges[axis][edge - 1]; - Handle pHandleEdge = GetHandle(pEdge.Handle); - - while (pEdge.Position < pPrev.Position) - { - Handle pHandlePrev = GetHandle(pPrev.Handle); - - if (pPrev.IsMax()) - { - // if previous edge is a maximum check the bounds and add an overlap if necessary - if (updateOverlaps && TestOverlap(axis, pHandleEdge, pHandlePrev)) - { - AddOverlappingPair(pHandleEdge, pHandlePrev); - } - - // update edge reference in other handle - pHandlePrev.MaxEdges[axis]++; - } - else - pHandlePrev.MinEdges[axis]++; - - pHandleEdge.MinEdges[axis]--; - - // swap the edges - pEdge.Swap(ref pPrev); - - // decrement - edge--; - pEdge = _edges[axis][edge]; - pPrev = _edges[axis][edge - 1]; - } - } - - private void SortMinUp(int axis, ushort edge, bool updateOverlaps) - { - Edge pEdge = _edges[axis][edge]; - Edge pNext = _edges[axis][edge + 1]; - Handle pHandleEdge = GetHandle(pEdge.Handle); - - while ((pNext.Handle != 0) && (pEdge.Position >= pNext.Position)) - { - Handle pHandleNext = GetHandle(pNext.Handle); - - if (pNext.IsMax()) - { - // if next edge is maximum remove any overlap between the two handles - if (updateOverlaps) - { - //Handle handle0 = GetHandle(pEdge.Handle); - //Handle handle1 = GetHandle(pNext.Handle); - //BroadphasePair tmpPair = new BroadphasePair(handle0, handle1); - //RemoveOverlappingPair(tmpPair); - } - - // update edge reference in other handle - pHandleNext.MaxEdges[axis]--; - } - else - pHandleNext.MinEdges[axis]--; - - pHandleEdge.MinEdges[axis]++; - - // swap the edges - pEdge.Swap(ref pNext); - - // increment - edge++; - pEdge = _edges[axis][edge]; - pNext = _edges[axis][edge + 1]; - } - } - - private void SortMaxDown(int axis, ushort edge, bool updateOverlaps) - { - Edge pEdge = _edges[axis][edge]; - Edge pPrev = _edges[axis][edge - 1]; - Handle pHandleEdge = GetHandle(pEdge.Handle); - - while (pEdge.Position < pPrev.Position) - { - Handle pHandlePrev = GetHandle(pPrev.Handle); - - if (!pPrev.IsMax()) - { - // if previous edge was a minimum remove any overlap between the two handles - if (updateOverlaps) - { - //this is done during the overlappingpairarray iteration/narrowphase collision - //Handle handle0 = GetHandle(pEdge.Handle); - //Handle handle1 = GetHandle(pPrev.Handle); - //BroadphasePair pair = FindPair(handle0, handle1); - - //if (pair != null) - //{ - // RemoveOverlappingPair(pair); - //} - } - - // update edge reference in other handle - pHandlePrev.MinEdges[axis]++; ; - } - else - pHandlePrev.MaxEdges[axis]++; - - pHandleEdge.MaxEdges[axis]--; - - // swap the edges - pEdge.Swap(ref pPrev); - - // decrement - edge--; - pEdge = _edges[axis][edge]; - pPrev = _edges[axis][edge - 1]; - } - } - - private void SortMaxUp(int axis, ushort edge, bool updateOverlaps) - { - Edge pEdge = _edges[axis][edge]; - Edge pNext = _edges[axis][edge + 1]; - Handle pHandleEdge = GetHandle(pEdge.Handle); - - while ((pNext.Handle!=0) && (pEdge.Position >= pNext.Position)) - { - Handle pHandleNext = GetHandle(pNext.Handle); - - if (!pNext.IsMax()) - { - // if next edge is a minimum check the bounds and add an overlap if necessary - if (updateOverlaps && TestOverlap(axis, pHandleEdge, pHandleNext)) - { - Handle handle0 = GetHandle(pEdge.Handle); - Handle handle1 = GetHandle(pNext.Handle); - AddOverlappingPair(handle0, handle1); - } - - // update edge reference in other handle - pHandleNext.MinEdges[axis]--; - } - else - pHandleNext.MaxEdges[axis]--; - - pHandleEdge.MaxEdges[axis]++; - - // swap the edges - pEdge.Swap(ref pNext); - - // increment - edge++; - pEdge = _edges[axis][edge]; - pNext = _edges[axis][edge + 1]; - } - } - - #region Abstract - - public override void RefreshOverlappingPairs() - { - } - - public override BroadphaseProxy CreateProxy(Vector3 min, Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask) - { - ushort handleId = AddHandle(min, max, userData, collisionFilterGroup, collisionFilterMask); - - Handle handle = GetHandle(handleId); - - return handle; - } - - public override void DestroyProxy(BroadphaseProxy proxy) - { - Handle handle = proxy as Handle; - RemoveHandle(handle.HandleID); - } - - public override void SetAabb(BroadphaseProxy proxy, Vector3 aabbMin, Vector3 aabbMax) - { - Handle handle = proxy as Handle; - UpdateHandle(handle.HandleID, aabbMin, aabbMax); - } - #endregion - } - - public class Edge - { - ushort position; - ushort handle; - - public ushort Position - { - get { return position; } - set { position = value; } - } - - public ushort Handle - { - get { return handle; } - set { handle = value; } - } - - public bool IsMax() - { - return (position & (ushort)1) == 1; - } - - public void Swap(ref Edge e) - { - ushort tmpPosition = this.position; - ushort tmpHandle = this.handle; - this.position = e.position; - this.handle = e.handle; - e.position = tmpPosition; - e.handle = tmpHandle; - } - } - - public class Handle: BroadphaseProxy - { - ushort[] minEdges, maxEdges; - ushort pad; - ushort handleID; - - public ushort[] MinEdges - { - get { return minEdges; } - set { minEdges = value; } - } - - public ushort[] MaxEdges - { - get { return maxEdges; } - set { maxEdges = value; } - } - - public ushort HandleID - { - get { return handleID; } - set { handleID = value; } - } - - public ushort Pad - { - get { return pad; } - set { pad = value; } - } - - public ushort NextFree - { - get { return minEdges[0]; } - set { minEdges[0] = value;} - } - - public Handle() - { - minEdges = new ushort[3]; - maxEdges = new ushort[3]; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/BroadphaseNativeTypes.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/BroadphaseNativeTypes.cs deleted file mode 100644 index dcfd0d870..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/BroadphaseNativeTypes.cs +++ /dev/null @@ -1,68 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - /// Dispatcher uses these types - /// IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and concave - /// to facilitate type checking - public enum BroadphaseNativeTypes - { - // polyhedral convex shapes - Box, - Triangle, - Tetrahedral, - ConvexTriangleMesh, - ConvexHull, - //implicit convex shapes - ImplicitConvexShapes, - Sphere, - MultiSphere, - Capsule, - Cone, - Convex, - Cylinder, - MinkowskiSum, - MinkowskiDifference, - //concave shapes - ConcaveShapesStart, - //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy! - TriangleMesh, - //used for demo integration FAST/Swift collision library and Bullet - FastConcaveMesh, - //terrain - Terrain, - //Used for GIMPACT Trimesh integration - Gimpact, - - Empty, - StaticPlane, - ConcaveShapesEnd, - - Compound, - - MaxBroadphaseCollisionTypes, - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/BroadphasePair.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/BroadphasePair.cs deleted file mode 100644 index 2b9e114eb..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/BroadphasePair.cs +++ /dev/null @@ -1,113 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public class BroadphasePair - { - private BroadphaseProxy _proxyA; - private BroadphaseProxy _proxyB; - - private CollisionAlgorithm _algorithm; - private object _userInfo; - - public BroadphasePair() - { - } - - public BroadphasePair(BroadphasePair other) - { - _proxyA = other._proxyA; - _proxyB = other._proxyB; - - _algorithm = other._algorithm; - _userInfo = null; - } - - public BroadphasePair(BroadphaseProxy proxyA, BroadphaseProxy proxyB) - { - _proxyA = proxyA; - _proxyB = proxyB; - - _algorithm = null; - _userInfo = null; - } - - public BroadphaseProxy ProxyA { get { return _proxyA; } set { _proxyA = value; } } - public BroadphaseProxy ProxyB { get { return _proxyB; } set { _proxyB = value; } } - - public CollisionAlgorithm CollisionAlgorithm { get { return _algorithm; } set { _algorithm = value; } } - public object UserInfo { get { return _userInfo; } set { _userInfo = value; } } - - public override int GetHashCode() - { - return _proxyA.GetHashCode() ^ _proxyB.GetHashCode(); - } - - public override bool Equals(object obj) - { - if (obj is BroadphasePair) - return this == (BroadphasePair)obj; - return false; - } - - public static int ComparisonSort(BroadphasePair a, BroadphasePair b) - { - int aAId = a.ProxyA != null ? a.ProxyA.ComparisonID : -1; - int aBId = a.ProxyB != null ? a.ProxyB.ComparisonID : -1; - int aCId = a.CollisionAlgorithm != null ? a.CollisionAlgorithm.ComparisonID : -1; - int bAId = b.ProxyA != null ? b.ProxyA.ComparisonID : -1; - int bBId = b.ProxyB != null ? b.ProxyB.ComparisonID : -1; - int bCId = b.CollisionAlgorithm != null ? b.CollisionAlgorithm.ComparisonID : -1; - - if (aAId > bAId || - (a.ProxyA == b.ProxyA && aBId > bBId) || - (a.ProxyA == b.ProxyA && a.ProxyB == b.ProxyB && aCId > bCId)) - return -1; - else - return 1; - } - - public static bool operator ==(BroadphasePair a, BroadphasePair b) - { - if (object.Equals(a, null) && object.Equals(b, null)) - return true; - if (object.Equals(a, null) || object.Equals(b, null)) - return false; - - return (a.ProxyA == b.ProxyA) && (a.ProxyB == b.ProxyB); - } - - public static bool operator !=(BroadphasePair a, BroadphasePair b) - { - if (object.Equals(a, null) && object.Equals(b, null)) - return true; - if (object.Equals(a, null) || object.Equals(b, null)) - return false; - - return (a.ProxyA != b.ProxyA) || (a.ProxyB != b.ProxyB); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/BroadphaseProxy.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/BroadphaseProxy.cs deleted file mode 100644 index aed82d5da..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/BroadphaseProxy.cs +++ /dev/null @@ -1,91 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public class BroadphaseProxy - { - //Usually the client CollisionObject or Rigidbody class - private object _clientObject; - private CollisionFilterGroups _collisionFilterGroup; - private CollisionFilterGroups _collisionFilterMask; - private readonly int _comparisonID; - - private static int _globalCount = 0; - - public BroadphaseProxy() - { - _comparisonID = _globalCount++; - } - - public BroadphaseProxy(object userData, CollisionFilterGroups collisionFilterGroup, CollisionFilterGroups collisionFilterMask) - : this() - { - _clientObject = userData; - _collisionFilterGroup = collisionFilterGroup; - _collisionFilterMask = collisionFilterMask; - } - - public object ClientData { get { return _clientObject; } set { _clientObject = value; } } - public CollisionFilterGroups CollisionFilterGroup { get { return _collisionFilterGroup; } set { _collisionFilterGroup = value; } } - public CollisionFilterGroups CollisionFilterMask { get { return _collisionFilterMask; } set { _collisionFilterMask = value; } } - internal int ComparisonID { get { return _comparisonID; } } - - public static bool IsPolyhedral(BroadphaseNativeTypes proxyType) - { - return (proxyType < BroadphaseNativeTypes.ImplicitConvexShapes); - } - - public static bool IsConvex(BroadphaseNativeTypes proxyType) - { - return (proxyType < BroadphaseNativeTypes.ConcaveShapesStart); - } - - public static bool IsConcave(BroadphaseNativeTypes proxyType) - { - return ((proxyType > BroadphaseNativeTypes.ConcaveShapesStart) && - (proxyType < BroadphaseNativeTypes.ConcaveShapesEnd)); - } - public static bool IsCompound(BroadphaseNativeTypes proxyType) - { - return (proxyType == BroadphaseNativeTypes.Compound); - } - public static bool IsInfinite(BroadphaseNativeTypes proxyType) - { - return (proxyType == BroadphaseNativeTypes.StaticPlane); - } - - //optional filtering to cull potential collisions - public enum CollisionFilterGroups - { - Default = 1, - Static = 2, - Kinematic = 4, - Debris = 8, - Sensor = 16, - All = Default | Static | Kinematic | Debris | Sensor, - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/CollisionAlgorithm.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/CollisionAlgorithm.cs deleted file mode 100644 index 1e59ad8da..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/CollisionAlgorithm.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - /// - /// CollisionAlgorithm is an collision interface that is compatible with the Broadphase and Dispatcher. - /// It is persistent over frames - /// - public abstract class CollisionAlgorithm - { - private IDispatcher _dispatcher; - private readonly int _comparisonID = 0; - - private static int _globalCount = 0; - - public CollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo) - { - _comparisonID = _globalCount++; - _dispatcher = collisionAlgorithmConstructionInfo.Dispatcher; - } - - protected IDispatcher Dispatcher { get { return _dispatcher; } set { _dispatcher = value; } } - internal int ComparisonID { get { return _comparisonID; } } - - public abstract void ProcessCollision(CollisionObject colA, CollisionObject colB, DispatcherInfo dispatchInfo, ManifoldResult resultOut); - public abstract float CalculateTimeOfImpact(CollisionObject colA, CollisionObject colB, DispatcherInfo dispatchInfo, ManifoldResult resultOut); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/CollisionAlgorithmConstructionInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/CollisionAlgorithmConstructionInfo.cs deleted file mode 100644 index 381752a2c..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/CollisionAlgorithmConstructionInfo.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public struct CollisionAlgorithmConstructionInfo - { - private IDispatcher _dispatcher; - private PersistentManifold _manifold; - - public CollisionAlgorithmConstructionInfo(IDispatcher dispatcher) - { - _dispatcher = dispatcher; - _manifold = null; - } - - public IDispatcher Dispatcher { get { return _dispatcher; } set { _dispatcher = value; } } - public PersistentManifold Manifold { get { return _manifold; } set { _manifold = value; } } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/DispatcherInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/DispatcherInfo.cs deleted file mode 100644 index 8c0367f3b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/DispatcherInfo.cs +++ /dev/null @@ -1,54 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public enum DispatchFunction - { - Discrete = 1, - Continuous, - } - - public class DispatcherInfo - { - private float _timeStep; - private int _stepCount; - private DispatchFunction _dispatchFunc = DispatchFunction.Discrete; - private float _timeOfImpact = 1; - private bool _useContinuous; - private bool _enableSatConvex; - private bool _enableSpu; - private IDebugDraw _debugDraw; - - public float TimeStep { get { return _timeStep; } set { _timeStep = value; } } - public int StepCount { get { return _stepCount; } set { _stepCount = value; } } - public DispatchFunction DispatchFunction { get { return _dispatchFunc; } set { _dispatchFunc = value; } } - public float TimeOfImpact { get { return _timeOfImpact; } set { _timeOfImpact = value; } } - public bool UseContinuous { get { return _useContinuous; } set { _useContinuous = value; } } - public bool EnableSatConvex { get { return _enableSatConvex; } set { _enableSatConvex = value; } } - public bool enableSpu { get { return _enableSpu; } set { _enableSpu = value; } } - public IDebugDraw DebugDraw { get { return _debugDraw; } set { _debugDraw = value; } } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/IBroadphase.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/IBroadphase.cs deleted file mode 100644 index 8c77a2383..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/IBroadphase.cs +++ /dev/null @@ -1,36 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public interface IBroadphase - { - BroadphaseProxy CreateProxy(Vector3 min, Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask); - void DestroyProxy(BroadphaseProxy proxy); - void SetAabb(BroadphaseProxy proxy, Vector3 aabbMin, Vector3 aabbMax); - void CleanProxyFromPairs(BroadphaseProxy proxy); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/IDispatcher.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/IDispatcher.cs deleted file mode 100644 index 52831b770..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/IDispatcher.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public interface IDispatcher - { - CollisionAlgorithm FindAlgorithm(CollisionObject bodyA, CollisionObject bodyB, PersistentManifold sharedManifold); - CollisionAlgorithm FindAlgorithm(CollisionObject bodyA, CollisionObject bodyB); - PersistentManifold GetNewManifold(object bodyA, object bodyB); - void ReleaseManifold(PersistentManifold manifold); - void ClearManifold(PersistentManifold manifold); - bool NeedsCollision(CollisionObject bodyA, CollisionObject bodyB); - bool NeedsResponse(CollisionObject bodyA, CollisionObject bodyB); - void DispatchAllCollisionPairs(OverlappingPairCache pairCache, DispatcherInfo dispatchInfo); - PersistentManifold GetManifoldByIndex(int index); - - int ManifoldCount { get; } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/IOverlapCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/IOverlapCallback.cs deleted file mode 100644 index 4e128da19..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/IOverlapCallback.cs +++ /dev/null @@ -1,33 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public interface IOverlapCallback - { - //return true for deletion of the pair - bool ProcessOverlap(ref BroadphasePair pair); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/OverlappingPairCache.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/OverlappingPairCache.cs deleted file mode 100644 index 0bf5be6e1..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/OverlappingPairCache.cs +++ /dev/null @@ -1,159 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public abstract class OverlappingPairCache : IBroadphase - { - private static int _overlappingPairCount = 0; - private List _overlappingPairs = new List(); - //during the dispatch, check that user doesn't destroy/create proxy - private bool _blockedForChanges; - - public List OverlappingPairs { get { return _overlappingPairs; } set { _overlappingPairs = value; } } - public bool BlockedForChanges { get { return _blockedForChanges; } set { _blockedForChanges = value; } } - - public static int OverlappingPairCount { get { return _overlappingPairCount; } set { _overlappingPairCount = value; } } - - public void RemoveOverlappingPair(BroadphasePair pair) - { - if (!_overlappingPairs.Contains(pair)) - return; - - CleanOverlappingPair(ref pair); - _overlappingPairs.Remove(pair); - } - - public void AddOverlappingPair(BroadphaseProxy proxyA, BroadphaseProxy proxyB) - { - //don't add overlap with own - bool test = proxyA != proxyB; - BulletDebug.Assert(proxyA != proxyB); - - if (!NeedsBroadphaseCollision(proxyA, proxyB)) - return; - - BroadphasePair pair = new BroadphasePair(proxyA, proxyB); - _overlappingPairs.Add(pair); - _overlappingPairCount++; - } - - //this FindPair becomes really slow. Either sort the list to speedup the query, or - //use a different solution. It is mainly used for Removing overlapping pairs. Removal could be delayed. - //we could keep a linked list in each proxy, and store pair in one of the proxies (with lowest memory address) - //Also we can use a 2D bitmap, which can be useful for a future GPU implementation - public BroadphasePair FindPair(BroadphaseProxy proxyA, BroadphaseProxy proxyB) - { - if (!NeedsBroadphaseCollision(proxyA, proxyB)) - return null; - - BroadphasePair pair = new BroadphasePair(proxyA, proxyB); - for (int i = 0; i < _overlappingPairs.Count; i++) - { - if (_overlappingPairs[i] == pair) - { - return _overlappingPairs[i]; - } - } - - return null; - } - - public void CleanProxyFromPairs(BroadphaseProxy proxy) - { - for (int i = 0; i < _overlappingPairs.Count; i++) - { - BroadphasePair pair = _overlappingPairs[i]; - if (pair.ProxyA == proxy || - pair.ProxyB == proxy) - { - CleanOverlappingPair(ref pair); - _overlappingPairs[i] = pair; - } - } - } - - public void RemoveOverlappingPairsContainingProxy(BroadphaseProxy proxy) - { - for (int i = _overlappingPairs.Count - 1; i >= 0; i--) - { - BroadphasePair pair = _overlappingPairs[i]; - if (pair.ProxyA == proxy || - pair.ProxyB == proxy) - { - RemoveOverlappingPair(pair); - i++; - } - } - } - - public bool NeedsBroadphaseCollision(BroadphaseProxy proxy0, BroadphaseProxy proxy1) - { - bool collides = (proxy0.CollisionFilterGroup & proxy1.CollisionFilterMask) != 0; - collides = collides && ((proxy1.CollisionFilterGroup & proxy0.CollisionFilterMask) != 0); - - return collides; - } - - public virtual void ProcessAllOverlappingPairs(IOverlapCallback callback) - { - List deleting = new List(); - for (int i = 0; i < _overlappingPairs.Count; i++) - { - BroadphasePair p = _overlappingPairs[i]; - if (callback.ProcessOverlap(ref p)) - { - CleanOverlappingPair(ref p); - deleting.Add(p); - _overlappingPairCount--; - } - } - - for (int i = 0; i < deleting.Count; i++) - _overlappingPairs.Remove(deleting[i]); - } - - public void CleanOverlappingPair(ref BroadphasePair pair) - { - if (pair.CollisionAlgorithm != null) - { - if (pair.CollisionAlgorithm is IDisposable) - (pair.CollisionAlgorithm as IDisposable).Dispose(); - pair.CollisionAlgorithm = null; - } - } - - public abstract void RefreshOverlappingPairs(); - - #region IBroadphase Members - public abstract BroadphaseProxy CreateProxy(Microsoft.Xna.Framework.Vector3 min, Microsoft.Xna.Framework.Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask); - - public abstract void DestroyProxy(BroadphaseProxy proxy); - - public abstract void SetAabb(BroadphaseProxy proxy, Microsoft.Xna.Framework.Vector3 aabbMin, Microsoft.Xna.Framework.Vector3 aabbMax); - - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs deleted file mode 100644 index fbbda1a9e..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs +++ /dev/null @@ -1,128 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class SimpleBroadphase : OverlappingPairCache - { - private int _maxProxies; - private List _proxies = new List(); - - public SimpleBroadphase() - : this(16384) { } - - public SimpleBroadphase(int maxProxies) - : base() - { - _maxProxies = maxProxies; - } - - public override BroadphaseProxy CreateProxy(Vector3 min, Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask) - { - if (_proxies.Count >= _maxProxies) - { - BulletDebug.Assert(false); - return null; //should never happen, but don't let the game crash ;-) - } - BulletDebug.Assert(min.X <= max.X && min.Y <= max.Y && min.Z <= max.Z); - - SimpleBroadphaseProxy proxy = new SimpleBroadphaseProxy(min, max, shapeType, userData, collisionFilterGroup, collisionFilterMask); - _proxies.Add(proxy); - - return proxy; - } - - - public override void DestroyProxy(BroadphaseProxy proxy) - { - RemoveOverlappingPairsContainingProxy(proxy); - _proxies.Remove(proxy as SimpleBroadphaseProxy); - } - - public override void SetAabb(BroadphaseProxy proxy, Vector3 aabbMin, Vector3 aabbMax) - { - SimpleBroadphaseProxy simpleProxy = GetSimpleProxyFromProxy(proxy); - simpleProxy.Minimum = aabbMin; - simpleProxy.Maximum = aabbMax; - } - - private SimpleBroadphaseProxy GetSimpleProxyFromProxy(BroadphaseProxy proxy) - { - return proxy as SimpleBroadphaseProxy; - } - - public override void RefreshOverlappingPairs() - { - for (int i = 0; i < _proxies.Count; i++) - { - SimpleBroadphaseProxy proxyA = _proxies[i]; - - for (int j = i + 1; j < _proxies.Count; j++) - { - SimpleBroadphaseProxy proxyB = _proxies[j]; - - if (AabbOverlap(proxyA, proxyB)) - { - if (FindPair(proxyA, proxyB) == null) - { - AddOverlappingPair(proxyA, proxyB); - } - } - } - } - - CheckOverlapCallback check = new CheckOverlapCallback(); - ProcessAllOverlappingPairs(check); - } - - public static bool AabbOverlap(SimpleBroadphaseProxy proxyA, SimpleBroadphaseProxy proxyB) - { - return proxyA.Minimum.X <= proxyB.Maximum.X && proxyB.Minimum.X <= proxyA.Maximum.X && - proxyA.Minimum.Y <= proxyB.Maximum.Y && proxyB.Minimum.Y <= proxyA.Maximum.Y && - proxyA.Minimum.Z <= proxyB.Maximum.Z && proxyB.Minimum.Z <= proxyA.Maximum.Z; - } - - private void Validate() - { - for (int i = 0; i < _proxies.Count; i++) - { - for (int j = i + 1; j < _proxies.Count; j++) - { - if (_proxies[i] == _proxies[j]) - throw new BulletException(); - } - } - } - } - - public class CheckOverlapCallback : IOverlapCallback - { - public bool ProcessOverlap(ref BroadphasePair pair) - { - return (!SimpleBroadphase.AabbOverlap(pair.ProxyA as SimpleBroadphaseProxy, pair.ProxyB as SimpleBroadphaseProxy)); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/SimpleBroadphaseProxy.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/SimpleBroadphaseProxy.cs deleted file mode 100644 index 213462131..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/BroadphaseCollision/SimpleBroadphaseProxy.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class SimpleBroadphaseProxy : BroadphaseProxy - { - private Vector3 _min; - private Vector3 _max; - - public SimpleBroadphaseProxy() { } - - public SimpleBroadphaseProxy(Vector3 minPoint, Vector3 maxPoint, BroadphaseNativeTypes shapeType, object userData, CollisionFilterGroups collisionFilterGroup, CollisionFilterGroups collisionFilterMask) - : base(userData, collisionFilterGroup, collisionFilterMask) - { - _min = minPoint; - _max = maxPoint; - } - - public Vector3 Minimum { get { return _min; } set { _min = value; } } - public Vector3 Maximum { get { return _max; } set { _max = value; } } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/BridgeTriangleRaycastCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/BridgeTriangleRaycastCallback.cs deleted file mode 100644 index 3e9723be2..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/BridgeTriangleRaycastCallback.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - internal class BridgeTriangleRaycastCallback : TriangleRaycastCallback - { - CollisionWorld.RayResultCallback _resultCallback; - CollisionObject _collisionObject; - TriangleMeshShape _triangleMesh; - - public BridgeTriangleRaycastCallback(Vector3 from, Vector3 to, - CollisionWorld.RayResultCallback resultCallback, CollisionObject collisionObject, TriangleMeshShape triangleMesh) - : base(from, to) - { - _resultCallback = resultCallback; - _collisionObject = collisionObject; - _triangleMesh = triangleMesh; - } - - public override float ReportHit(Vector3 hitNormalLocal, float hitFraction, int partId, int triangleIndex) - { - CollisionWorld.LocalShapeInfo shapeInfo = new CollisionWorld.LocalShapeInfo(); - shapeInfo.ShapePart = partId; - shapeInfo.TriangleIndex = triangleIndex; - - CollisionWorld.LocalRayResult rayResult = new CollisionWorld.LocalRayResult - (_collisionObject, - shapeInfo, - hitNormalLocal, - hitFraction); - - return _resultCallback.AddSingleResult(rayResult); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionAlgorithmCreateFunc.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionAlgorithmCreateFunc.cs deleted file mode 100644 index edb783a7b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionAlgorithmCreateFunc.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class CollisionAlgorithmCreateFunction - { - private bool _swapped; - - public bool IsSwapped { get { return _swapped; } set { _swapped = value; } } - - public virtual CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo ci, CollisionObject body0, CollisionObject body1) - { - return null; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionDispatcher.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionDispatcher.cs deleted file mode 100644 index da868704e..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionDispatcher.cs +++ /dev/null @@ -1,280 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public delegate void NearCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo); - - public class CollisionDispatcher : IDispatcher - { - private List _manifolds = new List(); - - //private bool _useIslands; - private NearCallback _nearCallback; - - //private ManifoldResult _defaultManifoldResult; - - private CollisionAlgorithmCreateFunction[,] _doubleDispatch = new CollisionAlgorithmCreateFunction[(int)BroadphaseNativeTypes.MaxBroadphaseCollisionTypes, (int)BroadphaseNativeTypes.MaxBroadphaseCollisionTypes]; - - //default CreationFunctions, filling the m_doubleDispatch table - private CollisionAlgorithmCreateFunction _convexConvexCreateFunc; - private CollisionAlgorithmCreateFunction _convexConcaveCreateFunc; - private CollisionAlgorithmCreateFunction _swappedConvexConcaveCreateFunc; - private CollisionAlgorithmCreateFunction _compoundCreateFunc; - private CollisionAlgorithmCreateFunction _swappedCompoundCreateFunc; - private CollisionAlgorithmCreateFunction _emptyCreateFunc; - - private int _count; - private static int _manifoldCount = 0; - - public CollisionDispatcher() - { - NearCallback = DefaultNearCallback; - //_useIslands = true; - //default CreationFunctions, filling the m_doubleDispatch table - _convexConvexCreateFunc = new ConvexConvexAlgorithm.CreateFunc(); - _convexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm.CreateFunc(); - _swappedConvexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm.SwappedCreateFunc(); - _compoundCreateFunc = new CompoundCollisionAlgorithm.CreateFunc(); - _swappedCompoundCreateFunc = new CompoundCollisionAlgorithm.SwappedCreateFunc(); - _emptyCreateFunc = new EmptyAlgorithm.CreateFunc(); - - for (BroadphaseNativeTypes i = BroadphaseNativeTypes.Box; i < BroadphaseNativeTypes.MaxBroadphaseCollisionTypes; i++) - { - for (BroadphaseNativeTypes j = BroadphaseNativeTypes.Box; j < BroadphaseNativeTypes.MaxBroadphaseCollisionTypes; j++) - { - _doubleDispatch[(int)i, (int)j] = FindCreateFunction(i, j); - if (_doubleDispatch[(int)i, (int)j] == null) - throw new BulletException(); - } - } - } - - public int Count { get { return _count; } set { _count = value; } } - public int ManifoldCount { get { return _manifolds.Count; } } - public List Manifolds { get { return _manifolds; } } - - public static int GlobalManifoldCount { get { return _manifoldCount; } set { _manifoldCount = value; } } - - public PersistentManifold GetManifoldByIndex(int index) - { - return _manifolds[index]; - } - - //registerCollisionCreateFunc allows registration of custom/alternative collision create functions - public void RegisterCollisionCreateFunc(BroadphaseNativeTypes proxyTypeA, BroadphaseNativeTypes proxyTypeB, CollisionAlgorithmCreateFunction createFunc) - { - _doubleDispatch[(int)proxyTypeA, (int)proxyTypeB] = createFunc; - } - - public virtual PersistentManifold GetNewManifold(object bodyA, object bodyB) - { - _manifoldCount++; - - CollisionObject body0 = bodyA as CollisionObject; - CollisionObject body1 = bodyB as CollisionObject; - - PersistentManifold manifold = new PersistentManifold(body0, body1); - _manifolds.Add(manifold); - - return manifold; - } - - public virtual void ReleaseManifold(PersistentManifold manifold) - { - _manifoldCount--; - - ClearManifold(manifold); - _manifolds.Remove(manifold); - } - - - public virtual void ClearManifold(PersistentManifold manifold) - { - manifold.ClearManifold(); - } - - public CollisionAlgorithm FindAlgorithm(CollisionObject bodyA, CollisionObject bodyB) - { - return FindAlgorithm(bodyA, bodyB, null); - } - - public CollisionAlgorithm FindAlgorithm(CollisionObject bodyA, CollisionObject bodyB, PersistentManifold sharedManifold) - { - CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo = new CollisionAlgorithmConstructionInfo(); - collisionAlgorithmConstructionInfo.Dispatcher = this; - collisionAlgorithmConstructionInfo.Manifold = sharedManifold; - CollisionAlgorithm collisionAlgorithm = _doubleDispatch[(int)bodyA.CollisionShape.ShapeType, (int)bodyB.CollisionShape.ShapeType].CreateCollisionAlgorithm(collisionAlgorithmConstructionInfo, bodyA, bodyB); - return collisionAlgorithm; - } - - /*public CollisionAlgorithm internalFindAlgorithm(CollisionObject body0, CollisionObject body1) - { - return internalFindAlgorithm(body0, body1, null); - } - - public CollisionAlgorithm internalFindAlgorithm(CollisionObject body0, CollisionObject body1, PersistentManifold sharedManifold) - { - m_count++; - - CollisionAlgorithmConstructionInfo ci = new CollisionAlgorithmConstructionInfo(); - ci.m_dispatcher = this; - - if (body0.getCollisionShape().isConvex() && body1.getCollisionShape().isConvex()) - { - return new ConvexConvexAlgorithm(sharedManifold, ci, body0, body1); - } - - if (body0.getCollisionShape().isConvex() && body1.getCollisionShape().isConcave()) - { - return new ConvexConcaveCollisionAlgorithm(ci, body0, body1, false); - } - - if (body1.getCollisionShape().isConvex() && body0.getCollisionShape().isConcave()) - { - return new ConvexConcaveCollisionAlgorithm(ci, body0, body1, true); - } - - if (body0.getCollisionShape().isCompound()) - { - return new CompoundCollisionAlgorithm(ci, body0, body1, false); - } - else - { - if (body1.getCollisionShape().isCompound()) - { - return new CompoundCollisionAlgorithm(ci, body0, body1, true); - } - } - - //failed to find an algorithm - return new EmptyAlgorithm(ci); - }*/ - - public virtual bool NeedsCollision(CollisionObject bodyA, CollisionObject bodyB) - { - if (bodyA == null || bodyB == null) - throw new BulletException(); - - bool needsCollision = true; - - //broadphase filtering already deals with this - /*if ((body0.isStaticObject() || body0.isKinematicObject()) && - (body1.isStaticObject() || body1.isKinematicObject())) - { - printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n"); - }*/ - - if ((!bodyA.IsActive) && (!bodyB.IsActive)) - needsCollision = false; - - return needsCollision; - } - - public virtual bool NeedsResponse(CollisionObject bodyA, CollisionObject bodyB) - { - //here you can do filtering - bool hasResponse = bodyA.HasContactResponse && bodyB.HasContactResponse; - hasResponse = hasResponse && (!bodyA.IsStaticOrKinematicObject || !bodyB.IsStaticOrKinematicObject); - return hasResponse; - } - - public virtual void DispatchAllCollisionPairs(OverlappingPairCache pairCache, DispatcherInfo dispatchInfo) - { - CollisionPairCallback collisionCallback = new CollisionPairCallback(dispatchInfo, this); - pairCache.ProcessAllOverlappingPairs(collisionCallback); - } - - private CollisionAlgorithmCreateFunction FindCreateFunction(BroadphaseNativeTypes proxyTypeA, BroadphaseNativeTypes proxyTypeB) - { - if (BroadphaseProxy.IsConvex(proxyTypeA) && BroadphaseProxy.IsConvex(proxyTypeB)) - { - return _convexConvexCreateFunc; - } - - if (BroadphaseProxy.IsConvex(proxyTypeA) && BroadphaseProxy.IsConcave(proxyTypeB)) - { - return _convexConcaveCreateFunc; - } - - if (BroadphaseProxy.IsConvex(proxyTypeB) && BroadphaseProxy.IsConcave(proxyTypeA)) - { - return _swappedConvexConcaveCreateFunc; - } - - if (BroadphaseProxy.IsCompound(proxyTypeA)) - { - return _compoundCreateFunc; - } - else - { - if (BroadphaseProxy.IsCompound(proxyTypeB)) - { - return _swappedCompoundCreateFunc; - } - } - - //failed to find an algorithm - return _emptyCreateFunc; - } - - public NearCallback NearCallback { get { return _nearCallback; } set { _nearCallback = value; } } - - //by default, Bullet will use this near callback - public static void DefaultNearCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo) - { - CollisionObject collisionObjectA = collisionPair.ProxyA.ClientData as CollisionObject; - CollisionObject collisionObjectB = collisionPair.ProxyB.ClientData as CollisionObject; - - if (dispatcher.NeedsCollision(collisionObjectA, collisionObjectB)) - { - //dispatcher will keep algorithms persistent in the collision pair - if (collisionPair.CollisionAlgorithm == null) - { - collisionPair.CollisionAlgorithm = dispatcher.FindAlgorithm(collisionObjectA, collisionObjectB); - } - - if (collisionPair.CollisionAlgorithm != null) - { - ManifoldResult contactPointResult = new ManifoldResult(collisionObjectA, collisionObjectB); - - if (dispatchInfo.DispatchFunction == DispatchFunction.Discrete) - { - //discrete collision detection query - collisionPair.CollisionAlgorithm.ProcessCollision(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult); - } - else - { - //continuous collision detection query, time of impact (toi) - float timeOfImpact = collisionPair.CollisionAlgorithm.CalculateTimeOfImpact(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult); - if (dispatchInfo.TimeOfImpact > timeOfImpact) - dispatchInfo.TimeOfImpact = timeOfImpact; - } - } - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionObject.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionObject.cs deleted file mode 100644 index d3448a269..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionObject.cs +++ /dev/null @@ -1,163 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public enum ActivationState - { - Nothing = 0, - Active, - IslandSleeping, - WantsDeactivation, - DisableDeactivation, - DisableSimulation, - } - - public enum CollisionOptions - { - StaticObject = 1, - KinematicObject = 2, - NoContactResponse = 4, - CustomMaterialCallback = 8,//this allows per-triangle material (friction/restitution) - } - - /// - /// btCollisionObject can be used to manage collision detection objects. - /// btCollisionObject maintains all information that is needed for a collision detection: Shape, Transform and AABB proxy. - /// They can be added to the btCollisionWorld. - /// - public class CollisionObject - { - protected Matrix _worldTransform; - private BroadphaseProxy _broadphase; - private CollisionShape _collisionShape; - - //m_interpolationWorldTransform is used for CCD and interpolation - //it can be either previous or future (predicted) transform - private Matrix _interpolationWorldTransform; - - private CollisionOptions _collisionFlags; - - private int _islandTag; - private ActivationState _activationState; - private float _deactivationTime; - - private float _friction; - private float _restitution; - - //users can point to their objects, m_userPointer is not used by Bullet - private object _userData; - - //m_internalOwner one is used by optional Bullet high level interface - private object _internalOwner; - - //time of impact calculation - private float _hitFraction; - - //Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm:: - private float _ccdSweptSphereRadius; - - // Don't do continuous collision detection if square motion (in one step) is less then m_ccdSquareMotionTreshold - private float _ccdSquareMotionThreshold; - //those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities) - //without destroying the continuous interpolated motion (which uses this interpolation velocities) - private Vector3 _interpolationLinearVelocity; - private Vector3 _interpolationAngularVelocity; - - private int _companionID; - - public CollisionObject() - { - _activationState = ActivationState.Active; - _hitFraction = 1; - } - - public bool IsStaticObject { get { return (_collisionFlags & CollisionOptions.StaticObject) != 0; } } - public bool IsKinematicObject { get { return (_collisionFlags & CollisionOptions.KinematicObject) != 0; } } - public bool IsStaticOrKinematicObject { get { return (_collisionFlags & (CollisionOptions.KinematicObject | CollisionOptions.StaticObject)) != 0; } } - - public bool HasContactResponse { get { return (_collisionFlags & CollisionOptions.NoContactResponse) == 0; } } - public bool MergesSimulationIslands - { - get - { - //static objects, kinematic and object without contact response don't merge islands - return (_collisionFlags & (CollisionOptions.StaticObject | CollisionOptions.KinematicObject | CollisionOptions.NoContactResponse)) == 0; - } - } - - public ActivationState ActivationState - { - get { return _activationState; } - set - { - if ((_activationState != ActivationState.DisableDeactivation) && (_activationState != ActivationState.DisableSimulation)) - _activationState = value; - } - } - - public bool IsActive { get { return ((ActivationState != ActivationState.IslandSleeping) && (ActivationState != ActivationState.DisableSimulation)); } } - public float Restitution { get { return _restitution; } set { _restitution = value; } } - public float Friction { get { return _friction; } set { _friction = value; } } - public CollisionShape CollisionShape { get { return _collisionShape; } set { _collisionShape = value; } } - public float DeactivationTime { get { return _deactivationTime; } set { _deactivationTime = value; } } - public object Owner { get { return _internalOwner; } protected set { _internalOwner = value; } } - public Matrix WorldTransform { get { return _worldTransform; } set { _worldTransform = value; } } - public BroadphaseProxy Broadphase { get { return _broadphase; } set { _broadphase = value; } } - public Matrix InterpolationWorldTransform { get { return _interpolationWorldTransform; } set { _interpolationWorldTransform = value; } } - public Vector3 InterpolationLinearVelocity { get { return _interpolationLinearVelocity; } protected set { _interpolationLinearVelocity = value; } } - public Vector3 InterpolationAngularVelocity { get { return _interpolationAngularVelocity; } protected set { _interpolationAngularVelocity = value; } } - public int IslandTag { get { return _islandTag; } set { _islandTag = value; } } - public float HitFraction { get { return _hitFraction; } set { _hitFraction = value; } } - public CollisionOptions CollisionFlags { get { return _collisionFlags; } set { _collisionFlags = value; } } - //Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm - public float CcdSweptSphereRadius { get { return _ccdSweptSphereRadius; } set { _ccdSweptSphereRadius = value; } } - // Don't do continuous collision detection if square motion (in one step) is less then m_ccdSquareMotionThreshold - public float CcdSquareMotionThreshold { get { return _ccdSquareMotionThreshold; } set { _ccdSquareMotionThreshold = value; } } - //users can point to their objects, userPointer is not used by Bullet - public object UserData { get { return _userData; } set { _userData = value; } } - public int CompanionID { get { return _companionID; } set { _companionID = value; } } - - public void ForceActivationState(ActivationState newState) - { - _activationState = newState; - } - - public void Activate() - { - Activate(false); - } - - public void Activate(bool forceActivation) - { - if (forceActivation || (_collisionFlags & (CollisionOptions.StaticObject | CollisionOptions.KinematicObject)) == 0) - { - ActivationState = ActivationState.Active; - _deactivationTime = 0; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionPairCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionPairCallback.cs deleted file mode 100644 index 91752f1aa..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionPairCallback.cs +++ /dev/null @@ -1,48 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class CollisionPairCallback : IOverlapCallback - { - private DispatcherInfo _dispatchInfo; - private CollisionDispatcher _dispatcher; - - public CollisionPairCallback(DispatcherInfo dispatchInfo, CollisionDispatcher dispatcher) - { - _dispatchInfo = dispatchInfo; - _dispatcher = dispatcher; - } - - #region IOverlapCallback Members - public bool ProcessOverlap(ref BroadphasePair pair) - { - _dispatcher.NearCallback(ref pair, _dispatcher, _dispatchInfo); - return false; - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionWorld.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionWorld.cs deleted file mode 100644 index 1b3d7394c..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CollisionWorld.cs +++ /dev/null @@ -1,358 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class CollisionWorld - { - private List _collisionObjects = new List(); - private IDispatcher _dispatcher; - private OverlappingPairCache _broadphasePairCache; - private bool _ownsDispatcher; - private bool _ownsBroadphasePairCache; - private DispatcherInfo _dispatchInfo = new DispatcherInfo(); - - /// - /// this constructor doesn't own the dispatcher and paircache/broadphase - /// - /// - /// - public CollisionWorld(IDispatcher dispatcher, OverlappingPairCache pairCache) - { - _dispatcher = dispatcher; - _broadphasePairCache = pairCache; - _ownsDispatcher = false; - _ownsBroadphasePairCache = false; - } - - public DispatcherInfo DispatchInfo { get { return _dispatchInfo; } protected set { _dispatchInfo = value; } } - public List CollisionObjects { get { return _collisionObjects; } protected set { _collisionObjects = value; } } - public IBroadphase Broadphase { get { return _broadphasePairCache; } } - public OverlappingPairCache BroadphasePairCache { get { return _broadphasePairCache; } protected set { _broadphasePairCache = value; } } - public IDispatcher Dispatcher { get { return _dispatcher; } protected set { _dispatcher = value; } } - public int CollisionObjectsCount { get { return _collisionObjects.Count; } } - protected bool OwnsDispatcher { get { return _ownsDispatcher; } set { _ownsDispatcher = value; } } - protected bool OwnsBroadphasePairCache { get { return _ownsBroadphasePairCache; } set { _ownsBroadphasePairCache = value; } } - - // rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback - // This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback. - public void RayTest(Vector3 rayFromWorld, Vector3 rayToWorld, RayResultCallback resultCallback) - { - Matrix rayFromTrans, rayToTrans; - - rayFromTrans = Matrix.Identity; - rayFromTrans.Translation = rayFromWorld; - - rayToTrans = Matrix.Identity; - rayToTrans.Translation = rayToWorld; - - // brute force go over all objects. Once there is a broadphase, use that, or - // add a raycast against aabb first. - - foreach (CollisionObject collisionObject in _collisionObjects) - { - //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject(); - Vector3 collisionObjectAabbMin, collisionObjectAabbMax; - collisionObject.CollisionShape.GetAabb(collisionObject.WorldTransform, out collisionObjectAabbMin, out collisionObjectAabbMax); - - float hitLambda = 1f; //could use resultCallback.m_closestHitFraction, but needs testing - Vector3 hitNormal = new Vector3(); - - //if (MathHelper.TestAabbAgainstAabb2(rayAabbMin, rayAabbMax, collisionObjectAabbMin, collisionObjectAabbMax)) - if (MathHelper.RayAabb(rayFromWorld, rayToWorld, collisionObjectAabbMin, collisionObjectAabbMax, hitLambda, hitNormal)) - { - RayTestSingle(rayFromTrans, rayToTrans, - collisionObject, collisionObject.CollisionShape, - collisionObject.WorldTransform, resultCallback); - - } - } - } - - // rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest. - // In a future implementation, we consider moving the ray test as a virtual method in CollisionShape. - // This allows more customization. - public static void RayTestSingle(Matrix rayFromTrans, Matrix rayToTrans, - CollisionObject collisionObject, - CollisionShape collisionShape, - Matrix colObjWorldTransform, - RayResultCallback resultCallback) - { - SphereShape pointShape=new SphereShape(0.0f); - - if (collisionShape.IsConvex) - { - CastResult castResult = new CastResult(); - castResult.Fraction = 1f;//?? - - ConvexShape convexShape = collisionShape as ConvexShape; - VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver(); - SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(pointShape, convexShape, simplexSolver); - //GjkConvexCast convexCaster(&pointShape,convexShape,&simplexSolver); - //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0); - - if (convexCaster.CalcTimeOfImpact(rayFromTrans, rayToTrans, colObjWorldTransform, colObjWorldTransform, castResult)) - { - //add hit - if (castResult.Normal.LengthSquared() > 0.0001f) - { - castResult.Normal.Normalize(); - if (castResult.Fraction < resultCallback.ClosestHitFraction) - { - - CollisionWorld.LocalRayResult localRayResult = new LocalRayResult - ( - collisionObject, - new LocalShapeInfo(), - castResult.Normal, - castResult.Fraction - ); - - resultCallback.AddSingleResult(localRayResult); - } - } - } - else - { - if (collisionShape.IsConcave) - { - - TriangleMeshShape triangleMesh = collisionShape as TriangleMeshShape; - - Matrix worldTocollisionObject = MathHelper.InvertMatrix(colObjWorldTransform); - - Vector3 rayFromLocal = Vector3.TransformNormal(rayFromTrans.Translation, worldTocollisionObject); - Vector3 rayToLocal = Vector3.TransformNormal(rayToTrans.Translation, worldTocollisionObject); - - BridgeTriangleRaycastCallback rcb = new BridgeTriangleRaycastCallback(rayFromLocal, rayToLocal, resultCallback, collisionObject, triangleMesh); - rcb.HitFraction = resultCallback.ClosestHitFraction; - - Vector3 rayAabbMinLocal = rayFromLocal; - MathHelper.SetMin(ref rayAabbMinLocal, rayToLocal); - Vector3 rayAabbMaxLocal = rayFromLocal; - MathHelper.SetMax(ref rayAabbMaxLocal, rayToLocal); - - triangleMesh.ProcessAllTriangles(rcb, rayAabbMinLocal, rayAabbMaxLocal); - } - else - { - //todo: use AABB tree or other BVH acceleration structure! - if (collisionShape.IsCompound) - { - CompoundShape compoundShape = collisionShape as CompoundShape; - for (int i = 0; i < compoundShape.ChildShapeCount; i++) - { - Matrix childTrans = compoundShape.GetChildTransform(i); - CollisionShape childCollisionShape = compoundShape.GetChildShape(i); - Matrix childWorldTrans = colObjWorldTransform * childTrans; - RayTestSingle(rayFromTrans, rayToTrans, - collisionObject, - childCollisionShape, - childWorldTrans, - resultCallback); - } - } - } - } - } - } - - public void AddCollisionObject(CollisionObject collisionObject, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask) - { - //check that the object isn't already added - if (!_collisionObjects.Contains(collisionObject)) - { - _collisionObjects.Add(collisionObject); - - //calculate new AABB - Matrix trans = collisionObject.WorldTransform; - - Vector3 minAabb; - Vector3 maxAabb; - collisionObject.CollisionShape.GetAabb(trans, out minAabb, out maxAabb); - - BroadphaseNativeTypes type = collisionObject.CollisionShape.ShapeType; - collisionObject.Broadphase = Broadphase.CreateProxy( - minAabb, - maxAabb, - type, - collisionObject, - collisionFilterGroup, - collisionFilterMask - ); - } - } - - public void AddCollisionObject(CollisionObject collisionObject) - { - AddCollisionObject(collisionObject, BroadphaseProxy.CollisionFilterGroups.Default, BroadphaseProxy.CollisionFilterGroups.Default); - } - - public void RemoveCollisionObject(CollisionObject collisionObject) - { - BroadphaseProxy bp = collisionObject.Broadphase; - if (bp != null) - { - // - // only clear the cached algorithms - // - Broadphase.CleanProxyFromPairs(bp); - Broadphase.DestroyProxy(bp); - collisionObject.Broadphase = null; - } - - _collisionObjects.Remove(collisionObject); - } - - public virtual void PerformDiscreteCollisionDetection() - { - DispatcherInfo dispatchInfo = DispatchInfo; - //update aabb (of all moved objects) - - Vector3 aabbMin, aabbMax; - for (int i = 0; i < _collisionObjects.Count; i++) - { - _collisionObjects[i].CollisionShape.GetAabb(_collisionObjects[i].WorldTransform, out aabbMin, out aabbMax); - _broadphasePairCache.SetAabb(_collisionObjects[i].Broadphase, aabbMin, aabbMax); - } - - _broadphasePairCache.RefreshOverlappingPairs(); - - IDispatcher dispatcher = Dispatcher; - if (dispatcher != null) - dispatcher.DispatchAllCollisionPairs(_broadphasePairCache, dispatchInfo); - } - - public void Dispose(bool disposing) - { - if (disposing) - { - //clean up remaining objects - foreach (CollisionObject collisionObject in _collisionObjects) - { - BroadphaseProxy bp = collisionObject.Broadphase; - if (bp != null) - { - // - // only clear the cached algorithms - // - Broadphase.CleanProxyFromPairs(bp); - Broadphase.DestroyProxy(bp); - } - } - } - } - - /// - /// LocalShapeInfo gives extra information for complex shapes - /// Currently, only TriangleMeshShape is available, so it just contains triangleIndex and subpart - /// - public struct LocalShapeInfo - { - private int _shapePart; - private int _triangleIndex; - - public int ShapePart { get { return _shapePart; } set { _shapePart = value; } } - public int TriangleIndex { get { return _triangleIndex; } set { _triangleIndex = value; } } - } - - public struct LocalRayResult - { - private CollisionObject _collisionObject; - private LocalShapeInfo _localShapeInfo; - private Vector3 _hitNormalLocal; - private float _hitFraction; - - public LocalRayResult(CollisionObject collisionObject, - LocalShapeInfo localShapeInfo, - Vector3 hitNormalLocal, - float hitFraction) - { - _collisionObject = collisionObject; - _localShapeInfo = localShapeInfo; - _hitNormalLocal = hitNormalLocal; - _hitFraction = hitFraction; - } - - public CollisionObject CollisionObject { get { return _collisionObject; } set { _collisionObject = value; } } - public LocalShapeInfo LocalShapeInfo { get { return _localShapeInfo; } set { _localShapeInfo = value; } } - public Vector3 HitNormalLocal { get { return _hitNormalLocal; } set { _hitNormalLocal = value; } } - public float HitFraction { get { return _hitFraction; } set { _hitFraction = value; } } - } - - /// - /// RayResultCallback is used to report new raycast results - /// - public abstract class RayResultCallback - { - private float _closestHitFraction; - - public RayResultCallback() - { - _closestHitFraction = 1; - } - - public float ClosestHitFraction { get { return _closestHitFraction; } set { _closestHitFraction = value; } } - public bool HasHit { get { return _closestHitFraction < 1; } } - - public abstract float AddSingleResult(LocalRayResult rayResult); - } - - public class ClosestRayResultCallback : RayResultCallback - { - private Vector3 _rayFromWorld;//used to calculate hitPointWorld from hitFraction - private Vector3 _rayToWorld; - - private Vector3 _hitNormalWorld; - private Vector3 _hitPointWorld; - private CollisionObject _collisionObject; - - public ClosestRayResultCallback(Vector3 rayFromWorld, Vector3 rayToWorld) - { - _rayFromWorld = rayFromWorld; - _rayToWorld = rayToWorld; - _collisionObject = null; - } - - public Vector3 RayFromWorld { get { return _rayFromWorld; } set { _rayFromWorld = value; } } - public Vector3 RayToWorld { get { return _rayToWorld; } set { _rayToWorld = value; } } - public Vector3 HitNormalWorld { get { return _hitNormalWorld; } set { _hitNormalWorld = value; } } - public Vector3 HitPointWorld { get { return _hitPointWorld; } set { _hitPointWorld = value; } } - public CollisionObject CollisionObject { get { return _collisionObject; } set { _collisionObject = value; } } - - public override float AddSingleResult(LocalRayResult rayResult) - { - //caller already does the filter on the m_closestHitFraction - //assert(rayResult.m_hitFraction <= m_closestHitFraction); - ClosestHitFraction = rayResult.HitFraction; - _collisionObject = rayResult.CollisionObject; - _hitNormalWorld = Vector3.TransformNormal(rayResult.HitNormalLocal, _collisionObject.WorldTransform); - MathHelper.SetInterpolate3(_rayFromWorld, _rayToWorld, rayResult.HitFraction, ref _hitPointWorld); - return rayResult.HitFraction; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CompoundCollisionAlgorithm.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CompoundCollisionAlgorithm.cs deleted file mode 100644 index a52c2fc0c..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/CompoundCollisionAlgorithm.cs +++ /dev/null @@ -1,157 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using System.Diagnostics; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class CompoundCollisionAlgorithm : CollisionAlgorithm - { - private List _childCollisionAlgorithms; - private bool _isSwapped; - - public CompoundCollisionAlgorithm( - CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, - CollisionObject bodyA, - CollisionObject bodyB, bool isSwapped) - : base(collisionAlgorithmConstructionInfo) - { - //Begin - _isSwapped = isSwapped; - - CollisionObject collisionObject = isSwapped ? bodyB : bodyA; - CollisionObject otherObject = isSwapped ? bodyA : bodyB; - - BulletDebug.Assert(collisionObject.CollisionShape.IsCompound); - - CompoundShape compoundShape = collisionObject.CollisionShape as CompoundShape; - int childrenNumber = compoundShape.ChildShapeCount; - int index = 0; - - _childCollisionAlgorithms = new List(childrenNumber); - - for (index = 0; index < childrenNumber; index++) - { - CollisionShape childShape = compoundShape.GetChildShape(index); - CollisionShape orgShape = collisionObject.CollisionShape; - - collisionObject.CollisionShape = childShape; - _childCollisionAlgorithms[index] = collisionAlgorithmConstructionInfo.Dispatcher.FindAlgorithm(collisionObject, otherObject); - collisionObject.CollisionShape = orgShape; - } - } - - public override void ProcessCollision( - CollisionObject bodyA, - CollisionObject bodyB, - DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - //Begin - - CollisionObject collisionObject = _isSwapped ? bodyB : bodyB; - CollisionObject otherObject = _isSwapped ? bodyA : bodyB; - - //Debug.Assert(collisionObject.getCollisionShape().isCompound()); - BulletDebug.Assert(collisionObject.CollisionShape.IsCompound); - - CompoundShape compoundShape = (CompoundShape)collisionObject.CollisionShape; - - int childrenNumber = _childCollisionAlgorithms.Count; - - for (int i = 0; i < childrenNumber; i++) - { - CompoundShape childShape = compoundShape.GetChildShape(i) as CompoundShape; - - Matrix orgTransform = collisionObject.WorldTransform; - CollisionShape orgShape = collisionObject.CollisionShape; - - Matrix childTransform = compoundShape.GetChildTransform(i); - Matrix newChildWorld = orgTransform * childTransform; - - collisionObject.WorldTransform = newChildWorld; - collisionObject.CollisionShape = childShape; - _childCollisionAlgorithms[i].ProcessCollision(collisionObject, otherObject, dispatchInfo, resultOut); - - collisionObject.CollisionShape = orgShape; - collisionObject.WorldTransform = orgTransform; - } - } - - public override float CalculateTimeOfImpact(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - CollisionObject collisionObject = _isSwapped ? bodyB : bodyA; - CollisionObject otherObject = _isSwapped ? bodyA : bodyB; - - BulletDebug.Assert(collisionObject.CollisionShape.IsCompound); - - CompoundShape compoundShape = (CompoundShape)collisionObject.CollisionShape; - - float hitFraction = 1.0f; - - for (int i = 0; i < _childCollisionAlgorithms.Count; i++) - { - CollisionShape childShape = compoundShape.GetChildShape(i); - - Matrix orgTransform = collisionObject.WorldTransform; - CollisionShape orgShape = collisionObject.CollisionShape; - - Matrix childTransform = compoundShape.GetChildTransform(i); - Matrix newChildWorld = orgTransform * childTransform; - collisionObject.WorldTransform = newChildWorld; - - collisionObject.CollisionShape = childShape; - float frac = _childCollisionAlgorithms[i].CalculateTimeOfImpact( - collisionObject, otherObject, dispatchInfo, resultOut - ); - - if (frac < hitFraction) - { - hitFraction = frac; - } - - collisionObject.CollisionShape = orgShape; - collisionObject.WorldTransform = orgTransform; - } - - return hitFraction; - } - - public class CreateFunc : CollisionAlgorithmCreateFunction - { - public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - { - return new CompoundCollisionAlgorithm(collisionAlgorithmConstructionInfo, bodyA, bodyB, false); - } - }; - - public class SwappedCreateFunc : CollisionAlgorithmCreateFunction - { - public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - { - return new CompoundCollisionAlgorithm(collisionAlgorithmConstructionInfo, bodyA, bodyB, true); - } - }; - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cs deleted file mode 100644 index 97ed0959f..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cs +++ /dev/null @@ -1,189 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class ConvexConcaveCollisionAlgorithm : CollisionAlgorithm - { - private bool _isSwapped; - private ConvexTriangleCallback _convexTriangleCallback; - - public ConvexConcaveCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB, bool isSwapped) - : base(collisionAlgorithmConstructionInfo) - { - _isSwapped = isSwapped; - _convexTriangleCallback = new ConvexTriangleCallback(collisionAlgorithmConstructionInfo.Dispatcher, bodyA, bodyB, isSwapped); - } - - public void ClearCache() - { - _convexTriangleCallback.ClearCache(); - } - - public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - CollisionObject convexBody = _isSwapped ? bodyB : bodyA; - CollisionObject triBody = _isSwapped ? bodyA : bodyB; - - if (triBody.CollisionShape.IsConcave) - { - CollisionObject triOb = triBody; - ConcaveShape concaveShape = triOb.CollisionShape as ConcaveShape; - - if (convexBody.CollisionShape.IsConvex) - { - float collisionMarginTriangle = concaveShape.Margin; - - resultOut.SetPersistentManifold(_convexTriangleCallback.Manifold); - _convexTriangleCallback.SetTimeStepAndCounters(collisionMarginTriangle, dispatchInfo, resultOut); - - //Disable persistency. previously, some older algorithm calculated all contacts in one go, so you can clear it here. - //m_dispatcher->clearManifold(m_btConvexTriangleCallback.m_manifoldPtr); - - _convexTriangleCallback.Manifold.SetBodies(convexBody, triBody); - concaveShape.ProcessAllTriangles(_convexTriangleCallback, _convexTriangleCallback.AabbMin, _convexTriangleCallback.AabbMax); - } - } - } - - public override float CalculateTimeOfImpact(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - CollisionObject convexbody = _isSwapped ? bodyB : bodyA; - CollisionObject triBody = _isSwapped ? bodyA : bodyB; - - - //quick approximation using raycast, todo: hook up to the continuous collision detection (one of the btConvexCast) - - //only perform CCD above a certain threshold, this prevents blocking on the long run - //because object in a blocked ccd state (hitfraction<1) get their linear velocity halved each frame... - float squareMot0 = (convexbody.InterpolationWorldTransform.Translation - convexbody.WorldTransform.Translation).LengthSquared(); - if (squareMot0 < convexbody.CcdSquareMotionThreshold) - { - return 1; - } - - Matrix triInv = MathHelper.InvertMatrix(triBody.WorldTransform); - Matrix convexFromLocal = triInv * convexbody.WorldTransform; - Matrix convexToLocal = triInv * convexbody.InterpolationWorldTransform; - - if (triBody.CollisionShape.IsConcave) - { - Vector3 rayAabbMin = convexFromLocal.Translation; - MathHelper.SetMin(ref rayAabbMin, convexToLocal.Translation); - Vector3 rayAabbMax = convexFromLocal.Translation; - MathHelper.SetMax(ref rayAabbMax, convexToLocal.Translation); - float ccdRadius0 = convexbody.CcdSweptSphereRadius; - rayAabbMin -= new Vector3(ccdRadius0, ccdRadius0, ccdRadius0); - rayAabbMax += new Vector3(ccdRadius0, ccdRadius0, ccdRadius0); - - float curHitFraction = 1f; //is this available? - LocalTriangleSphereCastCallback raycastCallback = new LocalTriangleSphereCastCallback(convexFromLocal, convexToLocal, - convexbody.CcdSweptSphereRadius, curHitFraction); - - raycastCallback.HitFraction = convexbody.HitFraction; - - CollisionObject concavebody = triBody; - - ConcaveShape triangleMesh = concavebody.CollisionShape as ConcaveShape; - - if (triangleMesh != null) - { - triangleMesh.ProcessAllTriangles(raycastCallback, rayAabbMin, rayAabbMax); - } - - if (raycastCallback.HitFraction < convexbody.HitFraction) - { - convexbody.HitFraction = raycastCallback.HitFraction; - return raycastCallback.HitFraction; - } - } - - return 1; - } - - public class CreateFunc : CollisionAlgorithmCreateFunction - { - public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - { - return new ConvexConcaveCollisionAlgorithm(collisionAlgorithmConstructionInfo, bodyA, bodyB, false); - } - } - - public class SwappedCreateFunc : CollisionAlgorithmCreateFunction - { - public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - { - return new ConvexConcaveCollisionAlgorithm(collisionAlgorithmConstructionInfo, bodyA, bodyB, true); - } - } - - private class LocalTriangleSphereCastCallback : ITriangleCallback - { - private Matrix _ccdSphereFromTrans; - private Matrix _ccdSphereToTrans; - private Matrix _meshTransform; - - private float _ccdSphereRadius; - private float _hitFraction; - - public LocalTriangleSphereCastCallback(Matrix from, Matrix to, float ccdSphereRadius, float hitFraction) - { - _ccdSphereFromTrans = from; - _ccdSphereToTrans = to; - _ccdSphereRadius = ccdSphereRadius; - _hitFraction = hitFraction; - } - - public Matrix CcdSphereFromTrans { get { return _ccdSphereFromTrans; } set { _ccdSphereFromTrans = value; } } - public Matrix CcdSphereToTrans { get { return _ccdSphereToTrans; } set { _ccdSphereToTrans = value; } } - public Matrix MeshTransform { get { return _meshTransform; } set { _meshTransform = value; } } - public float CcdSphereRadius { get { return _ccdSphereRadius; } set { _ccdSphereRadius = value; } } - public float HitFraction { get { return _hitFraction; } set { _hitFraction = value; } } - - public void ProcessTriangle(Vector3[] triangle, int partId, int triangleIndex) - { - //do a swept sphere for now - Matrix ident = Matrix.Identity; - CastResult castResult = new CastResult(); - castResult.Fraction = _hitFraction; - SphereShape pointShape = new SphereShape(_ccdSphereRadius); - TriangleShape triShape = new TriangleShape(triangle[0], triangle[1], triangle[2]); - VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver(); - SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(pointShape, triShape, simplexSolver); - //GjkConvexCast convexCaster(&pointShape,convexShape,&simplexSolver); - //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0); - //local space? - - if (convexCaster.CalcTimeOfImpact(_ccdSphereFromTrans, _ccdSphereToTrans, - ident, ident, castResult)) - { - if (_hitFraction > castResult.Fraction) - _hitFraction = castResult.Fraction; - } - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ConvexConvexCollisionAlgorithm.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ConvexConvexCollisionAlgorithm.cs deleted file mode 100644 index 8fa4837eb..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ConvexConvexCollisionAlgorithm.cs +++ /dev/null @@ -1,193 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public class ConvexConvexAlgorithm : CollisionAlgorithm, IDisposable - { - private const bool DisableCcd = false; - private GjkPairDetector _gjkPairDetector; - private bool _ownManifold; - private PersistentManifold _manifold; - private bool _lowLevelOfDetail; - - public ConvexConvexAlgorithm(PersistentManifold manifold, CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB, ISimplexSolver simplexSolver, IConvexPenetrationDepthSolver penetrationDepthSolver) - : base(collisionAlgorithmConstructionInfo) - { - _gjkPairDetector = new GjkPairDetector(null, null, simplexSolver, penetrationDepthSolver); - _ownManifold = false; - _manifold = manifold; - _lowLevelOfDetail = false; - } - - public bool LowLevelOfDetail { get { return _lowLevelOfDetail; } set { _lowLevelOfDetail = value; } } - public bool OwnManifold { get { return _ownManifold; } set { _ownManifold = value; } } - public PersistentManifold Manifold { get { return _manifold; } set { _manifold = value; } } - - public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - if (_manifold == null) - { - //swapped? - _manifold = Dispatcher.GetNewManifold(bodyA, bodyB); - _ownManifold = true; - } - resultOut.SetPersistentManifold(_manifold); - - ConvexShape min0 = bodyA.CollisionShape as ConvexShape; - ConvexShape min1 = bodyB.CollisionShape as ConvexShape; - - GjkPairDetector.ClosestPointInput input = new DiscreteCollisionDetectorInterface.ClosestPointInput(); - - //TODO: if (dispatchInfo.m_useContinuous) - _gjkPairDetector.setMinkowskiA(min0); - _gjkPairDetector.setMinkowskiB(min1); - input.MaximumDistanceSquared = min0.Margin + min1.Margin + PersistentManifold.ContactBreakingThreshold; - input.MaximumDistanceSquared *= input.MaximumDistanceSquared; - - // input.m_maximumDistanceSquared = 1e30f; - - input.TransformA = bodyA.WorldTransform; - input.TransformB = bodyB.WorldTransform; - - _gjkPairDetector.GetClosestPoints(input, resultOut, dispatchInfo.DebugDraw); - } - - public override float CalculateTimeOfImpact(CollisionObject colA, CollisionObject colB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - //Rather then checking ALL pairs, only calculate TOI when motion exceeds threshold - - //Linear motion for one of objects needs to exceed m_ccdSquareMotionThreshold - //col0->m_worldTransform, - float resultFraction = 1f; - - float squareMotA = (colA.InterpolationWorldTransform.Translation - colA.WorldTransform.Translation).LengthSquared(); - float squareMotB = (colB.InterpolationWorldTransform.Translation - colB.WorldTransform.Translation).LengthSquared(); - - if (squareMotA < colA.CcdSquareMotionThreshold && - squareMotB < colB.CcdSquareMotionThreshold) - return resultFraction; - - if (DisableCcd) - return 1f; - - //An adhoc way of testing the Continuous Collision Detection algorithms - //One object is approximated as a sphere, to simplify things - //Starting in penetration should report no time of impact - //For proper CCD, better accuracy and handling of 'allowed' penetration should be added - //also the mainloop of the physics should have a kind of toi queue (something like Brian Mirtich's application of Timewarp for Rigidbodies) - - // Convex0 against sphere for Convex1 - { - ConvexShape convexA = colA.CollisionShape as ConvexShape; - - SphereShape sphereB = new SphereShape(colB.CcdSweptSphereRadius); //todo: allow non-zero sphere sizes, for better approximation - CastResult result = new CastResult(); - VoronoiSimplexSolver voronoiSimplex = new VoronoiSimplexSolver(); - //SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex); - //Simplification, one object is simplified as a sphere - GjkConvexCast ccdB = new GjkConvexCast(convexA, sphereB, voronoiSimplex); - //ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0); - if (ccdB.CalcTimeOfImpact(colA.WorldTransform, colA.InterpolationWorldTransform, - colB.WorldTransform, colB.InterpolationWorldTransform, result)) - { - //store result.m_fraction in both bodies - if (colA.HitFraction > result.Fraction) - colA.HitFraction = result.Fraction; - - if (colB.HitFraction > result.Fraction) - colB.HitFraction = result.Fraction; - - if (resultFraction > result.Fraction) - resultFraction = result.Fraction; - } - } - - // Sphere (for convex0) against Convex1 - { - ConvexShape convexB = colB.CollisionShape as ConvexShape; - - SphereShape sphereA = new SphereShape(colA.CcdSweptSphereRadius); //todo: allow non-zero sphere sizes, for better approximation - CastResult result = new CastResult(); - VoronoiSimplexSolver voronoiSimplex = new VoronoiSimplexSolver(); - //SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex); - ///Simplification, one object is simplified as a sphere - GjkConvexCast ccdB = new GjkConvexCast(sphereA, convexB, voronoiSimplex); - //ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0); - if (ccdB.CalcTimeOfImpact(colA.WorldTransform, colA.InterpolationWorldTransform, - colB.WorldTransform, colB.InterpolationWorldTransform, result)) - { - //store result.m_fraction in both bodies - if (colA.HitFraction > result.Fraction) - colA.HitFraction = result.Fraction; - - if (colB.HitFraction > result.Fraction) - colB.HitFraction = result.Fraction; - - if (resultFraction > result.Fraction) - resultFraction = result.Fraction; - } - } - return resultFraction; - } - - public class CreateFunc : CollisionAlgorithmCreateFunction - { - private IConvexPenetrationDepthSolver _penetrationDepthSolver; - private ISimplexSolver _simplexSolver; - //private bool _ownsSolvers; - - public CreateFunc() - { - //_ownsSolvers = true; - _simplexSolver = new VoronoiSimplexSolver(); - _penetrationDepthSolver = new GjkEpaPenetrationDepthSolver(); - } - - public CreateFunc(ISimplexSolver simplexSolver, IConvexPenetrationDepthSolver penetrationDepthSolver) - { - //_ownsSolvers = false; - _simplexSolver = simplexSolver; - _penetrationDepthSolver = penetrationDepthSolver; - } - - public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - { - return new ConvexConvexAlgorithm(collisionAlgorithmConstructionInfo.Manifold, collisionAlgorithmConstructionInfo, bodyA, bodyB, _simplexSolver, _penetrationDepthSolver); - } - } - - #region IDisposable Members - public void Dispose() - { - if (_ownManifold) - { - if (_manifold != null) - Dispatcher.ReleaseManifold(_manifold); - } - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ConvexTriangleCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ConvexTriangleCallback.cs deleted file mode 100644 index 42052445c..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ConvexTriangleCallback.cs +++ /dev/null @@ -1,130 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class ConvexTriangleCallback : ITriangleCallback, IDisposable - { - private CollisionObject _convexBody; - private CollisionObject _triBody; - - private Vector3 _aabbMin; - private Vector3 _aabbMax; - - private ManifoldResult _resultOut; - - private IDispatcher _dispatcher; - private DispatcherInfo _dispatchInfo; - private float _collisionMarginTriangle; - - private int _triangleCount; - - private PersistentManifold _manifold; - - public ConvexTriangleCallback(IDispatcher dispatcher, CollisionObject bodyA, CollisionObject bodyB, bool isSwapped) - { - _dispatcher = dispatcher; - _dispatchInfo = null; - _convexBody = isSwapped ? bodyB : bodyA; - _triBody = isSwapped ? bodyA : bodyB; - - // create the manifold from the dispatcher 'manifold pool' - _manifold = _dispatcher.GetNewManifold(_convexBody, _triBody); - ClearCache(); - } - - public Vector3 AabbMin { get { return _aabbMin; } } - public Vector3 AabbMax { get { return _aabbMax; } } - public int TriangleCount { get { return _triangleCount; } set { _triangleCount = value; } } - public PersistentManifold Manifold { get { return _manifold; } set { _manifold = value; } } - - public void SetTimeStepAndCounters(float collisionMarginTriangle, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - _dispatchInfo = dispatchInfo; - _collisionMarginTriangle = collisionMarginTriangle; - _resultOut = resultOut; - - //recalc aabbs - Matrix convexInTriangleSpace = MathHelper.InvertMatrix(_triBody.WorldTransform) * _convexBody.WorldTransform; - CollisionShape convexShape = _convexBody.CollisionShape; - //CollisionShape* triangleShape = static_cast(triBody->m_collisionShape); - convexShape.GetAabb(convexInTriangleSpace, out _aabbMin, out _aabbMax); - float extraMargin = collisionMarginTriangle; - Vector3 extra = new Vector3(extraMargin, extraMargin, extraMargin); - - _aabbMax += extra; - _aabbMin -= extra; - } - - public void ClearCache() - { - _dispatcher.ClearManifold(_manifold); - } - - #region ITriangleCallback Members - public void ProcessTriangle(Vector3[] triangle, int partID, int triangleIndex) - { - //aabb filter is already applied! - CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo = new CollisionAlgorithmConstructionInfo(); - collisionAlgorithmConstructionInfo.Dispatcher = _dispatcher; - - CollisionObject collisionObject = _triBody; - - //debug drawing of the overlapping triangles - /*if (m_dispatchInfoPtr && m_dispatchInfoPtr.m_debugDraw && m_dispatchInfoPtr->m_debugDraw->getDebugMode() > 0) - { - Vector3 color = new Vector3(255, 255, 0); - btTransform & tr = ob->WorldTransform; - m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]), tr(triangle[1]), color); - m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]), tr(triangle[2]), color); - m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]), tr(triangle[0]), color); - }*/ - - if (_convexBody.CollisionShape.IsConvex) - { - TriangleShape triangleShape = new TriangleShape(triangle[0], triangle[1], triangle[2]); - triangleShape.Margin=_collisionMarginTriangle; - - CollisionShape tempShape = collisionObject.CollisionShape; - collisionObject.CollisionShape = triangleShape; - - CollisionAlgorithm collisionAlgorithm = collisionAlgorithmConstructionInfo.Dispatcher.FindAlgorithm(_convexBody, _triBody, _manifold); - - _resultOut.SetShapeIdentifiers(-1, -1, partID, triangleIndex); - collisionAlgorithm.ProcessCollision(_convexBody, _triBody, _dispatchInfo, _resultOut); - collisionObject.CollisionShape = tempShape; - } - } - #endregion - #region IDisposable Members - public void Dispose() - { - ClearCache(); - _dispatcher.ReleaseManifold(_manifold); - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/EmptyAlgorithm.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/EmptyAlgorithm.cs deleted file mode 100644 index 13cb3d9b1..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/EmptyAlgorithm.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - /// - /// EmptyAlgorithm is a stub for unsupported collision pairs. - /// The dispatcher can dispatch a persistent btEmptyAlgorithm to avoid a search every frame. - /// - public class EmptyAlgorithm : CollisionAlgorithm - { - public EmptyAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo) - : base(collisionAlgorithmConstructionInfo) { } - - public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) { } - - public override float CalculateTimeOfImpact(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - return 1f; - } - - public class CreateFunc : CollisionAlgorithmCreateFunction - { - public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - { - return new EmptyAlgorithm(collisionAlgorithmConstructionInfo); - } - }; - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ManifoldResult.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ManifoldResult.cs deleted file mode 100644 index ee92d7fdb..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/ManifoldResult.cs +++ /dev/null @@ -1,147 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public delegate bool ContactAddedCallback(ManifoldPoint contactPoint, CollisionObject collisionObjectA, int partIdA, int indexA, CollisionObject collisionObjectB, int partIdB, int indexB); - - public class ManifoldResult : DiscreteCollisionDetectorInterface.Result - { - private PersistentManifold _manifold; - private static ContactAddedCallback _contactAddedCallback = null; - - //we need this for compounds - private Matrix _rootTransA; - private Matrix _rootTransB; - - private CollisionObject _bodyA; - private CollisionObject _bodyB; - private int _partIdA; - private int _partIdB; - private int _indexA; - private int _indexB; - - public ManifoldResult() - { - } - - public ManifoldResult(CollisionObject bodyA, CollisionObject bodyB) - { - _bodyA = bodyA; - _bodyB = bodyB; - _rootTransA = bodyA.WorldTransform; - _rootTransB = bodyB.WorldTransform; - } - - public static ContactAddedCallback ContactAddedCallback { get { return _contactAddedCallback; } set { _contactAddedCallback = value; } } - - public void SetPersistentManifold(PersistentManifold manifold) - { - _manifold = manifold; - } - - public override void SetShapeIdentifiers(int partIdA, int indexA, int partIdB, int indexB) - { - _partIdA = partIdA; - _partIdB = partIdB; - _indexA = indexA; - _indexB = indexB; - } - - public override void AddContactPoint(Vector3 normalOnBInWorld, Vector3 pointInWorld, float depth) - { - if (_manifold == null) - throw new BulletException("Manifold Pointer is null."); - - //order in manifold needs to match - - if (depth > PersistentManifold.ContactBreakingThreshold) - return; - - bool isSwapped = _manifold.BodyA != _bodyA; - - Vector3 pointA = pointInWorld + normalOnBInWorld * depth; - Vector3 localA; - Vector3 localB; - - if (isSwapped) - { - localA = MathHelper.InvXForm(_rootTransB, pointA); - localB = MathHelper.InvXForm(_rootTransA, pointInWorld); - } - else - { - localA = MathHelper.InvXForm(_rootTransA, pointA); - localB = MathHelper.InvXForm(_rootTransB, pointInWorld); - } - - ManifoldPoint newPt = new ManifoldPoint(localA, localB, normalOnBInWorld, depth); - - int insertIndex = _manifold.GetCacheEntry(newPt); - - newPt.CombinedFriction = CalculateCombinedFriction(_bodyA, _bodyB); - newPt.CombinedRestitution = CalculateCombinedRestitution(_bodyA, _bodyB); - - //User can override friction and/or restitution - if (_contactAddedCallback != null && - //and if either of the two bodies requires custom material - ((_bodyA.CollisionFlags & CollisionOptions.CustomMaterialCallback) != 0 || - (_bodyB.CollisionFlags & CollisionOptions.CustomMaterialCallback) != 0)) - { - //experimental feature info, for per-triangle material etc. - CollisionObject obj0 = isSwapped ? _bodyB : _bodyA; - CollisionObject obj1 = isSwapped ? _bodyA : _bodyB; - _contactAddedCallback(newPt, obj0, _partIdA, _indexA, obj1, _partIdB, _indexB); - } - - if (insertIndex >= 0) - { - _manifold.ReplaceContactPoint(newPt, insertIndex); - } - else - { - _manifold.AddManifoldPoint(newPt); - } - } - - private float CalculateCombinedFriction(CollisionObject bodyA, CollisionObject bodyB) - { - float friction = bodyA.Friction * bodyB.Friction; - - float MaxFriction = 10; - if (friction < -MaxFriction) - friction = -MaxFriction; - if (friction > MaxFriction) - friction = MaxFriction; - return friction; - } - - private float CalculateCombinedRestitution(CollisionObject bodyA, CollisionObject bodyB) - { - return bodyA.Restitution * bodyB.Restitution; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SimulationIslandManager.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SimulationIslandManager.cs deleted file mode 100644 index b47340706..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SimulationIslandManager.cs +++ /dev/null @@ -1,304 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class SimulationIslandManager - { - private UnionFind _unionFind = new UnionFind(); - - public void InitUnionFind(int n) - { - _unionFind.Reset(n); - } - - public UnionFind UnionFind { get { return _unionFind; } } - - public virtual void UpdateActivationState(CollisionWorld world, IDispatcher dispatcher) - { - InitUnionFind(world.CollisionObjectsCount); - - // put the index into m_controllers into m_tag - int index = 0; - for (int i = 0; i < world.CollisionObjects.Count; i++) - { - world.CollisionObjects[i].IslandTag = index; - world.CollisionObjects[i].HitFraction = 1; - world.CollisionObjects[i].CompanionID = -1; - index++; - } - // do the union find - FindUnions(dispatcher); - } - - public virtual void StoreIslandActivationState(CollisionWorld world) - { - // put the islandId ('find' value) into m_tag - int index = 0; - for (int i = 0; i < world.CollisionObjects.Count; i++) - { - if (world.CollisionObjects[i].MergesSimulationIslands) - { - world.CollisionObjects[i].IslandTag = _unionFind.Find(index); - world.CollisionObjects[i].CompanionID = -1; - } - else - { - world.CollisionObjects[i].IslandTag = -1; - world.CollisionObjects[i].CompanionID = -2; - } - index++; - } - } - - public void FindUnions(IDispatcher dispatcher) - { - for (int i = 0; i < dispatcher.ManifoldCount; i++) - { - PersistentManifold manifold = dispatcher.GetManifoldByIndex(i); - //static objects (invmass 0.f) don't merge ! - - CollisionObject colObjA = manifold.BodyA as CollisionObject; - CollisionObject colObjB = manifold.BodyB as CollisionObject; - - if (((colObjA != null) && (colObjA.MergesSimulationIslands)) && - ((colObjB != null) && (colObjB.MergesSimulationIslands))) - { - _unionFind.Unite(colObjA.IslandTag, colObjB.IslandTag); - } - } - } - - public void BuildAndProcessIslands(IDispatcher dispatcher, List collisionObjects, IIslandCallback callback) - { - //we are going to sort the unionfind array, and store the element id in the size - //afterwards, we clean unionfind, to make sure no-one uses it anymore - UnionFind.SortIslands(); - int numElem = UnionFind.ElementCount; - - int endIslandIndex = 1; - int startIslandIndex; - - //update the sleeping state for bodies, if all are sleeping - for (startIslandIndex = 0; startIslandIndex < numElem; startIslandIndex = endIslandIndex) - { - int islandId = UnionFind[startIslandIndex].ID; - for (endIslandIndex = startIslandIndex + 1; (endIslandIndex < numElem) && (UnionFind[endIslandIndex].ID == islandId); endIslandIndex++) - { - } - - //int numSleeping = 0; - - bool allSleeping = true; - - int idx; - for (idx = startIslandIndex; idx < endIslandIndex; idx++) - { - int i = UnionFind[idx].Size; - - CollisionObject colObjA = collisionObjects[i]; - if ((colObjA.IslandTag != islandId) && (colObjA.IslandTag != -1)) - { - Console.WriteLine("error in island management"); - } - - BulletDebug.Assert((colObjA.IslandTag == islandId) || (colObjA.IslandTag == -1)); - if (colObjA.IslandTag == islandId) - { - if (colObjA.ActivationState == ActivationState.Active) - { - allSleeping = false; - } - if (colObjA.ActivationState == ActivationState.DisableDeactivation) - { - allSleeping = false; - } - } - } - - - if (allSleeping) - { - for (idx = startIslandIndex; idx < endIslandIndex; idx++) - { - int i = UnionFind[idx].Size; - CollisionObject colObjA = collisionObjects[i]; - if ((colObjA.IslandTag != islandId) && (colObjA.IslandTag != -1)) - { - Console.WriteLine("error in island management"); - } - - BulletDebug.Assert((colObjA.IslandTag == islandId) || (colObjA.IslandTag == -1)); - - if (colObjA.IslandTag == islandId) - { - colObjA.ActivationState =ActivationState.IslandSleeping; - } - } - } - else - { - for (idx = startIslandIndex; idx < endIslandIndex; idx++) - { - int i = UnionFind[idx].Size; - - CollisionObject colObjA = collisionObjects[i]; - if ((colObjA.IslandTag != islandId) && (colObjA.IslandTag != -1)) - { - Console.WriteLine("error in island management"); - } - - BulletDebug.Assert((colObjA.IslandTag == islandId) || (colObjA.IslandTag == -1)); - - if (colObjA.IslandTag == islandId) - { - if (colObjA.ActivationState == ActivationState.IslandSleeping) - { - colObjA.ActivationState = ActivationState.WantsDeactivation; - } - } - } - } - } - - //int maxNumManifolds = dispatcher.ManifoldCount; - List islandmanifold = new List(dispatcher.ManifoldCount); - - for (int i = 0; i < dispatcher.ManifoldCount; i++) - { - PersistentManifold manifold = dispatcher.GetManifoldByIndex(i); - - CollisionObject colObjA = manifold.BodyA as CollisionObject; - CollisionObject colObjB = manifold.BodyB as CollisionObject; - - //todo: check sleeping conditions! - if (((colObjA != null) && colObjA.ActivationState != ActivationState.IslandSleeping) || - ((colObjB != null) && colObjB.ActivationState != ActivationState.IslandSleeping)) - { - - //kinematic objects don't merge islands, but wake up all connected objects - if (colObjA.IsStaticOrKinematicObject && colObjA.ActivationState != ActivationState.IslandSleeping) - { - colObjB.Activate(); - } - if (colObjB.IsStaticOrKinematicObject && colObjB.ActivationState != ActivationState.IslandSleeping) - { - colObjA.Activate(); - } - - //filtering for response - if (dispatcher.NeedsResponse(colObjA, colObjB)) - islandmanifold.Add(manifold); - } - } - - int numManifolds = islandmanifold.Count; - - // Sort manifolds, based on islands - // Sort the vector using predicate and std::sort - islandmanifold.Sort(new Comparison(PersistentManifoldSortPredicate)); - - //now process all active islands (sets of manifolds for now) - int startManifoldIndex = 0; - int endManifoldIndex = 1; - - List islandBodies = new List(); - - for (startIslandIndex = 0; startIslandIndex < numElem; startIslandIndex = endIslandIndex) - { - int islandId = UnionFind[startIslandIndex].ID; - bool islandSleeping = false; - for (endIslandIndex = startIslandIndex; (endIslandIndex < numElem) && (UnionFind[endIslandIndex].ID == islandId); endIslandIndex++) - { - int i = UnionFind[endIslandIndex].Size; - CollisionObject colObjA = collisionObjects[i]; - islandBodies.Add(colObjA); - if (!colObjA.IsActive) - islandSleeping = true; - } - - //find the accompanying contact manifold for this islandId - int numIslandManifolds = 0; - List startManifold = new List(numIslandManifolds); - - if (startManifoldIndex < numManifolds) - { - int curIslandID = GetIslandId(islandmanifold[startManifoldIndex]); - if (curIslandID == islandId) - { - for (int k = startManifoldIndex; k < islandmanifold.Count; k++) - { - startManifold.Add(islandmanifold[k]); - } - for (endManifoldIndex = startManifoldIndex + 1; (endManifoldIndex < numManifolds) && (islandId == GetIslandId(islandmanifold[endManifoldIndex])); endManifoldIndex++) { } - - // Process the actual simulation, only if not sleeping/deactivated - numIslandManifolds = endManifoldIndex - startManifoldIndex; - } - } - - if (!islandSleeping) - { - callback.ProcessIsland(islandBodies, startManifold, numIslandManifolds, islandId); - } - - if (numIslandManifolds != 0) - { - startManifoldIndex = endManifoldIndex; - } - - islandBodies.Clear(); - } - } - - private static int GetIslandId(PersistentManifold lhs) - { - int islandId; - CollisionObject rcolObjA = lhs.BodyA as CollisionObject; - CollisionObject rcolObjB = lhs.BodyB as CollisionObject; - islandId = rcolObjA.IslandTag >= 0 ? rcolObjA.IslandTag : rcolObjB.IslandTag; - return islandId; - } - - private static int PersistentManifoldSortPredicate(PersistentManifold lhs, PersistentManifold rhs) - { - int rIslandIdA, lIslandIdB; - rIslandIdA = GetIslandId(rhs); - lIslandIdB = GetIslandId(lhs); - //return lIslandId0 < rIslandId0; - if (lIslandIdB < rIslandIdA) - return -1; - //else if (lIslandIdB > rIslandIdA) - // return 1; - return 1; - } - - public interface IIslandCallback - { - void ProcessIsland(List bodies, List manifolds, int numManifolds, int islandID); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereBoxCollisionAlgorithm.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereBoxCollisionAlgorithm.cs deleted file mode 100644 index 5a1b971c0..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereBoxCollisionAlgorithm.cs +++ /dev/null @@ -1,270 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// SphereBoxCollisionAlgorithm provides sphere-box collision detection. - /// Other features are frame-coherency (persistent data) and collision response. - /// - public class SphereBoxCollisionAlgorithm : CollisionAlgorithm, IDisposable - { - private bool _ownManifold; - private PersistentManifold _manifold; - private bool _isSwapped; - - public SphereBoxCollisionAlgorithm(PersistentManifold manifold, CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject collisionObjectA, CollisionObject collisionObjectB, bool isSwapped) - : base(collisionAlgorithmConstructionInfo) - { - _ownManifold = false; - _manifold = manifold; - _isSwapped = isSwapped; - - CollisionObject sphereObject = _isSwapped ? collisionObjectB : collisionObjectA; - CollisionObject boxObject = _isSwapped ? collisionObjectA : collisionObjectB; - - if (_manifold == null && Dispatcher.NeedsCollision(sphereObject, boxObject)) - { - _manifold = Dispatcher.GetNewManifold(sphereObject, boxObject); - _ownManifold = true; - } - } - - public float GetSphereDistance(CollisionObject boxObject, out Vector3 pointOnBox, out Vector3 pointOnSphere, Vector3 sphereCenter, float radius) - { - pointOnBox = new Vector3(); - pointOnSphere = new Vector3(); - - float margins; - Vector3[] bounds = new Vector3[2]; - BoxShape boxShape = boxObject.CollisionShape as BoxShape; - - bounds[0] = -boxShape.HalfExtents; - bounds[1] = boxShape.HalfExtents; - - margins = boxShape.Margin; //also add sphereShape margin? - - Matrix m44T = boxObject.WorldTransform; - - Vector3[] boundsVec = new Vector3[2]; - float penetration; - - boundsVec[0] = bounds[0]; - boundsVec[1] = bounds[1]; - - Vector3 marginsVec = new Vector3(margins, margins, margins); - - // add margins - bounds[0] += marginsVec; - bounds[1] -= marginsVec; - - ///////////////////////////////////////////////// - - Vector3 tmp, prel, normal, v3P; - Vector3[] n = new Vector3[6]; - float sep = 10000000.0f, sepThis; - - n[0] = new Vector3(-1.0f, 0.0f, 0.0f); - n[1] = new Vector3(0.0f, -1.0f, 0.0f); - n[2] = new Vector3(0.0f, 0.0f, -1.0f); - n[3] = new Vector3(1.0f, 0.0f, 0.0f); - n[4] = new Vector3(0.0f, 1.0f, 0.0f); - n[5] = new Vector3(0.0f, 0.0f, 1.0f); - - // convert point in local space - prel = MathHelper.InvXForm(m44T, sphereCenter); - - bool found = false; - - v3P = prel; - - for (int i = 0; i < 6; i++) - { - int j = i < 3 ? 0 : 1; - if ((sepThis = (Vector3.Dot(v3P - bounds[j], n[i]))) > 0.0f) - { - v3P = v3P - n[i] * sepThis; - found = true; - } - } - - // - - if (found) - { - bounds[0] = boundsVec[0]; - bounds[1] = boundsVec[1]; - - normal = Vector3.Normalize(prel - v3P); - pointOnBox = v3P + normal * margins; - pointOnSphere = prel - normal * radius; - - if ((Vector3.Dot(pointOnSphere - pointOnBox, normal)) > 0.0f) - { - return 1.0f; - } - - // transform back in world space - tmp = MathHelper.MatrixToVector(m44T, pointOnBox); - pointOnBox = tmp; - tmp = MathHelper.MatrixToVector(m44T, pointOnSphere); - pointOnSphere = tmp; - float seps2 = (pointOnBox - pointOnSphere).LengthSquared(); - - //if this fails, fallback into deeper penetration case, below - if (seps2 > MathHelper.Epsilon) - { - sep = -(float)Math.Sqrt(seps2); - normal = (pointOnBox - pointOnSphere); - normal *= 1f / sep; - } - return sep; - } - - ////////////////////////////////////////////////// - // Deep penetration case - - penetration = GetSpherePenetration(boxObject, ref pointOnBox, ref pointOnSphere, sphereCenter, radius, bounds[0], bounds[1]); - - bounds[0] = boundsVec[0]; - bounds[1] = boundsVec[1]; - - if (penetration <= 0.0f) - return (penetration - margins); - else - return 1.0f; - } - - public float GetSpherePenetration(CollisionObject boxObject, ref Vector3 pointOnBox, ref Vector3 pointOnSphere, Vector3 sphereCenter, float radius, Vector3 aabbMin, Vector3 aabbMax) - { - Vector3[] bounds = new Vector3[2]; - - bounds[0] = aabbMin; - bounds[1] = aabbMax; - - Vector3 p0 = new Vector3(), tmp, prel, normal = new Vector3(); - Vector3[] n = new Vector3[6]; - float sep = -10000000.0f, sepThis; - - n[0] = new Vector3(-1.0f, 0.0f, 0.0f); - n[1] = new Vector3(0.0f, -1.0f, 0.0f); - n[2] = new Vector3(0.0f, 0.0f, -1.0f); - n[3] = new Vector3(1.0f, 0.0f, 0.0f); - n[4] = new Vector3(0.0f, 1.0f, 0.0f); - n[5] = new Vector3(0.0f, 0.0f, 1.0f); - - Matrix m44T = boxObject.WorldTransform; - - // convert point in local space - prel = MathHelper.InvXForm(m44T, sphereCenter); - - /////////// - - for (int i = 0; i < 6; i++) - { - int j = i < 3 ? 0 : 1; - if ((sepThis = (Vector3.Dot(prel - bounds[j], n[i])) - radius) > 0.0f) return 1.0f; - if (sepThis > sep) - { - p0 = bounds[j]; - normal = n[i]; - sep = sepThis; - } - } - - pointOnBox = prel - normal * (Vector3.Dot(normal, (prel - p0))); - pointOnSphere = pointOnBox + normal * sep; - - // transform back in world space - tmp = MathHelper.MatrixToVector(m44T, pointOnBox); - pointOnBox = tmp; - tmp = MathHelper.MatrixToVector(m44T, pointOnSphere); - pointOnSphere = tmp; - normal = Vector3.Normalize(pointOnBox - pointOnSphere); - - return sep; - } - - public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - if (_manifold == null) - return; - - CollisionObject sphereObject = _isSwapped ? bodyB : bodyA; - CollisionObject boxObject = _isSwapped ? bodyA : bodyB; - - SphereShape sphereA = sphereObject.CollisionShape as SphereShape; - - Vector3 pOnBox, pOnSphere; - Vector3 sphereCenter = sphereObject.WorldTransform.Translation; - float radius = sphereA.Radius; - - float dist = GetSphereDistance(boxObject, out pOnBox, out pOnSphere, sphereCenter, radius); - - if (dist < MathHelper.Epsilon) - { - Vector3 normalOnSurfaceB = Vector3.Normalize(pOnBox - pOnSphere); - - // report a contact. internally this will be kept persistent, and contact reduction is done - resultOut.SetPersistentManifold(_manifold); - resultOut.AddContactPoint(normalOnSurfaceB, pOnBox, dist); - } - } - - public override float CalculateTimeOfImpact(CollisionObject collisionObjectA, CollisionObject collisionObjectB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - //not yet - return 1; - } - - public class CreateFunc : CollisionAlgorithmCreateFunction - { - public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - { - if (!IsSwapped) - return new SphereBoxCollisionAlgorithm(null, collisionAlgorithmConstructionInfo, bodyA, bodyB, false); - else - return new SphereBoxCollisionAlgorithm(null, collisionAlgorithmConstructionInfo, bodyA, bodyB, true); - } - } - - #region IDisposable Members - public void Dispose() - { - Dispose(true); - } - - public void Dispose(bool disposing) - { - if (disposing && _ownManifold) - { - if (_manifold != null) - Dispatcher.ReleaseManifold(_manifold); - } - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs deleted file mode 100644 index bdd8ba7f6..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereSphereCollisionAlgorithm.cs +++ /dev/null @@ -1,104 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class SphereSphereCollisionAlgorithm : CollisionAlgorithm - { - private bool _ownManifold; - private PersistentManifold _manifold; - - public SphereSphereCollisionAlgorithm(PersistentManifold manifold, CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - : base(collisionAlgorithmConstructionInfo) - { - _ownManifold = false; - _manifold = manifold; - - if (_manifold == null) - { - _manifold = Dispatcher.GetNewManifold(bodyA, bodyB); - _ownManifold = true; - } - } - - public SphereSphereCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo) - : base(collisionAlgorithmConstructionInfo) { } - - ~SphereSphereCollisionAlgorithm() - { - if (_ownManifold) - { - if (_manifold != null) - Dispatcher.ReleaseManifold(_manifold); - } - } - - public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - if (_manifold == null) - return; - - SphereShape sphereA = bodyA.CollisionShape as SphereShape; - SphereShape sphereB = bodyB.CollisionShape as SphereShape; - - Vector3 diff = bodyA.WorldTransform.Translation - bodyB.WorldTransform.Translation; - float len = diff.Length(); - float radiusA = sphereA.Radius; - float radiusB = sphereB.Radius; - - //if distance positive, don't generate a new contact - if (len > (radiusA + radiusB)) - return; - - //distance (negative means penetration) - float dist = len - (radiusA + radiusB); - - Vector3 normalOnSurfaceB = diff / len; - //point on A (worldspace) - Vector3 posA = bodyA.WorldTransform.Translation - radiusA * normalOnSurfaceB; - //point on B (worldspace) - Vector3 posB = bodyB.WorldTransform.Translation + radiusB * normalOnSurfaceB; - - // report a contact. internally this will be kept persistent, and contact reduction is done - resultOut.SetPersistentManifold(_manifold); - resultOut.AddContactPoint(normalOnSurfaceB, posB, dist); - } - - public override float CalculateTimeOfImpact(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - //not yet - return 1f; - } - - public class CreateFunc : CollisionAlgorithmCreateFunction - { - public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - { - return new SphereSphereCollisionAlgorithm(null, collisionAlgorithmConstructionInfo, bodyA, bodyB); - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereTriangleCollisionAlgorithm.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereTriangleCollisionAlgorithm.cs deleted file mode 100644 index c53d78a69..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereTriangleCollisionAlgorithm.cs +++ /dev/null @@ -1,100 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// SphereSphereCollisionAlgorithm provides sphere-sphere collision detection. - /// Other features are frame-coherency (persistent data) and collision response. - /// Also provides the most basic sample for custom/user btCollisionAlgorithm - /// - public class SphereTriangleCollisionAlgorithm : CollisionAlgorithm, IDisposable - { - private bool _ownManifold; - private PersistentManifold _manifold; - private bool _isSwapped; - - public SphereTriangleCollisionAlgorithm(PersistentManifold manifold, CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB, bool isSwapped) - : base(collisionAlgorithmConstructionInfo) - { - _ownManifold = false; - _manifold = manifold; - _isSwapped = isSwapped; - - if (_manifold == null) - { - _manifold = Dispatcher.GetNewManifold(bodyA, bodyB); - _ownManifold = true; - } - } - - public SphereTriangleCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo) - : base(collisionAlgorithmConstructionInfo) { } - - public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - if (_manifold == null) - return; - - SphereShape sphere = bodyA.CollisionShape as SphereShape; - TriangleShape triangle = bodyB.CollisionShape as TriangleShape; - - /// report a contact. internally this will be kept persistent, and contact reduction is done - resultOut.SetPersistentManifold(_manifold); - SphereTriangleDetector detector = new SphereTriangleDetector(sphere, triangle); - - DiscreteCollisionDetectorInterface.ClosestPointInput input = new DiscreteCollisionDetectorInterface.ClosestPointInput(); - input.MaximumDistanceSquared = 1e30f;//todo: tighter bounds - input.TransformA = bodyA.WorldTransform; - input.TransformB = bodyB.WorldTransform; - - detector.GetClosestPoints(input, resultOut, null); - } - - public override float CalculateTimeOfImpact(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut) - { - //not yet - return 1f; - } - - public class CreateFunc : CollisionAlgorithmCreateFunction - { - public override CollisionAlgorithm CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo, CollisionObject bodyA, CollisionObject bodyB) - { - return new SphereTriangleCollisionAlgorithm(collisionAlgorithmConstructionInfo.Manifold, collisionAlgorithmConstructionInfo, bodyA, bodyB, IsSwapped); - } - } - - #region IDisposable Members - public void Dispose() - { - if (_ownManifold) - if (_manifold != null) - Dispatcher.ReleaseManifold(_manifold); - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereTriangleDetector.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereTriangleDetector.cs deleted file mode 100644 index 5e8b42e0b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/SphereTriangleDetector.cs +++ /dev/null @@ -1,214 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class SphereTriangleDetector : DiscreteCollisionDetectorInterface - { - private SphereShape _sphere; - private TriangleShape _triangle; - private const int MaxOverlap = 0; - - public SphereTriangleDetector(SphereShape sphere, TriangleShape triangle) - { - this._sphere = sphere; - this._triangle = triangle; - } - - public override void GetClosestPoints(DiscreteCollisionDetectorInterface.ClosestPointInput input, DiscreteCollisionDetectorInterface.Result output, IDebugDraw debugDraw) - { - Matrix transformA = input.TransformA; - Matrix transformB = input.TransformB; - - Vector3 point = new Vector3(); - Vector3 normal = new Vector3(); - Single timeOfImpact = 1.0f; - Single depth = 0.0f; - - //move sphere into triangle space - Matrix sphereInTr = MathHelper.InverseTimes(transformB, transformA); - - if (Collide(sphereInTr.Translation, point, normal, depth, timeOfImpact)) - output.AddContactPoint(Vector3.TransformNormal(normal, transformB), Vector3.TransformNormal(point, transformB), depth); - } - - /// - /// See also geometrictools.com - /// Basic idea: D = |p - (lo + t0*lv)| where t0 = lv . (p - lo) / lv . lv - /// - /// - /// - /// - /// - /// - private float SegmentSquareDistance(Vector3 from, Vector3 to, Vector3 point, Vector3 nearest) - { - Vector3 diff = point - from; - Vector3 v = to - from; - float t = Vector3.Dot(v, diff); - - if (t > 0) - { - float dotVV = Vector3.Dot(v, v); - if (t < dotVV) - { - t /= dotVV; - diff -= t * v; - } - else - { - t = 1; - diff -= v; - } - } - else - t = 0; - - nearest = from + t * v; - return Vector3.Dot(diff, diff); - } - - private bool Collide(Vector3 sphereCenter, Vector3 point, Vector3 resultNormal, float depth, float timeOfImpact) - { - Vector3[] vertices = _triangle.Vertices; - Vector3 c = sphereCenter; - float r = _sphere.Radius; - - Vector3 delta = new Vector3(); - - Vector3 normal = Vector3.Cross(vertices[1] - vertices[0], vertices[2] - vertices[0]); - normal = Vector3.Normalize(normal); - Vector3 p1ToCentre = c - vertices[0]; - float distanceFromPlane = Vector3.Dot(p1ToCentre, normal); - - if (distanceFromPlane < 0) - { - //triangle facing the other way - distanceFromPlane *= -1; - normal *= -1; - } - - float contactMargin = PersistentManifold.ContactBreakingThreshold; - bool isInsideContactPlane = distanceFromPlane < r + contactMargin; - bool isInsideShellPlane = distanceFromPlane < r; - - float deltaDotNormal = Vector3.Dot(delta, normal); - if (!isInsideShellPlane && deltaDotNormal >= 0.0f) - return false; - - // Check for contact / intersection - bool hasContact = false; - Vector3 contactPoint = new Vector3(); - if (isInsideContactPlane) - { - if (FaceContains(c, vertices, normal)) - { - // Inside the contact wedge - touches a point on the shell plane - hasContact = true; - contactPoint = c - normal * distanceFromPlane; - } - else - { - // Could be inside one of the contact capsules - float contactCapsuleRadiusSqr = (r + contactMargin) * (r + contactMargin); - Vector3 nearestOnEdge = new Vector3(); - for (int i = 0; i < _triangle.EdgeCount; i++) - { - Vector3 pa, pb; - _triangle.GetEdge(i, out pa, out pb); - - float distanceSqr = SegmentSquareDistance(pa, pb, c, nearestOnEdge); - if (distanceSqr < contactCapsuleRadiusSqr) - { - // Yep, we're inside a capsule - hasContact = true; - contactPoint = nearestOnEdge; - } - } - } - } - - if (hasContact) - { - Vector3 contactToCentre = c - contactPoint; - float distanceSqr = contactToCentre.LengthSquared(); - if (distanceSqr < (r - MaxOverlap) * (r - MaxOverlap)) - { - float distance = (float)Math.Sqrt(distanceSqr); - resultNormal = contactToCentre; - resultNormal = Vector3.Normalize(resultNormal); - point = contactPoint; - depth = -(r - distance); - return true; - } - - if (Vector3.Dot(delta, contactToCentre) >= 0.0f) - return false; - - // Moving towards the contact point -> collision - point = contactPoint; - timeOfImpact = 0.0f; - return true; - } - return false; - } - - private bool PointInTriangle(Vector3[] vertices, Vector3 normal, Vector3 p) - { - Vector3 p1 = vertices[0]; - Vector3 p2 = vertices[1]; - Vector3 p3 = vertices[2]; - - Vector3 edge1 = p2 - p1; - Vector3 edge2 = p3 - p2; - Vector3 edge3 = p1 - p3; - - Vector3 p1ToP = p - p1; - Vector3 p2ToP = p - p2; - Vector3 p3ToP = p - p3; - - Vector3 edge1Normal = Vector3.Cross(edge1, normal); - Vector3 edge2Normal = Vector3.Cross(edge2, normal); - Vector3 edge3Normal = Vector3.Cross(edge3, normal); - - float r1, r2, r3; - r1 = Vector3.Dot(edge1Normal, p1ToP); - r2 = Vector3.Dot(edge2Normal, p2ToP); - r3 = Vector3.Dot(edge3Normal, p3ToP); - if ((r1 > 0 && r2 > 0 && r3 > 0) || - (r1 <= 0 && r2 <= 0 && r3 <= 0)) - return true; - return false; - } - - private bool FaceContains(Vector3 p, Vector3[] vertices, Vector3 normal) - { - Vector3 lp = p; - Vector3 lnormal = normal; - return PointInTriangle(vertices, lnormal, lp); - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/UnionFind.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/UnionFind.cs deleted file mode 100644 index a825fad2d..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionDispatch/UnionFind.cs +++ /dev/null @@ -1,151 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public class UnionFind : IDisposable - { - private List _elements = new List(); - - public int ElementCount - { - get { return _elements.Count; } - } - - public void SortIslands() - { - for (int i = 0; i < _elements.Count; i++) - { - _elements[i].ID = Find(i); - _elements[i].Size = i; - } - - _elements.Sort(Sort); - } - - private static int Sort(Element x, Element y) - { - if (x.ID < y.ID) return -1; - //else if (x.ID > y.ID) return 1; - else return 0; - } - - public void Reset(int number) - { - Allocate(number); - - for (int i = 0; i < number; i++) - { - Element element = new Element(); - element.ID = i; - element.Size = 1; - _elements.Insert(i, element); - } - } - - public bool IsRoot(int index) - { - return (_elements[index].Size == index); - } - - public Element this[int index] - { - get { return _elements[index]; } - } - - public void Allocate(int number) - { - //Does nothing - _elements = new List(number); - } - - public bool Find(int i, int j) - { - return (Find(i) == Find(j)); - } - - public int Find(int i) - { - while (i != _elements[i].ID) - { - //Element element = _elements[i]; - //element.ID = _elements[_elements[i].ID].ID; - _elements[i].ID = _elements[_elements[i].ID].ID; - i = _elements[i].ID; - } - - return i; - } - - public void Unite(int p, int q) - { - int i = Find(p), j = Find(q); - if (i == j) - return; - - //weighted quick union, this keeps the 'trees' balanced, and keeps performance of unite O( log(n) ) - //if (_elements[i].Size < _elements[j].Size) - //{ - // Element element = _elements[i]; - // element.ID = j; - // _elements[i] = element; - - // element = _elements[j]; - // element.Size += _elements[i].Size; - // _elements[j] = element; - //} - //else - //{ - // Element element = _elements[j]; - // element.ID = i; - // _elements[j] = element; - - // element = _elements[i]; - // element.Size += _elements[j].Size; - // _elements[i] = element; - //} - _elements[i].ID = j; - _elements[j].Size += _elements[i].Size; - } - - #region IDisposable Members - - public void Dispose() - { - _elements.Clear(); - } - - #endregion - } - - public class Element - { - private int _id; - private int _size; - - public int ID { get { return _id; } set { _id = value; } } - public int Size { get { return _size; } set { _size = value; } } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/BUSimplex1to4.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/BUSimplex1to4.cs deleted file mode 100644 index 625c7c92e..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/BUSimplex1to4.cs +++ /dev/null @@ -1,215 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// BUSimplex1to4 implements feature based and implicit simplex of up to 4 vertices (tetrahedron, triangle, line, vertex). - /// - public class BUSimplex1to4 : PolyhedralConvexShape - { - private int _numVertices = 0; - private Vector3[] _vertices = new Vector3[4]; - - public BUSimplex1to4() { } - - public BUSimplex1to4(Vector3 pointA) - { - AddVertex(pointA); - } - - public BUSimplex1to4(Vector3 pointA, Vector3 pointB) - { - AddVertex(pointA); - AddVertex(pointB); - } - - public BUSimplex1to4(Vector3 pointA, Vector3 pointB, Vector3 pointC) - { - AddVertex(pointA); - AddVertex(pointB); - AddVertex(pointC); - } - - public BUSimplex1to4(Vector3 pointA, Vector3 pointB, Vector3 pointC, Vector3 pointD) - { - AddVertex(pointA); - AddVertex(pointB); - AddVertex(pointC); - AddVertex(pointD); - } - - protected Vector3[] Vertices { get { return _vertices; } set { _vertices = value; } } - - public override int VertexCount - { - get - { - return _numVertices; - } - } - - public override int EdgeCount - { - get - { - //euler formula, F-E+V = 2, so E = F+V-2 - switch (_numVertices) - { - case 0: return 0; - case 1: return 0; - case 2: return 1; - case 3: return 3; - case 4: return 6; - } - return 0; - } - } - - public override int PlaneCount - { - get - { - switch (_numVertices) - { - case 0: - return 0; - case 1: - return 0; - case 2: - return 0; - case 3: - return 2; - case 4: - return 4; - } - return 0; - } - } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.Tetrahedral; - } - } - - public override string Name - { - get - { - return "BUSimplex1to4"; - } - } - - public void AddVertex(Vector3 v) - { - _vertices[_numVertices++] = v; - } - - public void Reset() - { - _numVertices = 0; - } - - public override void GetEdge(int i, out Vector3 pa, out Vector3 pb) - { - switch (_numVertices) - { - case 2: - pa = _vertices[0]; - pb = _vertices[1]; - return; - case 3: - switch (i) - { - case 0: - pa = _vertices[0]; - pb = _vertices[1]; - return; - case 1: - pa = _vertices[1]; - pb = _vertices[2]; - return; - case 2: - pa = _vertices[2]; - pb = _vertices[0]; - return; - } - break; - case 4: - switch (i) - { - case 0: - pa = _vertices[0]; - pb = _vertices[1]; - return; - case 1: - pa = _vertices[1]; - pb = _vertices[2]; - return; - case 2: - pa = _vertices[2]; - pb = _vertices[0]; - return; - case 3: - pa = _vertices[0]; - pb = _vertices[3]; - return; - case 4: - pa = _vertices[1]; - pb = _vertices[3]; - return; - case 5: - pa = _vertices[2]; - pb = _vertices[3]; - return; - } - break; - } - - pa = new Vector3(); - pb = new Vector3(); - } - - public override void GetVertex(int i, out Vector3 vtx) - { - vtx = _vertices[i]; - } - - public override void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i) - { - planeNormal = new Vector3(); - planeSupport = new Vector3(); - } - - public override bool IsInside(Vector3 pt, float tolerance) - { - return false; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/BoxShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/BoxShape.cs deleted file mode 100644 index dcf38110f..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/BoxShape.cs +++ /dev/null @@ -1,316 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class BoxShape : PolyhedralConvexShape - { - public BoxShape(Vector3 boxHalfExtents) - { - ImplicitShapeDimensions = boxHalfExtents; - } - - public override int VertexCount - { - get - { - return 8; - } - } - - public override int EdgeCount - { - get - { - return 12; - } - } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.Box; - } - } - - public override string Name - { - get - { - return "Box"; - } - } - - public override int PreferredPenetrationDirectionsCount - { - get - { - return 6; - } - } - - public override int PlaneCount - { - get - { - return 6; - } - } - - public Vector3 HalfExtents { get { return ImplicitShapeDimensions * LocalScaling; } } - - public override void GetEdge(int i, out Vector3 pa, out Vector3 pb) - { - int edgeVert0 = 0; - int edgeVert1 = 0; - - switch (i) - { - case 0: - edgeVert0 = 0; - edgeVert1 = 1; - break; - case 1: - edgeVert0 = 0; - edgeVert1 = 2; - break; - case 2: - edgeVert0 = 1; - edgeVert1 = 3; - - break; - case 3: - edgeVert0 = 2; - edgeVert1 = 3; - break; - case 4: - edgeVert0 = 0; - edgeVert1 = 4; - break; - case 5: - edgeVert0 = 1; - edgeVert1 = 5; - - break; - case 6: - edgeVert0 = 2; - edgeVert1 = 6; - break; - case 7: - edgeVert0 = 3; - edgeVert1 = 7; - break; - case 8: - edgeVert0 = 4; - edgeVert1 = 5; - break; - case 9: - edgeVert0 = 4; - edgeVert1 = 6; - break; - case 10: - edgeVert0 = 5; - edgeVert1 = 7; - break; - case 11: - edgeVert0 = 6; - edgeVert1 = 7; - break; - default: - throw new BulletException(); - - } - - GetVertex(edgeVert0, out pa); - GetVertex(edgeVert1, out pb); - } - - public override void GetVertex(int i, out Vector3 vtx) - { - Vector3 halfExtents = HalfExtents; - - vtx = new Vector3( - halfExtents.X * (1 - (i & 1)) - halfExtents.X * (i & 1), - halfExtents.Y * (1 - ((i & 2) >> 1)) - halfExtents.Y * ((i & 2) >> 1), - halfExtents.Z * (1 - ((i & 4) >> 2)) - halfExtents.Z * ((i & 4) >> 2)); - } - - public override void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i) - { - //this plane might not be aligned... - Vector4 plane; - GetPlaneEquation(out plane, i); - planeNormal = new Vector3(plane.X, plane.Y, plane.Z); - planeSupport = LocalGetSupportingVertex(-planeNormal); - } - - public override bool IsInside(Vector3 pt, float tolerance) - { - Vector3 halfExtents = HalfExtents; - - //btScalar minDist = 2*tolerance; - - bool result = (pt.X <= ( halfExtents.X + tolerance)) && - (pt.X >= (-halfExtents.X - tolerance)) && - (pt.Y <= ( halfExtents.Y + tolerance)) && - (pt.Y >= (-halfExtents.Y - tolerance)) && - (pt.Z <= ( halfExtents.Z + tolerance)) && - (pt.Z >= (-halfExtents.Z - tolerance)); - - return result; - } - - public override Vector3 LocalGetSupportingVertex(Vector3 vec) - { - Vector3 halfExtents = HalfExtents; - - return new Vector3( vec.X < 0.0f ? -halfExtents.X : halfExtents.X, - vec.Y < 0.0f ? -halfExtents.Y : halfExtents.Y, - vec.Z < 0.0f ? -halfExtents.Z : halfExtents.Z); - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - Vector3 halfExtents = HalfExtents; - Vector3 margin = new Vector3(Margin, Margin, Margin); - halfExtents -= margin; - - return new Vector3( vec.X < 0.0f ? -halfExtents.X : halfExtents.X, - vec.Y < 0.0f ? -halfExtents.Y : halfExtents.Y, - vec.Z < 0.0f ? -halfExtents.Z : halfExtents.Z); - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - Vector3 halfExtents = HalfExtents; - Vector3 margin = new Vector3(Margin, Margin, Margin); - halfExtents -= margin; - - for (int i = 0; i < vectors.Length; i++) - { - Vector3 vec = vectors[i]; - supportVerticesOut[i] = new Vector3(vec.X < 0.0f ? -halfExtents.X : halfExtents.X, - vec.Y < 0.0f ? -halfExtents.Y : halfExtents.Y, - vec.Z < 0.0f ? -halfExtents.Z : halfExtents.Z); - } - } - - public virtual void GetPlaneEquation(out Vector4 plane, int i) - { - Vector3 halfExtents = HalfExtents; - - switch (i) - { - case 0: - plane = new Vector4(1, 0, 0, 0); - plane.W = -halfExtents.X; - break; - case 1: - plane = new Vector4(-1, 0, 0, 0); - plane.W = -halfExtents.X; - break; - case 2: - plane = new Vector4(0, 1, 0, 0); - plane.W = -halfExtents.Y; - break; - case 3: - plane = new Vector4(0, -1, 0, 0); - plane.W = -halfExtents.Y; - break; - case 4: - plane = new Vector4(0, 0, 1, 0); - plane.W = -halfExtents.Z; - break; - case 5: - plane = new Vector4(0, 0, -1, 0); - plane.W = -halfExtents.Z; - break; - default: - throw new BulletException(); - } - } - - public override void GetPreferredPenetrationDirection(int index, out Vector3 penetrationVector) - { - switch (index) - { - case 0: - penetrationVector = new Vector3(1, 0, 0); - break; - case 1: - penetrationVector = new Vector3(-1, 0, 0); - break; - case 2: - penetrationVector = new Vector3(0, 1, 0); - break; - case 3: - penetrationVector = new Vector3(0, -1, 0); - break; - case 4: - penetrationVector = new Vector3(0, 0, 1); - break; - case 5: - penetrationVector = new Vector3(0, 0, -1); - break; - default: - throw new BulletException(); - } - } - - public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - Vector3 halfExtents = HalfExtents; - - Matrix abs_b = MathHelper.Absolute(t); - Vector3 center = t.Translation; - Vector3 row1 = new Vector3(abs_b.M11, abs_b.M12, abs_b.M13); - Vector3 row2 = new Vector3(abs_b.M21, abs_b.M22, abs_b.M23); - Vector3 row3 = new Vector3(abs_b.M31, abs_b.M32, abs_b.M33); - Vector3 extent = new Vector3(Vector3.Dot(row1, halfExtents), - Vector3.Dot(row2, halfExtents), - Vector3.Dot(row3, halfExtents)); - extent += new Vector3(Margin, Margin, Margin); - - aabbMin = center - extent; - aabbMax = center + extent; - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - Vector3 halfExtents = HalfExtents; - - float lx = 2f * (halfExtents.X); - float ly = 2f * (halfExtents.Y); - float lz = 2f * (halfExtents.Z); - - inertia = new Vector3(); - inertia.X = mass / (12.0f) * (ly * ly + lz * lz); - inertia.Y = mass / (12.0f) * (lx * lx + lz * lz); - inertia.Z = mass / (12.0f) * (lx * lx + ly * ly); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/BvhTriangleMeshShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/BvhTriangleMeshShape.cs deleted file mode 100644 index 9db3d211b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/BvhTriangleMeshShape.cs +++ /dev/null @@ -1,83 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - class MyNodeOverlapCallback : INodeOverlapCallback - { - StridingMeshInterface _meshInterface; - ITriangleCallback _callback; - Vector3[] _triangle = new Vector3[3]; - - public MyNodeOverlapCallback(ITriangleCallback callback, StridingMeshInterface meshInterface) - { - _meshInterface = meshInterface; - _callback = callback; - } - - public void ProcessNode(OptimizedBvhNode node) - { - List verts; - List indicies; - int numtriangles; - - _meshInterface.GetLockedReadOnlyVertexIndexBase(out verts, out indicies, out numtriangles, node.SubPart); - Vector3 meshScaling = _meshInterface.Scaling; - - for (int j = 0; j < 3; j++) - { - _triangle[j] = verts[indicies[j + node.TriangleIndex * 3]] * meshScaling; - } - - _callback.ProcessTriangle(_triangle, node.SubPart, node.TriangleIndex); - _meshInterface.UnLockReadOnlyVertexBase(node.SubPart); - } - } - - public class BvhTriangleMeshShape : TriangleMeshShape - { - OptimizedBvh _bvh = new OptimizedBvh(); - - public BvhTriangleMeshShape(StridingMeshInterface meshInterface) : base(meshInterface) - { - _bvh.Build(meshInterface); - } - - public override void ProcessAllTriangles(ITriangleCallback callback, Vector3 aabbMin, Vector3 aabbMax) - { - MyNodeOverlapCallback myNodeCallback = new MyNodeOverlapCallback(callback, MeshInterface); - _bvh.ReportAabbOverlappingNodex(myNodeCallback, aabbMin, aabbMax); - } - - public override string Name - { - get - { - return "BvhTriangleMesh"; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CollisionShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CollisionShape.cs deleted file mode 100644 index 81749c03d..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CollisionShape.cs +++ /dev/null @@ -1,148 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// CollisionShape provides generic interface for collidable objects - /// - public abstract class CollisionShape - { - //debugging support - private string _tempDebug; - - public abstract string Name { get; } - public string ExtraDebugInfo { get { return _tempDebug; } set { _tempDebug = value; } } - - public bool IsPolyhedral - { - get - { - return BroadphaseProxy.IsPolyhedral(ShapeType); - } - } - - public bool IsConvex - { - get - { - return BroadphaseProxy.IsConvex(ShapeType); - } - } - public bool IsConcave - { - get - { - return BroadphaseProxy.IsConcave(ShapeType); - } - } - public bool IsCompound - { - get - { - return BroadphaseProxy.IsCompound(ShapeType); - } - } - - //isInfinite is used to catch simulation error (aabb check) - public bool IsInfinite - { - get - { - return BroadphaseProxy.IsInfinite(ShapeType); - } - } - - public abstract float Margin { get; set; } - public abstract Vector3 LocalScaling { get; set; } - public abstract BroadphaseNativeTypes ShapeType { get; } - - - public virtual void GetBoundingSphere(out Vector3 center, out float radius) - { - Matrix tr = Matrix.Identity; - Vector3 aabbMin, aabbMax; - - GetAabb(tr, out aabbMin, out aabbMax); - - radius = (aabbMax - aabbMin).Length() * 0.5f; - center = (aabbMin + aabbMax) * 0.5f; - } - - public virtual float GetAngularMotionDisc() - { - Vector3 center; - float disc; - GetBoundingSphere(out center, out disc); - disc += center.Length(); - return disc; - } - - //calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep) - //result is conservative - public void CalculateTemporalAabb(Matrix currentTransform, Vector3 linearVelocity, Vector3 angularVelocity, float timeStep, out Vector3 temporalAabbMin, out Vector3 temporalAabbMax) - { - //start with static aabb - GetAabb(currentTransform, out temporalAabbMin, out temporalAabbMax); - - float temporalAabbMaxx = temporalAabbMax.X; - float temporalAabbMaxy = temporalAabbMax.Y; - float temporalAabbMaxz = temporalAabbMax.Z; - float temporalAabbMinx = temporalAabbMin.X; - float temporalAabbMiny = temporalAabbMin.Y; - float temporalAabbMinz = temporalAabbMin.Z; - - // add linear motion - Vector3 linMotion = linearVelocity * timeStep; - //todo: simd would have a vector max/min operation, instead of per-element access - if (linMotion.X > 0) - temporalAabbMaxx += linMotion.X; - else - temporalAabbMinx += linMotion.X; - if (linMotion.Y > 0) - temporalAabbMaxy += linMotion.Y; - else - temporalAabbMiny += linMotion.Y; - if (linMotion.Z > 0) - temporalAabbMaxz += linMotion.Z; - else - temporalAabbMinz += linMotion.Z; - - //add conservative angular motion - float angularMotion = angularVelocity.Length() * GetAngularMotionDisc() * timeStep; - Vector3 angularMotion3d = new Vector3(angularMotion, angularMotion, angularMotion); - temporalAabbMin = new Vector3(temporalAabbMinx, temporalAabbMiny, temporalAabbMinz); - temporalAabbMax = new Vector3(temporalAabbMaxx, temporalAabbMaxy, temporalAabbMaxz); - - temporalAabbMin -= angularMotion3d; - temporalAabbMax += angularMotion3d; - } - - public abstract void GetAabb(Matrix transform, out Vector3 aabbMin, out Vector3 aabbMax); - - public abstract void CalculateLocalInertia(float mass, out Vector3 inertia); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CompoundShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CompoundShape.cs deleted file mode 100644 index 503c8049b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CompoundShape.cs +++ /dev/null @@ -1,183 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// CompoundShape allows to store multiple other CollisionShapes - /// This allows for concave collision objects. This is more general then the Static Concave TriangleMeshShape. - /// - public class CompoundShape : CollisionShape - { - private List _childTransforms = new List(); - private List _childShapes = new List(); - private Vector3 _localAabbMin; - private Vector3 _localAabbMax; - - private OptimizedBvh _aabbTree; - private float _collisionMargin; - private Vector3 _localScaling; - - public CompoundShape() - { - _localAabbMin = new Vector3(1e30f, 1e30f, 1e30f); - _localAabbMax = new Vector3(-1e30f, -1e30f, -1e30f); - _aabbTree = null; - _collisionMargin = 0f; - _localScaling = new Vector3(1f, 1f, 1f); - } - - public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - Vector3 localHalfExtents = 0.5f * (_localAabbMax - _localAabbMin); - Vector3 localCenter = 0.5f * (_localAabbMax + _localAabbMin); - - Matrix abs_b = MathHelper.Absolute(t); - - Vector3 row1 = new Vector3(abs_b.M11, abs_b.M12, abs_b.M13); - Vector3 row2 = new Vector3(abs_b.M21, abs_b.M22, abs_b.M23); - Vector3 row3 = new Vector3(abs_b.M31, abs_b.M32, abs_b.M33); - - Vector3 center = new Vector3(Vector3.Dot(row1, localCenter) + t.Translation.X, - Vector3.Dot(row2, localCenter) + t.Translation.Y, - Vector3.Dot(row3, localCenter) + t.Translation.Z); - - Vector3 extent = new Vector3(Vector3.Dot(row1, localHalfExtents), - Vector3.Dot(row2, localHalfExtents), - Vector3.Dot(row3, localHalfExtents)); - - aabbMin = center - extent; - aabbMax = center + extent; - } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.Compound; - } - } - - public override Vector3 LocalScaling - { - get - { - return _localScaling; - } - set - { - _localScaling = value; - } - } - - public override string Name - { - get - { - return "Compound"; - } - } - - public override float Margin - { - get - { - return _collisionMargin; - } - set - { - _collisionMargin = value; - } - } - - public int ChildShapeCount { get { return _childShapes.Count; } } - //this is optional, but should make collision queries faster, by culling non-overlapping nodes - public OptimizedBvh AabbTree { get { return _aabbTree; } } - - public CollisionShape GetChildShape(int index) - { - return _childShapes[index]; - } - - public Matrix GetChildTransform(int index) - { - return _childTransforms[index]; - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - //approximation: take the inertia from the aabb for now - Matrix ident = Matrix.Identity; - Vector3 aabbMin, aabbMax; - GetAabb(ident, out aabbMin, out aabbMax); - - Vector3 halfExtents = (aabbMax - aabbMin) * 0.5f; - - float lx = 2f * (halfExtents.X); - float ly = 2f * (halfExtents.Y); - float lz = 2f * (halfExtents.Z); - - inertia = new Vector3(); - inertia.X = mass / (12.0f) * (ly * ly + lz * lz); - inertia.Y = mass / (12.0f) * (lx * lx + lz * lz); - inertia.Z = mass / (12.0f) * (lx * lx + ly * ly); - } - - public void AddChildShape(Matrix localTransform, CollisionShape shape) - { - _childTransforms.Add(localTransform); - _childShapes.Add(shape); - - //extend the local aabbMin/aabbMax - Vector3 localAabbMin, localAabbMax; - shape.GetAabb(localTransform, out localAabbMin, out localAabbMax); - if (_localAabbMin.X > localAabbMin.X) - { - _localAabbMin.X = localAabbMin.X; - } - if (_localAabbMax.X < localAabbMax.X) - { - _localAabbMax.X = localAabbMax.X; - } - if (_localAabbMin.Y > localAabbMin.Y) - { - _localAabbMin.Y = localAabbMin.Y; - } - if (_localAabbMax.Y < localAabbMax.Y) - { - _localAabbMax.Y = localAabbMax.Y; - } - if (_localAabbMin.Z > localAabbMin.Z) - { - _localAabbMin.Z = localAabbMin.Z; - } - if (_localAabbMax.Z < localAabbMax.Z) - { - _localAabbMax.Z = localAabbMax.Z; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConcaveShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConcaveShape.cs deleted file mode 100644 index 30df00f44..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConcaveShape.cs +++ /dev/null @@ -1,55 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public abstract class ConcaveShape : CollisionShape - { - private float _collisionMargin; - - public ConcaveShape() { } - - public float CollisionMargin - { - get { return _collisionMargin; } - set { _collisionMargin = value; } - } - - public override float Margin - { - get - { - return _collisionMargin; - } - set - { - _collisionMargin = value; - } - } - - public abstract void ProcessAllTriangles(ITriangleCallback callback, Vector3 aabbMin, Vector3 aabbMax); - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConeShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConeShape.cs deleted file mode 100644 index 3563c8305..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConeShape.cs +++ /dev/null @@ -1,208 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// ConeShape implements a Cone shape, around the X axis - /// - public class ConeShapeX : ConeShape - { - public ConeShapeX(float radius, float height) - : base(radius, height) - { - ConeUpIndex = 0; - } - } - - /// - /// ConeShape implements a Cone shape, around the Z axis - /// - public class ConeShapeZ : ConeShape - { - public ConeShapeZ(float radius, float height) - : base(radius, height) - { - ConeUpIndex = 2; - } - } - - /// - /// ConeShape implements a Cone shape, around the Y axis - /// - public class ConeShape : ConvexShape - { - private float _sinAngle; - private float _radius; - private float _height; - private int[] _coneIndices = new int[3]; - - public ConeShape(float radius, float height) - { - _radius = radius; - _height = height; - ConeUpIndex = 1; - _sinAngle = (_radius / (float)Math.Sqrt(_radius * _radius + _height * _height)); - } - - public float Radius { get { return _radius; } } - public float Height { get { return _height; } } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.Cone; - } - } - - public override string Name - { - get - { - return "Cone"; - } - } - - //choose upAxis index - public int ConeUpIndex - { - get { return _coneIndices[1]; } - set - { - switch (value) - { - case 0: - _coneIndices[0] = 1; - _coneIndices[1] = 0; - _coneIndices[2] = 2; - break; - case 1: - _coneIndices[0] = 0; - _coneIndices[1] = 1; - _coneIndices[2] = 2; - break; - case 2: - _coneIndices[0] = 0; - _coneIndices[1] = 2; - _coneIndices[2] = 1; - break; - default: - BulletDebug.Assert(false); - break; - } - } - } - - private Vector3 ConeLocalSupport(Vector3 v) - { - float halfHeight = _height * 0.5f; - bool condition; - - if (_coneIndices[1] == 0) - condition = v.X > v.Length() * _sinAngle; - else if (_coneIndices[1] == 1) - condition = v.Y > v.Length() * _sinAngle; - else - condition = v.Z > v.Length() * _sinAngle; - - if (condition) - { - Vector3 tmp = new Vector3(); - MathHelper.SetValueByIndex(ref tmp, _coneIndices[1], halfHeight); - return tmp; - } - else - { - float s = (float)Math.Sqrt(MathHelper.GetValueByIndex(v, _coneIndices[0]) * MathHelper.GetValueByIndex(v, _coneIndices[0]) - + MathHelper.GetValueByIndex(v, _coneIndices[2]) * MathHelper.GetValueByIndex(v, _coneIndices[2])); - if (s > MathHelper.Epsilon) - { - float d = _radius / s; - Vector3 tmp = new Vector3(); - MathHelper.SetValueByIndex(ref tmp, _coneIndices[0], MathHelper.GetValueByIndex(v, _coneIndices[0]) * d); - MathHelper.SetValueByIndex(ref tmp, _coneIndices[1], -halfHeight); - MathHelper.SetValueByIndex(ref tmp, _coneIndices[2], MathHelper.GetValueByIndex(v, _coneIndices[2]) * d); - return tmp; - } - else - { - Vector3 tmp = new Vector3(); - MathHelper.SetValueByIndex(ref tmp, _coneIndices[1], -halfHeight); - return tmp; - } - } - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - return ConeLocalSupport(vec); - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - for (int i = 0; i < vectors.Length; i++) - supportVerticesOut[i] = ConeLocalSupport(vectors[i]); - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - Matrix identity = Matrix.Identity; - Vector3 aabbMin, aabbMax; - GetAabb(identity, out aabbMin, out aabbMax); - - Vector3 halfExtents = (aabbMax - aabbMin) * 0.5f; - - float margin = Margin; - - float lx = 2f * (halfExtents.X + margin); - float ly = 2f * (halfExtents.Y + margin); - float lz = 2f * (halfExtents.Z + margin); - float x2 = lx * lx; - float y2 = ly * ly; - float z2 = lz * lz; - float scaledmass = mass * 0.08333333f; - - inertia = scaledmass * (new Vector3(y2 + z2, x2 + z2, x2 + y2)); - } - - public override Vector3 LocalGetSupportingVertex(Vector3 vec) - { - Vector3 supVertex = ConeLocalSupport(vec); - if (Margin != 0) - { - Vector3 vecnorm = vec; - if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) - { - vecnorm = new Vector3(-1f, -1f, -1f); - } - vecnorm = Vector3.Normalize(vecnorm); - supVertex += Margin * vecnorm; - } - return supVertex; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConvexHullShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConvexHullShape.cs deleted file mode 100644 index dc4ed3abc..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConvexHullShape.cs +++ /dev/null @@ -1,184 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// ConvexHullShape implements an implicit (getSupportingVertex) Convex Hull of a Point Cloud (vertices) - /// No connectivity is needed. localGetSupportingVertex iterates linearly though all vertices. - /// on modern hardware, due to cache coherency this isn't that bad. Complex algorithms tend to trash the cash. - /// (memory is much slower then the cpu) - /// - public class ConvexHullShape : PolyhedralConvexShape - { - private List _points = new List(); - - public ConvexHullShape() { } - - public override int VertexCount - { - get - { - return _points.Count; - } - } - - public override int EdgeCount - { - get - { - return _points.Count; - } - } - - public override int PlaneCount - { - get - { - return 0; - } - } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.ConvexHull; - } - } - - public override string Name - { - get - { - return "Convex"; - } - } - - public override Vector3 LocalGetSupportingVertex(Vector3 vec) - { - Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec); - - if (Margin != 0) - { - Vector3 vecnorm = vec; - if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) - { - vecnorm=new Vector3(-1, -1, -1); - } - vecnorm = Vector3.Normalize(vecnorm); - supVertex += Margin * vecnorm; - } - return supVertex; - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec0) - { - Vector3 supVec = new Vector3(); - float newDot, maxDot = -1e30f; - - Vector3 vec = vec0; - float lenSqr = vec.LengthSquared(); - if (lenSqr < 0.0001f) - { - vec = new Vector3(1, 0, 0); - } - else - { - float rlen = 1f / (float)Math.Sqrt(lenSqr); - vec *= rlen; - } - - for (int i = 0; i < _points.Count; i++) - { - Vector3 vtx = _points[i] * LocalScaling; - - newDot = Vector3.Dot(vec, vtx); - if (newDot > maxDot) - { - maxDot = newDot; - supVec = vtx; - } - } - return supVec; - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - float newDot; - //use 'w' component of supportVerticesOut? - /*{ - for (int i = 0; i < numVectors; i++) - { - supportVerticesOut[i][3] = -1e30f; - } - }*/ - #warning Warning! - for (int i = 0; i < _points.Count; i++) - { - Vector3 vtx = _points[i] * LocalScaling; - - for (int j = 0; j < vectors.Length; j++) - { - newDot = Vector3.Dot(vectors[j], vtx); - if (newDot > -1e30f) - { - //WARNING: don't swap next lines, the w component would get overwritten! - supportVerticesOut[j] = vtx; - //supportVerticesOut[j][3] = newDot; - #warning Warning! - } - } - } - } - - public override void GetEdge(int i, out Vector3 pa, out Vector3 pb) - { - int index0 = i % _points.Count; - int index1 = (i + 1) % _points.Count; - pa = _points[index0] * LocalScaling; - pb = _points[index1] * LocalScaling; - } - - public override void GetVertex(int i, out Vector3 vtx) - { - vtx = _points[i] * LocalScaling; - } - - public override void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i) - { - planeNormal = new Vector3(); - planeSupport = new Vector3(); - BulletDebug.Assert(false); - } - - public override bool IsInside(Vector3 pt, float tolerance) - { - BulletDebug.Assert(false); - return false; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConvexShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConvexShape.cs deleted file mode 100644 index 18ace9983..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConvexShape.cs +++ /dev/null @@ -1,141 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// ConvexShape is an abstract shape interface. - /// The explicit part provides plane-equations, the implicit part provides GetClosestPoint interface. - /// used in combination with GJK or btConvexCast - /// - public abstract class ConvexShape : CollisionShape - { - private const int _maxPreferredPenetrationDirections = 10; - private const float _convexDistanceMargin = 0.04f; - - private Vector3 _localScaling; - private Vector3 _implicitShapeDimensions; - private float _collisionMargin; - - public ConvexShape() - : base() - { - _localScaling = Vector3.One; - _collisionMargin = ConvexDistanceMargin; - } - - public static int MaxPreferredPenetrationDirections { get { return _maxPreferredPenetrationDirections; } } - public static float ConvexDistanceMargin { get { return _convexDistanceMargin; } } - - public Vector3 ImplicitShapeDimensions { get { return _implicitShapeDimensions; } protected set { _implicitShapeDimensions = value; } } - public virtual int PreferredPenetrationDirectionsCount { get { return 0; } } - - protected float CollisionMargin { get { return _collisionMargin; } set { _collisionMargin = value; } } - - public virtual void GetPreferredPenetrationDirection(int index, out Vector3 penetrationVector) - { - penetrationVector = new Vector3(); - BulletDebug.Assert(false); - } - - public abstract Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec); - //notice that the vectors should be unit length - public abstract void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut); - - /// - /// getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version - /// - /// - /// - /// - public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - GetAabbSlow(t, out aabbMin, out aabbMax); - } - - public override Vector3 LocalScaling - { - get - { - return _localScaling; - } - set - { - _localScaling = value; - } - } - - public override float Margin - { - get - { - return _collisionMargin; - } - set - { - _collisionMargin = value; - } - } - - public virtual Vector3 LocalGetSupportingVertex(Vector3 vec) - { - Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec); - - if (Margin != 0f) - { - Vector3 vecnorm = vec; - if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) - { - vecnorm = new Vector3(-1f, -1f, -1f); - } - vecnorm.Normalize(); - supVertex += Margin * vecnorm; - } - return supVertex; - } - - public virtual void GetAabbSlow(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - float margin = Margin; - aabbMax = new Vector3(); - aabbMin = new Vector3(); - - for (int i = 0; i < 3; i++) - { - Vector3 vec = new Vector3(0f, 0f, 0f); - MathHelper.SetElement(ref vec, i, 1); - - Vector3 sv = LocalGetSupportingVertex(Vector3.TransformNormal(vec, t)); - - Vector3 tmp = MathHelper.MatrixToVector(t, sv); - MathHelper.SetElement(ref aabbMax, i, MathHelper.GetElement(tmp, i) + margin); - MathHelper.SetElement(ref vec, i, -1f); - tmp = MathHelper.MatrixToVector(t, LocalGetSupportingVertex(Vector3.TransformNormal(vec, t))); - MathHelper.SetElement(ref aabbMin, i, MathHelper.GetElement(tmp, i) - margin); - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConvexTriangleMeshShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConvexTriangleMeshShape.cs deleted file mode 100644 index 546f232bd..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/ConvexTriangleMeshShape.cs +++ /dev/null @@ -1,185 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// ConvexTriangleMeshShape is a convex hull of a triangle mesh. If you just have a point cloud, you can use ConvexHullShape instead. - /// It uses the StridingMeshInterface instead of a point cloud. This can avoid the duplication of the triangle mesh data. - /// - public class ConvexTriangleMeshShape : PolyhedralConvexShape - { - private StridingMeshInterface _stridingMesh; - - public ConvexTriangleMeshShape(StridingMeshInterface meshInterface) - { - _stridingMesh = meshInterface; - } - - public StridingMeshInterface getStridingMesh() - { - return _stridingMesh; - } - - public override int VertexCount - { - get - { - return 0; - } - } - - public override int EdgeCount - { - get - { - return 0; - } - } - - public override int PlaneCount - { - get - { - return 0; - } - } - - public override Vector3 LocalScaling - { - get - { - return base.LocalScaling; - } - set - { - _stridingMesh.Scaling = value; - } - } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.ConvexTriangleMesh; - } - } - - public override string Name - { - get - { - return "ConvexTrimesh"; - } - } - - public override void GetEdge(int i, out Vector3 pa, out Vector3 pb) - { - pa = new Vector3(); - pb = new Vector3(); - BulletDebug.Assert(false); - } - - public override void GetVertex(int i, out Vector3 vtx) - { - vtx = new Vector3(); - BulletDebug.Assert(false); - } - - public override void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i) - { - planeNormal = new Vector3(); - planeSupport = new Vector3(); - BulletDebug.Assert(false); - } - - public override bool IsInside(Vector3 pt, float tolerance) - { - BulletDebug.Assert(false); - return false; - } - - public override Vector3 LocalGetSupportingVertex(Vector3 vec) - { - Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec); - - if (Margin != 0) - { - Vector3 vecnorm = vec; - if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) - { - vecnorm = new Vector3(-1, -1, -1); - } - vecnorm = Vector3.Normalize(vecnorm); - supVertex += Margin * vecnorm; - } - return supVertex; - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec0) - { - Vector3 supVec = new Vector3(); - - Vector3 vec = vec0; - float lenSqr = vec.LengthSquared(); - if (lenSqr < 0.0001f) - { - vec = new Vector3(1, 0, 0); - } - else - { - float rlen = 1f / (float)Math.Sqrt(lenSqr); - vec *= rlen; - } - - LocalSupportVertexCallback supportCallback = new LocalSupportVertexCallback(vec); - Vector3 aabbMax = new Vector3(1e30f, 1e30f, 1e30f); - _stridingMesh.InternalProcessAllTriangles(supportCallback, -aabbMax, aabbMax); - supVec = supportCallback.SupportVertexLocal; - - return supVec; - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - //use 'w' component of supportVerticesOut? - /*{ - for (int i = 0; i < numVectors; i++) - { - supportVerticesOut[i][3] = -1e30f; - } - }*/ - for (int j = 0; j < vectors.Length; j++) - { - Vector3 vec = vectors[j]; - LocalSupportVertexCallback supportCallback = new LocalSupportVertexCallback(vec); - Vector3 aabbMax = new Vector3(1e30f, 1e30f, 1e30f); - _stridingMesh.InternalProcessAllTriangles(supportCallback, -aabbMax, aabbMax); - supportVerticesOut[j] = supportCallback.SupportVertexLocal; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CylinderShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CylinderShape.cs deleted file mode 100644 index d6c4db6b2..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CylinderShape.cs +++ /dev/null @@ -1,136 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// implements cylinder shape interface - /// - public class CylinderShape : BoxShape - { - public CylinderShape(Vector3 halfExtents) - : base(halfExtents) - { - } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.Cylinder; - } - } - - public virtual int UpAxis - { - get - { - return 1; - } - } - - public virtual float Radius - { - get - { - return HalfExtents.Z; - } - } - - //debugging - public override string Name - { - get - { - return "CylinderY"; - } - } - - //getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version - public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - GetAabbSlow(t, out aabbMin, out aabbMax); - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - return CylinderLocalSupportY(HalfExtents, vec); - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - for (int i = 0; i < vectors.Length; i++) - { - supportVerticesOut[i] = CylinderLocalSupportY(HalfExtents, vectors[i]); - } - } - - public override Vector3 LocalGetSupportingVertex(Vector3 vec) - { - - Vector3 supVertex; - supVertex = LocalGetSupportingVertexWithoutMargin(vec); - - if (Margin != 0) - { - Vector3 vecnorm = vec; - if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) - { - vecnorm=new Vector3(-1, -1, -1); - } - vecnorm = Vector3.Normalize(vecnorm); - supVertex += Margin * vecnorm; - } - return supVertex; - } - - private Vector3 CylinderLocalSupportY(Vector3 halfExtents, Vector3 v) - { - float radius = halfExtents.X; - float halfHeight = halfExtents.Y; - - Vector3 tmp = new Vector3(); - float d; - - float s = (float)Math.Sqrt(v.X * v.X + v.Z * v.Z); - if (s != 0) - { - d = radius / s; - tmp.X = v.X * d; - tmp.Y = v.Y < 0 ? -halfHeight : halfHeight; - tmp.Z = v.Z * d; - return tmp; - } - else - { - tmp.X = radius; - tmp.Y = v.Y < 0 ? -halfHeight : halfHeight; - tmp.Z = 0; - return tmp; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CylinderShapeX.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CylinderShapeX.cs deleted file mode 100644 index 107dfc286..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CylinderShapeX.cs +++ /dev/null @@ -1,100 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class CylinderShapeX : CylinderShape - { - public CylinderShapeX(Vector3 halfExtents) - : base(halfExtents) { } - - public override int UpAxis - { - get - { - return 0; - } - } - - public override float Radius - { - get - { - return HalfExtents.Y; - } - } - - //debugging - public override string Name - { - get - { - return "CylinderX"; - } - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - return CylinderLocalSupportX(HalfExtents, vec); - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - for (int i = 0; i < vectors.Length; i++) - { - supportVerticesOut[i] = CylinderLocalSupportX(HalfExtents, vectors[i]); - } - } - - private Vector3 CylinderLocalSupportX(Vector3 halfExtents, Vector3 v) - { - //mapping depends on how cylinder local orientation is - // extents of the cylinder is: X,Y is for radius, and Z for height - float radius = halfExtents.Y; - float halfHeight = halfExtents.X; - - Vector3 tmp = new Vector3(); - float d; - - float s = (float)Math.Sqrt(v.Y * v.Y + v.Z * v.Z); - if (s != 0) - { - d = radius / s; - tmp.Y = v.Y * d; - tmp.X = v.X < 0 ? -halfHeight : halfHeight; - tmp.Z = v.Z * d; - return tmp; - } - else - { - tmp.Y = radius; - tmp.X = v.X < 0 ? -halfHeight : halfHeight; - tmp.Z = 0; - return tmp; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CylinderShapeZ.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CylinderShapeZ.cs deleted file mode 100644 index a7167e9c4..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/CylinderShapeZ.cs +++ /dev/null @@ -1,100 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class CylinderShapeZ : CylinderShape - { - public CylinderShapeZ(Vector3 halfExtents) - : base(halfExtents) { } - - public override int UpAxis - { - get - { - return 2; - } - } - - public override float Radius - { - get - { - return HalfExtents.X; - } - } - - //debugging - public override string Name - { - get - { - return "CylinderZ"; - } - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - return CylinderLocalSupportZ(HalfExtents, vec); - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - for (int i = 0; i < vectors.Length; i++) - { - supportVerticesOut[i] = CylinderLocalSupportZ(HalfExtents, vectors[i]); - } - } - - Vector3 CylinderLocalSupportZ(Vector3 halfExtents, Vector3 v) - { - //mapping depends on how cylinder local orientation is - // extents of the cylinder is: X,Y is for radius, and Z for height - float radius = halfExtents.X; - float halfHeight = halfExtents.Z; - - Vector3 tmp = new Vector3(); - float d; - - float s = (float)Math.Sqrt(v.X * v.X + v.Y * v.Y); - if (s != 0) - { - d = radius / s; - tmp.X = v.X * d; - tmp.Z = v.Z < 0 ? -halfHeight : halfHeight; - tmp.Y = v.Y * d; - return tmp; - } - else - { - tmp.X = radius; - tmp.Z = v.Z < 0 ? -halfHeight : halfHeight; - tmp.Y = 0; - return tmp; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/EmptyShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/EmptyShape.cs deleted file mode 100644 index 077a63635..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/EmptyShape.cs +++ /dev/null @@ -1,80 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; -using System.Diagnostics; - -namespace XnaDevRu.BulletX -{ - public class EmptyShape : ConcaveShape - { - private Vector3 _localScaling; - - public override string Name - { - get - { - return "Empty"; - } - } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.Empty; - } - } - - public override Vector3 LocalScaling - { - get - { - return _localScaling; - } - set - { - _localScaling = value; - } - } - - public override void ProcessAllTriangles(ITriangleCallback callback, Microsoft.Xna.Framework.Vector3 aabbMin, Microsoft.Xna.Framework.Vector3 aabbMax) - { - throw new Exception("The method or operation is not implemented."); - } - - public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - Vector3 margin = new Vector3(Margin, Margin, Margin); - aabbMin = t.Translation - margin; - aabbMax = t.Translation + margin; - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - inertia = new Vector3(); - BulletDebug.Assert(false); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/FilteredCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/FilteredCallback.cs deleted file mode 100644 index 2e148e31b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/FilteredCallback.cs +++ /dev/null @@ -1,55 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class FilteredCallback : ITriangleIndexCallback - { - private ITriangleCallback _callback; - private Vector3 _aabbMin; - private Vector3 _aabbMax; - - public FilteredCallback(ITriangleCallback callback, Vector3 aabbMin, Vector3 aabbMax) - { - _callback = callback; - _aabbMin = aabbMin; - _aabbMax = aabbMax; - } - - public ITriangleCallback TriangleCallback { get { return _callback; } set { _callback = value; } } - public Vector3 AabbMin { get { return _aabbMin; } set { _aabbMin = value; } } - public Vector3 AabbMax { get { return _aabbMax; } set { _aabbMax = value; } } - - public void ProcessTriangleIndex(Vector3[] triangle, int partId, int triangleIndex) - { - if (MathHelper.TestTriangleAgainstAabb2(triangle, _aabbMin, _aabbMax)) - { - //check aabb in triangle-space, before doing this - _callback.ProcessTriangle(triangle, partId, triangleIndex); - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/InternalTriangleIndexCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/InternalTriangleIndexCallback.cs deleted file mode 100644 index 75c17778c..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/InternalTriangleIndexCallback.cs +++ /dev/null @@ -1,33 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public interface ITriangleIndexCallback - { - void ProcessTriangleIndex(Vector3[] triangle, int partId, int triangleIndex); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/LocalSupportVertexCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/LocalSupportVertexCallback.cs deleted file mode 100644 index 8cf3236a5..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/LocalSupportVertexCallback.cs +++ /dev/null @@ -1,58 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class LocalSupportVertexCallback : ITriangleIndexCallback - { - private Vector3 _supportVertexLocal; - private float _maxDot; - private Vector3 _supportVecLocal; - - public LocalSupportVertexCallback(Vector3 supportVecLocal) - { - _supportVertexLocal = new Vector3(); - _maxDot = -1e30f; - _supportVecLocal = supportVecLocal; - } - - public float MaxDot { get { return _maxDot; } set { _maxDot = value; } } - public Vector3 SupportVertexLocal { get { return _supportVecLocal; } set { _supportVecLocal = value; } } - - public void ProcessTriangleIndex(Vector3[] triangle, int partId, int triangleIndex) - { - for (int i = 0; i < 3; i++) - { - float dot = Vector3.Dot(_supportVecLocal, triangle[i]); - if (dot > _maxDot) - { - _maxDot = dot; - _supportVertexLocal = triangle[i]; - } - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/MinkowskiSumShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/MinkowskiSumShape.cs deleted file mode 100644 index e5e954237..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/MinkowskiSumShape.cs +++ /dev/null @@ -1,99 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// MinkowskiSumShape represents implicit (getSupportingVertex) based minkowski sum of two convex implicit shapes. - /// - public class MinkowskiSumShape : ConvexShape - { - private Matrix _transformA; - private Matrix _transformB; - private ConvexShape _shapeA; - private ConvexShape _shapeB; - - public MinkowskiSumShape(ConvexShape shapeA, ConvexShape shapeB) - { - _shapeA = shapeA; - _shapeB = shapeB; - _transformA = Matrix.Identity; - _transformB = Matrix.Identity; - } - - public Matrix TransformA { get { return _transformA; } set { _transformA = value; } } - public Matrix TransformB { get { return _transformB; } set { _transformB = value; } } - public ConvexShape ShapeA { get { return _shapeA; } } - public ConvexShape ShapeB { get { return _shapeB; } } - - public override float Margin - { - get - { - return _shapeA.Margin + _shapeB.Margin; - } - set - { - base.Margin = value; - } - } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.MinkowskiDifference; - } - } - - public override string Name - { - get - { - return "MinkowskiSum"; - } - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - Vector3 supVertexA = MathHelper.MatrixToVector(_transformA, _shapeA.LocalGetSupportingVertexWithoutMargin(Vector3.TransformNormal(vec, _transformA))); - Vector3 supVertexB = MathHelper.MatrixToVector(_transformB, _shapeB.LocalGetSupportingVertexWithoutMargin(Vector3.TransformNormal(vec, _transformB))); - return supVertexA + supVertexB; - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - for (int i = 0; i < vectors.Length; i++) - supportVerticesOut[i] = LocalGetSupportingVertexWithoutMargin(vectors[i]); - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - inertia = new Vector3(); - BulletDebug.Assert(false); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/MultiSphereShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/MultiSphereShape.cs deleted file mode 100644 index 11abb5c6b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/MultiSphereShape.cs +++ /dev/null @@ -1,154 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// MultiSphereShape represents implicit convex hull of a collection of spheres (using getSupportingVertex) - /// - public class MultiSphereShape : ConvexShape - { - private const int _maxNumSpheres = 5; - private Vector3[] _localPositions = new Vector3[MaxNumSpheres]; - private float[] _radi = new float[MaxNumSpheres]; - private Vector3 _inertiaHalfExtents; - - private int m_numSpheres; - - public MultiSphereShape(Vector3 inertiaHalfExtents, Vector3[] positions, float[] radi, int numSpheres) - { - _inertiaHalfExtents = inertiaHalfExtents; - float startMargin = 1e30f; - - m_numSpheres = numSpheres; - for (int i = 0; i < m_numSpheres; i++) - { - _localPositions[i] = positions[i]; - _radi[i] = radi[i]; - if (radi[i] < startMargin) - startMargin = radi[i]; - } - Margin = startMargin; - } - - public static int MaxNumSpheres { get { return _maxNumSpheres; } } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.MultiSphere; - } - } - - public override string Name - { - get - { - return "MultiSphere"; - } - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vecA) - { - Vector3 supVec = new Vector3(); - - float maxDot = -1e30f; - - - Vector3 vec = vecA; - float lenSqr = vec.LengthSquared(); - if (lenSqr < 0.0001f) - { - vec = new Vector3(1, 0, 0); - } - else - { - float rlen = 1f / (float)Math.Sqrt(lenSqr); - vec *= rlen; - } - - Vector3 vtx; - float newDot; - - for (int i = 0; i < m_numSpheres; i++) - { - vtx = _localPositions[i] + vec * LocalScaling * _radi[i] - vec * Margin; - newDot = Vector3.Dot(vec, vtx); - if (newDot > maxDot) - { - maxDot = newDot; - supVec = vtx; - } - } - - return supVec; - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - for (int j = 0; j < vectors.Length; j++) - { - float maxDot = -1e30f; - Vector3 vtx; - float newDot; - - for (int i = 0; i < m_numSpheres; i++) - { - vtx = _localPositions[i] + vectors[j] * LocalScaling * _radi[i] - vectors[j] * Margin; - newDot = Vector3.Dot(vectors[j], vtx); - if (newDot > maxDot) - { - maxDot = newDot; - supportVerticesOut[j] = vtx; - } - } - } - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - //as an approximation, take the inertia of the box that bounds the spheres - Matrix ident = Matrix.Identity; - Vector3 halfExtents = _inertiaHalfExtents; - - float margin = ConvexDistanceMargin; - - float lx = 2f * (halfExtents.X + margin); - float ly = 2f * (halfExtents.Y + margin); - float lz = 2f * (halfExtents.Z + margin); - float x2 = lx * lx; - float y2 = ly * ly; - float z2 = lz * lz; - float scaledmass = mass * 0.08333333f; - - inertia = new Vector3(); - inertia.X = scaledmass * (y2 + z2); - inertia.Y = scaledmass * (x2 + z2); - inertia.Z = scaledmass * (x2 + y2); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/NodeOverlapCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/NodeOverlapCallback.cs deleted file mode 100644 index fac344e14..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/NodeOverlapCallback.cs +++ /dev/null @@ -1,32 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX -{ - public interface INodeOverlapCallback - { - void ProcessNode(OptimizedBvhNode node); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/OptimizedBvh.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/OptimizedBvh.cs deleted file mode 100644 index 0460f9b38..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/OptimizedBvh.cs +++ /dev/null @@ -1,293 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// OptimizedBvh store an AABB tree that can be quickly traversed on CPU (and SPU,GPU in future) - /// - public class OptimizedBvh - { - private static int _maxIterations = 0; - private OptimizedBvhNode _rootNode; - - private OptimizedBvhNode[] _contiguousNodes; - private int _curNodeIndex; - - private List _leafNodes = new List(); - - public OptimizedBvh() { } - - public void Build(StridingMeshInterface triangles) - { - NodeTriangleCallback callback = new NodeTriangleCallback(_leafNodes); - - Vector3 aabbMin = new Vector3(-1e30f, -1e30f, -1e30f); - Vector3 aabbMax = new Vector3(1e30f, 1e30f, 1e30f); - - triangles.InternalProcessAllTriangles(callback, aabbMin, aabbMax); - - //now we have an array of leafnodes in m_leafNodes - _contiguousNodes = new OptimizedBvhNode[2 * _leafNodes.Count]; - for (int i = 0; i < _contiguousNodes.Length; i++) - _contiguousNodes[i] = new OptimizedBvhNode(); - _curNodeIndex = 0; - - _rootNode = BuildTree(_leafNodes, 0, _leafNodes.Count); - } - - public OptimizedBvhNode BuildTree(List leafNodes, int startIndex, int endIndex) - { - OptimizedBvhNode internalNode; - - int splitAxis, splitIndex, i; - int numIndices = endIndex - startIndex; - int curIndex = _curNodeIndex; - - if (numIndices <= 0) - throw new BulletException(); - - if (numIndices == 1) - { - _contiguousNodes[_curNodeIndex++] = leafNodes[startIndex]; - //return new (&m_contiguousNodes[m_curNodeIndex++]) btOptimizedBvhNode(leafNodes[startIndex]); - return leafNodes[startIndex]; - } - - //calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'. - splitAxis = CalculateSplittingAxis(leafNodes, startIndex, endIndex); - - splitIndex = SortAndCalculateSplittingIndex(leafNodes, startIndex, endIndex, splitAxis); - - internalNode = _contiguousNodes[_curNodeIndex++]; - - internalNode.AabbMax = new Vector3(-1e30f, -1e30f, -1e30f); - internalNode.AabbMin = new Vector3(1e30f, 1e30f, 1e30f); - - for (i = startIndex; i < endIndex; i++) - { - internalNode.AabbMax = MathHelper.SetMax(internalNode.AabbMax, leafNodes[i].AabbMax); - internalNode.AabbMin = MathHelper.SetMin(internalNode.AabbMin, leafNodes[i].AabbMin); - } - - //internalNode->m_escapeIndex; - internalNode.LeftChild = BuildTree(leafNodes, startIndex, splitIndex); - internalNode.RightChild = BuildTree(leafNodes, splitIndex, endIndex); - - internalNode.EscapeIndex = _curNodeIndex - curIndex; - return internalNode; - } - - public int CalculateSplittingAxis(List leafNodes, int startIndex, int endIndex) - { - Vector3 means = new Vector3(); - Vector3 variance = new Vector3(); - int numIndices = endIndex - startIndex; - - for (int i = startIndex; i < endIndex; i++) - { - Vector3 center = 0.5f * (leafNodes[i].AabbMax + leafNodes[i].AabbMin); - means += center; - } - means *= (1f / (float)numIndices); - - for (int i = startIndex; i < endIndex; i++) - { - Vector3 center = 0.5f * (leafNodes[i].AabbMax + leafNodes[i].AabbMin); - Vector3 diff2 = center - means; - diff2 = diff2 * diff2; - variance += diff2; - } - variance *= (1f / ((float)numIndices - 1)); - - return MathHelper.MaxAxis(variance); - } - - public int SortAndCalculateSplittingIndex(List leafNodes, int startIndex, int endIndex, int splitAxis) - { - int splitIndex = startIndex; - int numIndices = endIndex - startIndex; - float splitValue; - - Vector3 means = new Vector3(); - for (int i = startIndex; i < endIndex; i++) - { - Vector3 center = 0.5f * (leafNodes[i].AabbMax + leafNodes[i].AabbMin); - means += center; - } - means *= (1f / (float)numIndices); - - if (splitAxis == 0) - splitValue = means.X; - else if (splitAxis == 1) - splitValue = means.Y; - else if (splitAxis == 2) - splitValue = means.Z; - else - throw new ArgumentException(); - - //sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'. - for (int i = startIndex; i < endIndex; i++) - { - Vector3 center = 0.5f * (leafNodes[i].AabbMax + leafNodes[i].AabbMin); - float centerSplit; - - if (splitAxis == 0) - centerSplit = means.X; - else if (splitAxis == 1) - centerSplit = means.Y; - else if (splitAxis == 2) - centerSplit = means.Z; - else - throw new ArgumentException(); - - if (centerSplit > splitValue) - { - //swap - OptimizedBvhNode tmp = leafNodes[i]; - leafNodes[i] = leafNodes[splitIndex]; - leafNodes[splitIndex] = tmp; - splitIndex++; - } - } - if ((splitIndex == startIndex) || (splitIndex == (endIndex - 1))) - { - splitIndex = startIndex + (numIndices >> 1); - } - return splitIndex; - } - - public void WalkTree(OptimizedBvhNode rootNode, INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax) - { - bool isLeafNode, aabbOverlap = MathHelper.TestAabbAgainstAabb2(aabbMin, aabbMax, rootNode.AabbMin, rootNode.AabbMax); - if (aabbOverlap) - { - isLeafNode = (rootNode.LeftChild == null && rootNode.RightChild == null); - if (isLeafNode) - { - nodeCallback.ProcessNode(rootNode); - } - else - { - WalkTree(rootNode.LeftChild, nodeCallback, aabbMin, aabbMax); - WalkTree(rootNode.RightChild, nodeCallback, aabbMin, aabbMax); - } - } - } - - public void WalkStacklessTree(OptimizedBvhNode[] rootNodeArray, INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax) - { - int escapeIndex, curIndex = 0; - int walkIterations = 0; - bool aabbOverlap, isLeafNode; - int rootNodeIndex = 0; - OptimizedBvhNode rootNode = rootNodeArray[rootNodeIndex]; - - while (curIndex < _curNodeIndex) - { - //catch bugs in tree data - if (walkIterations >= _curNodeIndex) - throw new BulletException(); - - walkIterations++; - aabbOverlap = MathHelper.TestAabbAgainstAabb2(aabbMin, aabbMax, rootNode.AabbMin, rootNode.AabbMax); - isLeafNode = (rootNode.LeftChild == null && rootNode.RightChild == null); - - if (isLeafNode && aabbOverlap) - { - nodeCallback.ProcessNode(rootNode); - } - - if (aabbOverlap || isLeafNode) - { - rootNodeIndex++; // this - curIndex++; - if (rootNodeIndex < rootNodeArray.Length) - rootNode = rootNodeArray[rootNodeIndex]; - } - else - { - escapeIndex = rootNode.EscapeIndex; - rootNodeIndex += escapeIndex; // and this - curIndex += escapeIndex; - if (rootNodeIndex < rootNodeArray.Length) - rootNode = rootNodeArray[rootNodeIndex]; - } - - } - - if (_maxIterations < walkIterations) - _maxIterations = walkIterations; - } - - public void ReportAabbOverlappingNodex(INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax) - { - //either choose recursive traversal (walkTree) or stackless (walkStacklessTree) - //walkTree(m_rootNode1,nodeCallback,aabbMin,aabbMax); - //WalkStacklessTree(_rootNode, nodeCallback, aabbMin, aabbMax); - WalkStacklessTree(_contiguousNodes, nodeCallback, aabbMin, aabbMax); - } - - public void ReportSphereOverlappingNodex(INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax) { } - } - - public class NodeTriangleCallback : ITriangleIndexCallback - { - private List _triangleNodes; - - public NodeTriangleCallback(List triangleNodes) - { - _triangleNodes = triangleNodes; - } - - public List TriangleNodes { get { return _triangleNodes; } set { _triangleNodes = value; } } - - public void ProcessTriangleIndex(Vector3[] triangle, int partId, int triangleIndex) - { - - OptimizedBvhNode node = new OptimizedBvhNode(); - node.AabbMin = new Vector3(1e30f, 1e30f, 1e30f); - node.AabbMax = new Vector3(-1e30f, -1e30f, -1e30f); - - node.AabbMin = MathHelper.SetMin(node.AabbMin, triangle[0]); - node.AabbMax = MathHelper.SetMax(node.AabbMax, triangle[0]); - node.AabbMin = MathHelper.SetMin(node.AabbMin, triangle[1]); - node.AabbMax = MathHelper.SetMax(node.AabbMax, triangle[1]); - node.AabbMin = MathHelper.SetMin(node.AabbMin, triangle[2]); - node.AabbMax = MathHelper.SetMax(node.AabbMax, triangle[2]); - - node.EscapeIndex = -1; - node.LeftChild = null; - node.RightChild = null; - - //for child nodes - node.SubPart = partId; - node.TriangleIndex = triangleIndex; - - _triangleNodes.Add(node); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/OptimizedBvhNode.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/OptimizedBvhNode.cs deleted file mode 100644 index 0bd0a1c94..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/OptimizedBvhNode.cs +++ /dev/null @@ -1,63 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// OptimizedBvhNode contains both internal and leaf node information. - /// It hasn't been optimized yet for storage. Some obvious optimizations are: - /// Removal of the pointers (can already be done, they are not used for traversal) - /// and storing aabbmin/max as quantized integers. - /// 'subpart' doesn't need an integer either. It allows to re-use graphics triangle - /// meshes stored in a non-uniform way (like batches/subparts of triangle-fans - /// - public class OptimizedBvhNode - { - private Vector3 _aabbMin; - private Vector3 _aabbMax; - - //these 2 pointers are obsolete, the stackless traversal just uses the escape index - private OptimizedBvhNode _leftChild; - private OptimizedBvhNode _rightChild; - - private int _escapeIndex; - - //for child nodes - private int _subPart; - private int _triangleIndex; - - public Vector3 AabbMin { get { return _aabbMin; } set { _aabbMin = value; } } - public Vector3 AabbMax { get { return _aabbMax; } set { _aabbMax = value; } } - - public OptimizedBvhNode LeftChild { get { return _leftChild; } set { _leftChild = value; } } - public OptimizedBvhNode RightChild { get { return _rightChild; } set { _rightChild = value; } } - - public int EscapeIndex { get { return _escapeIndex; } set { _escapeIndex = value; } } - - public int SubPart { get { return _subPart; } set { _subPart = value; } } - public int TriangleIndex { get { return _triangleIndex; } set { _triangleIndex = value; } } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs deleted file mode 100644 index 25524bd48..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs +++ /dev/null @@ -1,133 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public abstract class PolyhedralConvexShape : ConvexShape - { - public PolyhedralConvexShape() - { - //m_optionalHull = null; - } - - public abstract int VertexCount { get; } - public abstract int EdgeCount { get; } - public abstract int PlaneCount { get; } - - public abstract void GetEdge(int i, out Vector3 pointA, out Vector3 pointB); - public abstract void GetVertex(int i, out Vector3 vertex); - public abstract void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i); - // abstract int getIndex(int i); - - public abstract bool IsInside(Vector3 point, float tolerance); - - // optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp - //public class Hull m_optionalHull; - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - Vector3 supVec = new Vector3(); - - float maxDot = -1e30f; - - float lenSqr = vec.LengthSquared(); - if (lenSqr < 0.0001f) - { - vec = new Vector3(1, 0, 0); - } - else - { - float rlen = 1f / (float)Math.Sqrt(lenSqr); - vec *= rlen; - } - - Vector3 vtx; - float newDot; - - for (int i = 0; i < VertexCount; i++) - { - GetVertex(i, out vtx); - newDot = Vector3.Dot(vec, vtx); - if (newDot > maxDot) - { - maxDot = newDot; - supVec = vtx; - } - } - return supVec; - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - #warning Think about this - /*Vector3 vtx; - float newDot; - - for (int i = 0; i < vectors.Length; i++) - { - supportVerticesOut[i][3] = -1e30f; - } - - for (int j = 0; j < vectors.Length; j++) - { - Vector3 vec = vectors[j]; - - for (int i = 0; i < getNumVertices(); i++) - { - getVertex(i, out vtx); - newDot = Vector3.Dot(vec,vtx); - if (newDot > supportVerticesOut[j][3]) - { - //WARNING: don't swap next lines, the w component would get overwritten! - supportVerticesOut[j] = vtx; - supportVerticesOut[j][3] = newDot; - } - } - }*/ - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - //not yet, return box inertia - float margin = Margin; - - Matrix ident = Matrix.Identity; - Vector3 aabbMin, aabbMax; - GetAabb(ident, out aabbMin, out aabbMax); - Vector3 halfExtents = (aabbMax - aabbMin) * 0.5f; - - float lx = 2f * (halfExtents.X + margin); - float ly = 2f * (halfExtents.Y + margin); - float lz = 2f * (halfExtents.Z + margin); - float x2 = lx * lx; - float y2 = ly * ly; - float z2 = lz * lz; - float scaledmass = mass * 0.08333333f; - - inertia = scaledmass * (new Vector3(y2 + z2, x2 + z2, x2 + y2)); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/SphereShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/SphereShape.cs deleted file mode 100644 index 0b15e5611..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/SphereShape.cs +++ /dev/null @@ -1,116 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// btSphereShape implements an implicit (getSupportingVertex) Sphere - /// - public class SphereShape : ConvexShape - { - public SphereShape(float radius) - : base() - { - Vector3 temp = ImplicitShapeDimensions; - temp.X = radius; - ImplicitShapeDimensions = temp; - } - - public float Radius { get { return ImplicitShapeDimensions.X; } } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.Sphere; - } - } - - public override string Name - { - get - { - return "Sphere"; - } - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - return new Vector3(); - } - - /// - /// to improve gjk behaviour, use radius+margin as the full margin, so never get into the penetration case - /// this means, non-uniform scaling is not supported anymore - /// - public override float Margin - { - get - { - return LocalScaling.X * Radius + base.Margin; - } - set - { - base.Margin = value; - } - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - if (supportVerticesOut != null) - for (int i = 0; i < supportVerticesOut.Length; i++) - supportVerticesOut[i] = new Vector3(); - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - float elem = 0.4f * mass * Margin * Margin; - inertia = new Vector3(elem, elem, elem); - } - - public override Vector3 LocalGetSupportingVertex(Vector3 vec) - { - Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec); - - Vector3 vecnorm = vec; - if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) - { - vecnorm = new Vector3(-1f, -1f, -1f); - } - vecnorm.Normalize(); - supVertex += Margin * vecnorm; - return supVertex; - } - - public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - Vector3 center = t.Translation; - Vector3 extent = new Vector3(Margin, Margin, Margin); - aabbMin = center - extent; - aabbMax = center + extent; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/StaticPlaneShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/StaticPlaneShape.cs deleted file mode 100644 index 57c4e9e20..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/StaticPlaneShape.cs +++ /dev/null @@ -1,124 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class StaticPlaneShape : ConcaveShape - { - private Vector3 _localAabbMin; - private Vector3 _localAabbMax; - - private Vector3 _planeNormal; - private float _planeConstant; - private Vector3 _localScaling; - - public StaticPlaneShape(Vector3 planeNormal, float planeConstant) - { - _planeNormal = planeNormal; - _planeConstant = planeConstant; - _localScaling = new Vector3(); - } - - protected Vector3 LocalAabbMin { get { return _localAabbMin; } set { _localAabbMin = value; } } - protected Vector3 LocalAabbMax { get { return _localAabbMax; } set { _localAabbMax = value; } } - - protected Vector3 PlaneNormal { get { return _planeNormal; } set { _planeNormal = value; } } - protected float PlaneConstant { get { return _planeConstant; } set { _planeConstant = value; } } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.StaticPlane; - } - } - - public override Vector3 LocalScaling - { - get - { - return _localScaling; - } - set - { - _localScaling = value; - } - } - - public override string Name - { - get - { - return "StaticPlane"; - } - } - - public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - Vector3 infvec = new Vector3(1e30f, 1e30f, 1e30f); - - Vector3 center = _planeNormal * _planeConstant; - aabbMin = center + infvec * _planeNormal; - aabbMax = aabbMin; - MathHelper.SetMin(ref aabbMin, center - infvec * _planeNormal); - MathHelper.SetMax(ref aabbMax, center - infvec * _planeNormal); - - aabbMin = new Vector3(-1e30f, -1e30f, -1e30f); - aabbMax = new Vector3(1e30f, 1e30f, 1e30f); - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - //moving concave objects not supported - inertia = new Vector3(); - } - - public override void ProcessAllTriangles(ITriangleCallback callback, Vector3 aabbMin, Vector3 aabbMax) { - Vector3 halfExtents = (aabbMax - aabbMin) * 0.5f; - float radius = halfExtents.Length(); - Vector3 center = (aabbMax + aabbMin) * 0.5f; - - //this is where the triangles are generated, given AABB and plane equation (normal/constant) - Vector3 tangentDir0 = new Vector3(), tangentDir1 = new Vector3(); - - //tangentDir0/tangentDir1 can be precalculated - MathHelper.PlaneSpace1(_planeNormal, ref tangentDir0, ref tangentDir1); - - Vector3 projectedCenter = center - (Vector3.Dot(_planeNormal, center) - _planeConstant) * _planeNormal; - - Vector3[] triangle = new Vector3[3]; - triangle[0] = projectedCenter + tangentDir0 * radius + tangentDir1 * radius; - triangle[1] = projectedCenter + tangentDir0 * radius - tangentDir1 * radius; - triangle[2] = projectedCenter - tangentDir0 * radius - tangentDir1 * radius; - callback.ProcessTriangle(triangle, 0, 0); - - triangle[0] = projectedCenter - tangentDir0 * radius - tangentDir1 * radius; - triangle[1] = projectedCenter - tangentDir0 * radius + tangentDir1 * radius; - triangle[2] = projectedCenter + tangentDir0 * radius + tangentDir1 * radius; - callback.ProcessTriangle(triangle, 0, 1); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/StridingMeshInterface.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/StridingMeshInterface.cs deleted file mode 100644 index d58c68aa5..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/StridingMeshInterface.cs +++ /dev/null @@ -1,115 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// PHY_ScalarType enumerates possible scalar types. - /// See the StridingMeshInterface for its use - /// - public enum PHY_ScalarType - { - PHY_FLOAT, - PHY_DOUBLE, - PHY_INTEGER, - PHY_SHORT, - PHY_FIXEDPOINT88 - } - - /// - /// StridingMeshInterface is the interface class for high performance access to triangle meshes - /// It allows for sharing graphics and collision meshes. Also it provides locking/unlocking of graphics meshes that are in gpu memory. - /// - public abstract class StridingMeshInterface - { - protected Vector3 _scaling; - - public StridingMeshInterface() - { - _scaling = new Vector3(1f,1f,1f); - } - - public void InternalProcessAllTriangles(ITriangleIndexCallback callback, Vector3 aabbMin, Vector3 aabbMax) - { - int numtotalphysicsverts = 0; - int numtriangles, gfxindex; - int part, graphicssubparts = SubPartsCount(); - Vector3[] triangle = new Vector3[3]; - List verts; - List indicies; - - Vector3 meshScaling = Scaling; - - //if the number of parts is big, the performance might drop due to the innerloop switch on indextype - for (part = 0; part < graphicssubparts; part++) - { - GetLockedReadOnlyVertexIndexBase(out verts, out indicies, out numtriangles, part); - numtotalphysicsverts += numtriangles * 3; //upper bound - - for (gfxindex = 0; gfxindex < numtriangles; gfxindex++) - { - triangle[0] = verts[indicies[gfxindex * 3 + 0]]; - triangle[1] = verts[indicies[gfxindex * 3 + 1]]; - triangle[2] = verts[indicies[gfxindex * 3 + 2]]; - - callback.ProcessTriangleIndex(triangle, part, gfxindex); - } - - UnLockReadOnlyVertexBase(part); - } - } - - - // get read and write access to a subpart of a triangle mesh - // this subpart has a continuous array of vertices and indices - // in this way the mesh can be handled as chunks of memory with striding - // very similar to OpenGL vertexarray support - // make a call to unLockVertexBase when the read and write access is finished - public abstract void GetLockedVertexIndexBase(out List verts, out List indicies, out int numfaces, int subpart); - - public abstract void GetLockedReadOnlyVertexIndexBase(out List verts, out List indicies, out int numfaces, int subpart); - - // unLockVertexBase finishes the access to a subpart of the triangle mesh - // make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished - public abstract void UnLockVertexBase(int subpart); - - public abstract void UnLockReadOnlyVertexBase(int subpart); - - - // getNumSubParts returns the number of seperate subparts - // each subpart has a continuous array of vertices and indices - public abstract int SubPartsCount(); - - public abstract void PreallocateVertices(int numverts); - public abstract void PreallocateIndices(int numindices); - - public Vector3 Scaling - { - get { return _scaling; } - set { _scaling = value; } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/SupportVertexCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/SupportVertexCallback.cs deleted file mode 100644 index 3560bfe2c..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/SupportVertexCallback.cs +++ /dev/null @@ -1,67 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - internal class SupportVertexCallback : ITriangleCallback - { - private Vector3 _supportVertexLocal; - - private Matrix _worldTransform; - private float _maxDot; - private Vector3 _supportVecLocal; - - public SupportVertexCallback(Vector3 supportVecWorld, Matrix trans) - { - _supportVertexLocal = new Vector3(); - _worldTransform = trans; - _maxDot = -1e30f; - _supportVecLocal = Vector3.TransformNormal(supportVecWorld, _worldTransform); - } - - public Matrix WorldTransform { get { return _worldTransform; } set { _worldTransform = value; } } - public float MaxDot { get { return _maxDot; } set { _maxDot = value; } } - public Vector3 SupportVectorLocal { get { return _supportVecLocal; } set { _supportVecLocal = value; } } - - public Vector3 SupportVertexLocal { get { return _supportVertexLocal; } } - public Vector3 SupportVertexWorldSpace { get { return MathHelper.MatrixToVector(_worldTransform, _supportVertexLocal); } } - - #region ITriangleCallback Members - public void ProcessTriangle(Vector3[] triangle, int partID, int triangleIndex) - { - for (int i = 0; i < 3; i++) - { - float dot = Vector3.Dot(_supportVecLocal, triangle[i]); - if (dot > _maxDot) - { - _maxDot = dot; - _supportVertexLocal = triangle[i]; - } - } - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleBuffer.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleBuffer.cs deleted file mode 100644 index c992d906b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleBuffer.cs +++ /dev/null @@ -1,80 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class Triangle - { - private Vector3 _vertexA; - private Vector3 _vertexB; - private Vector3 _vertexC; - private int _partId; - private int _triangleIndex; - - public Vector3 VertexA { get { return _vertexA; } set { _vertexA = value; } } - public Vector3 VertexB { get { return _vertexB; } set { _vertexB = value; } } - public Vector3 VertexC { get { return _vertexC; } set { _vertexC = value; } } - public int PartId { get { return _partId; } set { _partId = value; } } - public int TriangleIndex { get { return _triangleIndex; } set { _triangleIndex = value; } } - } - - /// - /// example usage of this class: - /// TriangleBuffer triBuf; - /// concaveShape.processAllTriangles(triBuf, out aabbMin, out aabbMax); - /// for (int i = 0; i < triBuf.getNumTriangles(); i++) - /// { - /// Triangle tri = triBuf.getTriangle(i); - /// //do something useful here with the triangle - /// } - /// - public class TriangleBuffer : ITriangleCallback - { - private List _triangleBuffer = new List(); - - public int TriangleCount { get { return _triangleBuffer.Count; } } - public Triangle this[int index] { get { return _triangleBuffer[index]; } } - - public void ClearBuffer() - { - _triangleBuffer.Clear(); - } - - #region ITriangleCallback Members - public void ProcessTriangle(Vector3[] triangle, int partID, int triangleIndex) - { - Triangle tri = new Triangle(); - tri.VertexA = triangle[0]; - tri.VertexB = triangle[1]; - tri.VertexC = triangle[2]; - tri.PartId = partID; - tri.TriangleIndex = triangleIndex; - - _triangleBuffer.Add(tri); - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleCallback.cs deleted file mode 100644 index c4b55401d..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleCallback.cs +++ /dev/null @@ -1,33 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public interface ITriangleCallback - { - void ProcessTriangle(Vector3[] triangle, int partId, int triangleIndex); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleIndexVertexArray.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleIndexVertexArray.cs deleted file mode 100644 index b0b66c69c..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleIndexVertexArray.cs +++ /dev/null @@ -1,136 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// IndexedMesh indexes into existing vertex and index arrays, in a similar way OpenGL glDrawElements - /// instead of the number of indices, we pass the number of triangles - /// - public struct IndexedMesh - { - private int _numTriangles; - private int[] _triangleIndexBase; - private int _triangleIndexStride; - private int _numVertices; - private Vector3[] _vertexBase; - private int _vertexStride; - - public IndexedMesh(int numTriangleIndices, int[] triangleIndexBase, int triangleIndexStride, int numVertices, Vector3[] vertexBase, int vertexStride) - { - _numTriangles = numTriangleIndices; - _triangleIndexBase = triangleIndexBase; - _triangleIndexStride = triangleIndexStride; - _vertexBase = vertexBase; - _numVertices = numVertices; - _vertexStride = vertexStride; - } - - public IndexedMesh(int[] triangleIndexBase, Vector3[] vertexBase) - { - _numTriangles = triangleIndexBase.Length; - _triangleIndexBase = triangleIndexBase; - _triangleIndexStride = 32; - _vertexBase = vertexBase; - _numVertices = vertexBase.Length; - _vertexStride = 24; - } - - public int TriangleCount { get { return _numTriangles; } set { _numTriangles = value; } } - public int[] TriangleIndexBase { get { return _triangleIndexBase; } set { _triangleIndexBase = value; } } - public int TriangleIndexStride { get { return _triangleIndexStride; } set { _triangleIndexStride = value; } } - public int VertexCount { get { return _numVertices; } set { _numVertices = value; } } - public Vector3[] VertexBase { get { return _vertexBase; } set { _vertexBase = value; } } - public int VertexStride { get { return _vertexStride; } set { _vertexStride = value; } } - } - - /// - /// TriangleIndexVertexArray allows to use multiple meshes, by indexing into existing triangle/index arrays. - /// Additional meshes can be added using addIndexedMesh - /// - public class TriangleIndexVertexArray : StridingMeshInterface - { - List _indexedMeshes = new List(); - - public TriangleIndexVertexArray() { } - - public TriangleIndexVertexArray(int numTriangleIndices, int[] triangleIndexBase, int triangleIndexStride, int numVertices, Vector3[] vertexBase, int vertexStride) - { - IndexedMesh mesh = new IndexedMesh(); - mesh.TriangleCount = numTriangleIndices; - mesh.TriangleIndexBase = triangleIndexBase; - mesh.TriangleIndexStride = triangleIndexStride; - mesh.VertexBase = vertexBase; - mesh.VertexCount = numVertices; - mesh.VertexStride = vertexStride; - - AddIndexedMesh(mesh); - } - - public TriangleIndexVertexArray(int[] triangleIndexBase, Vector3[] vertexBase) - : this(triangleIndexBase.Length, triangleIndexBase, 32, vertexBase.Length, vertexBase, 24) { } - - public void AddIndexedMesh(IndexedMesh indexedMesh) - { - _indexedMeshes.Add(indexedMesh); - } - - public override void GetLockedVertexIndexBase(out List verts, out List indicies, out int numfaces, int subpart) - { - throw new Exception("The method or operation is not implemented."); - } - - public override void GetLockedReadOnlyVertexIndexBase(out List verts, out List indicies, out int numfaces, int subpart) - { - throw new Exception("The method or operation is not implemented."); - } - - public override void UnLockVertexBase(int subpart) - { - throw new Exception("The method or operation is not implemented."); - } - - public override void UnLockReadOnlyVertexBase(int subpart) - { - throw new Exception("The method or operation is not implemented."); - } - - public override int SubPartsCount() - { - return _indexedMeshes.Count; - } - - public override void PreallocateVertices(int numverts) - { - throw new Exception("The method or operation is not implemented."); - } - - public override void PreallocateIndices(int numindices) - { - throw new Exception("The method or operation is not implemented."); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleMesh.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleMesh.cs deleted file mode 100644 index add17e3d4..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleMesh.cs +++ /dev/null @@ -1,102 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - class TriangleMesh : StridingMeshInterface - { - int _numTriangles; - List _verts; - - public TriangleMesh() - { - _numTriangles = 0; - _verts = new List(); - } - - void AddTriangle(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2) - { - _verts.Add(vertex0); - _verts.Add(vertex1); - _verts.Add(vertex2); - _numTriangles++; - } - - public override void GetLockedVertexIndexBase(out List verts, out List indicies, out int numfaces, int subpart) - { - verts = new List(); - for (int i = 0; i < 3; i++) - { - verts.Add(_verts[subpart * 3 + i]); - } - indicies = new List(); - indicies.Add(0); - indicies.Add(1); - indicies.Add(2); - numfaces = 1; - } - - public override void GetLockedReadOnlyVertexIndexBase(out List verts, out List indicies, out int numfaces, int subpart) - { - verts = new List(); - for (int i = 0; i < 3; i++) - { - verts.Add(_verts[subpart * 3 + i]); - } - indicies = new List(); - indicies.Add(0); - indicies.Add(1); - indicies.Add(2); - numfaces = 1; - } - - public override void UnLockVertexBase(int subpart) - { - - } - - public override void UnLockReadOnlyVertexBase(int subpart) - { - - } - - public override int SubPartsCount() - { - return _numTriangles; - } - - public override void PreallocateVertices(int numverts) - { - - } - - public override void PreallocateIndices(int numindices) - { - - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleMeshShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleMeshShape.cs deleted file mode 100644 index c4d621014..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleMeshShape.cs +++ /dev/null @@ -1,160 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// Concave triangle mesh. Uses an interface to access the triangles to allow for sharing graphics/physics triangles. - /// - public class TriangleMeshShape : ConcaveShape - { - private StridingMeshInterface _meshInterface; - private Vector3 _localAabbMin; - private Vector3 _localAabbMax; - - public TriangleMeshShape(StridingMeshInterface meshInterface) - { - this._meshInterface = meshInterface; - RecalcLocalAabb(); - } - - protected StridingMeshInterface MeshInterface { get { return _meshInterface; } set { _meshInterface = value; } } - protected Vector3 LocalAabbMin { get { return _localAabbMin; } set { _localAabbMin = value; } } - protected Vector3 LocalAabbMax { get { return _localAabbMax; } set { _localAabbMax = value; } } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.TriangleMesh; - } - } - - public override Vector3 LocalScaling - { - get - { - return _meshInterface.Scaling; - } - set - { - _meshInterface.Scaling = value; - } - } - - public override string Name - { - get - { - return "TriangleMesh"; - } - } - - public void RecalcLocalAabb() - { - { - Vector3 vec = new Vector3(); - vec.X = 1f; - Vector3 tmp = LocalGetSupportingVertex(vec); - _localAabbMax.X = tmp.X + CollisionMargin; - vec.X = -1f; - tmp = LocalGetSupportingVertex(vec); - _localAabbMin.X = tmp.X - CollisionMargin; - } - { - Vector3 vec = new Vector3(); - vec.Y = 1f; - Vector3 tmp = LocalGetSupportingVertex(vec); - _localAabbMax.Y = tmp.Y + CollisionMargin; - vec.Y = -1f; - tmp = LocalGetSupportingVertex(vec); - _localAabbMin.Y = tmp.Y - CollisionMargin; - } - { - Vector3 vec = new Vector3(); - vec.Z = 1f; - Vector3 tmp = LocalGetSupportingVertex(vec); - _localAabbMax.Z = tmp.Z + CollisionMargin; - vec.Z = -1f; - tmp = LocalGetSupportingVertex(vec); - _localAabbMin.Z = tmp.Z - CollisionMargin; - } - } - - public override void ProcessAllTriangles(ITriangleCallback callback, Vector3 aabbMin, Vector3 aabbMax) - { - LocalProcessAllTriangles(callback, aabbMax, aabbMax); - } - - protected void LocalProcessAllTriangles(ITriangleCallback callback, Vector3 aabbMin, Vector3 aabbMax) - { - FilteredCallback filterCallback = new FilteredCallback(callback, aabbMin, aabbMax); - _meshInterface.InternalProcessAllTriangles(filterCallback, aabbMin, aabbMax); - } - - public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - Vector3 localHalfExtents = 0.5f * (_localAabbMax - _localAabbMin); - Vector3 localCenter = 0.5f * (_localAabbMax + _localAabbMin); - - Matrix abs_b = MathHelper.Absolute(t); - - Vector3 center = MathHelper.MatrixToVector(t, localCenter); - - Vector3 extent = new Vector3(Vector3.Dot(new Vector3(abs_b.M11, abs_b.M12, abs_b.M13), localHalfExtents), - Vector3.Dot(new Vector3(abs_b.M21, abs_b.M22, abs_b.M23), localHalfExtents), - Vector3.Dot(new Vector3(abs_b.M31, abs_b.M32, abs_b.M33), localHalfExtents)); - extent += new Vector3(Margin, Margin, Margin); - - aabbMin = center - extent; - aabbMax = center + extent; - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - inertia = new Vector3(); - //moving concave objects not supported - BulletDebug.Assert(false); - } - - public virtual Vector3 LocalGetSupportingVertex(Vector3 vec) - { - Vector3 supportVertex; - Matrix ident = Matrix.Identity; - SupportVertexCallback supportCallback = new SupportVertexCallback(vec, ident); - Vector3 aabbMax = new Vector3(1e30f, 1e30f, 1e30f); - LocalProcessAllTriangles(supportCallback, -aabbMax, aabbMax); - supportVertex = supportCallback.SupportVertexLocal; - return supportVertex; - } - - public virtual Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - BulletDebug.Assert(false); - return LocalGetSupportingVertex(vec); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleShape.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleShape.cs deleted file mode 100644 index 130de8d47..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/CollisionShapes/TriangleShape.cs +++ /dev/null @@ -1,187 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class TriangleShape : PolyhedralConvexShape - { - private Vector3[] _vertices = new Vector3[3]; - - public TriangleShape(Vector3 pointA, Vector3 pointB, Vector3 pointC) - { - _vertices[0] = pointA; - _vertices[1] = pointB; - _vertices[2] = pointC; - } - - public override int PreferredPenetrationDirectionsCount - { - get - { - return 2; - } - } - - public Vector3[] Vertices - { - get - { - return _vertices; - } - } - - public override int VertexCount - { - get - { - return 3; - } - } - - public override int EdgeCount - { - get - { - return 3; - } - } - - public override int PlaneCount - { - get - { - return 1; - } - } - - public override BroadphaseNativeTypes ShapeType - { - get - { - return BroadphaseNativeTypes.Triangle; - } - } - - public override string Name - { - get - { - return "Triangle"; - } - } - - public override void GetPreferredPenetrationDirection(int index, out Vector3 penetrationVector) - { - CalculateNormal(out penetrationVector); - if (index != 0) - penetrationVector *= -1f; - } - - public virtual void GetPlaneEquation(int i, out Vector3 planeNormal, out Vector3 planeSupport) - { - CalculateNormal(out planeNormal); - planeSupport = _vertices[0]; - } - - public void CalculateNormal(out Vector3 normal) - { - normal = Vector3.Normalize(Vector3.Cross(_vertices[1] - _vertices[0], _vertices[2] - _vertices[0])); - } - - public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) - { - Vector3 dots = new Vector3(Vector3.Dot(vec, _vertices[0]), Vector3.Dot(vec, _vertices[1]), Vector3.Dot(vec, _vertices[2])); - return _vertices[MathHelper.MaxAxis(dots)]; - } - - public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) - { - for (int i = 0; i < vectors.Length; i++) - { - Vector3 dir = vectors[i]; - Vector3 dots = new Vector3(Vector3.Dot(dir, _vertices[0]), Vector3.Dot(dir, _vertices[1]), Vector3.Dot(dir, _vertices[2])); - supportVerticesOut[i] = _vertices[MathHelper.MaxAxis(dots)]; - } - } - - public override void CalculateLocalInertia(float mass, out Vector3 inertia) - { - inertia = new Vector3(); - BulletDebug.Assert(false); - } - - public override void GetEdge(int i, out Vector3 pa, out Vector3 pb) - { - GetVertex(i, out pa); - GetVertex((i + 1) % 3, out pb); - } - - public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) - { - GetAabbSlow(t, out aabbMin, out aabbMax); - } - - public override void GetVertex(int i, out Vector3 vtx) - { - vtx = _vertices[i]; - } - - public override void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i) - { - GetPlaneEquation(i, out planeNormal, out planeSupport); - } - - public override bool IsInside(Vector3 pt, float tolerance) - { - Vector3 normal; - CalculateNormal(out normal); - //distance to plane - float dist = Vector3.Dot(pt, normal); - float planeconst = Vector3.Dot(_vertices[0], normal); - dist -= planeconst; - if (dist >= -tolerance && dist <= tolerance) - { - //inside check on edge-planes - int i; - for (i = 0; i < 3; i++) - { - Vector3 pa, pb; - GetEdge(i, out pa, out pb); - Vector3 edge = pb - pa; - Vector3 edgeNormal = Vector3.Cross(edge, normal); - edgeNormal = Vector3.Normalize(edgeNormal); - float distance = Vector3.Dot(pt, edgeNormal); - float edgeConst = Vector3.Dot(pa, edgeNormal); - distance -= edgeConst; - if (distance < -tolerance) - return false; - } - return true; - } - return false; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ContinuousConvexCollision.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ContinuousConvexCollision.cs deleted file mode 100644 index e0cb38628..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ContinuousConvexCollision.cs +++ /dev/null @@ -1,199 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// ContinuousConvexCollision implements angular and linear time of impact for convex objects. - /// Based on Brian Mirtich's Conservative Advancement idea (PhD thesis). - /// Algorithm operates in worldspace, in order to keep inbetween motion globally consistent. - /// It uses GJK at the moment. Future improvement would use minkowski sum / supporting vertex, merging innerloops - /// - public class ContinuousConvexCollision : IConvexCast - { - /// - /// This maximum should not be necessary. It allows for untested/degenerate cases in production code. - /// You don't want your game ever to lock-up. - /// - private const int MaxIterations = 1000; - - private ISimplexSolver _simplexSolver; - private IConvexPenetrationDepthSolver _penetrationDepthSolver; - private ConvexShape _convexA; - private ConvexShape _convexB; - - public ContinuousConvexCollision(ConvexShape convexA, ConvexShape convexB, - ISimplexSolver simplexSolver, IConvexPenetrationDepthSolver penetrationDepthSolver) - { - _simplexSolver = simplexSolver; - _penetrationDepthSolver = penetrationDepthSolver; - _convexA = convexA; - _convexB = convexB; - } - - public bool CalcTimeOfImpact(Matrix fromA, Matrix toA, Matrix fromB, Matrix toB, CastResult result) - { - _simplexSolver.Reset(); - - // compute linear and angular velocity for this interval, to interpolate - Vector3 linVelA = new Vector3(), angVelA = new Vector3(), linVelB = new Vector3(), angVelB = new Vector3(); - TransformUtil.CalculateVelocity(fromA, toA, 1f, ref linVelA, ref angVelA); - TransformUtil.CalculateVelocity(fromB, toB, 1f, ref linVelB, ref angVelB); - - float boundingRadiusA = _convexA.GetAngularMotionDisc(); - float boundingRadiusB = _convexB.GetAngularMotionDisc(); - - float maxAngularProjectedVelocity = angVelA.Length() * boundingRadiusA + - angVelB.Length() * boundingRadiusB; - - float radius = 0.001f; - - float lambda = 0f; - Vector3 v = new Vector3(1f, 0f, 0f); - - int maxIter = MaxIterations; - - Vector3 n = new Vector3(); - bool hasResult = false; - Vector3 c; - - float lastLambda = lambda; - //float epsilon = 0.001f; - - int numIter = 0; - //first solution, using GJK - - - Matrix identityTrans = Matrix.Identity; - - SphereShape raySphere = new SphereShape(0f); - raySphere.Margin=0f; - - - //result.drawCoordSystem(sphereTr); - - PointCollector pointCollector1 = new PointCollector(); - - GjkPairDetector gjk = new GjkPairDetector(_convexA, _convexB, (VoronoiSimplexSolver)_simplexSolver, _penetrationDepthSolver); - GjkPairDetector.ClosestPointInput input = new DiscreteCollisionDetectorInterface.ClosestPointInput(); - - //we don't use margins during CCD - gjk.setIgnoreMargin(true); - - input.TransformA = fromA; - input.TransformB = fromB; - - DiscreteCollisionDetectorInterface.Result r = (DiscreteCollisionDetectorInterface.Result)pointCollector1; - gjk.GetClosestPoints(input, r, null); - - hasResult = pointCollector1.HasResult; - c = pointCollector1.PointInWorld; - - if (hasResult) - { - float dist; - dist = pointCollector1.Distance; - n = pointCollector1.NormalOnBInWorld; - - //not close enough - while (dist > radius) - { - numIter++; - if (numIter > maxIter) - return false; //todo: report a failure - - float dLambda = 0f; - - //calculate safe moving fraction from distance / (linear+rotational velocity) - - //float clippedDist = GEN_min(angularConservativeRadius,dist); - //float clippedDist = dist; - - float projectedLinearVelocity = Vector3.Dot(linVelB - linVelA, n); - - dLambda = dist / (projectedLinearVelocity + maxAngularProjectedVelocity); - - lambda = lambda + dLambda; - - if (lambda > 1f) return false; - if (lambda < 0f) return false; - - //todo: next check with relative epsilon - if (lambda <= lastLambda) - break; - lastLambda = lambda; - - - //interpolate to next lambda - Matrix interpolatedTransA = new Matrix(), interpolatedTransB = new Matrix(), relativeTrans; - - TransformUtil.IntegrateTransform(fromA, linVelA, angVelA, lambda, ref interpolatedTransA); - TransformUtil.IntegrateTransform(fromB, linVelB, angVelB, lambda, ref interpolatedTransB); - - relativeTrans = MathHelper.InverseTimes(interpolatedTransB, interpolatedTransA); - - result.DebugDraw(lambda); - - PointCollector pointCollector = new PointCollector(); - gjk = new GjkPairDetector(_convexA, _convexB, (VoronoiSimplexSolver)_simplexSolver, _penetrationDepthSolver); - input = new DiscreteCollisionDetectorInterface.ClosestPointInput(); - input.TransformA = interpolatedTransA; - input.TransformB = interpolatedTransB; - - // !!!!!!!!!! - r = (DiscreteCollisionDetectorInterface.Result)pointCollector1; - gjk.GetClosestPoints(input, r, null); - - if (pointCollector.HasResult) - { - if (pointCollector.Distance < 0f) - { - //degenerate ?! - result.Fraction = lastLambda; - result.Normal = n; - return true; - } - c = pointCollector.PointInWorld; - - dist = pointCollector.Distance; - } - else - { - //?? - return false; - } - - } - - result.Fraction = lambda; - result.Normal = n; - return true; - } - - return false; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ConvexCast.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ConvexCast.cs deleted file mode 100644 index b48257828..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ConvexCast.cs +++ /dev/null @@ -1,73 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - - /// - /// CastResult stores the closest result - /// alternatively, add a callback method to decide about closest/all results - /// - public class CastResult - { - private Vector3 _normal; - private float _fraction; - private Matrix _hitTransformA; - private Matrix _hitTransformB; - private IDebugDraw _debugDrawer; - - public CastResult() - { - _fraction = 1e30f; - } - - public Vector3 Normal { get { return _normal; } set { _normal = value; } } - public float Fraction { get { return _fraction; } set { _fraction = value; } } - public Matrix HitTransformA { get { return _hitTransformA; } set { _hitTransformA = value; } } - public Matrix HitTransformB { get { return _hitTransformB; } set { _hitTransformB = value; } } - public IDebugDraw DebugDrawer { get { return _debugDrawer; } set { _debugDrawer = value; } } - - public virtual void DebugDraw(float fraction) { } - public virtual void DrawCoordSystem(Matrix trans) { } - } - - /// - /// ConvexCast is an interface for Casting - /// - public interface IConvexCast - { - /// - /// cast a convex against another convex object - /// - /// - /// - /// - /// - /// - /// - bool CalcTimeOfImpact(Matrix fromA, Matrix toA, Matrix fromB, Matrix toB, CastResult result); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/DiscreteCollisionDetectorInterface.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/DiscreteCollisionDetectorInterface.cs deleted file mode 100644 index ccd59d364..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/DiscreteCollisionDetectorInterface.cs +++ /dev/null @@ -1,117 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public abstract class DiscreteCollisionDetectorInterface - { - public abstract class Result - { - public abstract void SetShapeIdentifiers(int partIdA, int indexA, int partIdB, int indexB); - public abstract void AddContactPoint(Vector3 normalOnBInWorld, Vector3 pointInWorld, float depth); - } - - public class ClosestPointInput - { - private float _maximumDistanceSquared; - private Matrix _transformA, _transformB; - - #region Properties - public Matrix TransformB - { - get { return _transformB; } - set { _transformB = value; } - } - - public Matrix TransformA - { - get { return _transformA; } - set { _transformA = value; } - } - - public float MaximumDistanceSquared - { - get { return _maximumDistanceSquared; } - set { _maximumDistanceSquared = value; } - } - #endregion - - public ClosestPointInput() - { - _maximumDistanceSquared = 1e30f; - } - } - - public abstract void GetClosestPoints(ClosestPointInput input, Result output, IDebugDraw debugDraw); - } - - public class StorageResult : DiscreteCollisionDetectorInterface.Result - { - private Vector3 _closestPointInB; - private Vector3 _normalOnSurfaceB; - private float _distance; //negative means penetration ! - - #region Properties - - public float Distance - { - get { return _distance; } - set { _distance = value; } - } - public Vector3 NormalOnSurfaceB - { - get { return _normalOnSurfaceB; } - set { _normalOnSurfaceB = value; } - } - public Vector3 ClosestPointInB - { - get { return _closestPointInB; } - set { _closestPointInB = value; } - } - - #endregion - - public StorageResult() - { - _distance = 1e30f; - } - - public override void AddContactPoint(Vector3 normalOnBInWorld, Vector3 pointInWorld, float depth) - { - if (depth < _distance) - { - _normalOnSurfaceB = normalOnBInWorld; - _closestPointInB = pointInWorld; - _distance = depth; - } - } - - public override void SetShapeIdentifiers(int partId0, int index0, int partId1, int index1) - { - throw new Exception("The method or operation is not implemented."); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkConvexCast.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkConvexCast.cs deleted file mode 100644 index b2d597ab8..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkConvexCast.cs +++ /dev/null @@ -1,176 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// GjkConvexCast performs a raycast on a convex object using support mapping. - /// - public class GjkConvexCast : IConvexCast - { - private VoronoiSimplexSolver _simplexSolver; - private ConvexShape _convexA, _convexB; - - public GjkConvexCast(ConvexShape convexShapeA, ConvexShape convexShapeB, VoronoiSimplexSolver solver) - { - _simplexSolver = solver; - - _convexA = convexShapeA; - _convexB = convexShapeB; - } - - #region IConvexCast Members - - /// - /// cast a convex against another convex object - /// - /// - /// - /// - /// - /// - /// - public bool CalcTimeOfImpact(Matrix fromA, Matrix toA, Matrix fromB, Matrix toB, CastResult result) - { - MinkowskiSumShape combined = new MinkowskiSumShape(_convexA, _convexB); - - Matrix rayFromLocalA = MathHelper.InvertMatrix(fromA) * fromB; - Matrix rayToLocalA = MathHelper.InvertMatrix(toA) * toB; - - Matrix transformA = fromA; - Matrix transformB = fromB; - - transformA.Translation = new Vector3(0, 0, 0); - transformB.Translation = new Vector3(0, 0, 0); - - combined.TransformA = transformA; - combined.TransformB = transformB; - - float radius = 0.01f; - float lambda = 0; - - Vector3 s = rayFromLocalA.Translation; - Vector3 r = rayToLocalA.Translation - rayFromLocalA.Translation; - Vector3 x = s; - Vector3 n = new Vector3(); - Vector3 c = new Vector3(); - - bool hasResult = false; - float lastLambda = lambda; - - IConvexPenetrationDepthSolver penSolver = null; - Matrix identityTransform = Matrix.Identity; - - SphereShape raySphere = new SphereShape(0.0f); - raySphere.Margin=0.0f; - - Matrix sphereTransform = Matrix.Identity; - sphereTransform.Translation = rayFromLocalA.Translation; - - result.DrawCoordSystem(sphereTransform); - - { - PointCollector pointCollector = new PointCollector(); - GjkPairDetector gjk = new GjkPairDetector(raySphere, combined, _simplexSolver, penSolver); - - GjkPairDetector.ClosestPointInput input = new DiscreteCollisionDetectorInterface.ClosestPointInput(); - input.TransformA = sphereTransform; - input.TransformB = identityTransform; - - gjk.GetClosestPoints(input, pointCollector, null); - - hasResult = pointCollector.HasResult; - - c = pointCollector.PointInWorld; - n = pointCollector.NormalOnBInWorld; - } - - if (hasResult) - { - float dist = (c - x).Length(); - - if (dist < radius) - { - lastLambda = 1.0f; - } - - while (dist > radius) - { - n = x - c; - float dot = Vector3.Dot(n, r); - - if (dot >= -(MathHelper.Epsilon * MathHelper.Epsilon)) return false; - - lambda = lambda - Vector3.Distance(n, n) / dot; - if (lambda <= lastLambda) break; - - lastLambda = lambda; - - x = s + lambda * r; - - sphereTransform.Translation = x; - result.DrawCoordSystem(sphereTransform); - PointCollector pointCollector = new PointCollector(); - - GjkPairDetector gjk = new GjkPairDetector(raySphere, combined, _simplexSolver, penSolver); - GjkPairDetector.ClosestPointInput input = new DiscreteCollisionDetectorInterface.ClosestPointInput(); - input.TransformA = sphereTransform; - input.TransformB = identityTransform; - - gjk.GetClosestPoints(input, pointCollector, null); - - if (pointCollector.HasResult) - { - if (pointCollector.Distance < 0.0f) - { - result.Fraction = lastLambda; - result.Normal = n; - return true; - } - - c = pointCollector.PointInWorld; - dist = (c - x).Length(); - } - else - { - return false; - } - } - - if (lastLambda < 1.0f) - { - result.Fraction = lastLambda; - result.Normal = n; - return true; - } - } - - return false; - } - - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkEpa.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkEpa.cs deleted file mode 100644 index aed6b5166..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkEpa.cs +++ /dev/null @@ -1,633 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// GJK-EPA collision solver by Nathanael Presson - /// Nov.2006 - /// - public class GjkEpa - { - //private static readonly int _precision = 1 /* U(sizeof(F) == 4)*/; - - private static readonly float _infinity = MathHelper.Infinity; - //private static readonly float _pi = (float)Math.PI; - private static readonly float _twoPi = (float)(Math.PI * 2); - - private static readonly int _gjkMaxIterations = 128; - private static readonly int _gjkHashSize = 1 << 6; - private static readonly int _gjkHashMask = _gjkHashSize - 1; - private static readonly float _gjkInSimplexEpsilon = 0.0001f; - private static readonly float _gjkSquareInSimplexEpsilon = _gjkInSimplexEpsilon * _gjkInSimplexEpsilon; - - private static readonly int _epaMaxIterations = 256; - private static readonly float _epaInFaceEpsilon = 0.01f; - private static readonly float _epaAccuracy = 0.001f; - - public static float EpaAccuracy { get { return _epaAccuracy; } } - - private static float Abs(float v) { return (v < 0 ? -v : v); } - private static float Sign(float v) { return (v < 0 ? -1 : 1); } - - static void Swap(ref T a, ref T b) - { - T t = a; - a = b; - b = t; - } - - public class Gjk - { - public class MinkowskiVertice - { - private Vector3 _vertice; /* Minkowski vertice */ - private Vector3 _ray; /* Ray */ - - public Vector3 Vertice { get { return _vertice; } set { _vertice = value; } } - public Vector3 Ray { get { return _ray; } set { _ray = value; } } - } - public class He - { - private Vector3 _ray; - private He _next; - - public He Next { get { return _next; } set { _next = value; } } - public Vector3 Ray { get { return _ray; } set { _ray = value; } } - } - - private He[] _table = new He[_gjkHashSize]; - private Matrix[] _wrotations = new Matrix[2]; - private Vector3[] _positions = new Vector3[2]; - private ConvexShape[] _shapes = new ConvexShape[2]; - private MinkowskiVertice[] _simplex = new MinkowskiVertice[5]; - private Vector3 _ray; - private int _order; - private int _iterations; - private float _margin; - private bool _failed; - - public Gjk(Matrix wrotationA, Vector3 positionA, ConvexShape shapeA, - Matrix wrotationB, Vector3 positionB, ConvexShape shapeB) - : this(wrotationA, positionA, shapeA, wrotationB, positionB, shapeB, 0) { } - - public Gjk(Matrix wrotationA, Vector3 positionA, ConvexShape shapeA, - Matrix wrotationB, Vector3 positionB, ConvexShape shapeB, - float pmargin) - { - for (int i = 0; i < _simplex.Length; i++) - _simplex[i] = new MinkowskiVertice(); - - for (int i = 0; i < _wrotations.Length; i++) - _wrotations[i] = new Matrix(); - - for (int i = 0; i < _positions.Length; i++) - _positions[i] = new Vector3(); - - _wrotations[0] = wrotationA; _positions[0] = positionA; - _shapes[0] = shapeA; - _wrotations[0].Translation = Vector3.Zero; - _wrotations[1] = wrotationB; _positions[1] = positionB; - _shapes[1] = shapeB; - _wrotations[1].Translation = Vector3.Zero; - //sablock = sa->BeginBlock(); - _margin = pmargin; - _failed = false; - } - - public bool Failed { get { return _failed; } } - public int Iterations { get { return _iterations; } } - public int Order { get { return _order; } } - public MinkowskiVertice[] Simplex { get { return _simplex; } } - - public int Hash(Vector3 v) - { - int h = ((int)(v.X * 15461) ^ (int)(v.Y * 83003) ^ (int)(v.Z * 15473)); - return (h * 169639) & _gjkHashMask; - } - - public bool FetchSupport() - { - int h = Hash(_ray); - He e = _table[h]; - while (e != null) - { - if (e.Ray == _ray) - { - --_order; - return (false); - } - else e = e.Next; - } - e = new He(); - e.Ray = _ray; - e.Next = _table[h]; - _table[h] = e; - Support(_ray, ref _simplex[++_order]); - return (Vector3.Dot(_ray, _simplex[_order].Vertice) > 0); - } - - public Vector3 LocalSupport(Vector3 d, int i) - { - Matrix m = _wrotations[i]; - m.Translation = Vector3.Zero; - Vector3 vtx = Vector3.TransformNormal(d, m); - Vector3 result = MathHelper.MatrixToVector(_wrotations[i], _shapes[i].LocalGetSupportingVertex(vtx)); - return (result + _positions[i]); - } - - public void Support(Vector3 d, ref MinkowskiVertice v) - { - v.Ray = d; - v.Vertice = LocalSupport(d, 0) - LocalSupport(-d, 1) + d * _margin; - } - - public bool SolveSimplex2(Vector3 ao, Vector3 ab) - { - if (Vector3.Dot(ab, ao) >= 0) - { - Vector3 cabo = Vector3.Cross(ab, ao); - if (cabo.LengthSquared() > _gjkSquareInSimplexEpsilon) - { _ray = Vector3.Cross(cabo, ab); } - else - { return true; } - } - else - { - _order = 0; - _simplex[0].Ray = _simplex[1].Ray; - _simplex[0].Vertice = _simplex[1].Vertice; - - _ray = ao; - } - return false; - } - - public bool SolveSimplex3(Vector3 ao, Vector3 ab, Vector3 ac) - { - return (SolveSimplex3a(ao, ab, ac, Vector3.Cross(ab, ac))); - } - - public bool SolveSimplex3a(Vector3 ao, Vector3 ab, Vector3 ac, Vector3 cabc) - { - if ((Vector3.Dot(Vector3.Cross(cabc, ab), ao)) < -_gjkInSimplexEpsilon) - { - _order = 1; - _simplex[0].Vertice = _simplex[1].Vertice; - _simplex[0].Ray = _simplex[1].Ray; - - _simplex[1].Vertice = _simplex[2].Vertice; - _simplex[1].Ray = _simplex[2].Ray; - - return (SolveSimplex2(ao, ab)); - } - else if (Vector3.Dot(Vector3.Cross(cabc, ac), ao) > +_gjkInSimplexEpsilon) - { - _order = 1; - _simplex[1].Vertice = _simplex[2].Vertice; - _simplex[1].Ray = _simplex[2].Ray; - - return (SolveSimplex2(ao, ac)); - } - else - { - float d = Vector3.Dot(cabc, ao); - if (Abs(d) > _gjkInSimplexEpsilon) - { - if (d > 0) - { _ray = cabc; } - else - { _ray = -cabc; Swap(ref _simplex[0], ref _simplex[1]); } - return (false); - } - else return (true); - } - } - - public bool SolveSimplex4(Vector3 ao, Vector3 ab, Vector3 ac, Vector3 ad) - { - Vector3 crs; - if (Vector3.Dot((crs = Vector3.Cross(ab, ac)), ao) > _gjkInSimplexEpsilon) - { - _order = 2; - _simplex[0].Vertice = _simplex[1].Vertice; - _simplex[0].Ray = _simplex[1].Ray; - - _simplex[1].Vertice = _simplex[2].Vertice; - _simplex[1].Ray = _simplex[2].Ray; - - _simplex[2].Vertice = _simplex[3].Vertice; - _simplex[2].Ray = _simplex[3].Ray; - - return (SolveSimplex3a(ao, ab, ac, crs)); - } - else if (Vector3.Dot((crs = Vector3.Cross(ac, ad)), ao) > _gjkInSimplexEpsilon) - { - _order = 2; - _simplex[2].Vertice = _simplex[3].Vertice; - _simplex[2].Ray = _simplex[3].Ray; - - return (SolveSimplex3a(ao, ac, ad, crs)); - } - else if (Vector3.Dot((crs = Vector3.Cross(ad, ab)), ao) > _gjkInSimplexEpsilon) - { - _order = 2; - - _simplex[1].Vertice = _simplex[0].Vertice; - _simplex[1].Ray = _simplex[0].Ray; - - _simplex[0].Vertice = _simplex[2].Vertice; - _simplex[0].Ray = _simplex[2].Ray; - - _simplex[2].Vertice = _simplex[3].Vertice; - _simplex[2].Ray = _simplex[3].Ray; - - return (SolveSimplex3a(ao, ad, ab, crs)); - } - else return (true); - } - - public bool SearchOrigin() - { - return SearchOrigin(new Vector3(1, 0, 0)); - } - - public bool SearchOrigin(Vector3 initray) - { - _iterations = 0; - unchecked - { - _order = (int)(-1); - } - _failed = false; - _ray = Vector3.Normalize(initray); - - //ClearMemory(table, sizeof(void*) * GJK_hashsize); - for (int i = 0; i < _table.Length; i++) - _table[i] = null; - FetchSupport(); - _ray = -_simplex[0].Vertice; - for (; _iterations < _gjkMaxIterations; ++_iterations) - { - float rl = _ray.Length(); - _ray /= rl > 0 ? rl : 1; - if (FetchSupport()) - { - bool found = (false); - switch (_order) - { - case 1: found = SolveSimplex2(-_simplex[1].Vertice, _simplex[0].Vertice - _simplex[1].Vertice); break; - case 2: found = SolveSimplex3(-_simplex[2].Vertice, _simplex[1].Vertice - _simplex[2].Vertice, _simplex[0].Vertice - _simplex[2].Vertice); break; - case 3: found = SolveSimplex4(-_simplex[3].Vertice, _simplex[2].Vertice - _simplex[3].Vertice, _simplex[1].Vertice - _simplex[3].Vertice, _simplex[0].Vertice - _simplex[3].Vertice); break; - } - if (found) return (true); - } - else return (false); - } - _failed = true; - return (false); - } - - public bool EncloseOrigin() - { - switch (_order) - { - /* Point */ - case 0: break; - /* Line */ - case 1: - Vector3 ab = _simplex[1].Vertice - _simplex[0].Vertice; - Vector3[] b ={ Vector3.Cross(ab, new Vector3(1, 0, 0)), - Vector3.Cross(ab, new Vector3(0, 1, 0)), - Vector3.Cross(ab, new Vector3(0, 0, 1)) }; - float[] m ={ b[0].LengthSquared(), b[1].LengthSquared(), b[2].LengthSquared() }; - Matrix r = Matrix.CreateFromQuaternion(new Quaternion(Vector3.Normalize(ab), _twoPi / 3)); - Vector3 w = b[m[0] > m[1] ? m[0] > m[2] ? 0 : 2 : m[1] > m[2] ? 1 : 2]; - Support(Vector3.Normalize(w), ref _simplex[4]); w = Vector3.TransformNormal(w, r); - Support(Vector3.Normalize(w), ref _simplex[2]); w = Vector3.TransformNormal(w, r); - Support(Vector3.Normalize(w), ref _simplex[3]); w = Vector3.TransformNormal(w, r); - _order = 4; - return true; - /* Triangle */ - case 2: - Vector3 n = Vector3.Normalize(Vector3.Cross(_simplex[1].Vertice - _simplex[0].Vertice, _simplex[2].Vertice - _simplex[0].Vertice)); - Support(n, ref _simplex[3]); - Support(-n, ref _simplex[4]); - _order = 4; - return true; - /* Tetrahedron */ - case 3: return (true); - /* Hexahedron */ - case 4: return (true); - } - return (false); - } - } - - public class Epa - { - public class Face - { - public Gjk.MinkowskiVertice[] _vertices = new Gjk.MinkowskiVertice[3]; - public Face[] _faces = new Face[3]; - public int[] _e = new int[3]; - public Vector3 _n; - public float _d; - public int _mark; - public Face _prev; - public Face _next; - } - - private Gjk _gjk; - private Face _root; - private int _nfaces; - private int _iterations; - private Vector3[,] _features = new Vector3[2, 3]; - private Vector3[] _nearest = new Vector3[2]; - private Vector3 _normal; - private float _depth; - private bool _failed; - - public Epa(Gjk gjk) - { - this._gjk = gjk; - } - - public bool Failed { get { return _failed; } } - public int Iterations { get { return _iterations; } } - public Vector3 Normal { get { return _normal; } } - public Vector3[] Nearest { get { return _nearest; } } - - public Vector3 GetCoordinates(Face face) - { - Vector3 o = face._n * -face._d; - float[] a ={ Vector3.Cross(face._vertices[0].Vertice - o, face._vertices[1].Vertice - o).Length(), - Vector3.Cross(face._vertices[1].Vertice - o, face._vertices[2].Vertice - o).Length(), - Vector3.Cross(face._vertices[2].Vertice - o, face._vertices[0].Vertice - o).Length()}; - float sm = a[0] + a[1] + a[2]; - return (new Vector3(a[1], a[2], a[0]) / (sm > 0 ? sm : 1)); - } - - public Face FindBest() - { - Face bf = null; - if (_root != null) - { - Face cf = _root; - float bd = _infinity; - do - { - if (cf._d < bd) { bd = cf._d; bf = cf; } - } while (null != (cf = cf._next)); - } - return bf; - } - - public bool Set(ref Face f, Gjk.MinkowskiVertice a, Gjk.MinkowskiVertice b, Gjk.MinkowskiVertice c) - { - Vector3 nrm = Vector3.Cross(b.Vertice - a.Vertice, c.Vertice - a.Vertice); - float len = nrm.Length(); - bool valid = (Vector3.Dot(Vector3.Cross(a.Vertice, b.Vertice), nrm) >= -_epaInFaceEpsilon && - Vector3.Dot(Vector3.Cross(b.Vertice, c.Vertice), nrm) >= -_epaInFaceEpsilon && - Vector3.Dot(Vector3.Cross(c.Vertice, a.Vertice), nrm) >= -_epaInFaceEpsilon); - f._vertices[0] = a; - f._vertices[1] = b; - f._vertices[2] = c; - f._mark = 0; - f._n = nrm / (len > 0 ? len : _infinity); - f._d = Max(0, -Vector3.Dot(f._n, a.Vertice)); - return valid; - } - - public Face NewFace(Gjk.MinkowskiVertice a, Gjk.MinkowskiVertice b, Gjk.MinkowskiVertice c) - { - Face pf = new Face(); - if (Set(ref pf, a, b, c)) - { - if (_root != null) _root._prev = pf; - pf._prev = null; - pf._next = _root; - _root = pf; - ++_nfaces; - } - else - { - pf._prev = pf._next = null; - } - return (pf); - } - - public void Detach(ref Face face) - { - if (face._prev != null || face._next != null) - { - --_nfaces; - if (face == _root) - { - _root = face._next; - _root._prev = null; - } - else - { - if (face._next == null) - { - face._prev._next = null; - } - else - { - face._prev._next = face._next; - face._next._prev = face._prev; - } - } - face._prev = face._next = null; - } - } - - public void Link(ref Face f0, int e0, ref Face f1, int e1) - { - f0._faces[e0] = f1; f1._e[e1] = e0; - f1._faces[e1] = f0; f0._e[e0] = e1; - } - - public Gjk.MinkowskiVertice Support(Vector3 w) - { - Gjk.MinkowskiVertice v = new Gjk.MinkowskiVertice(); - _gjk.Support(w, ref v); - return v; - } - - private static int[] mod3 ={ 0, 1, 2, 0, 1 }; - - public int BuildHorizon(int markid, Gjk.MinkowskiVertice w, ref Face f, int e, ref Face cf, ref Face ff) - { - int ne = (0); - if (f._mark != markid) - { - int e1 = (mod3[e + 1]); - if ((Vector3.Dot(f._n, w.Vertice) + f._d) > 0) - { - Face nf = NewFace(f._vertices[e1], f._vertices[e], w); - Link(ref nf, 0, ref f, e); - if (cf != null) Link(ref cf, 1, ref nf, 2); else ff = nf; - cf = nf; ne = 1; - } - else - { - int e2 = (mod3[e + 2]); - Detach(ref f); - f._mark = markid; - ne += BuildHorizon(markid, w, ref f._faces[e1], f._e[e1], ref cf, ref ff); - ne += BuildHorizon(markid, w, ref f._faces[e2], f._e[e2], ref cf, ref ff); - } - } - return (ne); - } - - public float EvaluatePD() - { - return EvaluatePD(_epaAccuracy); - } - - private int[,] fidx; - private int[,] eidx; - - public float EvaluatePD(float accuracy) - { - //Block* sablock = sa->BeginBlock(); - Face bestface = null; - int markid = 1; - _depth = -_infinity; - _normal = new Vector3(); - _root = null; - _nfaces = 0; - _iterations = 0; - _failed = false; - /* Prepare hull */ - if (_gjk.EncloseOrigin()) - { - int nfidx = 0; - int neidx = 0; - Gjk.MinkowskiVertice[] basemkv = new Gjk.MinkowskiVertice[5]; - Face[] basefaces = new Face[6]; - switch (_gjk.Order) - { - /* Tetrahedron */ - case 3: - { - fidx = new int[,] { { 2, 1, 0 }, { 3, 0, 1 }, { 3, 1, 2 }, { 3, 2, 0 } }; - eidx = new int[,] { { 0, 0, 2, 1 }, { 0, 1, 1, 1 }, { 0, 2, 3, 1 }, { 1, 0, 3, 2 }, { 2, 0, 1, 2 }, { 3, 0, 2, 2 } }; - nfidx = 4; neidx = 6; - } break; - /* Hexahedron */ - case 4: - { - fidx = new int[,] { { 2, 0, 4 }, { 4, 1, 2 }, { 1, 4, 0 }, { 0, 3, 1 }, { 0, 2, 3 }, { 1, 3, 2 } }; - eidx = new int[,] { { 0, 0, 4, 0 }, { 0, 1, 2, 1 }, { 0, 2, 1, 2 }, { 1, 1, 5, 2 }, { 1, 0, 2, 0 }, { 2, 2, 3, 2 }, { 3, 1, 5, 0 }, { 3, 0, 4, 2 }, { 5, 1, 4, 1 } }; - nfidx = 6; neidx = 9; - } break; - } - int i; - - for (i = 0; i <= _gjk.Order; ++i) - { - //basemkv[i] = (GJK::Mkv*)sa->Allocate(sizeof(GJK::Mkv)); - basemkv[i] = new Gjk.MinkowskiVertice(); - basemkv[i].Vertice = _gjk.Simplex[i].Vertice; - basemkv[i].Ray = _gjk.Simplex[i].Ray; - } - for (i = 0; i < nfidx; ++i) - { - basefaces[i] = NewFace(basemkv[fidx[i, 0]], basemkv[fidx[i, 1]], basemkv[fidx[i, 2]]); - } - for (i = 0; i < neidx; ++i) - { - Link(ref basefaces[eidx[i, 0]], eidx[i, 1], ref basefaces[eidx[i, 2]], eidx[i, 3]); - } - } - if (0 == _nfaces) - { - return _depth; - } - /* Expand hull */ - for (; _iterations < _epaMaxIterations; ++_iterations) - { - Face bf = FindBest(); - if (bf != null) - { - Gjk.MinkowskiVertice w = Support(-bf._n); - float d = Vector3.Dot(bf._n, w.Vertice) + bf._d; - bestface = bf; - if (d < -accuracy) - { - Face cf = null; - Face ff = null; - int nf = 0; - Detach(ref bf); - bf._mark = ++markid; - for (int i = 0; i < 3; ++i) - { - nf += BuildHorizon(markid, w, ref bf._faces[i], bf._e[i], ref cf, ref ff); - } - if (nf <= 2) { break; } - Link(ref cf, 1, ref ff, 2); - } - else break; - } - else break; - } - /* Extract contact */ - if (bestface != null) - { - Vector3 b = GetCoordinates(bestface); - _normal = bestface._n; - _depth = Max(0, bestface._d); - for (int i = 0; i < 2; ++i) - { - float s = i != 0 ? -1 : 1; - for (int j = 0; j < 3; ++j) - { - _features[i, j] = _gjk.LocalSupport(s * bestface._vertices[j].Ray, i); - } - } - _nearest[0] = _features[0, 0] * b.X + _features[0, 1] * b.Y + _features[0, 2] * b.Z; - _nearest[1] = _features[1, 0] * b.X + _features[1, 1] * b.Y + _features[1, 2] * b.Z; - } - else _failed = true; - return _depth; - } - - private float Max(float a, float b) - { - return (a > b ? a : b); - } - - private float Min(float a, float b) - { - return (a < b ? a : b); - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkEpaPenetrationDepthSolver.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkEpaPenetrationDepthSolver.cs deleted file mode 100644 index a1367db40..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkEpaPenetrationDepthSolver.cs +++ /dev/null @@ -1,56 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// EpaPenetrationDepthSolver uses the Expanding Polytope Algorithm to - /// calculate the penetration depth between two convex shapes. - /// - public class GjkEpaPenetrationDepthSolver : IConvexPenetrationDepthSolver - { - public bool CalculatePenetrationDepth(ISimplexSolver simplexSolver, ConvexShape convexA, ConvexShape convexB, Matrix transformA, Matrix transformB, Vector3 vector, out Vector3 ptrA, out Vector3 ptrB, IDebugDraw debugDraw) - { - float radialmargin = 0; - - GjkEpaSolver.Results results; - if (GjkEpaSolver.Collide(convexA, transformA, - convexB, transformB, - radialmargin, out results)) - { - // debugDraw->drawLine(results.witnesses[1],results.witnesses[1]+results.normal,btVector3(255,0,0)); - //resultOut->addContactPoint(results.normal,results.witnesses[1],-results.depth); - ptrA = results.Witnesses[0]; - ptrB = results.Witnesses[1]; - return true; - } - ptrA = new Vector3(); - ptrB = new Vector3(); - - return false; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkEpaSolver.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkEpaSolver.cs deleted file mode 100644 index c35c65b41..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkEpaSolver.cs +++ /dev/null @@ -1,101 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// GjkEpaSolver contributed under zlib by Nathanael Presson - /// - public class GjkEpaSolver - { - public struct Results - { - public enum Status - { - Separated, /* Shapes doesnt penetrate */ - Penetrating, /* Shapes are penetrating */ - GjkFailed, /* GJK phase fail, no big issue, shapes are probably just 'touching' */ - EpaFailed, /* EPA phase fail, bigger problem, need to save parameters, and debug */ - } - - private Vector3[] _witnesses; - private Vector3 _normal; - private float _depth; - private int _epaIterations; - private int _gjkIterations; - private Status _status; - - public Vector3[] Witnesses { get { return _witnesses; } set { _witnesses = value; } } - public Vector3 Normal { get { return _normal; } set { _normal = value; } } - public float Depth { get { return _depth; } set { _depth = value; } } - public int EpaIterations { get { return _epaIterations; } set { _epaIterations = value; } } - public int GjkIterations { get { return _gjkIterations; } set { _gjkIterations = value; } } - public Status ResultStatus { get { return _status; } set { _status = value; } } - } - - public static bool Collide(ConvexShape shapeA, Matrix wtrsA, - ConvexShape shapeB, Matrix wtrsB, - float radialmargin, - out Results results) - { - /* Initialize */ - results = new Results(); - results.Witnesses = new Vector3[2]; - results.Witnesses[0] = - results.Witnesses[1] = - results.Normal = new Vector3(); - results.Depth = 0; - results.ResultStatus = Results.Status.Separated; - results.EpaIterations = 0; - results.GjkIterations = 0; - /* Use GJK to locate origin */ - GjkEpa.Gjk gjk = new GjkEpa.Gjk(wtrsA, wtrsA.Translation, shapeA, - wtrsB, wtrsB.Translation, shapeB, - radialmargin + GjkEpa.EpaAccuracy); - bool collide = gjk.SearchOrigin(); - results.GjkIterations = gjk.Iterations + 1; - if (collide) - { - /* Then EPA for penetration depth */ - GjkEpa.Epa epa = new GjkEpa.Epa(gjk); - float pd = epa.EvaluatePD(); - results.EpaIterations = epa.Iterations + 1; - if (pd > 0) - { - results.ResultStatus = Results.Status.Penetrating; - results.Normal = epa.Normal; - results.Depth = pd; - results.Witnesses[0] = epa.Nearest[0]; - results.Witnesses[1] = epa.Nearest[1]; - return true; - } - else { if (epa.Failed) results.ResultStatus = Results.Status.EpaFailed; } - } - else { if (gjk.Failed) results.ResultStatus = Results.Status.GjkFailed; } - return false; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkPairDetector.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkPairDetector.cs deleted file mode 100644 index f5a12feb5..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/GjkPairDetector.cs +++ /dev/null @@ -1,343 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class GjkPairDetector : DiscreteCollisionDetectorInterface - { - private Vector3 _cachedSeparatingAxis; - private IConvexPenetrationDepthSolver _penetrationDepthSolver; - private ISimplexSolver _simplexSolver; - private ConvexShape _minkowskiA, _minkowskiB; - private bool _ignoreMargin; - - private int _lastUsedMethod; - private int _currentIteration; - private int _degenerateSimplex; - private int _catchDegeneracies; - - private static int _numDeepPenetrationChecks = 0; - private static int _numGjkChecks = 0; - - private const float RelativeError2 = 1.0e-6f; - - #region Properties - public int LastUsedMethod - { - get { return _lastUsedMethod; } - set { _lastUsedMethod = value; } - } - - public int CurrentIteration - { - get { return _currentIteration; } - set { _currentIteration = value; } - } - - public int DegenerateSimplex - { - get { return _degenerateSimplex; } - set { _degenerateSimplex = value; } - } - - public int CatchDegeneracies - { - get { return _catchDegeneracies; } - set { _catchDegeneracies = value; } - } - - public static int DeepPenetrationChecksCount { get { return _numDeepPenetrationChecks; } } - public static int GjkChecksCount { get { return _numGjkChecks; } } - #endregion - - public GjkPairDetector(ConvexShape objectA, ConvexShape objectB, - ISimplexSolver simplexSolver, - IConvexPenetrationDepthSolver penetrationDepthSolver) - { - _cachedSeparatingAxis = new Vector3(0, 0, 1); - - _penetrationDepthSolver = penetrationDepthSolver; - _simplexSolver = simplexSolver; - _minkowskiA = objectA; - _minkowskiB = objectB; - _ignoreMargin = false; - _lastUsedMethod = -1; - _catchDegeneracies = 1; - } - - public void setMinkowskiA(ConvexShape minkA) - { - _minkowskiA = minkA; - } - - public void setMinkowskiB(ConvexShape minkB) - { - _minkowskiB = minkB; - } - public void setCachedSeperatingAxis(Vector3 seperatingAxis) - { - _cachedSeparatingAxis = seperatingAxis; - } - - public void setPenetrationDepthSolver(IConvexPenetrationDepthSolver penetrationDepthSolver) - { - this._penetrationDepthSolver = penetrationDepthSolver; - } - - public void setIgnoreMargin(bool ignoreMargin) - { - this._ignoreMargin = ignoreMargin; - } - - public override void GetClosestPoints(DiscreteCollisionDetectorInterface.ClosestPointInput input, DiscreteCollisionDetectorInterface.Result output, IDebugDraw debugDraw) - { - float distance = 0; - - Vector3 normalInB = new Vector3(); - Vector3 pointOnA = new Vector3(), pointOnB = new Vector3(); - - Matrix localTransA = input.TransformA; - Matrix localTransB = input.TransformB; - - Vector3 positionOffset = (localTransA.Translation + localTransB.Translation) * 0.5f; - localTransA.Translation -= positionOffset; - localTransB.Translation -= positionOffset; - - float marginA = _minkowskiA.Margin; - float marginB = _minkowskiB.Margin; - - _numGjkChecks++; - - if (_ignoreMargin) - { - marginA = 0; - marginB = 0; - } - - _currentIteration = 0; - - int gjkMaxIter = 1000; - _cachedSeparatingAxis = new Vector3(0, 1, 0); - - bool isValid = false; - bool checkSimplex = false; - bool checkPenetration = true; - _degenerateSimplex = 0; - - _lastUsedMethod = -1; - - { - float squaredDistance = MathHelper.Infinity; - float delta = 0; - - float margin = marginA + marginB; - - _simplexSolver.Reset(); - - while (true) - { - Matrix transABasis = input.TransformA; - transABasis.Translation = Vector3.Zero; - - Matrix transBBasis = input.TransformB; - transBBasis.Translation = Vector3.Zero; - - Vector3 seperatingAxisInA = Vector3.TransformNormal(-_cachedSeparatingAxis, transABasis); - Vector3 seperatingAxisInB = Vector3.TransformNormal(_cachedSeparatingAxis, transBBasis); - - Vector3 pInA = _minkowskiA.LocalGetSupportingVertexWithoutMargin(seperatingAxisInA); - Vector3 qInB = _minkowskiB.LocalGetSupportingVertexWithoutMargin(seperatingAxisInB); - Vector3 pWorld = MathHelper.MatrixToVector(localTransA, pInA); - Vector3 qWorld = MathHelper.MatrixToVector(localTransB, qInB); - - Vector3 w = pWorld - qWorld; - delta = Vector3.Dot(_cachedSeparatingAxis, w); - - if ((delta > 0.0) && (delta * delta > squaredDistance * input.MaximumDistanceSquared)) - { - checkPenetration = false; - break; - } - - if (_simplexSolver.InSimplex(w)) - { - _degenerateSimplex = 1; - checkSimplex = true; - break; - } - - float f0 = squaredDistance - delta; - float f1 = squaredDistance * RelativeError2; - - if (f0 <= f1) - { - if (f0 <= 0.0f) - { - _degenerateSimplex = 2; - } - - checkSimplex = true; - break; - } - - _simplexSolver.AddVertex(w, pWorld, qWorld); - - if (!_simplexSolver.Closest(out _cachedSeparatingAxis)) - { - _degenerateSimplex = 3; - checkSimplex = true; - break; - } - - float previouseSquaredDistance = squaredDistance; - squaredDistance = _cachedSeparatingAxis.LengthSquared(); - - if (previouseSquaredDistance - squaredDistance <= MathHelper.Epsilon * previouseSquaredDistance) - { - _simplexSolver.BackupClosest(out _cachedSeparatingAxis); - checkSimplex = true; - break; - } - - if (_currentIteration++ > gjkMaxIter) - { -#if DEBUG - Console.WriteLine("GjkPairDetector maxIter exceeded: {0}", _currentIteration); - Console.WriteLine("sepAxis=({0},{1},{2}), squaredDistance = {3}, shapeTypeA={4}, shapeTypeB={5}", - _cachedSeparatingAxis.X, - _cachedSeparatingAxis.Y, - _cachedSeparatingAxis.Z, - squaredDistance, - _minkowskiA.ShapeType, - _minkowskiB.ShapeType - ); -#endif - break; - } - - bool check = (!_simplexSolver.FullSimplex); - - if (!check) - { - _simplexSolver.BackupClosest(out _cachedSeparatingAxis); - break; - } - } - - if (checkSimplex) - { - _simplexSolver.ComputePoints(out pointOnA, out pointOnB); - normalInB = pointOnA - pointOnB; - float lenSqr = _cachedSeparatingAxis.LengthSquared(); - - if (lenSqr < 0.0001f) - { - _degenerateSimplex = 5; - } - - if (lenSqr > MathHelper.Epsilon * MathHelper.Epsilon) - { - float rlen = 1.0f / (float)Math.Sqrt((float)lenSqr); - normalInB *= rlen; - float s = (float)Math.Sqrt((float)squaredDistance); - - BulletDebug.Assert(s > 0); - pointOnA -= _cachedSeparatingAxis * (marginA / s); - pointOnB += _cachedSeparatingAxis * (marginB / s); - distance = ((1 / rlen) - margin); - - isValid = true; - - _lastUsedMethod = 1; - } - else - { - _lastUsedMethod = 2; - } - } - - bool catchDegeneratePenetrationCase = - (_catchDegeneracies != 0 && _penetrationDepthSolver != null && _degenerateSimplex != 0 && ((distance + margin) < 0.01f)); - - if (checkPenetration && (!isValid || catchDegeneratePenetrationCase)) - { -#warning Check this - if (_penetrationDepthSolver != null) - { - Vector3 tmpPointOnA, tmpPointOnB; - - _numDeepPenetrationChecks++; - - bool isValid2 = _penetrationDepthSolver.CalculatePenetrationDepth( - _simplexSolver, _minkowskiA, _minkowskiB, localTransA, localTransB, - _cachedSeparatingAxis, out tmpPointOnA, out tmpPointOnB, - debugDraw - ); - - if (isValid2) - { - Vector3 tmpNormalInB = tmpPointOnB - tmpPointOnA; - float lengSqr = tmpNormalInB.LengthSquared(); - - if (lengSqr > (MathHelper.Epsilon * MathHelper.Epsilon)) - { - tmpNormalInB /= (float)Math.Sqrt((float)lengSqr); - float distance2 = -(tmpPointOnA - tmpPointOnB).Length(); - - if (!isValid || (distance2 < distance)) - { - distance = distance2; - pointOnA = tmpPointOnA; - pointOnB = tmpPointOnB; - normalInB = tmpNormalInB; - isValid = true; - _lastUsedMethod = 3; - } - else - { - - } - } - else - { - _lastUsedMethod = 4; - } - } - else - { - _lastUsedMethod = 5; - } - } - } - - if (isValid) - { - output.AddContactPoint(normalInB, pointOnB + positionOffset, distance); - } - } - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/IConvexPenetrationDepthSolver.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/IConvexPenetrationDepthSolver.cs deleted file mode 100644 index 53f5b3358..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/IConvexPenetrationDepthSolver.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// IConvexPenetrationDepthSolver provides an interface for penetration depth calculation. - /// - public interface IConvexPenetrationDepthSolver - { - bool CalculatePenetrationDepth( - ISimplexSolver simplexSolver, - ConvexShape convexA, ConvexShape convexB, - Matrix transformA, Matrix transformB, - Vector3 vector, out Vector3 ptrA, out Vector3 ptrB, - IDebugDraw debugDraw//, StackAlloc stackAlloc - ); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ISimplexSolver.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ISimplexSolver.cs deleted file mode 100644 index de87c015f..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ISimplexSolver.cs +++ /dev/null @@ -1,48 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// ISimplexSolver can incrementally calculate distance between origin and up to 4 vertices - /// Used by GJK or Linear Casting. Can be implemented by the Johnson-algorithm or alternative approaches based on - /// voronoi regions or barycentric coordinates - public interface ISimplexSolver - { - void Reset(); - void AddVertex(Vector3 w, Vector3 p, Vector3 q); - bool Closest(out Vector3 v); - - int GetSimplex(out Vector3[] pBuf, out Vector3[] qBuf, out Vector3[] yBuf); - bool InSimplex(Vector3 w); - void BackupClosest(out Vector3 v); - void ComputePoints(out Vector3 pA, out Vector3 pB); - - int NumVertices { get;} - bool EmptySimplex { get;} - float MaxVertex { get;} - bool FullSimplex { get;} - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ManifoldPoint.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ManifoldPoint.cs deleted file mode 100644 index d9def4d63..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/ManifoldPoint.cs +++ /dev/null @@ -1,78 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class ManifoldPoint - { - private Vector3 _localPointA; - private Vector3 _localPointB; - private Vector3 _positionWorldOnB; - private Vector3 _positionWorldOnA; - private Vector3 _normalWorldOnB; - - private float _distance; - private float _combinedFriction; - private float _combinedRestitution; - - private object _userPersistentData; - - private int _lifeTime;//lifetime of the contactpoint in frames - - public ManifoldPoint() - : this(new Vector3(), new Vector3(), new Vector3(), 0f) - { - } - - public ManifoldPoint(Vector3 pointA, Vector3 pointB, - Vector3 normal, - float distance) - { - _localPointA = pointA; - _localPointB = pointB; - _normalWorldOnB = normal; - _distance = distance; - _positionWorldOnA = new Vector3(); - _positionWorldOnB = new Vector3(); - } - - public float Distance { get { return _distance; } set { _distance = value; } } - public int LifeTime { get { return _lifeTime; } set { _lifeTime = value; } } - - public Vector3 PositionWorldOnA { get { return _positionWorldOnA; } set { _positionWorldOnA = value; } } - public Vector3 PositionWorldOnB { get { return _positionWorldOnB; } set { _positionWorldOnB = value; } } - - public Vector3 LocalPointA { get { return _localPointA; } set { _localPointA = value; } } - public Vector3 LocalPointB { get { return _localPointB; } set { _localPointB = value; } } - - public Vector3 NormalWorldOnB { get { return _normalWorldOnB; } } - - public float CombinedFriction { get { return _combinedFriction; } set { _combinedFriction = value; } } - public float CombinedRestitution { get { return _combinedRestitution; } set { _combinedRestitution = value; } } - - public object UserPersistentData { get { return _userPersistentData; } set { _userPersistentData = value; } } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cs deleted file mode 100644 index 277156de8..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cs +++ /dev/null @@ -1,246 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// MinkowskiPenetrationDepthSolver implements bruteforce penetration depth estimation. - /// Implementation is based on sampling the depth using support mapping, and using GJK step to get the witness points. - /// - public class MinkowskiPenetrationDepthSolver : IConvexPenetrationDepthSolver - { - private const int UnitSpherePointsCount = 42; - - private static Vector3[] penetrationDirections = - { - new Vector3(0.000000f , -0.000000f,-1.000000f), - new Vector3(0.723608f , -0.525725f,-0.447219f), - new Vector3(-0.276388f , -0.850649f,-0.447219f), - new Vector3(-0.894426f , -0.000000f,-0.447216f), - new Vector3(-0.276388f , 0.850649f,-0.447220f), - new Vector3(0.723608f , 0.525725f,-0.447219f), - new Vector3(0.276388f , -0.850649f,0.447220f), - new Vector3(-0.723608f , -0.525725f,0.447219f), - new Vector3(-0.723608f , 0.525725f,0.447219f), - new Vector3(0.276388f , 0.850649f,0.447219f), - new Vector3(0.894426f , 0.000000f,0.447216f), - new Vector3(-0.000000f , 0.000000f,1.000000f), - new Vector3(0.425323f , -0.309011f,-0.850654f), - new Vector3(-0.162456f , -0.499995f,-0.850654f), - new Vector3(0.262869f , -0.809012f,-0.525738f), - new Vector3(0.425323f , 0.309011f,-0.850654f), - new Vector3(0.850648f , -0.000000f,-0.525736f), - new Vector3(-0.525730f , -0.000000f,-0.850652f), - new Vector3(-0.688190f , -0.499997f,-0.525736f), - new Vector3(-0.162456f , 0.499995f,-0.850654f), - new Vector3(-0.688190f , 0.499997f,-0.525736f), - new Vector3(0.262869f , 0.809012f,-0.525738f), - new Vector3(0.951058f , 0.309013f,0.000000f), - new Vector3(0.951058f , -0.309013f,0.000000f), - new Vector3(0.587786f , -0.809017f,0.000000f), - new Vector3(0.000000f , -1.000000f,0.000000f), - new Vector3(-0.587786f , -0.809017f,0.000000f), - new Vector3(-0.951058f , -0.309013f,-0.000000f), - new Vector3(-0.951058f , 0.309013f,-0.000000f), - new Vector3(-0.587786f , 0.809017f,-0.000000f), - new Vector3(-0.000000f , 1.000000f,-0.000000f), - new Vector3(0.587786f , 0.809017f,-0.000000f), - new Vector3(0.688190f , -0.499997f,0.525736f), - new Vector3(-0.262869f , -0.809012f,0.525738f), - new Vector3(-0.850648f , 0.000000f,0.525736f), - new Vector3(-0.262869f , 0.809012f,0.525738f), - new Vector3(0.688190f , 0.499997f,0.525736f), - new Vector3(0.525730f , 0.000000f,0.850652f), - new Vector3(0.162456f , -0.499995f,0.850654f), - new Vector3(-0.425323f , -0.309011f,0.850654f), - new Vector3(-0.425323f , 0.309011f,0.850654f), - new Vector3(0.162456f , 0.499995f,0.850654f) - }; - - private class IntermediateResult : DiscreteCollisionDetectorInterface.Result - { - private Vector3 _normalOnBInWorld; - private Vector3 _pointInWorld; - private float _depth; - private bool _hasResult; - - public IntermediateResult() - { - _hasResult = false; - } - - public bool HasResult { get { return _hasResult; } } - public float Depth { get { return _depth; } } - public Vector3 PointInWorld { get { return _pointInWorld; } } - - public override void SetShapeIdentifiers(int partId0, int index0, int partId1, int index1) - { - } - - public override void AddContactPoint(Vector3 normalOnBInWorld, Vector3 pointInWorld, float depth) - { - _normalOnBInWorld = normalOnBInWorld; - _pointInWorld = pointInWorld; - _depth = depth; - _hasResult = true; - } - } - - #region IConvexPenetrationDepthSolver Members - public bool CalculatePenetrationDepth(ISimplexSolver simplexSolver, - ConvexShape convexA, ConvexShape convexB, - Matrix transformA, Matrix transformB, - Vector3 v, out Vector3 pa, out Vector3 pb, IDebugDraw debugDraw) - { - pa = new Vector3(); - pb = new Vector3(); - //just take fixed number of orientation, and sample the penetration depth in that direction - float minProj = 1e30f; - Vector3 minNorm = new Vector3(); - Vector3 minA = new Vector3(), minB = new Vector3(); - Vector3 seperatingAxisInA, seperatingAxisInB; - Vector3 pInA, qInB, pWorld, qWorld, w; - - Vector3[] supportVerticesABatch = new Vector3[UnitSpherePointsCount + ConvexShape.MaxPreferredPenetrationDirections * 2]; - Vector3[] supportVerticesBBatch = new Vector3[UnitSpherePointsCount + ConvexShape.MaxPreferredPenetrationDirections * 2]; - Vector3[] seperatingAxisInABatch = new Vector3[UnitSpherePointsCount + ConvexShape.MaxPreferredPenetrationDirections * 2]; - Vector3[] seperatingAxisInBBatch = new Vector3[UnitSpherePointsCount + ConvexShape.MaxPreferredPenetrationDirections * 2]; - - int numSampleDirections = UnitSpherePointsCount; - - for (int i = 0; i < numSampleDirections; i++) - { - Vector3 norm = penetrationDirections[i]; - seperatingAxisInABatch[i] = Vector3.TransformNormal((-norm), transformA); - seperatingAxisInBBatch[i] = Vector3.TransformNormal(norm, transformB); - } - - { - int numPDA = convexA.PreferredPenetrationDirectionsCount; - if (numPDA != 0) - { - for (int i = 0; i < numPDA; i++) - { - Vector3 norm; - convexA.GetPreferredPenetrationDirection(i, out norm); - norm = Vector3.TransformNormal(norm, transformA); - penetrationDirections[numSampleDirections] = norm; - seperatingAxisInABatch[numSampleDirections] = Vector3.TransformNormal((-norm), transformA); - seperatingAxisInBBatch[numSampleDirections] = Vector3.TransformNormal(norm, transformB); - numSampleDirections++; - } - } - } - - { - int numPDB = convexB.PreferredPenetrationDirectionsCount; - if (numPDB != 0) - { - for (int i = 0; i < numPDB; i++) - { - Vector3 norm; - convexB.GetPreferredPenetrationDirection(i, out norm); - norm = Vector3.TransformNormal(norm, transformB); - penetrationDirections[numSampleDirections] = norm; - seperatingAxisInABatch[numSampleDirections] = Vector3.TransformNormal((-norm), transformA); - seperatingAxisInBBatch[numSampleDirections] = Vector3.TransformNormal(norm, transformB); - numSampleDirections++; - } - } - } - - convexA.BatchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInABatch, supportVerticesABatch); //, numSampleDirections); - convexB.BatchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInBBatch, supportVerticesBBatch); //, numSampleDirections); - - for (int i = 0; i < numSampleDirections; i++) - { - Vector3 norm = penetrationDirections[i]; - seperatingAxisInA = seperatingAxisInABatch[i]; - seperatingAxisInB = seperatingAxisInBBatch[i]; - - pInA = supportVerticesABatch[i]; - qInB = supportVerticesBBatch[i]; - - pWorld = MathHelper.MatrixToVector(transformA, pInA); - qWorld = MathHelper.MatrixToVector(transformB, qInB); - w = qWorld - pWorld; - float delta = Vector3.Dot(norm, w); - //find smallest delta - if (delta < minProj) - { - minProj = delta; - minNorm = norm; - minA = pWorld; - minB = qWorld; - } - } - - //add the margins - minA += minNorm * convexA.Margin; - minB -= minNorm * convexB.Margin; - //no penetration - if (minProj < 0) - return false; - - minProj += (convexA.Margin + convexB.Margin); - - GjkPairDetector gjkdet = new GjkPairDetector(convexA, convexB, simplexSolver, null); - - float offsetDist = minProj; - Vector3 offset = minNorm * offsetDist; - - GjkPairDetector.ClosestPointInput input = new DiscreteCollisionDetectorInterface.ClosestPointInput(); - - Vector3 newOrg = transformA.Translation + offset; - - Matrix displacedTrans = transformA; - displacedTrans.Translation = newOrg; - - input.TransformA = displacedTrans; - input.TransformB = transformB; - input.MaximumDistanceSquared = 1e30f;//minProj; - - IntermediateResult res = new IntermediateResult(); - gjkdet.GetClosestPoints(input, res, debugDraw); - - float correctedMinNorm = minProj - res.Depth; - - //the penetration depth is over-estimated, relax it - float penetration_relaxation = 1; - minNorm *= penetration_relaxation; - - if (res.HasResult) - { - - pa = res.PointInWorld - minNorm * correctedMinNorm; - pb = res.PointInWorld; - } - - return res.HasResult; - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/PersistentManifold.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/PersistentManifold.cs deleted file mode 100644 index 69ba021ea..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/PersistentManifold.cs +++ /dev/null @@ -1,272 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public delegate bool ContactDestroyedCallback(object userPersistentData); - - public class PersistentManifold - { - private static ContactDestroyedCallback _contactDestroyedCallback = null; - private static float _contactBreakingThreshold = 0.02f; - - private ManifoldPoint[] _pointCache = new ManifoldPoint[4]; - - // this two body pointers can point to the physics rigidbody class. - // object will allow any rigidbody class - private object _bodyA; - private object _bodyB; - private int _cachedPoints; - - public PersistentManifold(object bodyA, object bodyB) - { - _bodyA = bodyA; - _bodyB = bodyB; - _cachedPoints = 0; - } - - public object BodyA { get { return _bodyA; } } - public object BodyB { get { return _bodyB; } } - - public int ContactsCount { get { return _cachedPoints; } } - - public static ContactDestroyedCallback ContactDestroyedCallback { get { return _contactDestroyedCallback; } set { _contactDestroyedCallback = value; } } - public static float ContactBreakingThreshold { get { return _contactBreakingThreshold; } } - - public void SetBodies(object bodyA, object bodyB) - { - _bodyA = bodyA; - _bodyB = bodyB; - } - - public ManifoldPoint GetContactPoint(int index) - { - if (index >= _cachedPoints) - throw new ArgumentOutOfRangeException("index", "index must be smaller than cachedPoints"); - - return _pointCache[index]; - } - - public int GetCacheEntry(ManifoldPoint newPoint) - { - float shortestDist = ContactBreakingThreshold * ContactBreakingThreshold; - int size = ContactsCount; - int nearestPoint = -1; - for (int i = 0; i < size; i++) - { - ManifoldPoint mp = _pointCache[i]; - - Vector3 diffA = mp.LocalPointA - newPoint.LocalPointA; - float distToManiPoint = Vector3.Dot(diffA, diffA); - if (distToManiPoint < shortestDist) - { - shortestDist = distToManiPoint; - nearestPoint = i; - } - } - return nearestPoint; - } - - public void AddManifoldPoint(ManifoldPoint newPoint) - { - if (!ValidContactDistance(newPoint)) - throw new BulletException(); - - int insertIndex = ContactsCount; - if (insertIndex == 4) - { - //sort cache so best points come first, based on area - insertIndex = SortCachedPoints(newPoint); - } - else - { - _cachedPoints++; - } - ReplaceContactPoint(newPoint, insertIndex); - } - - public void RemoveContactPoint(int index) - { - ClearUserCache(_pointCache[index]); - - int lastUsedIndex = ContactsCount - 1; - _pointCache[index] = _pointCache[lastUsedIndex]; - //get rid of duplicated userPersistentData pointer - _pointCache[lastUsedIndex].UserPersistentData = null; - _cachedPoints--; - } - - public void ReplaceContactPoint(ManifoldPoint newPoint, int insertIndex) - { - BulletDebug.Assert(ValidContactDistance(newPoint)); - - if (_pointCache[insertIndex] != null) - { - int lifeTime = _pointCache[insertIndex].LifeTime; - BulletDebug.Assert(lifeTime >= 0); - object cache = _pointCache[insertIndex].UserPersistentData; - - _pointCache[insertIndex] = newPoint; - - _pointCache[insertIndex].UserPersistentData = cache; - _pointCache[insertIndex].LifeTime = lifeTime; - } - else - { - _pointCache[insertIndex] = newPoint; - } - - //ClearUserCache(_pointCache[insertIndex]); - //_pointCache[insertIndex] = newPoint; - } - - public bool ValidContactDistance(ManifoldPoint pt) - { - return pt.Distance <= ContactBreakingThreshold; - } - - // calculated new worldspace coordinates and depth, and reject points that exceed the collision margin - public void RefreshContactPoints(Matrix trA, Matrix trB) - { - // first refresh worldspace positions and distance - for (int i = ContactsCount - 1; i >= 0; i--) - { - ManifoldPoint manifoldPoint = _pointCache[i]; - manifoldPoint.PositionWorldOnA = MathHelper.MatrixToVector(trA,manifoldPoint.LocalPointA); - manifoldPoint.PositionWorldOnB = MathHelper.MatrixToVector(trB, manifoldPoint.LocalPointB); - manifoldPoint.Distance = Vector3.Dot(manifoldPoint.PositionWorldOnA - manifoldPoint.PositionWorldOnB, manifoldPoint.NormalWorldOnB); - manifoldPoint.LifeTime++; - } - - // then - float distance2d; - Vector3 projectedDifference, projectedPoint; - for (int i = ContactsCount - 1; i >= 0; i--) - { - - ManifoldPoint manifoldPoint = _pointCache[i]; - //contact becomes invalid when signed distance exceeds margin (projected on contactnormal direction) - if (!ValidContactDistance(manifoldPoint)) - { - RemoveContactPoint(i); - } - else - { - //contact also becomes invalid when relative movement orthogonal to normal exceeds margin - projectedPoint = manifoldPoint.PositionWorldOnA - manifoldPoint.NormalWorldOnB * manifoldPoint.Distance; - projectedDifference = manifoldPoint.PositionWorldOnB - projectedPoint; - distance2d = Vector3.Dot(projectedDifference, projectedDifference); - if (distance2d > ContactBreakingThreshold * ContactBreakingThreshold) - { - RemoveContactPoint(i); - } - } - } - } - - public void ClearManifold() - { - for (int i = 0; i < _cachedPoints; i++) - { - ClearUserCache(_pointCache[i]); - } - _cachedPoints = 0; - } - - private void ClearUserCache(ManifoldPoint pt) - { - if (pt != null) - { - object oldPtr = pt.UserPersistentData; - - if (oldPtr != null) - { - if (pt.UserPersistentData != null && _contactDestroyedCallback != null) - { - _contactDestroyedCallback(pt.UserPersistentData); - pt.UserPersistentData = null; - } - } - } - } - - // sort cached points so most isolated points come first - private int SortCachedPoints(ManifoldPoint pt) - { - //calculate 4 possible cases areas, and take biggest area - //also need to keep 'deepest' - - int maxPenetrationIndex = -1; - float maxPenetration = pt.Distance; - for (int i = 0; i < 4; i++) - { - if (_pointCache[i].Distance < maxPenetration) - { - maxPenetrationIndex = i; - maxPenetration = _pointCache[i].Distance; - } - } - - float res0 = 0, res1 = 0, res2 = 0, res3 = 0; - if (maxPenetrationIndex != 0) - { - Vector3 a0 = pt.LocalPointA - _pointCache[1].LocalPointA; - Vector3 b0 = _pointCache[3].LocalPointA - _pointCache[2].LocalPointA; - Vector3 cross = Vector3.Cross(a0, b0); - res0 = cross.LengthSquared(); - } - if (maxPenetrationIndex != 1) - { - Vector3 a1 = pt.LocalPointA - _pointCache[0].LocalPointA; - Vector3 b1 = _pointCache[3].LocalPointA - _pointCache[2].LocalPointA; - Vector3 cross = Vector3.Cross(a1, b1); - res1 = cross.LengthSquared(); - } - - if (maxPenetrationIndex != 2) - { - Vector3 a2 = pt.LocalPointA - _pointCache[0].LocalPointA; - Vector3 b2 = _pointCache[3].LocalPointA - _pointCache[1].LocalPointA; - Vector3 cross = Vector3.Cross(a2, b2); - res2 = cross.LengthSquared(); - } - - if (maxPenetrationIndex != 3) - { - Vector3 a3 = pt.LocalPointA - _pointCache[0].LocalPointA; - Vector3 b3 = _pointCache[2].LocalPointA - _pointCache[1].LocalPointA; - Vector3 cross = Vector3.Cross(a3, b3); - res3 = cross.LengthSquared(); - } - - Vector4 maxvec = new Vector4(res0, res1, res2, res3); - int biggestarea = MathHelper.ClosestAxis(maxvec); - return biggestarea; - } - - private int FindContactPoint(ManifoldPoint unUsed, int numUnused, ManifoldPoint pt) { return 0; } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/PointCollector.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/PointCollector.cs deleted file mode 100644 index d993738b1..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/PointCollector.cs +++ /dev/null @@ -1,64 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class PointCollector : DiscreteCollisionDetectorInterface.Result - { - private Vector3 _normalOnBInWorld; - private Vector3 _pointInWorld; - private float _distance; //negative means penetration - private bool _hasResult; - - public PointCollector() - { - _distance = 1e30f; - _hasResult = false; - } - - public Vector3 NormalOnBInWorld { get { return _normalOnBInWorld; } } - public Vector3 PointInWorld { get { return _pointInWorld; } } - public float Distance { get { return _distance; } } - public bool HasResult { get { return _hasResult; } } - - public override void SetShapeIdentifiers(int partIdA, int indexA, int partIdB, int indexB) - { - //?? - } - - public override void AddContactPoint(Vector3 normalOnBInWorld, Vector3 pointInWorld, float depth) - { - if (depth < _distance) - { - _hasResult = true; - _normalOnBInWorld = normalOnBInWorld; - _pointInWorld = pointInWorld; - //negative means penetration - _distance = depth; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/SubsimplexConvexCast.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/SubsimplexConvexCast.cs deleted file mode 100644 index c736788b8..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/SubsimplexConvexCast.cs +++ /dev/null @@ -1,142 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - /// - /// SubsimplexConvexCast implements Gino van den Bergens' paper - /// "Ray Casting against bteral Convex Objects with Application to Continuous Collision Detection" - /// GJK based Ray Cast, optimized version - /// Objects should not start in overlap, otherwise results are not defined. - /// - public class SubsimplexConvexCast : IConvexCast - { - private ISimplexSolver _simplexSolver; - private ConvexShape _convexA; - private ConvexShape _convexB; - - /// - /// Typically the conservative advancement reaches solution in a few iterations, clip it to 32 for degenerate cases. - /// See discussion about this here http://continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=565 - /// - private const int MaxIterations = 32; - - public SubsimplexConvexCast(ConvexShape shapeA, ConvexShape shapeB, ISimplexSolver simplexSolver) - { - _simplexSolver = simplexSolver; - _convexA = shapeA; - _convexB = shapeB; - } - - #region IConvexCast Members - /// - /// SimsimplexConvexCast calculateTimeOfImpact calculates the time of impact+normal for the linear cast (sweep) between two moving objects. - /// Precondition is that objects should not penetration/overlap at the start from the interval. Overlap can be tested using GjkPairDetector. - /// - /// - /// - /// - /// - /// - /// - public bool CalcTimeOfImpact(Matrix fromA, Matrix toA, Matrix fromB, Matrix toB, CastResult result) - { - MinkowskiSumShape convex = new MinkowskiSumShape(_convexA, _convexB); - - Matrix rayFromLocalA; - Matrix rayToLocalA; - - rayFromLocalA = MathHelper.InvertMatrix(fromA) * fromB; - rayToLocalA = MathHelper.InvertMatrix(toA) * toB; - - _simplexSolver.Reset(); - - convex.TransformB = rayFromLocalA; - - float lambda = 0; - //todo: need to verify this: - //because of minkowski difference, we need the inverse direction - - Vector3 s = -rayFromLocalA.Translation; - Vector3 r = -(rayToLocalA.Translation - rayFromLocalA.Translation); - Vector3 x = s; - Vector3 v; - Vector3 arbitraryPoint = convex.LocalGetSupportingVertex(r); - - v = x - arbitraryPoint; - - int maxIter = MaxIterations; - - Vector3 n = new Vector3(); - float lastLambda = lambda; - - float dist2 = v.LengthSquared(); - float epsilon = 0.0001f; - - Vector3 w, p; - float VdotR; - - while ((dist2 > epsilon) && (maxIter-- != 0)) - { - p = convex.LocalGetSupportingVertex(v); - w = x - p; - - float VdotW = Vector3.Dot(v, w); - - if (VdotW > 0) - { - VdotR = Vector3.Dot(v, r); - - if (VdotR >= -(MathHelper.Epsilon * MathHelper.Epsilon)) - return false; - else - { - lambda = lambda - VdotW / VdotR; - x = s + lambda * r; - _simplexSolver.Reset(); - //check next line - w = x - p; - lastLambda = lambda; - n = v; - } - } - _simplexSolver.AddVertex(w, x, p); - if (_simplexSolver.Closest(out v)) - { - dist2 = v.LengthSquared(); - } - else - { - dist2 = 0f; - } - } - result.Fraction = lambda; - result.Normal = n; - return true; - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/TriangleRaycastCallback.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/TriangleRaycastCallback.cs deleted file mode 100644 index 062313ef5..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/TriangleRaycastCallback.cs +++ /dev/null @@ -1,115 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public abstract class TriangleRaycastCallback : ITriangleCallback - { - private Vector3 _from; - private Vector3 _to; - private float _hitFraction; - - public TriangleRaycastCallback(Vector3 from, Vector3 to) - { - _from = from; - _to = to; - _hitFraction = 1; - } - - public Vector3 From { get { return _from; } set { _from = value; } } - public Vector3 To { get { return _to; } set { _to = value; } } - public float HitFraction { get { return _hitFraction; } set { _hitFraction = value; } } - - public abstract float ReportHit(Vector3 hitNormalLocal, float hitFraction, int partId, int triangleIndex); - - #region ITriangleCallback Members - - public void ProcessTriangle(Vector3[] triangle, int partID, int triangleIndex) - { - Vector3 vertA = triangle[0]; - Vector3 vertB = triangle[1]; - Vector3 vertC = triangle[2]; - - Vector3 vBA = vertB - vertA; - Vector3 vCA = vertC - vertA; - - Vector3 triangleNormal = Vector3.Cross(vBA, vCA); - - float dist = Vector3.Dot(vertA, triangleNormal); - float distA = Vector3.Dot(triangleNormal, _from); - distA -= dist; - float distB = Vector3.Dot(triangleNormal, _to); - distB -= dist; - - if (distA * distB >= 0.0f) - { - return; // same sign - } - - float projLength = distA - distB; - float distance = (distA) / (projLength); - // Now we have the intersection point on the plane, we'll see if it's inside the triangle - // Add an epsilon as a tolerance for the raycast, - // in case the ray hits exacly on the edge of the triangle. - // It must be scaled for the triangle size. - - if (distance < _hitFraction) - { - float edgeTolerance = triangleNormal.LengthSquared(); - edgeTolerance *= -0.0001f; - Vector3 point = new Vector3(); - MathHelper.SetInterpolate3(_from, _to, distance, ref point); - - Vector3 vertexAPoint = vertA - point; - Vector3 vertexBPoint = vertB - point; - Vector3 contactPointA = Vector3.Cross(vertexAPoint, vertexBPoint); - - if (Vector3.Dot(contactPointA, triangleNormal) >= edgeTolerance) - { - Vector3 vertexCPoint = vertC - point; - Vector3 contactPointB = Vector3.Cross(vertexBPoint, vertexCPoint); - if (Vector3.Dot(contactPointB, triangleNormal) >= edgeTolerance) - { - Vector3 contactPointC = Vector3.Cross(vertexCPoint, vertexAPoint); - - if (Vector3.Dot(contactPointC, triangleNormal) >= edgeTolerance) - { - if (distA > 0) - { - _hitFraction = ReportHit(triangleNormal, distance, partID, triangleIndex); - } - else - { - _hitFraction = ReportHit(-triangleNormal, distance, partID, triangleIndex); - } - } - } - } - } - } - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/VoronoiSimplexSolver.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/VoronoiSimplexSolver.cs deleted file mode 100644 index 1051aca26..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Collision/NarrowPhaseCollision/VoronoiSimplexSolver.cs +++ /dev/null @@ -1,643 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public class UsageBitfield - { - private bool _usedVertexA, _usedVertexB, _usedVertexC, _usedVertexD; - - public bool UsedVertexA { get { return _usedVertexA; } set { _usedVertexA = value; } } - public bool UsedVertexB { get { return _usedVertexB; } set { _usedVertexB = value; } } - public bool UsedVertexC { get { return _usedVertexC; } set { _usedVertexC = value; } } - public bool UsedVertexD { get { return _usedVertexD; } set { _usedVertexD = value; } } - - public void Reset() - { - _usedVertexA = _usedVertexB = _usedVertexC = _usedVertexD = false; - } - } - - public class SubSimplexClosestResult - { - private Vector3 _closestPointOnSimplex; - - //MASK for m_usedVertices - //stores the simplex vertex-usage, using the MASK, - // if m_usedVertices & MASK then the related vertex is used - private UsageBitfield _usedVertices = new UsageBitfield(); - private float[] _barycentricCoords = new float[4]; - private bool _degenerate; - - public Vector3 ClosestPointOnSimplex { get { return _closestPointOnSimplex; } set { _closestPointOnSimplex = value; } } - public UsageBitfield UsedVertices { get { return _usedVertices; } set { _usedVertices = value; } } - public float[] BarycentricCoords { get { return _barycentricCoords; } set { _barycentricCoords = value; } } - public bool Degenerate { get { return _degenerate; } set { _degenerate = value; } } - - public void Reset() - { - _degenerate = false; - SetBarycentricCoordinates(); - _usedVertices.Reset(); - } - - public bool IsValid - { - get - { - return (_barycentricCoords[0] >= 0f) && - (_barycentricCoords[1] >= 0f) && - (_barycentricCoords[2] >= 0f) && - (_barycentricCoords[3] >= 0f); - } - } - - public void SetBarycentricCoordinates() - { - SetBarycentricCoordinates(0f, 0f, 0f, 0f); - } - - public void SetBarycentricCoordinates(float a, float b, float c, float d) - { - _barycentricCoords[0] = a; - _barycentricCoords[1] = b; - _barycentricCoords[2] = c; - _barycentricCoords[3] = d; - } - } - - /// VoronoiSimplexSolver is an implementation of the closest point distance - /// algorithm from a 1-4 points simplex to the origin. - /// Can be used with GJK, as an alternative to Johnson distance algorithm. - public class VoronoiSimplexSolver : ISimplexSolver - { - private const int VertexA = 0, VertexB = 1, VertexC = 2, VertexD = 3; - - private const int VoronoiSimplexMaxVerts = 5; - private const bool CatchDegenerateTetrahedron = true; - - private int _numVertices; - - private Vector3[] _simplexVectorW = new Vector3[VoronoiSimplexMaxVerts]; - private Vector3[] _simplexPointsP = new Vector3[VoronoiSimplexMaxVerts]; - private Vector3[] _simplexPointsQ = new Vector3[VoronoiSimplexMaxVerts]; - - private Vector3 _cachedPA; - private Vector3 _cachedPB; - private Vector3 _cachedV; - private Vector3 _lastW; - private bool _cachedValidClosest; - - private SubSimplexClosestResult _cachedBC = new SubSimplexClosestResult(); - - private bool _needsUpdate; - - #region ISimplexSolver Members - - public bool FullSimplex - { - get - { - return _numVertices == 4; - } - } - - public int NumVertices - { - get - { - return _numVertices; - } - } - - public void Reset() - { - _cachedValidClosest = false; - _numVertices = 0; - _needsUpdate = true; - _lastW = new Vector3(1e30f, 1e30f, 1e30f); - _cachedBC.Reset(); - } - - public void AddVertex(Vector3 w, Vector3 p, Vector3 q) - { - _lastW = w; - _needsUpdate = true; - - _simplexVectorW[_numVertices] = w; - _simplexPointsP[_numVertices] = p; - _simplexPointsQ[_numVertices] = q; - - _numVertices++; - } - - //return/calculate the closest vertex - public bool Closest(out Vector3 v) - { - bool succes = UpdateClosestVectorAndPoints(); - v = _cachedV; - return succes; - } - - public float MaxVertex - { - get - { - int numverts = NumVertices; - float maxV = 0f, curLen2; - for (int i = 0; i < numverts; i++) - { - curLen2 = _simplexVectorW[i].LengthSquared(); - if (maxV < curLen2) maxV = curLen2; - } - return maxV; - } - } - - //return the current simplex - public int GetSimplex(out Vector3[] pBuf, out Vector3[] qBuf, out Vector3[] yBuf) - { - int numverts = NumVertices; - pBuf = new Vector3[numverts]; - qBuf = new Vector3[numverts]; - yBuf = new Vector3[numverts]; - for (int i = 0; i < numverts; i++) - { - yBuf[i] = _simplexVectorW[i]; - pBuf[i] = _simplexPointsP[i]; - qBuf[i] = _simplexPointsQ[i]; - } - return numverts; - } - - public bool InSimplex(Vector3 w) - { - //check in case lastW is already removed - if (w == _lastW) return true; - - //w is in the current (reduced) simplex - int numverts = NumVertices; - for (int i = 0; i < numverts; i++) - if (_simplexVectorW[i] == w) return true; - - return false; - } - - public void BackupClosest(out Vector3 v) - { - v = _cachedV; - } - - public bool EmptySimplex - { - get - { - return NumVertices == 0; - } - } - - public void ComputePoints(out Vector3 p1, out Vector3 p2) - { - UpdateClosestVectorAndPoints(); - p1 = _cachedPA; - p2 = _cachedPB; - } - - #endregion - - public void RemoveVertex(int index) - { - BulletDebug.Assert(_numVertices > 0); - _numVertices--; - _simplexVectorW[index] = _simplexVectorW[_numVertices]; - _simplexPointsP[index] = _simplexPointsP[_numVertices]; - _simplexPointsQ[index] = _simplexPointsQ[_numVertices]; - } - - public void ReduceVertices(UsageBitfield usedVerts) - { - if ((NumVertices >= 4) && (!usedVerts.UsedVertexD)) RemoveVertex(3); - if ((NumVertices >= 3) && (!usedVerts.UsedVertexC)) RemoveVertex(2); - if ((NumVertices >= 2) && (!usedVerts.UsedVertexB)) RemoveVertex(1); - if ((NumVertices >= 1) && (!usedVerts.UsedVertexA)) RemoveVertex(0); - } - - public bool UpdateClosestVectorAndPoints() - { - if (_needsUpdate) - { - _cachedBC.Reset(); - _needsUpdate = false; - - Vector3 p, a, b, c, d; - switch (NumVertices) - { - case 0: - _cachedValidClosest = false; - break; - case 1: - _cachedPA = _simplexPointsP[0]; - _cachedPB = _simplexPointsQ[0]; - _cachedV = _cachedPA - _cachedPB; - _cachedBC.Reset(); - _cachedBC.SetBarycentricCoordinates(1f, 0f, 0f, 0f); - _cachedValidClosest = _cachedBC.IsValid; - break; - case 2: - //closest point origin from line segment - Vector3 from = _simplexVectorW[0]; - Vector3 to = _simplexVectorW[1]; - Vector3 nearest; - - Vector3 diff = -from; - Vector3 v = to - from; - float t = Vector3.Dot(v, diff); - - if (t > 0) - { - float dotVV = v.LengthSquared(); - if (t < dotVV) - { - t /= dotVV; - diff -= t * v; - _cachedBC.UsedVertices.UsedVertexA = true; - _cachedBC.UsedVertices.UsedVertexB = true; - } - else - { - t = 1; - diff -= v; - //reduce to 1 point - _cachedBC.UsedVertices.UsedVertexB = true; - } - } - else - { - t = 0; - //reduce to 1 point - _cachedBC.UsedVertices.UsedVertexA = true; - } - - _cachedBC.SetBarycentricCoordinates(1 - t, t, 0, 0); - nearest = from + t * v; - - _cachedPA = _simplexPointsP[0] + t * (_simplexPointsP[1] - _simplexPointsP[0]); - _cachedPB = _simplexPointsQ[0] + t * (_simplexPointsQ[1] - _simplexPointsQ[0]); - _cachedV = _cachedPA - _cachedPB; - - ReduceVertices(_cachedBC.UsedVertices); - - _cachedValidClosest = _cachedBC.IsValid; - break; - case 3: - //closest point origin from triangle - p = new Vector3(); - a = _simplexVectorW[0]; - b = _simplexVectorW[1]; - c = _simplexVectorW[2]; - - ClosestPtPointTriangle(p, a, b, c, ref _cachedBC); - _cachedPA = _simplexPointsP[0] * _cachedBC.BarycentricCoords[0] + - _simplexPointsP[1] * _cachedBC.BarycentricCoords[1] + - _simplexPointsP[2] * _cachedBC.BarycentricCoords[2] + - _simplexPointsP[3] * _cachedBC.BarycentricCoords[3]; - - _cachedPB = _simplexPointsQ[0] * _cachedBC.BarycentricCoords[0] + - _simplexPointsQ[1] * _cachedBC.BarycentricCoords[1] + - _simplexPointsQ[2] * _cachedBC.BarycentricCoords[2] + - _simplexPointsQ[3] * _cachedBC.BarycentricCoords[3]; - - _cachedV = _cachedPA - _cachedPB; - - ReduceVertices(_cachedBC.UsedVertices); - _cachedValidClosest = _cachedBC.IsValid; - break; - case 4: - p = new Vector3(); - a = _simplexVectorW[0]; - b = _simplexVectorW[1]; - c = _simplexVectorW[2]; - d = _simplexVectorW[3]; - - bool hasSeperation = ClosestPtPointTetrahedron(p, a, b, c, d, ref _cachedBC); - - if (hasSeperation) - { - _cachedPA = _simplexPointsP[0] * _cachedBC.BarycentricCoords[0] + - _simplexPointsP[1] * _cachedBC.BarycentricCoords[1] + - _simplexPointsP[2] * _cachedBC.BarycentricCoords[2] + - _simplexPointsP[3] * _cachedBC.BarycentricCoords[3]; - - _cachedPB = _simplexPointsQ[0] * _cachedBC.BarycentricCoords[0] + - _simplexPointsQ[1] * _cachedBC.BarycentricCoords[1] + - _simplexPointsQ[2] * _cachedBC.BarycentricCoords[2] + - _simplexPointsQ[3] * _cachedBC.BarycentricCoords[3]; - - _cachedV = _cachedPA - _cachedPB; - ReduceVertices(_cachedBC.UsedVertices); - } - else - { - if (_cachedBC.Degenerate) - { - _cachedValidClosest = false; - } - else - { - _cachedValidClosest = true; - //degenerate case == false, penetration = true + zero - _cachedV.X = _cachedV.Y = _cachedV.Z = 0f; - } - break; // !!!!!!!!!!!! proverit na vsakiy sluchai - } - - _cachedValidClosest = _cachedBC.IsValid; - - //closest point origin from tetrahedron - break; - default: - _cachedValidClosest = false; - break; - } - } - - return _cachedValidClosest; - } - - public bool ClosestPtPointTriangle(Vector3 p, Vector3 a, Vector3 b, Vector3 c, - ref SubSimplexClosestResult result) - { - result.UsedVertices.Reset(); - - float v, w; - - // Check if P in vertex region outside A - Vector3 ab = b - a; - Vector3 ac = c - a; - Vector3 ap = p - a; - float d1 = Vector3.Dot(ab, ap); - float d2 = Vector3.Dot(ac, ap); - if (d1 <= 0f && d2 <= 0f) - { - result.ClosestPointOnSimplex = a; - result.UsedVertices.UsedVertexA = true; - result.SetBarycentricCoordinates(1, 0, 0, 0); - return true; // a; // barycentric coordinates (1,0,0) - } - - // Check if P in vertex region outside B - Vector3 bp = p - b; - float d3 = Vector3.Dot(ab, bp); - float d4 = Vector3.Dot(ac, bp); - if (d3 >= 0f && d4 <= d3) - { - result.ClosestPointOnSimplex = b; - result.UsedVertices.UsedVertexB = true; - result.SetBarycentricCoordinates(0, 1, 0, 0); - - return true; // b; // barycentric coordinates (0,1,0) - } - // Check if P in edge region of AB, if so return projection of P onto AB - float vc = d1 * d4 - d3 * d2; - if (vc <= 0f && d1 >= 0f && d3 <= 0f) - { - v = d1 / (d1 - d3); - result.ClosestPointOnSimplex = a + v * ab; - result.UsedVertices.UsedVertexA = true; - result.UsedVertices.UsedVertexB = true; - result.SetBarycentricCoordinates(1 - v, v, 0, 0); - return true; - //return a + v * ab; // barycentric coordinates (1-v,v,0) - } - - // Check if P in vertex region outside C - Vector3 cp = p - c; - float d5 = Vector3.Dot(ab, cp); - float d6 = Vector3.Dot(ac, cp); - if (d6 >= 0f && d5 <= d6) - { - result.ClosestPointOnSimplex = c; - result.UsedVertices.UsedVertexC = true; - result.SetBarycentricCoordinates(0, 0, 1, 0); - return true;//c; // barycentric coordinates (0,0,1) - } - - // Check if P in edge region of AC, if so return projection of P onto AC - float vb = d5 * d2 - d1 * d6; - if (vb <= 0f && d2 >= 0f && d6 <= 0f) - { - w = d2 / (d2 - d6); - result.ClosestPointOnSimplex = a + w * ac; - result.UsedVertices.UsedVertexA = true; - result.UsedVertices.UsedVertexC = true; - result.SetBarycentricCoordinates(1 - w, 0, w, 0); - return true; - //return a + w * ac; // barycentric coordinates (1-w,0,w) - } - - // Check if P in edge region of BC, if so return projection of P onto BC - float va = d3 * d6 - d5 * d4; - if (va <= 0f && (d4 - d3) >= 0f && (d5 - d6) >= 0f) - { - w = (d4 - d3) / ((d4 - d3) + (d5 - d6)); - - result.ClosestPointOnSimplex = b + w * (c - b); - result.UsedVertices.UsedVertexB = true; - result.UsedVertices.UsedVertexC = true; - result.SetBarycentricCoordinates(0, 1 - w, w, 0); - return true; - // return b + w * (c - b); // barycentric coordinates (0,1-w,w) - } - - // P inside face region. Compute Q through its barycentric coordinates (u,v,w) - float denom = 1.0f / (va + vb + vc); - v = vb * denom; - w = vc * denom; - - result.ClosestPointOnSimplex = a + ab * v + ac * w; - result.UsedVertices.UsedVertexA = true; - result.UsedVertices.UsedVertexB = true; - result.UsedVertices.UsedVertexC = true; - result.SetBarycentricCoordinates(1 - v - w, v, w, 0); - - return true; - } - - /// Test if point p and d lie on opposite sides of plane through abc - public int PointOutsideOfPlane(Vector3 p, Vector3 a, Vector3 b, Vector3 c, Vector3 d) - { - Vector3 normal = Vector3.Cross(b - a, c - a); - - float signp = Vector3.Dot(p - a, normal); // [AP AB AC] - float signd = Vector3.Dot(d - a, normal); // [AD AB AC] - - if (CatchDegenerateTetrahedron) - if (signd * signd < (1e-4f * 1e-4f)) return -1; - - // Points on opposite sides if expression signs are opposite - return signp * signd < 0f ? 1 : 0; - } - - public bool ClosestPtPointTetrahedron(Vector3 p, Vector3 a, Vector3 b, Vector3 c, Vector3 d, - ref SubSimplexClosestResult finalResult) - { - SubSimplexClosestResult tempResult = new SubSimplexClosestResult(); - - // Start out assuming point inside all halfspaces, so closest to itself - finalResult.ClosestPointOnSimplex = p; - finalResult.UsedVertices.Reset(); - finalResult.UsedVertices.UsedVertexA = true; - finalResult.UsedVertices.UsedVertexB = true; - finalResult.UsedVertices.UsedVertexC = true; - finalResult.UsedVertices.UsedVertexD = true; - - int pointOutsideABC = PointOutsideOfPlane(p, a, b, c, d); - int pointOutsideACD = PointOutsideOfPlane(p, a, c, d, b); - int pointOutsideADB = PointOutsideOfPlane(p, a, d, b, c); - int pointOutsideBDC = PointOutsideOfPlane(p, b, d, c, a); - - if (pointOutsideABC < 0 || pointOutsideACD < 0 || pointOutsideADB < 0 || pointOutsideBDC < 0) - { - finalResult.Degenerate = true; - return false; - } - - if (pointOutsideABC == 0 && pointOutsideACD == 0 && pointOutsideADB == 0 && pointOutsideBDC == 0) - return false; - - float bestSqDist = float.MaxValue; - // If point outside face abc then compute closest point on abc - if (pointOutsideABC != 0) - { - ClosestPtPointTriangle(p, a, b, c, ref tempResult); - Vector3 q = tempResult.ClosestPointOnSimplex; - - float sqDist = ((Vector3)(q - p)).LengthSquared(); - // Update best closest point if (squared) distance is less than current best - if (sqDist < bestSqDist) - { - bestSqDist = sqDist; - finalResult.ClosestPointOnSimplex = q; - //convert result bitmask! - finalResult.UsedVertices.Reset(); - finalResult.UsedVertices.UsedVertexA = tempResult.UsedVertices.UsedVertexA; - finalResult.UsedVertices.UsedVertexB = tempResult.UsedVertices.UsedVertexB; - finalResult.UsedVertices.UsedVertexC = tempResult.UsedVertices.UsedVertexC; - finalResult.SetBarycentricCoordinates( - tempResult.BarycentricCoords[VertexA], - tempResult.BarycentricCoords[VertexB], - tempResult.BarycentricCoords[VertexC], - 0); - } - } - - // Repeat test for face acd - if (pointOutsideACD != 0) - { - ClosestPtPointTriangle(p, a, c, d, ref tempResult); - Vector3 q = tempResult.ClosestPointOnSimplex; - //convert result bitmask! - - float sqDist = ((Vector3)(q - p)).LengthSquared(); - if (sqDist < bestSqDist) - { - bestSqDist = sqDist; - finalResult.ClosestPointOnSimplex = q; - finalResult.UsedVertices.Reset(); - finalResult.UsedVertices.UsedVertexA = tempResult.UsedVertices.UsedVertexA; - finalResult.UsedVertices.UsedVertexC = tempResult.UsedVertices.UsedVertexB; - finalResult.UsedVertices.UsedVertexD = tempResult.UsedVertices.UsedVertexC; - finalResult.SetBarycentricCoordinates( - tempResult.BarycentricCoords[VertexA], - 0, - tempResult.BarycentricCoords[VertexB], - tempResult.BarycentricCoords[VertexC]); - } - } - // Repeat test for face adb - - if (pointOutsideADB != 0) - { - ClosestPtPointTriangle(p, a, d, b, ref tempResult); - Vector3 q = tempResult.ClosestPointOnSimplex; - //convert result bitmask! - - float sqDist = ((Vector3)(q - p)).LengthSquared(); - if (sqDist < bestSqDist) - { - bestSqDist = sqDist; - finalResult.ClosestPointOnSimplex = q; - finalResult.UsedVertices.Reset(); - finalResult.UsedVertices.UsedVertexA = tempResult.UsedVertices.UsedVertexA; - finalResult.UsedVertices.UsedVertexD = tempResult.UsedVertices.UsedVertexB; - finalResult.UsedVertices.UsedVertexB = tempResult.UsedVertices.UsedVertexC; - finalResult.SetBarycentricCoordinates( - tempResult.BarycentricCoords[VertexA], - tempResult.BarycentricCoords[VertexC], - 0, - tempResult.BarycentricCoords[VertexB]); - - } - } - // Repeat test for face bdc - - if (pointOutsideBDC != 0) - { - ClosestPtPointTriangle(p, b, d, c, ref tempResult); - Vector3 q = tempResult.ClosestPointOnSimplex; - //convert result bitmask! - float sqDist = ((Vector3)(q - p)).LengthSquared(); - if (sqDist < bestSqDist) - { - bestSqDist = sqDist; - finalResult.ClosestPointOnSimplex = q; - finalResult.UsedVertices.Reset(); - finalResult.UsedVertices.UsedVertexB = tempResult.UsedVertices.UsedVertexA; - finalResult.UsedVertices.UsedVertexD = tempResult.UsedVertices.UsedVertexB; - finalResult.UsedVertices.UsedVertexC = tempResult.UsedVertices.UsedVertexC; - - finalResult.SetBarycentricCoordinates( - 0, - tempResult.BarycentricCoords[VertexA], - tempResult.BarycentricCoords[VertexC], - tempResult.BarycentricCoords[VertexB]); - } - } - - //help! we ended up full ! - - if (finalResult.UsedVertices.UsedVertexA && - finalResult.UsedVertices.UsedVertexB && - finalResult.UsedVertices.UsedVertexC && - finalResult.UsedVertices.UsedVertexD) - { - return true; - } - - return true; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/ContactConstraint.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/ContactConstraint.cs deleted file mode 100644 index 4b6b0976f..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/ContactConstraint.cs +++ /dev/null @@ -1,488 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - public delegate float ContactSolverFunc (RigidBody bodyA, RigidBody bodyB, ManifoldPoint contactPoint, ContactSolverInfo info); - - public enum ContactSolverType - { - Default = 0, - TypeA, - TypeB, - User, - MaxContactSolverType, - } - - public class ConstraintPersistentData - { - // total applied impulse during most recent frame - private float _appliedImpulse; - private float _previousAppliedImpulse; - private float _accumulatedTangentImpulse0; - private float _accumulatedTangentImpulse1; - - private float _jacDiagABInv; - private float _jacDiagABInvTangentA; - private float _jacDiagABInvTangentB; - private int _persistentLifeTime; - private float _restitution; - private float _friction; - private float _penetration; - private Vector3 _frictionWorldTangentialA; - private Vector3 _frictionWorldTangentialB; - - private Vector3 _frictionAngularComponent0A; - private Vector3 _frictionAngularComponent0B; - private Vector3 _frictionAngularComponent1A; - private Vector3 _frictionAngularComponent1B; - - //some data doesn't need to be persistent over frames: todo: clean/reuse this - private Vector3 _angularComponentA; - private Vector3 _angularComponentB; - - private ContactSolverFunc _contactSolverFunc; - private ContactSolverFunc _frictionSolverFunc; - - public float AppliedImpulse { get { return _appliedImpulse; } set { _appliedImpulse = value; } } - public float PreviousAppliedImpulse { get { return _previousAppliedImpulse; } set { _previousAppliedImpulse = value; } } - public float AccumulatedTangentImpulseA { get { return _accumulatedTangentImpulse0; } set { _accumulatedTangentImpulse0 = value; } } - public float AccumulatedTangentImpulseB { get { return _accumulatedTangentImpulse1; } set { _accumulatedTangentImpulse1 = value; } } - - public float JacDiagABInv { get { return _jacDiagABInv; } set { _jacDiagABInv = value; } } - public float JacDiagABInvTangentA { get { return _jacDiagABInvTangentA; } set { _jacDiagABInvTangentA = value; } } - public float JacDiagABInvTangentB { get { return _jacDiagABInvTangentB; } set { _jacDiagABInvTangentB = value; } } - public int PersistentLifeTime { get { return _persistentLifeTime; } set { _persistentLifeTime = value; } } - public float Restitution { get { return _restitution; } set { _restitution = value; } } - public float Friction { get { return _friction; } set { _friction = value; } } - public float Penetration { get { return _penetration; } set { _penetration = value; } } - public Vector3 FrictionWorldTangentialA { get { return _frictionWorldTangentialA; } set { _frictionWorldTangentialA = value; } } - public Vector3 FrictionWorldTangentialB { get { return _frictionWorldTangentialB; } set { _frictionWorldTangentialB = value; } } - - public Vector3 FrictionAngularComponent0A { get { return _frictionAngularComponent0A; } set { _frictionAngularComponent0A = value; } } - public Vector3 FrictionAngularComponent0B { get { return _frictionAngularComponent0B; } set { _frictionAngularComponent0B = value; } } - public Vector3 FrictionAngularComponent1A { get { return _frictionAngularComponent1A; } set { _frictionAngularComponent1A = value; } } - public Vector3 FrictionAngularComponent1B { get { return _frictionAngularComponent1B; } set { _frictionAngularComponent1B = value; } } - - public Vector3 AngularComponentA { get { return _angularComponentA; } set { _angularComponentA = value; } } - public Vector3 AngularComponentB { get { return _angularComponentB; } set { _angularComponentB = value; } } - - public ContactSolverFunc ContactSolverFunc { get { return _contactSolverFunc; } set { _contactSolverFunc = value; } } - public ContactSolverFunc FrictionSolverFunc { get { return _frictionSolverFunc; } set { _frictionSolverFunc = value; } } - } - - public static class ContactConstraint - { - private const int UseInternalApplyImpulse = 1; - - /// - /// bilateral constraint between two dynamic objects - /// positive distance = separation, negative distance = penetration - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ResolveSingleBilateral(RigidBody bodyA, Vector3 posA, - RigidBody bodyB, Vector3 posB, - float distance, Vector3 normal, out float impulse, float timeStep) - { - float normalLenSqr = normal.LengthSquared(); - - if (Math.Abs(normalLenSqr) >= 1.1f) - throw new BulletException(); - - /*if (normalLenSqr > 1.1f) - { - impulse = 0f; - return; - }*/ - Vector3 rel_pos1 = posA - bodyA.CenterOfMassPosition; - Vector3 rel_pos2 = posB - bodyB.CenterOfMassPosition; - //this jacobian entry could be re-used for all iterations - - Vector3 vel1 = bodyA.GetVelocityInLocalPoint(rel_pos1); - Vector3 vel2 = bodyB.GetVelocityInLocalPoint(rel_pos2); - Vector3 vel = vel1 - vel2; - - - JacobianEntry jac = new JacobianEntry(Matrix.Transpose(bodyA.CenterOfMassTransform), - Matrix.Transpose(bodyB.CenterOfMassTransform), - rel_pos1, rel_pos2, normal, bodyA.InvInertiaDiagLocal, bodyA.InverseMass, - bodyB.InvInertiaDiagLocal, bodyB.InverseMass); - - float jacDiagAB = jac.Diagonal; - float jacDiagABInv = 1f / jacDiagAB; - - float rel_vel = jac.GetRelativeVelocity( - bodyA.LinearVelocity, - Vector3.TransformNormal(bodyA.AngularVelocity, Matrix.Transpose(bodyA.CenterOfMassTransform)), - bodyB.LinearVelocity, - Vector3.TransformNormal(bodyB.AngularVelocity, Matrix.Transpose(bodyB.CenterOfMassTransform))); - float a; - a = jacDiagABInv; - - - rel_vel = Vector3.Dot(normal, vel); - - float contactDamping = 0.2f; - - float velocityImpulse = -contactDamping * rel_vel * jacDiagABInv; - impulse = velocityImpulse; - } - - - /// - /// contact constraint resolution: - /// calculate and apply impulse to satisfy non-penetration and non-negative relative velocity constraint - /// positive distance = separation, negative distance = penetration - /// - /// - /// - /// - /// - /// - public static float ResolveSingleCollision(RigidBody bodyA, RigidBody bodyB, - ManifoldPoint contactPoint, ContactSolverInfo solverInfo) - { - Vector3 pos1 = contactPoint.PositionWorldOnA; - Vector3 pos2 = contactPoint.PositionWorldOnB; - - - // printf("distance=%f\n",distance); - - Vector3 normal = contactPoint.NormalWorldOnB; - - Vector3 rel_pos1 = pos1 - bodyA.CenterOfMassPosition; - Vector3 rel_pos2 = pos2 - bodyB.CenterOfMassPosition; - - Vector3 vel1 = bodyA.GetVelocityInLocalPoint(rel_pos1); - Vector3 vel2 = bodyB.GetVelocityInLocalPoint(rel_pos2); - Vector3 vel = vel1 - vel2; - float rel_vel; - rel_vel = Vector3.Dot(normal, vel); - - - float Kfps = 1f / solverInfo.TimeStep; - - //float damping = solverInfo.m_damping; - float Kerp = solverInfo.Erp; - - float Kcor = Kerp * Kfps; - - //printf("dist=%f\n",distance); - - ConstraintPersistentData cpd = contactPoint.UserPersistentData as ConstraintPersistentData; - if (cpd == null) - throw new BulletException(); - - float distance = cpd.Penetration;//contactPoint.getDistance(); - - - //distance = 0.f; - float positionalError = Kcor * -distance; - //jacDiagABInv; - float velocityError = cpd.Restitution - rel_vel;// * damping; - - - float penetrationImpulse = positionalError * cpd.JacDiagABInv; - float velocityImpulse = velocityError * cpd.JacDiagABInv; - float normalImpulse = penetrationImpulse + velocityImpulse; - - // See Erin Catto's GDC 2006 paper: Clamp the accumulated impulse - float oldNormalImpulse = cpd.AppliedImpulse; - float sum = oldNormalImpulse + normalImpulse; - cpd.AppliedImpulse = 0f > sum ? 0f : sum; - - normalImpulse = cpd.AppliedImpulse - oldNormalImpulse; - - if (bodyA.InverseMass != 0) - { - bodyA.InternalApplyImpulse(contactPoint.NormalWorldOnB * bodyA.InverseMass, cpd.AngularComponentA, normalImpulse); - } - if (bodyB.InverseMass != 0) - { - bodyB.InternalApplyImpulse(contactPoint.NormalWorldOnB * bodyB.InverseMass, cpd.AngularComponentB, -normalImpulse); - } - - /*body1.applyImpulse(normal * (normalImpulse), rel_pos1); - body2.applyImpulse(-normal * (normalImpulse), rel_pos2);*/ - - return normalImpulse; - } - - public static float ResolveSingleFriction(RigidBody bodyA, RigidBody bodyB, - ManifoldPoint contactPoint, ContactSolverInfo solverInfo) - { - - Vector3 pos1 = contactPoint.PositionWorldOnA; - Vector3 pos2 = contactPoint.PositionWorldOnB; - - Vector3 rel_pos1 = pos1 - bodyA.CenterOfMassPosition; - Vector3 rel_pos2 = pos2 - bodyB.CenterOfMassPosition; - - ConstraintPersistentData cpd = contactPoint.UserPersistentData as ConstraintPersistentData; - if (cpd == null) - throw new BulletException(); - - float combinedFriction = cpd.Friction; - - float limit = cpd.AppliedImpulse * combinedFriction; - - //friction - if (cpd.AppliedImpulse > 0) - { - //apply friction in the 2 tangential directions - - // 1st tangent - Vector3 vel1 = bodyA.GetVelocityInLocalPoint(rel_pos1); - Vector3 vel2 = bodyB.GetVelocityInLocalPoint(rel_pos2); - Vector3 vel = vel1 - vel2; - - float j1, j2; - - { - - float vrel = Vector3.Dot(cpd.FrictionWorldTangentialA, vel); - - // calculate j that moves us to zero relative velocity - j1 = -vrel * cpd.JacDiagABInvTangentA; - float oldTangentImpulse = cpd.AccumulatedTangentImpulseA; - cpd.AccumulatedTangentImpulseA = oldTangentImpulse + j1; - float atia = cpd.AccumulatedTangentImpulseA; - MathHelper.SetMin(ref atia, limit); - MathHelper.SetMax(ref atia, -limit); - cpd.AccumulatedTangentImpulseA = atia; - j1 = cpd.AccumulatedTangentImpulseA - oldTangentImpulse; - - } - { - // 2nd tangent - - float vrel = Vector3.Dot(cpd.FrictionWorldTangentialB, vel); - - // calculate j that moves us to zero relative velocity - j2 = -vrel * cpd.JacDiagABInvTangentB; - float oldTangentImpulse = cpd.AccumulatedTangentImpulseB; - cpd.AccumulatedTangentImpulseB = oldTangentImpulse + j2; - float atib = cpd.AccumulatedTangentImpulseB; - MathHelper.SetMin(ref atib, limit); - MathHelper.SetMax(ref atib, -limit); - cpd.AccumulatedTangentImpulseB = atib; - j2 = cpd.AccumulatedTangentImpulseB - oldTangentImpulse; - } - - if (bodyA.InverseMass != 0) - { - bodyA.InternalApplyImpulse(cpd.FrictionWorldTangentialA * bodyA.InverseMass, cpd.FrictionAngularComponent0A, j1); - bodyA.InternalApplyImpulse(cpd.FrictionWorldTangentialB * bodyA.InverseMass, cpd.FrictionAngularComponent1A, j2); - } - if (bodyB.InverseMass != 0) - { - bodyB.InternalApplyImpulse(cpd.FrictionWorldTangentialA * bodyB.InverseMass, cpd.FrictionAngularComponent0B, -j1); - bodyB.InternalApplyImpulse(cpd.FrictionWorldTangentialB * bodyB.InverseMass, cpd.FrictionAngularComponent1B, -j2); - } - - } - return cpd.AppliedImpulse; - } - - public static float ResolveSingleFrictionOriginal( - RigidBody bodyA, - RigidBody bodyB, - ManifoldPoint contactPoint, - ContactSolverInfo solverInfo) - { - Vector3 posA = contactPoint.PositionWorldOnA; - Vector3 posB = contactPoint.PositionWorldOnB; - - Vector3 relPosA = posA - bodyA.CenterOfMassPosition; - Vector3 relPosB = posB - bodyB.CenterOfMassPosition; - - ConstraintPersistentData cpd = contactPoint.UserPersistentData as ConstraintPersistentData; - if (cpd == null) - throw new BulletException(); - - float combinedFriction = cpd.Friction; - - float limit = cpd.AppliedImpulse * combinedFriction; - //if (contactPoint.m_appliedImpulse>0.f) - //friction - { - //apply friction in the 2 tangential directions - - { - // 1st tangent - Vector3 velA = bodyA.GetVelocityInLocalPoint(relPosA); - Vector3 velB = bodyB.GetVelocityInLocalPoint(relPosB); - Vector3 vel = velA - velB; - - float vrel = Vector3.Dot(cpd.FrictionWorldTangentialA, vel); - - // calculate j that moves us to zero relative velocity - float j = -vrel * cpd.JacDiagABInvTangentA; - float total = cpd.AccumulatedTangentImpulseA + j; - if (limit < total) - total = limit; - if (total < -limit) - total = -limit; - j = total - cpd.AccumulatedTangentImpulseA; - cpd.AccumulatedTangentImpulseA = total; - bodyA.ApplyImpulse(j * cpd.FrictionWorldTangentialA, relPosA); - bodyB.ApplyImpulse(j * -cpd.FrictionWorldTangentialA, relPosB); - } - - - { - // 2nd tangent - Vector3 velA = bodyA.GetVelocityInLocalPoint(relPosA); - Vector3 velB = bodyB.GetVelocityInLocalPoint(relPosB); - Vector3 vel = velA - velB; - - float vrel = Vector3.Dot(cpd.FrictionWorldTangentialB, vel); - - // calculate j that moves us to zero relative velocity - float j = -vrel * cpd.JacDiagABInvTangentB; - float total = cpd.AccumulatedTangentImpulseB + j; - if (limit < total) - total = limit; - if (total < -limit) - total = -limit; - j = total - cpd.AccumulatedTangentImpulseB; - cpd.AccumulatedTangentImpulseB = total; - bodyA.ApplyImpulse(j * cpd.FrictionWorldTangentialB, relPosA); - bodyB.ApplyImpulse(j * -cpd.FrictionWorldTangentialB, relPosB); - } - } - - return cpd.AppliedImpulse; - } - - //velocity + friction - //response between two dynamic objects with friction - public static float ResolveSingleCollisionCombined( - RigidBody bodyA, - RigidBody bodyB, - ManifoldPoint contactPoint, - ContactSolverInfo solverInfo) - { - - Vector3 posA = contactPoint.PositionWorldOnA; - Vector3 posB = contactPoint.PositionWorldOnB; - Vector3 normal = contactPoint.NormalWorldOnB; - - Vector3 relPosA = posA - bodyA.CenterOfMassPosition; - Vector3 relPosB = posB - bodyB.CenterOfMassPosition; - - Vector3 velA = bodyA.GetVelocityInLocalPoint(relPosA); - Vector3 velB = bodyB.GetVelocityInLocalPoint(relPosB); - Vector3 vel = velA - velB; - float relVel; - relVel = Vector3.Dot(normal, vel); - - float Kfps = 1f / solverInfo.TimeStep; - - //float damping = solverInfo.m_damping; - float Kerp = solverInfo.Erp; - float Kcor = Kerp * Kfps; - - ConstraintPersistentData cpd = contactPoint.UserPersistentData as ConstraintPersistentData; - if (cpd == null) - throw new BulletException(); - - float distance = cpd.Penetration; - float positionalError = Kcor * -distance; - float velocityError = cpd.Restitution - relVel;// * damping; - - float penetrationImpulse = positionalError * cpd.JacDiagABInv; - - float velocityImpulse = velocityError * cpd.JacDiagABInv; - - float normalImpulse = penetrationImpulse + velocityImpulse; - - // See Erin Catto's GDC 2006 paper: Clamp the accumulated impulse - float oldNormalImpulse = cpd.AppliedImpulse; - float sum = oldNormalImpulse + normalImpulse; - cpd.AppliedImpulse = 0 > sum ? 0 : sum; - - normalImpulse = cpd.AppliedImpulse - oldNormalImpulse; - - if (bodyA.InverseMass != 0) - { - bodyA.InternalApplyImpulse(contactPoint.NormalWorldOnB * bodyA.InverseMass, cpd.AngularComponentA, normalImpulse); - } - if (bodyB.InverseMass != 0) - { - bodyB.InternalApplyImpulse(contactPoint.NormalWorldOnB * bodyB.InverseMass, cpd.AngularComponentB, -normalImpulse); - } - - { - //friction - Vector3 vel12 = bodyA.GetVelocityInLocalPoint(relPosA); - Vector3 vel22 = bodyB.GetVelocityInLocalPoint(relPosB); - Vector3 vel3 = vel12 - vel22; - - relVel = Vector3.Dot(normal, vel3); - - - Vector3 latVel = vel3 - normal * relVel; - float lat_rel_vel = latVel.Length(); - - float combinedFriction = cpd.Friction; - - if (cpd.AppliedImpulse > 0) - if (lat_rel_vel > float.Epsilon) - { - latVel /= lat_rel_vel; - Vector3 temp1 = Vector3.TransformNormal(Vector3.Cross(relPosA, latVel), bodyA.InvInertiaTensorWorld); - Vector3 temp2 = Vector3.TransformNormal(Vector3.Cross(relPosB, latVel), bodyB.InvInertiaTensorWorld); - float friction_impulse = lat_rel_vel / - (bodyA.InverseMass + bodyB.InverseMass + Vector3.Dot(latVel, Vector3.Cross(temp1, relPosA) + Vector3.Cross(temp2, relPosB))); - float normal_impulse = cpd.AppliedImpulse * combinedFriction; - - MathHelper.SetMin(ref friction_impulse, normal_impulse); - MathHelper.SetMin(ref friction_impulse, -normal_impulse); - bodyA.ApplyImpulse(latVel * -friction_impulse, relPosA); - bodyB.ApplyImpulse(latVel * friction_impulse, relPosB); - } - } - return normalImpulse; - } - - public static float ResolveSingleFrictionEmpty( - RigidBody bodyA, - RigidBody bodyB, - ManifoldPoint contactPoint, - ContactSolverInfo solverInfo) - { - return 0; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/ContactSolverInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/ContactSolverInfo.cs deleted file mode 100644 index c1763df4b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/ContactSolverInfo.cs +++ /dev/null @@ -1,62 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX.Dynamics -{ - public class ContactSolverInfo - { - private float _tau; - private float _damping; - private float _friction; - private float _timeStep; - private float _restitution; - private int _numIterations; - private float _maxErrorReduction; - private float _sor; - private float _erp; - - public ContactSolverInfo() - { - _tau = 0.6f; - _damping = 1.0f; - _friction = 0.3f; - _restitution = 0f; - _maxErrorReduction = 20f; - _numIterations = 10; - _erp = 0.4f; - _sor = 1.3f; - } - - public float Tau { get { return _tau; } set { _tau = value; } } - public float Damping { get { return _damping; } set { _damping = value; } } - public float Friction { get { return _friction; } set { _friction = value; } } - public float TimeStep { get { return _timeStep; } set { _timeStep = value; } } - public float Restitution { get { return _restitution; } set { _restitution = value; } } - public int IterationsCount { get { return _numIterations; } set { _numIterations = value; } } - public float MaxErrorReduction { get { return _maxErrorReduction; } set { _maxErrorReduction = value; } } - public float Sor { get { return _sor; } set { _sor = value; } } - public float Erp { get { return _erp; } set { _erp = value; } } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/Generic6DofConstraint.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/Generic6DofConstraint.cs deleted file mode 100644 index 899841815..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/Generic6DofConstraint.cs +++ /dev/null @@ -1,440 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - /// - /// Generic6DofConstraint between two rigidbodies each with a pivotpoint that descibes the axis location in local space - /// Generic6DofConstraint can leave any of the 6 degree of freedom 'free' or 'locked' - /// Work in progress (is still a Hinge actually) - /// - public class Generic6DofConstraint : TypedConstraint - { - private static readonly float[] _sign = { 1.0f, -1.0f, 1.0f }; - private static readonly int[] _axisA = { 1, 0, 0 }; - private static readonly int[] _axisB = { 2, 2, 1 }; - - private JacobianEntry[] _jacLinear = new JacobianEntry[3]; // 3 orthogonal linear constraints - private JacobianEntry[] _jacAng = new JacobianEntry[3]; // 3 orthogonal angular constraints - - private Matrix _frameInA; // the constraint space w.r.t body A - private Matrix _frameInB; // the constraint space w.r.t body B - - private float[] _lowerLimit = new float[6]; // the constraint lower limits - private float[] _upperLimit = new float[6]; // the constraint upper limits - - private float[] _accumulatedImpulse = new float[6]; - - public Generic6DofConstraint(RigidBody rbA, RigidBody rbB, Matrix frameInA, Matrix frameInB) - : base(rbA, rbB) - { - _frameInA = frameInA; - _frameInB = frameInB; - //free means upper < lower, - //locked means upper == lower - //limited means upper > lower - //so start all locked - for (int i = 0; i < 6; ++i) - { - _lowerLimit[i] = 0.0f; - _upperLimit[i] = 0.0f; - _accumulatedImpulse[i] = 0.0f; - } - } - - public Generic6DofConstraint() { } - - public void UpdateRHS(float timeStep) { } - - public float ComputeAngle(int axis) - { - float angle = 0; - - switch (axis) - { - case 0: - { - Vector3 v1 = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInA, 1), RigidBodyA.CenterOfMassTransform); - Vector3 v2 = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInB, 1), RigidBodyB.CenterOfMassTransform); - Vector3 w2 = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInB, 2), RigidBodyB.CenterOfMassTransform); - - float s = Vector3.Dot(v1, w2); - float c = Vector3.Dot(v1, v2); - - angle = (float)Math.Atan2(s, c); - break; - } - case 1: - { - Vector3 w1 = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInA, 2), RigidBodyA.CenterOfMassTransform); - Vector3 w2 = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInB, 2), RigidBodyB.CenterOfMassTransform); - Vector3 u2 = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInB, 0), RigidBodyB.CenterOfMassTransform); - - float s = Vector3.Dot(w1, u2); - float c = Vector3.Dot(w1, w2); - - angle = (float)Math.Atan2(s, c); - break; - } - case 2: - { - Vector3 u1 = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInA, 0), RigidBodyA.CenterOfMassTransform); - Vector3 u2 = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInB, 0), RigidBodyB.CenterOfMassTransform); - Vector3 v2 = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInB, 1), RigidBodyB.CenterOfMassTransform); - - float s = Vector3.Dot(u1, v2); - float c = Vector3.Dot(u1, u2); - - angle = (float)Math.Atan2(s, c); - break; - } - default: BulletDebug.Assert(false); break; - } - - return angle; - } - - public void SetLinearLowerLimit(Vector3 linearLower) - { - _lowerLimit[0] = linearLower.X; - _lowerLimit[1] = linearLower.Y; - _lowerLimit[2] = linearLower.Z; - } - - public void SetLinearUpperLimit(Vector3 linearUpper) - { - _upperLimit[0] = linearUpper.X; - _upperLimit[1] = linearUpper.Y; - _upperLimit[2] = linearUpper.Z; - } - - public void SetAngularLowerLimit(Vector3 angularLower) - { - _lowerLimit[3] = angularLower.X; - _lowerLimit[4] = angularLower.Y; - _lowerLimit[5] = angularLower.Z; - } - - public void SetAngularUpperLimit(Vector3 angularUpper) - { - _upperLimit[3] = angularUpper.X; - _upperLimit[4] = angularUpper.Y; - _upperLimit[5] = angularUpper.Z; - } - - //first 3 are linear, next 3 are angular - public void SetLimit(int axis, float lo, float hi) - { - _lowerLimit[axis] = lo; - _upperLimit[axis] = hi; - } - - //free means upper < lower, - //locked means upper == lower - //limited means upper > lower - //limitIndex: first 3 are linear, next 3 are angular - public bool IsLimited(int limitIndex) - { - return (_upperLimit[limitIndex] >= _lowerLimit[limitIndex]); - } - - public override void BuildJacobian() - { - Vector3 localNormalInA = new Vector3(0, 0, 0); - - Vector3 pivotInA = _frameInA.Translation; - Vector3 pivotInB = _frameInB.Translation; - - Vector3 pivotAInW = MathHelper.Transform(_frameInA.Translation, RigidBodyA.CenterOfMassTransform); - Vector3 pivotBInW = MathHelper.Transform(_frameInB.Translation, RigidBodyB.CenterOfMassTransform); - - Vector3 rel_pos1 = pivotAInW - RigidBodyA.CenterOfMassPosition; - Vector3 rel_pos2 = pivotBInW - RigidBodyB.CenterOfMassPosition; - - //linear part - for (int i = 0; i < 3; i++) - { - if (IsLimited(i)) - { - if (i == 0) - localNormalInA = new Vector3(1, 0, 0); - else if (i == 1) - localNormalInA = new Vector3(0, 1, 0); - else - localNormalInA = new Vector3(0, 0, 1); - - Vector3 normalWorld = MathHelper.TransformNormal(localNormalInA, RigidBodyA.CenterOfMassTransform); - - // Create linear atom - _jacLinear[i] = new JacobianEntry( - MatrixOperations.Transpose(RigidBodyA.CenterOfMassTransform), - MatrixOperations.Transpose(RigidBodyB.CenterOfMassTransform), - MathHelper.Transform(pivotInA, RigidBodyA.CenterOfMassTransform) - RigidBodyA.CenterOfMassPosition, - MathHelper.Transform(pivotInB, RigidBodyB.CenterOfMassTransform) - RigidBodyB.CenterOfMassPosition, - normalWorld, - RigidBodyA.InvInertiaDiagLocal, - RigidBodyA.InverseMass, - RigidBodyB.InvInertiaDiagLocal, - RigidBodyB.InverseMass); - - //optionally disable warmstarting - _accumulatedImpulse[i] = 0f; - - // Apply accumulated impulse - Vector3 impulse_vector = _accumulatedImpulse[i] * normalWorld; - - RigidBodyA.ApplyImpulse(impulse_vector, rel_pos1); - RigidBodyB.ApplyImpulse(-impulse_vector, rel_pos2); - } - } - - // angular part - for (int i = 0; i < 3; i++) - { - if (IsLimited(i + 3)) - { - Vector3 axisA = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInA, _axisA[i] + 1), RigidBodyA.CenterOfMassTransform); - Vector3 axisB = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInB, _axisB[i] + 1), RigidBodyB.CenterOfMassTransform); - - Vector3 axis = _sign[i] * Vector3.Cross(axisA, axisB); - - // Create angular atom - _jacAng[i] = new JacobianEntry(axis, - MatrixOperations.Transpose(RigidBodyA.CenterOfMassTransform), - MatrixOperations.Transpose(RigidBodyB.CenterOfMassTransform), - RigidBodyA.InvInertiaDiagLocal, - RigidBodyB.InvInertiaDiagLocal); - - _accumulatedImpulse[i + 3] = 0f; - - // Apply accumulated impulse - Vector3 impulse_vector = _accumulatedImpulse[i + 3] * axis; - - RigidBodyA.ApplyTorqueImpulse(impulse_vector); - RigidBodyB.ApplyTorqueImpulse(-impulse_vector); - } - } - } - - public override void SolveConstraint(float timeStep) - { - float tau = 0.1f; - float damping = 1.0f; - - Vector3 pivotAInW = MathHelper.Transform(_frameInA.Translation, RigidBodyA.CenterOfMassTransform); - Vector3 pivotBInW = MathHelper.Transform(_frameInB.Translation, RigidBodyB.CenterOfMassTransform); - - Vector3 rel_pos1 = pivotAInW - RigidBodyA.CenterOfMassPosition; - Vector3 rel_pos2 = pivotBInW - RigidBodyB.CenterOfMassPosition; - - Vector3 localNormalInA = new Vector3(); - - // linear - for (int i = 0; i < 3; i++) - { - if (IsLimited(i)) - { - Vector3 angvelA = MathHelper.TransformNormal(RigidBodyA.AngularVelocity, MatrixOperations.Transpose(RigidBodyA.CenterOfMassTransform)); - Vector3 angvelB = MathHelper.TransformNormal(RigidBodyB.AngularVelocity, MatrixOperations.Transpose(RigidBodyB.CenterOfMassTransform)); - - if (i == 0) - localNormalInA = new Vector3(1, 0, 0); - else if (i == 1) - localNormalInA = new Vector3(0, 1, 0); - else - localNormalInA = new Vector3(0, 0, 1); - - Vector3 normalWorld = MathHelper.TransformNormal(localNormalInA, RigidBodyA.CenterOfMassTransform); - - float jacDiagABInv = 1f / _jacLinear[i].Diagonal; - - //velocity error (first order error) - float rel_vel = _jacLinear[i].GetRelativeVelocity(RigidBodyA.LinearVelocity, angvelA, - RigidBodyB.LinearVelocity, angvelB); - - //positional error (zeroth order error) - float depth = -Vector3.Dot(pivotAInW - pivotBInW, normalWorld); - float lo = -1e30f; - float hi = 1e30f; - - //handle the limits - if (_lowerLimit[i] < _upperLimit[i]) - { - if (depth > _upperLimit[i]) - { - depth -= _upperLimit[i]; - lo = 0f; - } - else - { - if (depth < _lowerLimit[i]) - { - depth -= _lowerLimit[i]; - hi = 0f; - } - else - { - continue; - } - } - } - - float normalImpulse = (tau * depth / timeStep - damping * rel_vel) * jacDiagABInv; - float oldNormalImpulse = _accumulatedImpulse[i]; - float sum = oldNormalImpulse + normalImpulse; - _accumulatedImpulse[i] = sum > hi ? 0f : sum < lo ? 0f : sum; - normalImpulse = _accumulatedImpulse[i] - oldNormalImpulse; - - Vector3 impulse_vector = normalWorld * normalImpulse; - RigidBodyA.ApplyImpulse(impulse_vector, rel_pos1); - RigidBodyB.ApplyImpulse(-impulse_vector, rel_pos2); - } - } - - Vector3 axis; - float angle; - Matrix frameAWorld = RigidBodyA.CenterOfMassTransform * _frameInA; - Matrix frameBWorld = RigidBodyB.CenterOfMassTransform * _frameInB; - - TransformUtil.CalculateDiffAxisAngle(frameAWorld, frameBWorld, out axis, out angle); - Quaternion diff = new Quaternion(axis, angle); - Matrix diffMat = Matrix.CreateFromQuaternion(diff); - Vector3 xyz; - // this is not perfect, we can first check which axis are limited, and choose a more appropriate order - MatrixToEulerXYZ(diffMat, out xyz); - - // angular - for (int i = 0; i < 3; i++) - { - if (IsLimited(i + 3)) - { - Vector3 angvelA = MathHelper.TransformNormal(RigidBodyA.AngularVelocity, MatrixOperations.Transpose(RigidBodyA.CenterOfMassTransform)); - Vector3 angvelB = MathHelper.TransformNormal(RigidBodyB.AngularVelocity, MatrixOperations.Transpose(RigidBodyB.CenterOfMassTransform)); - - float jacDiagABInv = 1f / _jacAng[i].Diagonal; - - //velocity error (first order error) - float rel_vel = _jacAng[i].GetRelativeVelocity(RigidBodyA.LinearVelocity, angvelA, - RigidBodyB.LinearVelocity, angvelB); - - //positional error (zeroth order error) - Vector3 axisA = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInA, _axisA[i] + 1), RigidBodyA.CenterOfMassTransform); - Vector3 axisB = MathHelper.TransformNormal(MathHelper.GetColumn(_frameInB, _axisB[i] + 1), RigidBodyB.CenterOfMassTransform); - - float rel_pos = _sign[i] * Vector3.Dot(axisA, axisB); - - float lo = -1e30f; - float hi = 1e30f; - - //handle the twist limit - if (_lowerLimit[i + 3] < _upperLimit[i + 3]) - { - //clamp the values - float loLimit = _upperLimit[i + 3] > -3.1415 ? _lowerLimit[i + 3] : -1e30f; - float hiLimit = _upperLimit[i + 3] < 3.1415 ? _upperLimit[i + 3] : 1e30f; - - float projAngle; - - if (i == 0) - projAngle = -2f * xyz.Z; - else if (i == 1) - projAngle = -2f * xyz.Y; - else - projAngle = -2f * xyz.Z; - - if (projAngle < loLimit) - { - hi = 0f; - rel_pos = loLimit - projAngle; - } - else - { - if (projAngle > hiLimit) - { - lo = 0f; - rel_pos = (hiLimit - projAngle); - } - else - { - continue; - } - } - } - - //impulse - - float normalImpulse = -(tau * rel_pos / timeStep + damping * rel_vel) * jacDiagABInv; - float oldNormalImpulse = _accumulatedImpulse[i + 3]; - float sum = oldNormalImpulse + normalImpulse; - _accumulatedImpulse[i + 3] = sum > hi ? 0f : sum < lo ? 0f : sum; - normalImpulse = _accumulatedImpulse[i + 3] - oldNormalImpulse; - - Vector3 axis2 = _sign[i] * Vector3.Cross(axisA, axisB); - Vector3 impulse_vector = axis2 * normalImpulse; - - RigidBodyA.ApplyTorqueImpulse(impulse_vector); - RigidBodyB.ApplyTorqueImpulse(-impulse_vector); - } - } - } - - //MatrixToEulerXYZ from http://www.geometrictools.com/LibFoundation/Mathematics/Wm4Matrix3.inl.html - private bool MatrixToEulerXYZ(Matrix mat, out Vector3 xyz) - { - // rot = cy*cz -cy*sz sy - // cz*sx*sy+cx*sz cx*cz-sx*sy*sz -cy*sx - // -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy - xyz = new Vector3(); - - if (MathHelper.GetElement(mat, 2) < 1.0f) - { - if (MathHelper.GetElement(mat, 2) > -1.0f) - { - xyz.X = (float)Math.Atan2(-MathHelper.GetElement(mat, 5), MathHelper.GetElement(mat, 8)); - xyz.Y = (float)Math.Asin(MathHelper.GetElement(mat, 2)); - xyz.Z = (float)Math.Atan2(-MathHelper.GetElement(mat, 1), MathHelper.GetElement(mat, 0)); - return true; - } - else - { - // WARNING. Not unique. XA - ZA = -atan2(r10,r11) - xyz.X = -(float)Math.Atan2(MathHelper.GetElement(mat, 3), MathHelper.GetElement(mat, 4)); - xyz.Y = -(float)Math.PI / 2; - xyz.Z = 0.0f; - return false; - } - } - else - { - // WARNING. Not unique. XAngle + ZAngle = atan2(r10,r11) - xyz.X = (float)Math.Atan2(MathHelper.GetElement(mat, 3), MathHelper.GetElement(mat, 4)); - xyz.Y = (float)Math.PI / 2; - xyz.Z = 0.0f; - return false; - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/HingeConstraint.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/HingeConstraint.cs deleted file mode 100644 index e3ddf0180..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/HingeConstraint.cs +++ /dev/null @@ -1,246 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - /// - /// hinge constraint between two rigidbodies each with a pivotpoint that descibes the axis location in local space - /// axis defines the orientation of the hinge axis - /// - public class HingeConstraint : TypedConstraint - { - private JacobianEntry[] _jac = new JacobianEntry[3]; //3 orthogonal linear constraints - private JacobianEntry[] _jacAng = new JacobianEntry[3]; //2 orthogonal angular constraints + 1 for limit/motor - - private Vector3 _pivotInA; - private Vector3 _pivotInB; - private Vector3 _axisInA; - private Vector3 _axisInB; - - private bool _angularOnly; - - private float _motorTargetVelocity; - private float _maxMotorImpulse; - private bool _enableAngularMotor; - - public HingeConstraint(RigidBody rbA, RigidBody rbB, Vector3 pivotInA, Vector3 pivotInB, Vector3 axisInA, Vector3 axisInB) - : base(rbA, rbB) - { - _pivotInA = pivotInA; - _pivotInB = pivotInB; - _axisInA = axisInA; - _axisInB = -axisInB; - _angularOnly = false; - } - - public HingeConstraint(RigidBody rbA, Vector3 pivotInA, Vector3 axisInA) - : base(rbA) - { - _pivotInA = pivotInA; - _pivotInB = MathHelper.MatrixToVector(rbA.CenterOfMassTransform, pivotInA); - _axisInA = axisInA; - //fixed axis in worldspace - _axisInB = MathHelper.TransformNormal(-axisInA, rbA.CenterOfMassTransform); - _angularOnly = false; - } - - public HingeConstraint() { } - - public bool AngularOnly { set { _angularOnly = value; } } - - public override void BuildJacobian() - { - AppliedImpulse = 0f; - - Vector3 normal = new Vector3(); - - if (!_angularOnly) - { - for (int i = 0; i < 3; i++) - { - MathHelper.SetElement(ref normal, i, 1); - _jac[i] = new JacobianEntry( - MatrixOperations.Transpose(RigidBodyA.CenterOfMassTransform), - MatrixOperations.Transpose(RigidBodyB.CenterOfMassTransform), - MathHelper.Transform(_pivotInA, RigidBodyA.CenterOfMassTransform) - RigidBodyA.CenterOfMassPosition, - MathHelper.Transform(_pivotInB, RigidBodyB.CenterOfMassTransform) - RigidBodyB.CenterOfMassPosition, - normal, - RigidBodyA.InvInertiaDiagLocal, - RigidBodyA.InverseMass, - RigidBodyB.InvInertiaDiagLocal, - RigidBodyB.InverseMass); - MathHelper.SetElement(ref normal, i, 0); - } - } - - //calculate two perpendicular jointAxis, orthogonal to hingeAxis - //these two jointAxis require equal angular velocities for both bodies - //this is unused for now, it's a todo - Vector3 jointAxisALocal = new Vector3(); - Vector3 jointAxisBLocal = new Vector3(); - MathHelper.PlaneSpace1(_axisInA, ref jointAxisALocal, ref jointAxisBLocal); - - Vector3 jointAxisA = MathHelper.TransformNormal(jointAxisALocal, RigidBodyA.CenterOfMassTransform); - Vector3 jointAxisB = MathHelper.TransformNormal(jointAxisBLocal, RigidBodyA.CenterOfMassTransform); - Vector3 hingeAxisWorld = MathHelper.TransformNormal(_axisInA, RigidBodyA.CenterOfMassTransform); - - _jacAng[0] = new JacobianEntry(jointAxisA, - MatrixOperations.Transpose(RigidBodyA.CenterOfMassTransform), - MatrixOperations.Transpose(RigidBodyB.CenterOfMassTransform), - RigidBodyA.InvInertiaDiagLocal, - RigidBodyB.InvInertiaDiagLocal); - - _jacAng[1] = new JacobianEntry(jointAxisB, - MatrixOperations.Transpose(RigidBodyA.CenterOfMassTransform), - MatrixOperations.Transpose(RigidBodyB.CenterOfMassTransform), - RigidBodyA.InvInertiaDiagLocal, - RigidBodyB.InvInertiaDiagLocal); - - _jacAng[2] = new JacobianEntry(hingeAxisWorld, - MatrixOperations.Transpose(RigidBodyA.CenterOfMassTransform), - MatrixOperations.Transpose(RigidBodyB.CenterOfMassTransform), - RigidBodyA.InvInertiaDiagLocal, - RigidBodyB.InvInertiaDiagLocal); - } - - public override void SolveConstraint(float timeStep) - { - Vector3 pivotAInW = MathHelper.Transform(_pivotInA, RigidBodyA.CenterOfMassTransform); - Vector3 pivotBInW = MathHelper.Transform(_pivotInB, RigidBodyB.CenterOfMassTransform); - - Vector3 normal = new Vector3(0, 0, 0); - float tau = 0.3f; - float damping = 1f; - - //linear part - if (!_angularOnly) - { - for (int i = 0; i < 3; i++) - { - if (i == 0) - normal = new Vector3(1, 0, 0); - else if (i == 1) - normal = new Vector3(0, 1, 0); - else - normal = new Vector3(0, 0, 1); - - float jacDiagABInv = 1f / _jac[i].Diagonal; - - Vector3 rel_pos1 = pivotAInW - RigidBodyA.CenterOfMassPosition; - Vector3 rel_pos2 = pivotBInW - RigidBodyB.CenterOfMassPosition; - - Vector3 vel1 = RigidBodyA.GetVelocityInLocalPoint(rel_pos1); - Vector3 vel2 = RigidBodyB.GetVelocityInLocalPoint(rel_pos2); - Vector3 vel = vel1 - vel2; - float rel_vel; - rel_vel = Vector3.Dot(normal, vel); - //positional error (zeroth order error) - float depth = -Vector3.Dot(pivotAInW - pivotBInW, normal); //this is the error projected on the normal - float impulse = depth * tau / timeStep * jacDiagABInv - damping * rel_vel * jacDiagABInv * damping; - AppliedImpulse += impulse; - Vector3 impulse_vector = normal * impulse; - RigidBodyA.ApplyImpulse(impulse_vector, pivotAInW - RigidBodyA.CenterOfMassPosition); - RigidBodyB.ApplyImpulse(-impulse_vector, pivotBInW - RigidBodyB.CenterOfMassPosition); - } - } - //solve angular part - // get axes in world space - Vector3 axisA = MathHelper.TransformNormal(_axisInA, RigidBodyA.CenterOfMassTransform); - Vector3 axisB = MathHelper.TransformNormal(_axisInB, RigidBodyB.CenterOfMassTransform); - - Vector3 angVelA = RigidBodyA.AngularVelocity; - Vector3 angVelB = RigidBodyB.AngularVelocity; - Vector3 angVelAroundHingeAxisA = axisA * Vector3.Dot(axisA, angVelA); - Vector3 angVelAroundHingeAxisB = axisB * Vector3.Dot(axisB, angVelB); - - Vector3 angAOrthog = angVelA - angVelAroundHingeAxisA; - Vector3 angBOrthog = angVelB - angVelAroundHingeAxisB; - Vector3 velrelOrthog = angAOrthog - angBOrthog; - - //solve angular velocity correction - float relaxation = 1f; - float len = velrelOrthog.Length(); - if (len > 0.00001f) - { - Vector3 normal2 = Vector3.Normalize(velrelOrthog); - float denom = RigidBodyA.ComputeAngularImpulseDenominator(normal2) + - RigidBodyB.ComputeAngularImpulseDenominator(normal2); - // scale for mass and relaxation - velrelOrthog *= (1f / denom) * 0.9f; - } - - //solve angular positional correction - Vector3 angularError = -Vector3.Cross(axisA, axisB) * (1f / timeStep); - float len2 = angularError.Length(); - if (len2 > 0.00001f) - { - Vector3 normal2 = Vector3.Normalize(angularError); - float denom2 = RigidBodyA.ComputeAngularImpulseDenominator(normal2) + - RigidBodyB.ComputeAngularImpulseDenominator(normal2); - angularError *= (1f / denom2) * relaxation; - } - - RigidBodyA.ApplyTorqueImpulse(-velrelOrthog + angularError); - RigidBodyB.ApplyTorqueImpulse(velrelOrthog - angularError); - - //apply motor - if (_enableAngularMotor) - { - //todo: add limits too - Vector3 angularLimit = Vector3.Zero; - - Vector3 velrel = angVelAroundHingeAxisA - angVelAroundHingeAxisB; - float projRelVel = Vector3.Dot(velrel, axisA); - - float desiredMotorVel = _motorTargetVelocity; - float motorRelvel = desiredMotorVel - projRelVel; - - float denom3 = RigidBodyA.ComputeAngularImpulseDenominator(axisA) + - RigidBodyB.ComputeAngularImpulseDenominator(axisA); - - float unclippedMotorImpulse = (1f / denom3) * motorRelvel; - //todo: should clip against accumulated impulse - float clippedMotorImpulse = unclippedMotorImpulse > _maxMotorImpulse ? _maxMotorImpulse : unclippedMotorImpulse; - clippedMotorImpulse = clippedMotorImpulse < -_maxMotorImpulse ? -_maxMotorImpulse : clippedMotorImpulse; - Vector3 motorImp = clippedMotorImpulse * axisA; - - RigidBodyA.ApplyTorqueImpulse(motorImp + angularLimit); - RigidBodyB.ApplyTorqueImpulse(-motorImp - angularLimit); - } - } - - public void EnableAngularMotor(bool enableMotor, float targetVelocity, float maxMotorImpulse) - { - _enableAngularMotor = enableMotor; - _motorTargetVelocity = targetVelocity; - _maxMotorImpulse = maxMotorImpulse; - } - - public void UpdateRHS(float timeStep) - { - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/IConstraintSolver.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/IConstraintSolver.cs deleted file mode 100644 index de2522548..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/IConstraintSolver.cs +++ /dev/null @@ -1,32 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX.Dynamics -{ - public interface IConstraintSolver - { - float SolveGroup(List bodies, List manifolds, int numManifolds, List constraints, ContactSolverInfo info, IDebugDraw debugDrawer); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/JacobianEntry.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/JacobianEntry.cs deleted file mode 100644 index 7e9b0cde6..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/JacobianEntry.cs +++ /dev/null @@ -1,155 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - /// - /// Jacobian entry is an abstraction that allows to describe constraints - /// it can be used in combination with a constraint solver - /// Can be used to relate the effect of an impulse to the constraint error - /// - public class JacobianEntry - { - private Vector3 _linearJointAxis; - private Vector3 _aJ; - private Vector3 _bJ; - private Vector3 _0MinvJt; - private Vector3 _1MinvJt; - private float _adiag; - - public JacobianEntry() { } - - //constraint between two different rigidbodies - public JacobianEntry( - Matrix world2A, - Matrix world2B, - Vector3 relPosA, Vector3 relPosB, - Vector3 jointAxis, - Vector3 inertiaInvA, - float massInvA, - Vector3 inertiaInvB, - float massInvB) - { - _linearJointAxis = jointAxis; - _aJ = Vector3.TransformNormal(Vector3.Cross(relPosA, _linearJointAxis), world2A); - _bJ = Vector3.TransformNormal(Vector3.Cross(relPosB, -_linearJointAxis), world2B); - _0MinvJt = inertiaInvA * _aJ; - _1MinvJt = inertiaInvB * _bJ; - _adiag = massInvA + Vector3.Dot(_0MinvJt, _aJ) + massInvB + Vector3.Dot(_1MinvJt, _bJ); - - if (_adiag <= 0.0f) - throw new BulletException(); - } - - //angular constraint between two different rigidbodies - public JacobianEntry(Vector3 jointAxis, - Matrix world2A, - Matrix world2B, - Vector3 inertiaInvA, - Vector3 inertiaInvB) - { - _linearJointAxis = new Vector3(); - _aJ = Vector3.TransformNormal(jointAxis, world2A); - _bJ = Vector3.TransformNormal(-jointAxis, world2B); - _0MinvJt = inertiaInvA * _aJ; - _1MinvJt = inertiaInvB * _bJ; - _adiag = Vector3.Dot(_0MinvJt, _aJ) + Vector3.Dot(_1MinvJt, _bJ); - - if (_adiag <= 0.0f) - throw new BulletException(); - } - - //angular constraint between two different rigidbodies - public JacobianEntry(Vector3 axisInA, - Vector3 axisInB, - Vector3 inertiaInvA, - Vector3 inertiaInvB) - { - _linearJointAxis = new Vector3(); - _aJ = axisInA; - _bJ = -axisInB; - _0MinvJt = inertiaInvA * _aJ; - _1MinvJt = inertiaInvB * _bJ; - _adiag = Vector3.Dot(_0MinvJt, _aJ) + Vector3.Dot(_1MinvJt, _bJ); - - if (_adiag <= 0.0f) - throw new BulletException(); - } - - //constraint on one rigidbody - public JacobianEntry( - Matrix world2A, - Vector3 rel_pos1, Vector3 rel_pos2, - Vector3 jointAxis, - Vector3 inertiaInvA, - float massInvA) - { - _linearJointAxis = jointAxis; - _aJ = Vector3.TransformNormal(Vector3.Cross(rel_pos1, jointAxis), world2A); - _bJ = Vector3.TransformNormal(Vector3.Cross(rel_pos2, -jointAxis), world2A); - _0MinvJt = inertiaInvA * _aJ; - _1MinvJt = new Vector3(); - _adiag = massInvA + Vector3.Dot(_0MinvJt, _aJ); - - if (_adiag <= 0.0f) - throw new BulletException(); - } - - public float Diagonal { get { return _adiag; } } - - // for two constraints on the same rigidbody (for example vehicle friction) - public float GetNonDiagonal(JacobianEntry jacB, float massInvA) - { - float lin = massInvA * Vector3.Dot(_linearJointAxis, jacB._linearJointAxis); - float ang = Vector3.Dot(_0MinvJt, jacB._aJ); - return lin + ang; - } - - // for two constraints on sharing two same rigidbodies (for example two contact points between two rigidbodies) - public float GetNonDiagonal(JacobianEntry jacB, float massInvA, float massInvB) - { - Vector3 lin = _linearJointAxis * jacB._linearJointAxis; - Vector3 ang0 = _0MinvJt * jacB._aJ; - Vector3 ang1 = _1MinvJt * jacB._bJ; - Vector3 lin0 = massInvA * lin; - Vector3 lin1 = massInvB * lin; - Vector3 sum = ang0 + ang1 + lin0 + lin1; - return sum.X + sum.Y + sum.Z; - } - - public float GetRelativeVelocity(Vector3 linvelA, Vector3 angvelA, Vector3 linvelB, Vector3 angvelB) - { - Vector3 linrel = linvelA - linvelB; - Vector3 angvela = angvelA * _aJ; - Vector3 angvelb = angvelB * _bJ; - linrel *= _linearJointAxis; - angvela += angvelb; - angvela += linrel; - float rel_vel2 = angvela.X + angvela.Y + angvela.Z; - return rel_vel2 + float.Epsilon; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/Point2PointConstraint.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/Point2PointConstraint.cs deleted file mode 100644 index 771a9082c..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/Point2PointConstraint.cs +++ /dev/null @@ -1,157 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - public class ConstraintSetting - { - private float _tau, _damping; - - public ConstraintSetting() - { - _tau = 0.3f; - _damping = 1.0f; - } - - public float Damping - { - get { return _damping; } - set { _damping = value; } - } - - public float Tau - { - get { return _tau; } - set { _tau = value; } - } - } - - public class Point2PointConstraint : TypedConstraint - { - private JacobianEntry[] _jacobian; - private Vector3 _pivotInA, _pivotInB; - - private ConstraintSetting _setting = new ConstraintSetting(); - - public Point2PointConstraint() - { - _jacobian = new JacobianEntry[3]; - } - - public Point2PointConstraint(RigidBody rbA, RigidBody rbB, Vector3 pivotInA, Vector3 pivotInB) - : base(rbA, rbB) - { - _jacobian = new JacobianEntry[3]; - - _pivotInA = pivotInA; - _pivotInB = pivotInB; - } - - public Point2PointConstraint(RigidBody rbA, Vector3 pivotInA) - : base(rbA) - { - _jacobian = new JacobianEntry[3]; - - _pivotInA = pivotInA; - _pivotInB = MathHelper.MatrixToVector(rbA.CenterOfMassTransform, _pivotInA); - } - - public ConstraintSetting Settings { get { return _setting; } set { _setting = value; } } - - public Vector3 PivotInA - { - set - { - _pivotInA = value; - } - } - - public Vector3 PivotInB - { - set - { - _pivotInB = value; - } - } - - public override void BuildJacobian() - { - Vector3 normal = new Vector3(); - - for (int i = 0; i < 3; i++) - { - MathHelper.SetElement(ref normal, i, 1); - _jacobian[i] = new JacobianEntry( - MatrixOperations.Transpose(RigidBodyA.CenterOfMassTransform), - MatrixOperations.Transpose(RigidBodyB.CenterOfMassTransform), - MathHelper.Transform(_pivotInA, RigidBodyA.CenterOfMassTransform) - RigidBodyA.CenterOfMassPosition, - MathHelper.Transform(_pivotInB, RigidBodyB.CenterOfMassTransform) - RigidBodyB.CenterOfMassPosition, - normal, - RigidBodyA.InvInertiaDiagLocal, - RigidBodyA.InverseMass, - RigidBodyB.InvInertiaDiagLocal, - RigidBodyB.InverseMass - ); - MathHelper.SetElement(ref normal, i, 0); - } - } - - public override void SolveConstraint(float timeStep) - { - Vector3 pivotAInW = MathHelper.Transform(_pivotInA, RigidBodyA.CenterOfMassTransform); - Vector3 pivotBInW = MathHelper.Transform(_pivotInB, RigidBodyB.CenterOfMassTransform); - - Vector3 normal = new Vector3(); - - for (int i = 0; i < 3; i++) - { - MathHelper.SetElement(ref normal, i, 1); - - float jacDiagABInv = 1.0f / _jacobian[i].Diagonal; - - Vector3 rel_pos1 = pivotAInW - RigidBodyA.CenterOfMassPosition; - Vector3 rel_pos2 = pivotBInW - RigidBodyB.CenterOfMassPosition; - - Vector3 vel1 = RigidBodyA.GetVelocityInLocalPoint(rel_pos1); - Vector3 vel2 = RigidBodyB.GetVelocityInLocalPoint(rel_pos2); - - Vector3 vel = vel1 - vel2; - - float rel_vel = Vector3.Dot(normal, vel); - float depth = -Vector3.Dot((pivotAInW - pivotBInW), normal); - - float impulse = depth * _setting.Tau / timeStep * jacDiagABInv - _setting.Damping * rel_vel * jacDiagABInv; - AppliedImpulse += impulse; - Vector3 impulseVector = normal * impulse; - - RigidBodyA.ApplyImpulse(impulseVector, pivotAInW - RigidBodyA.CenterOfMassPosition); - RigidBodyB.ApplyImpulse(-impulseVector, pivotBInW - RigidBodyB.CenterOfMassPosition); - - MathHelper.SetElement(ref normal, i, 0); - } - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/SequentialImpulseConstraintSolver.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/SequentialImpulseConstraintSolver.cs deleted file mode 100644 index fe46265f0..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/SequentialImpulseConstraintSolver.cs +++ /dev/null @@ -1,915 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - [Flags] - public enum SolverMode - { - None = 0, - RandomizeOrder = 1, - FrictionSeperate = 2, - UseWarmstarting = 4, - CacheFriendly = 8, - } - - public class SequentialImpulseConstraintSolver : IConstraintSolver - { - private static int _totalContactPoints = 0; - - private SolverMode _solverMode; - private int _totalCpd = 0; - private ContactSolverFunc[,] _contactDispatch = new ContactSolverFunc[(int)ContactSolverType.MaxContactSolverType, (int)ContactSolverType.MaxContactSolverType]; - private ContactSolverFunc[,] _frictionDispatch = new ContactSolverFunc[(int)ContactSolverType.MaxContactSolverType, (int)ContactSolverType.MaxContactSolverType]; - - private float _penetrationResolveFactor = 0.9f; - private List _tmpSolverBodyPool = new List(); - private List _tmpSolverConstraintPool = new List(); - private List _tmpSolverFrictionConstraintPool = new List(); - - private const int _sequentialImpulseMaxSolverPoints = 16384; - private static OrderIndex[] _order = new OrderIndex[SequentialImpulseMaxSolverPoints]; - private static long _seed2 = 0; - - public SequentialImpulseConstraintSolver() - { - _solverMode = SolverMode.RandomizeOrder | SolverMode.CacheFriendly; - PersistentManifold.ContactDestroyedCallback = MyContactDestroyedCallback; - - //initialize default friction/contact funcs - int i, j; - for (i = 0; i < (int)ContactSolverType.MaxContactSolverType; i++) - for (j = 0; j < (int)ContactSolverType.MaxContactSolverType; j++) - { - - _contactDispatch[i, j] = ContactConstraint.ResolveSingleCollision; - _frictionDispatch[i, j] = ContactConstraint.ResolveSingleFriction; - } - } - - public SolverMode SolverMode { get { return _solverMode; } set { _solverMode = value; } } - public static int SequentialImpulseMaxSolverPoints { get { return _sequentialImpulseMaxSolverPoints; } } - protected static OrderIndex[] Order { get { return _order; } set { _order = value; } } - public static long RandSeed { get { return _seed2; } set { _seed2 = value; } } - - /// - /// Advanced: Override the default contact solving function for contacts, for certain types of rigidbody - /// See btRigidBody::m_contactSolverType and btRigidBody::m_frictionSolverType - /// - public void SetContactSolverFunc(ContactSolverFunc func, int typeA, int typeB) - { - _contactDispatch[typeA, typeB] = func; - } - - /// - /// Advanced: Override the default friction solving function for contacts, for certain types of rigidbody - /// See btRigidBody::m_contactSolverType and btRigidBody::m_frictionSolverType - /// - public void SetFrictionSolverFunc(ContactSolverFunc func, int typeA, int typeB) - { - _frictionDispatch[typeA, typeB] = func; - } - - protected float Solve(RigidBody bodyA, RigidBody bodyB, ManifoldPoint cp, ContactSolverInfo info, int iter, IDebugDraw debugDraw) - { - float maxImpulse = 0; - - Vector3 color = new Vector3(0, 1, 0); - if (cp.Distance <= 0) - { - if (iter == 0) - if(debugDraw != null) - debugDraw.DrawContactPoint(cp.PositionWorldOnB, cp.NormalWorldOnB, cp.Distance, cp.LifeTime, color); - - ConstraintPersistentData cpd = cp.UserPersistentData as ConstraintPersistentData; - float impulse = cpd.ContactSolverFunc( - bodyA, bodyB, - cp, - info); - - if (maxImpulse < impulse) - maxImpulse = impulse; - } - return maxImpulse; - } - - protected float Solve(RigidBody bodyA, RigidBody bodyB, ManifoldPoint cp, ContactSolverInfo info, int iter) - { - return Solve(bodyA, bodyB, cp, info, iter, null); - } - - protected float SolveCombinedContactFriction(RigidBody bodyA, RigidBody bodyB, ManifoldPoint cp, ContactSolverInfo info, int iter, IDebugDraw debugDraw) - { - float maxImpulse = 0; - - Vector3 color = new Vector3(0, 1, 0); - if (cp.Distance <= 0) - { - if (iter == 0) - if (debugDraw != null) - debugDraw.DrawContactPoint(cp.PositionWorldOnB, cp.NormalWorldOnB, cp.Distance, cp.LifeTime, color); - - float impulse = ContactConstraint.ResolveSingleCollisionCombined( - bodyA, bodyB, - cp, - info); - - if (maxImpulse < impulse) - maxImpulse = impulse; - } - return maxImpulse; - } - - protected float SolveFriction(RigidBody bodyA, RigidBody bodyB, ManifoldPoint cp, ContactSolverInfo info, int iter, IDebugDraw debugDraw) - { - Vector3 color = new Vector3(0, 1, 0); - - if (cp.Distance <= 0) - { - - ConstraintPersistentData cpd = cp.UserPersistentData as ConstraintPersistentData; - cpd.FrictionSolverFunc( - bodyA, bodyB, - cp, - info); - } - return 0; - } - - protected void PrepareConstraints(PersistentManifold manifold, ContactSolverInfo info) - { - RigidBody body0 = manifold.BodyA as RigidBody; - RigidBody body1 = manifold.BodyB as RigidBody; - - - //only necessary to refresh the manifold once (first iteration). The integration is done outside the loop - { - manifold.RefreshContactPoints(body0.CenterOfMassTransform, body1.CenterOfMassTransform); - - int numpoints = manifold.ContactsCount; - - _totalContactPoints += numpoints; - - Vector3 color = new Vector3(0, 1, 0); - for (int i = 0; i < numpoints; i++) - { - ManifoldPoint cp = manifold.GetContactPoint(i); - if (cp.Distance <= 0) - { - Vector3 pos1 = cp.PositionWorldOnA; - Vector3 pos2 = cp.PositionWorldOnB; - - Vector3 rel_pos1 = pos1 - body0.CenterOfMassPosition; - Vector3 rel_pos2 = pos2 - body1.CenterOfMassPosition; - - - //this jacobian entry is re-used for all iterations - JacobianEntry jac = new JacobianEntry(MatrixOperations.Transpose(body0.CenterOfMassTransform), - MatrixOperations.Transpose(body1.CenterOfMassTransform), - rel_pos1, rel_pos2, cp.NormalWorldOnB, body0.InvInertiaDiagLocal, body0.InverseMass, - body1.InvInertiaDiagLocal, body1.InverseMass); - - float jacDiagAB = jac.Diagonal; - - ConstraintPersistentData cpd = cp.UserPersistentData as ConstraintPersistentData; - if (cpd != null) - { - //might be invalid - cpd.PersistentLifeTime++; - if (cpd.PersistentLifeTime != cp.LifeTime) - { - //printf("Invalid: cpd->m_persistentLifeTime = %i cp.getLifeTime() = %i\n",cpd->m_persistentLifeTime,cp.getLifeTime()); - cpd = new ConstraintPersistentData(); - cpd.PersistentLifeTime = cp.LifeTime; - - } - } - else - { - - cpd = new ConstraintPersistentData(); - _totalCpd++; - //printf("totalCpd = %i Created Ptr %x\n",totalCpd,cpd); - cp.UserPersistentData = cpd; - cpd.PersistentLifeTime = cp.LifeTime; - //printf("CREATED: %x . cpd->m_persistentLifeTime = %i cp.getLifeTime() = %i\n",cpd,cpd->m_persistentLifeTime,cp.getLifeTime()); - - } - if (cpd == null) - throw new BulletException(); - - cpd.JacDiagABInv = 1f / jacDiagAB; - - //Dependent on Rigidbody A and B types, fetch the contact/friction response func - //perhaps do a similar thing for friction/restutution combiner funcs... - - cpd.FrictionSolverFunc = _frictionDispatch[(int)body0.FrictionSolverType, (int)body1.FrictionSolverType]; - cpd.ContactSolverFunc = _contactDispatch[(int)body0.ContactSolverType, (int)body1.ContactSolverType]; - - Vector3 vel1 = body0.GetVelocityInLocalPoint(rel_pos1); - Vector3 vel2 = body1.GetVelocityInLocalPoint(rel_pos2); - Vector3 vel = vel1 - vel2; - float rel_vel; - rel_vel = Vector3.Dot(cp.NormalWorldOnB, vel); - - float combinedRestitution = cp.CombinedRestitution; - - cpd.Penetration = cp.Distance; - cpd.Friction = cp.CombinedFriction; - cpd.Restitution = RestitutionCurve(rel_vel, combinedRestitution); - if (cpd.Restitution < 0f) - { - cpd.Restitution = 0.0f; - - }; - - //restitution and penetration work in same direction so - //rel_vel - - float penVel = -cpd.Penetration / info.TimeStep; - - if (cpd.Restitution > penVel) - { - cpd.Penetration = 0; - } - - - float relaxation = info.Damping; - if ((_solverMode & SolverMode.UseWarmstarting) != 0) - { - cpd.AppliedImpulse *= relaxation; - } - else - { - cpd.AppliedImpulse = 0f; - } - - //for friction - cpd.PreviousAppliedImpulse = cpd.AppliedImpulse; - - //re-calculate friction direction every frame, todo: check if this is really needed - Vector3 fwta = cpd.FrictionWorldTangentialA; - Vector3 fwtb = cpd.FrictionWorldTangentialB; - MathHelper.PlaneSpace1(cp.NormalWorldOnB, ref fwta, ref fwtb); - cpd.FrictionWorldTangentialA = fwta; - cpd.FrictionWorldTangentialB = fwtb; - - cpd.AccumulatedTangentImpulseA = 0; - cpd.AccumulatedTangentImpulseB = 0; - float denom0 = body0.ComputeImpulseDenominator(pos1, cpd.FrictionWorldTangentialA); - float denom1 = body1.ComputeImpulseDenominator(pos2, cpd.FrictionWorldTangentialA); - float denom = relaxation / (denom0 + denom1); - cpd.JacDiagABInvTangentA = denom; - - - denom0 = body0.ComputeImpulseDenominator(pos1, cpd.FrictionWorldTangentialB); - denom1 = body1.ComputeImpulseDenominator(pos2, cpd.FrictionWorldTangentialB); - denom = relaxation / (denom0 + denom1); - cpd.JacDiagABInvTangentB = denom; - - Vector3 totalImpulse = cp.NormalWorldOnB * cpd.AppliedImpulse; - - { - Vector3 torqueAxis0 = Vector3.Cross(rel_pos1, cp.NormalWorldOnB); - cpd.AngularComponentA = Vector3.TransformNormal(torqueAxis0, body0.InvInertiaTensorWorld); - Vector3 torqueAxis1 = Vector3.Cross(rel_pos2, cp.NormalWorldOnB); - cpd.AngularComponentB = Vector3.TransformNormal(torqueAxis1, body1.InvInertiaTensorWorld); - } - { - Vector3 ftorqueAxis0 = Vector3.Cross(rel_pos1, cpd.FrictionWorldTangentialA); - cpd.FrictionAngularComponent0A = Vector3.TransformNormal(ftorqueAxis0, body0.InvInertiaTensorWorld); - } - { - Vector3 ftorqueAxis1 = Vector3.Cross(rel_pos1, cpd.FrictionWorldTangentialB); - cpd.FrictionAngularComponent1A = Vector3.TransformNormal(ftorqueAxis1, body0.InvInertiaTensorWorld); - } - { - Vector3 ftorqueAxis0 = Vector3.Cross(rel_pos2, cpd.FrictionWorldTangentialA); - cpd.FrictionAngularComponent0B = Vector3.TransformNormal(ftorqueAxis0, body1.InvInertiaTensorWorld); - } - { - Vector3 ftorqueAxis1 = Vector3.Cross(rel_pos2, cpd.FrictionWorldTangentialB); - cpd.FrictionAngularComponent1B = Vector3.TransformNormal(ftorqueAxis1, body1.InvInertiaTensorWorld); - } - - - //apply previous frames impulse on both bodies - body0.ApplyImpulse(totalImpulse, rel_pos1); - body1.ApplyImpulse(-totalImpulse, rel_pos2); - } - } - } - } - - private bool MyContactDestroyedCallback(object userPersistentData) - { - if (userPersistentData == null) - throw new BulletException(); - ConstraintPersistentData cpd = userPersistentData as ConstraintPersistentData; - _totalCpd--; - return true; - } - - private float RestitutionCurve(float relVel, float restitution) - { - float rest = restitution * -relVel; - return rest; - } - - //velocity + friction - //response between two dynamic objects with friction - public virtual float ResolveSingleCollisionCombinedCacheFriendly( - SolverBody bodyA, - SolverBody bodyB, - SolverConstraint contactConstraint, - ContactSolverInfo solverInfo) - { - float normalImpulse = 0; - - if (contactConstraint.Penetration < 0) - return 0; - - float relVel; - float velADotn = Vector3.Dot(contactConstraint.ContactNormal,bodyA.LinearVelocity) - + Vector3.Dot(contactConstraint.RelPosACrossNormal,bodyA.AngularVelocity); - float velBDotn = Vector3.Dot(contactConstraint.ContactNormal,bodyB.LinearVelocity) - + Vector3.Dot(contactConstraint.RelPosBCrossNormal,bodyB.AngularVelocity); - - relVel = velADotn - velBDotn; - - float positionalError = contactConstraint.Penetration; - float velocityError = contactConstraint.Restitution - relVel;// * damping; - - float penetrationImpulse = positionalError * contactConstraint.JacDiagABInv; - float velocityImpulse = velocityError * contactConstraint.JacDiagABInv; - normalImpulse = penetrationImpulse + velocityImpulse; - - // See Erin Catto's GDC 2006 paper: Clamp the accumulated impulse - float oldNormalImpulse = contactConstraint.AppliedImpulse; - float sum = oldNormalImpulse + normalImpulse; - contactConstraint.AppliedImpulse = 0 > sum ? 0 : sum; - - float oldVelocityImpulse = contactConstraint.AppliedVelocityImpulse; - float velocitySum = oldVelocityImpulse + velocityImpulse; - contactConstraint.AppliedVelocityImpulse = 0 > velocitySum ? 0 : velocitySum; - - normalImpulse = contactConstraint.AppliedImpulse - oldNormalImpulse; - - if (bodyA.InvMass != 0) - { - bodyA.ApplyImpulse(contactConstraint.ContactNormal * bodyA.InvMass, - contactConstraint.AngularComponentA, normalImpulse); - } - if (bodyB.InvMass != 0) - { - bodyB.ApplyImpulse(contactConstraint.ContactNormal * bodyB.InvMass, - contactConstraint.AngularComponentB, -normalImpulse); - } - - return normalImpulse; - } - - public virtual float ResolveSingleFrictionCacheFriendly( - SolverBody bodyA, - SolverBody bodyB, - SolverConstraint contactConstraint, - ContactSolverInfo solverInfo, - float appliedNormalImpulse) - { - float combinedFriction = contactConstraint.Friction; - float limit = appliedNormalImpulse * combinedFriction; - - if (appliedNormalImpulse > 0) - //friction - { - float j1; - { - float relVel; - float velADotn = Vector3.Dot(contactConstraint.ContactNormal, bodyA.LinearVelocity) - + Vector3.Dot(contactConstraint.RelPosACrossNormal, bodyA.AngularVelocity); - float velBDotn = Vector3.Dot(contactConstraint.ContactNormal, bodyB.LinearVelocity) - + Vector3.Dot(contactConstraint.RelPosBCrossNormal, bodyB.AngularVelocity); - relVel = velADotn - velBDotn; - - // calculate j that moves us to zero relative velocity - j1 = -relVel * contactConstraint.JacDiagABInv; - float oldTangentImpulse = contactConstraint.AppliedImpulse; - contactConstraint.AppliedImpulse = oldTangentImpulse + j1; - - float test = contactConstraint.AppliedImpulse; - MathHelper.SetMin(ref test, limit); - MathHelper.SetMax(ref test, -limit); - contactConstraint.AppliedImpulse = test; - - j1 = contactConstraint.AppliedImpulse - oldTangentImpulse; - } - - if (bodyA.InvMass != 0) - { - bodyA.ApplyImpulse(contactConstraint.ContactNormal * bodyA.InvMass, contactConstraint.AngularComponentA, j1); - } - if (bodyB.InvMass != 0) - { - bodyB.ApplyImpulse(contactConstraint.ContactNormal * bodyB.InvMass, contactConstraint.AngularComponentB, -j1); - } - } - return 0; - } - - public virtual float SolveGroupCacheFriendly(List bodies, List manifolds, int numManifolds, List constraints, ContactSolverInfo infoGlobal, IDebugDraw debugDrawer) - { - if (constraints.Count + numManifolds == 0) - { - return 0; - } - - for (int i = 0; i < numManifolds; i++) - { - PersistentManifold manifold = manifolds[i]; - RigidBody rbA = (RigidBody)manifold.BodyA; - RigidBody rbB = (RigidBody)manifold.BodyB; - - manifold.RefreshContactPoints(rbA.CenterOfMassTransform, rbB.CenterOfMassTransform); - } - - int minReservation = manifolds.Count * 2; - - _tmpSolverBodyPool = new List(minReservation); - - for (int i = 0; i < bodies.Count; i++) - { - RigidBody rb = RigidBody.Upcast(bodies[i]); - if (rb != null && rb.IslandTag >= 0) - { - BulletDebug.Assert(rb.CompanionID < 0); - int solverBodyId = _tmpSolverBodyPool.Count; - SolverBody solverBody; - InitSolverBody(out solverBody, rb); - _tmpSolverBodyPool.Add(solverBody); - rb.CompanionID = solverBodyId; - } - } - - _tmpSolverConstraintPool = new List(minReservation); - _tmpSolverFrictionConstraintPool = new List(minReservation); - - for (int i = 0; i < numManifolds; i++) - { - PersistentManifold manifold = manifolds[i]; - RigidBody rb0 = (RigidBody)manifold.BodyA; - RigidBody rb1 = (RigidBody)manifold.BodyB; - - int solverBodyIdA = -1; - int solverBodyIdB = -1; - - //if (i == 89) - // System.Diagnostics.Debugger.Break(); - - if (manifold.ContactsCount != 0) - { - if (rb0.IslandTag >= 0) - { - solverBodyIdA = rb0.CompanionID; - } - else - { - //create a static body - solverBodyIdA = _tmpSolverBodyPool.Count; - SolverBody solverBody; - InitSolverBody(out solverBody, rb0); - _tmpSolverBodyPool.Add(solverBody); - } - - if (rb1.IslandTag >= 0) - { - solverBodyIdB = rb1.CompanionID; - } - else - { - //create a static body - solverBodyIdB = _tmpSolverBodyPool.Count; - SolverBody solverBody; - InitSolverBody(out solverBody, rb1); - _tmpSolverBodyPool.Add(solverBody); - } - } - - if (solverBodyIdB == -1 || solverBodyIdA == -1) - System.Diagnostics.Debug.WriteLine(string.Format("We're in ass ! {0}", i)); - - for (int j = 0; j < manifold.ContactsCount; j++) - { - ManifoldPoint cp = manifold.GetContactPoint(j); - - int frictionIndex = _tmpSolverConstraintPool.Count; - - if (cp.Distance <= 0) - { - - Vector3 pos1 = cp.PositionWorldOnA; - Vector3 pos2 = cp.PositionWorldOnB; - - Vector3 rel_pos1 = pos1 - rb0.CenterOfMassPosition; - Vector3 rel_pos2 = pos2 - rb1.CenterOfMassPosition; - - float relaxation = 1; - { - SolverConstraint solverConstraint = new SolverConstraint(); - _tmpSolverConstraintPool.Add(solverConstraint); - - solverConstraint.SolverBodyIdA = solverBodyIdA; - solverConstraint.SolverBodyIdB = solverBodyIdB; - solverConstraint.ConstraintType = SolverConstraint.SolverConstraintType.Contact; - - //can be optimized, the cross products are already calculated - float denom0 = rb0.ComputeImpulseDenominator(pos1, cp.NormalWorldOnB); - float denom1 = rb1.ComputeImpulseDenominator(pos2, cp.NormalWorldOnB); - float denom = relaxation / (denom0 + denom1); - solverConstraint.JacDiagABInv = denom; - - solverConstraint.ContactNormal = cp.NormalWorldOnB; - solverConstraint.RelPosACrossNormal = Vector3.Cross(rel_pos1, cp.NormalWorldOnB); - solverConstraint.RelPosBCrossNormal = Vector3.Cross(rel_pos2, cp.NormalWorldOnB); - - Vector3 vel1 = rb0.GetVelocityInLocalPoint(rel_pos1); - Vector3 vel2 = rb1.GetVelocityInLocalPoint(rel_pos2); - - Vector3 vel = vel1 - vel2; - float rel_vel; - rel_vel = Vector3.Dot(cp.NormalWorldOnB, vel); - - - solverConstraint.Penetration = cp.Distance;//btScalar(infoGlobal.m_numIterations); - solverConstraint.Friction = cp.CombinedFriction; - float rest = RestitutionCurve(rel_vel, cp.CombinedRestitution); - if (rest <= 0) - { - rest = 0; - } - - float penVel = -solverConstraint.Penetration / infoGlobal.TimeStep; - if (rest > penVel) - { - rest = 0; - } - solverConstraint.Restitution = rest; - - solverConstraint.Penetration *= -(infoGlobal.Erp / infoGlobal.TimeStep); - - solverConstraint.AppliedImpulse = 0f; - solverConstraint.AppliedVelocityImpulse = 0f; - -#warning Check to see if we need Vector3.Transform - Vector3 torqueAxis0 = Vector3.Cross(rel_pos1, cp.NormalWorldOnB); - solverConstraint.AngularComponentA = Vector3.TransformNormal(torqueAxis0, rb0.InvInertiaTensorWorld); - Vector3 torqueAxis1 = Vector3.Cross(rel_pos2, cp.NormalWorldOnB); - solverConstraint.AngularComponentB = Vector3.TransformNormal(torqueAxis1, rb1.InvInertiaTensorWorld); - } - //create 2 '1d axis' constraints for 2 tangential friction directions - - //re-calculate friction direction every frame, todo: check if this is really needed - Vector3 frictionTangential0a = new Vector3(), - frictionTangential1b = new Vector3(); - - MathHelper.PlaneSpace1(cp.NormalWorldOnB, ref frictionTangential0a, ref frictionTangential1b); - { - SolverConstraint solverConstraint = new SolverConstraint(); - _tmpSolverFrictionConstraintPool.Add(solverConstraint); - solverConstraint.ContactNormal = frictionTangential0a; - - solverConstraint.SolverBodyIdA = solverBodyIdA; - solverConstraint.SolverBodyIdB = solverBodyIdB; - solverConstraint.ConstraintType = SolverConstraint.SolverConstraintType.Friction; - solverConstraint.FrictionIndex = frictionIndex; - - solverConstraint.Friction = cp.CombinedFriction; - - solverConstraint.AppliedImpulse = 0; - solverConstraint.AppliedVelocityImpulse = 0; - - float denom0 = rb0.ComputeImpulseDenominator(pos1, solverConstraint.ContactNormal); - float denom1 = rb1.ComputeImpulseDenominator(pos2, solverConstraint.ContactNormal); - float denom = relaxation / (denom0 + denom1); - solverConstraint.JacDiagABInv = denom; - - { - Vector3 ftorqueAxis0 = Vector3.Cross(rel_pos1, solverConstraint.ContactNormal); - solverConstraint.RelPosACrossNormal = ftorqueAxis0; - solverConstraint.AngularComponentA = Vector3.TransformNormal(ftorqueAxis0, rb0.InvInertiaTensorWorld); - } - { - Vector3 ftorqueAxis0 = Vector3.Cross(rel_pos2, solverConstraint.ContactNormal); - solverConstraint.RelPosBCrossNormal = ftorqueAxis0; - solverConstraint.AngularComponentB = Vector3.TransformNormal(ftorqueAxis0, rb1.InvInertiaTensorWorld); - } - } - - - { - - SolverConstraint solverConstraint = new SolverConstraint(); - _tmpSolverFrictionConstraintPool.Add(solverConstraint); - solverConstraint.ContactNormal = frictionTangential1b; - - solverConstraint.SolverBodyIdA = solverBodyIdA; - solverConstraint.SolverBodyIdB = solverBodyIdB; - solverConstraint.ConstraintType = SolverConstraint.SolverConstraintType.Friction; - solverConstraint.FrictionIndex = frictionIndex; - - solverConstraint.Friction = cp.CombinedFriction; - - solverConstraint.AppliedImpulse = 0; - solverConstraint.AppliedVelocityImpulse = 0; - - float denom0 = rb0.ComputeImpulseDenominator(pos1, solverConstraint.ContactNormal); - float denom1 = rb1.ComputeImpulseDenominator(pos2, solverConstraint.ContactNormal); - float denom = relaxation / (denom0 + denom1); - solverConstraint.JacDiagABInv = denom; - { - Vector3 ftorqueAxis1 = Vector3.Cross(rel_pos1, solverConstraint.ContactNormal); - solverConstraint.RelPosACrossNormal = ftorqueAxis1; - solverConstraint.AngularComponentA = Vector3.TransformNormal(ftorqueAxis1, rb0.InvInertiaTensorWorld); - } - { - Vector3 ftorqueAxis1 = Vector3.Cross(rel_pos2, solverConstraint.ContactNormal); - solverConstraint.RelPosBCrossNormal = ftorqueAxis1; - solverConstraint.AngularComponentB = Vector3.TransformNormal(ftorqueAxis1, rb1.InvInertiaTensorWorld); - } - } - } - } - } - - ContactSolverInfo info = infoGlobal; - { - for (int j = 0; j < constraints.Count; j++) - { - TypedConstraint constraint = constraints[j]; - constraint.BuildJacobian(); - } - } - - int numConstraintPool = _tmpSolverConstraintPool.Count; - int numFrictionPool = _tmpSolverFrictionConstraintPool.Count; - - //todo: use stack allocator for such temporarily memory, same for solver bodies/constraints - List gOrderTmpConstraintPool = new List(numConstraintPool); - List gOrderFrictionConstraintPool = new List(numFrictionPool); - { - for (int i = 0; i < numConstraintPool; i++) - { - gOrderTmpConstraintPool.Add(i); - } - for (int i = 0; i < numFrictionPool; i++) - { - gOrderFrictionConstraintPool.Add(i); - } - } - - //should traverse the contacts random order... - int iteration; - { - for (iteration = 0; iteration < info.IterationsCount; iteration++) - { - - int j; - if ((_solverMode & SolverMode.RandomizeOrder) != SolverMode.None) - { - if ((iteration & 7) == 0) - { - for (j = 0; j < numConstraintPool; ++j) - { - int tmp = gOrderTmpConstraintPool[j]; - int swapi = RandInt2(j + 1); - gOrderTmpConstraintPool[j] = gOrderTmpConstraintPool[swapi]; - gOrderTmpConstraintPool[swapi] = tmp; - } - - for (j = 0; j < numFrictionPool; ++j) - { - int tmp = gOrderFrictionConstraintPool[j]; - int swapi = RandInt2(j + 1); - gOrderFrictionConstraintPool[j] = gOrderFrictionConstraintPool[swapi]; - gOrderFrictionConstraintPool[swapi] = tmp; - } - } - } - - for (j = 0; j < constraints.Count; j++) - { - TypedConstraint constraint = constraints[j]; - //todo: use solver bodies, so we don't need to copy from/to btRigidBody - - if ((constraint.RigidBodyA.IslandTag >= 0) && (constraint.RigidBodyA.CompanionID >= 0)) - { - _tmpSolverBodyPool[constraint.RigidBodyA.CompanionID].WriteBackVelocity(); - } - if ((constraint.RigidBodyB.IslandTag >= 0) && (constraint.RigidBodyB.CompanionID >= 0)) - { - _tmpSolverBodyPool[constraint.RigidBodyB.CompanionID].WriteBackVelocity(); - } - - constraint.SolveConstraint(info.TimeStep); - - if ((constraint.RigidBodyA.IslandTag >= 0) && (constraint.RigidBodyA.CompanionID >= 0)) - { - _tmpSolverBodyPool[constraint.RigidBodyA.CompanionID].ReadVelocity(); - } - if ((constraint.RigidBodyB.IslandTag >= 0) && (constraint.RigidBodyB.CompanionID >= 0)) - { - _tmpSolverBodyPool[constraint.RigidBodyB.CompanionID].ReadVelocity(); - } - - } - - { - int numPoolConstraints = _tmpSolverConstraintPool.Count; - for (j = 0; j < numPoolConstraints; j++) - { - SolverConstraint solveManifold = _tmpSolverConstraintPool[gOrderTmpConstraintPool[j]]; - ResolveSingleCollisionCombinedCacheFriendly(_tmpSolverBodyPool[solveManifold.SolverBodyIdA], - _tmpSolverBodyPool[solveManifold.SolverBodyIdB], solveManifold, info); - } - } - - { - int numFrictionPoolConstraints = _tmpSolverFrictionConstraintPool.Count; - for (j = 0; j < numFrictionPoolConstraints; j++) - { - SolverConstraint solveManifold = _tmpSolverFrictionConstraintPool[gOrderFrictionConstraintPool[j]]; - float appliedNormalImpulse = _tmpSolverConstraintPool[solveManifold.FrictionIndex].AppliedImpulse; - - ResolveSingleFrictionCacheFriendly(_tmpSolverBodyPool[solveManifold.SolverBodyIdA], - _tmpSolverBodyPool[solveManifold.SolverBodyIdB], solveManifold, info, appliedNormalImpulse); - } - } - } - } - - for (int i = 0; i < _tmpSolverBodyPool.Count; i++) - { - _tmpSolverBodyPool[i].WriteBackVelocity(); - } - - _tmpSolverBodyPool.Clear(); - _tmpSolverConstraintPool.Clear(); - _tmpSolverFrictionConstraintPool.Clear(); - - return 0; - } - - public virtual float SolveGroup(List bodies, List manifolds, int numManifolds, List constraints, ContactSolverInfo infoGlobal, IDebugDraw debugDrawer) - { - if ((_solverMode & SolverMode.CacheFriendly) != SolverMode.None) - { - return SolveGroupCacheFriendly(bodies, manifolds, numManifolds, constraints, infoGlobal, debugDrawer); - } - - ContactSolverInfo info = infoGlobal; - int totalPoints = 0; - - int numiter = infoGlobal.IterationsCount; - - for (int j = 0; j < manifolds.Count; j++) - { - PersistentManifold manifold = manifolds[j]; - PrepareConstraints(manifold, info); - - for (int p = 0; p < manifolds[j].ContactsCount; p++) - { - _order[totalPoints].ManifoldIndex = j; - _order[totalPoints].PointIndex = p; - totalPoints++; - } - } - - for (int j = 0; j < constraints.Count; j++) - { - constraints[j].BuildJacobian(); - } - - //should traverse the contacts random order... - int iteration; - - for (iteration = 0; iteration < numiter; iteration++) - { - int j; - if ((_solverMode & SolverMode.RandomizeOrder) != SolverMode.None) - { - if ((iteration & 7) == 0) - { - for (j = 0; j < totalPoints; ++j) - { - OrderIndex tmp = _order[j]; - int swapi = RandInt2(j + 1); - _order[j] = _order[swapi]; - _order[swapi] = tmp; - } - } - } - - for (j = 0; j < constraints.Count; j++) - { - constraints[j].SolveConstraint(info.TimeStep); - } - - for (j = 0; j < totalPoints; j++) - { - PersistentManifold manifold = manifolds[_order[j].ManifoldIndex]; - Solve((RigidBody)manifold.BodyA, (RigidBody)manifold.BodyB, - manifold.GetContactPoint(_order[j].PointIndex), info, iteration, debugDrawer); - } - - for (j = 0; j < totalPoints; j++) - { - PersistentManifold manifold = manifolds[_order[j].ManifoldIndex]; - SolveFriction((RigidBody)manifold.BodyA, - (RigidBody)manifold.BodyB, manifold.GetContactPoint(_order[j].PointIndex), info, iteration, debugDrawer); - } - } - - return 0; - } - - private void InitSolverBody(out SolverBody solverBody, RigidBody rigidBody) - { - solverBody = new SolverBody(); - solverBody.AngularVelocity = rigidBody.AngularVelocity; - solverBody.CenterOfMassPosition = rigidBody.CenterOfMassPosition; - solverBody.Friction = rigidBody.Friction; - solverBody.InvMass = rigidBody.InverseMass; - solverBody.LinearVelocity = rigidBody.LinearVelocity; - solverBody.OriginalBody = rigidBody; - solverBody.AngularFactor = rigidBody.AngularFactor; - } - - private long Rand2() - { - _seed2 = (1664525L * _seed2 + 1013904223L) & 0xffffffff; - return _seed2; - } - - private int RandInt2(int n) - { - // seems good; xor-fold and modulus - long un = n; - long r = Rand2(); - - // note: probably more aggressive than it needs to be -- might be - // able to get away without one or two of the innermost branches. - if (un <= 0x00010000L) - { - r ^= (r >> 16); - if (un <= 0x00000100L) - { - r ^= (r >> 8); - if (un <= 0x00000010L) - { - r ^= (r >> 4); - if (un <= 0x00000004L) - { - r ^= (r >> 2); - if (un <= 0x00000002L) - { - r ^= (r >> 1); - } - } - } - } - } - return (int)(r % un); - } - - protected struct OrderIndex - { - private int _manifoldIndex; - private int _pointIndex; - - public int ManifoldIndex { get { return _manifoldIndex; } set { _manifoldIndex = value; } } - public int PointIndex { get { return _pointIndex; } set { _pointIndex = value; } } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/Solve2LinearConstraint.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/Solve2LinearConstraint.cs deleted file mode 100644 index e437147b0..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/Solve2LinearConstraint.cs +++ /dev/null @@ -1,188 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - /// - /// constraint class used for lateral tyre friction - /// - public class Solve2LinearConstraint - { - private float _tau; - private float _damping; - - public Solve2LinearConstraint(float tau, float damping) - { - _tau = tau; - _damping = damping; - } - - // solve unilateral constraint (equality, direct method) - public void ResolveUnilateralPairConstraint( - RigidBody body1, RigidBody body2, - Matrix world2A, - Matrix world2B, - Vector3 invInertiaADiag, - float invMassA, - Vector3 linvelA, Vector3 angvelA, - Vector3 rel_posA1, - Vector3 invInertiaBDiag, - float invMassB, - Vector3 linvelB, Vector3 angvelB, - Vector3 rel_posA2, - float depthA, Vector3 normalA, - Vector3 rel_posB1, Vector3 rel_posB2, - float depthB, Vector3 normalB, - out float imp0, out float imp1) - { - imp0 = 0; - imp1 = 0; - - float len = Math.Abs(normalA.Length()) - 1f; - if (Math.Abs(len) >= float.Epsilon) - return; - - BulletDebug.Assert(len < float.Epsilon); - - //this jacobian entry could be re-used for all iterations - JacobianEntry jacA = new JacobianEntry(world2A, world2B, rel_posA1, rel_posA2, normalA, invInertiaADiag, invMassA, - invInertiaBDiag, invMassB); - JacobianEntry jacB = new JacobianEntry(world2A, world2B, rel_posB1, rel_posB2, normalB, invInertiaADiag, invMassA, - invInertiaBDiag, invMassB); - - float vel0 = Vector3.Dot(normalA, body1.GetVelocityInLocalPoint(rel_posA1) - body2.GetVelocityInLocalPoint(rel_posA1)); - float vel1 = Vector3.Dot(normalB, body1.GetVelocityInLocalPoint(rel_posB1) - body2.GetVelocityInLocalPoint(rel_posB1)); - - // btScalar penetrationImpulse = (depth*contactTau*timeCorrection) * massTerm;//jacDiagABInv - float massTerm = 1f / (invMassA + invMassB); - - // calculate rhs (or error) terms - float dv0 = depthA * _tau * massTerm - vel0 * _damping; - float dv1 = depthB * _tau * massTerm - vel1 * _damping; - - float nonDiag = jacA.GetNonDiagonal(jacB, invMassA, invMassB); - float invDet = 1.0f / (jacA.Diagonal * jacB.Diagonal - nonDiag * nonDiag); - - imp0 = dv0 * jacA.Diagonal * invDet + dv1 * -nonDiag * invDet; - imp1 = dv1 * jacB.Diagonal * invDet + dv0 * -nonDiag * invDet; - } - - // solving 2x2 lcp problem (inequality, direct solution ) - public void ResolveBilateralPairConstraint( - RigidBody body1, RigidBody body2, - Matrix world2A, Matrix world2B, - Vector3 invInertiaADiag, - float invMassA, - Vector3 linvelA, Vector3 angvelA, - Vector3 rel_posA1, - Vector3 invInertiaBDiag, - float invMassB, - Vector3 linvelB, Vector3 angvelB, - Vector3 rel_posA2, - float depthA, Vector3 normalA, - Vector3 rel_posB1, Vector3 rel_posB2, - float depthB, Vector3 normalB, - out float imp0, out float imp1) - { - imp0 = 0f; - imp1 = 0f; - - float len = Math.Abs(normalA.Length()) - 1f; - if (Math.Abs(len) >= float.Epsilon) - return; - - BulletDebug.Assert(len < float.Epsilon); - - JacobianEntry jacA = new JacobianEntry(world2A, world2B, rel_posA1, rel_posA2, normalA, invInertiaADiag, invMassA, - invInertiaBDiag, invMassB); - JacobianEntry jacB = new JacobianEntry(world2A, world2B, rel_posB1, rel_posB2, normalB, invInertiaADiag, invMassA, - invInertiaBDiag, invMassB); - - float vel0 = Vector3.Dot(normalA, body1.GetVelocityInLocalPoint(rel_posA1) - body2.GetVelocityInLocalPoint(rel_posA1)); - float vel1 = Vector3.Dot(normalB, body1.GetVelocityInLocalPoint(rel_posB1) - body2.GetVelocityInLocalPoint(rel_posB1)); - - // calculate rhs (or error) terms - float dv0 = depthA * _tau - vel0 * _damping; - float dv1 = depthB * _tau - vel1 * _damping; - - float nonDiag = jacA.GetNonDiagonal(jacB, invMassA, invMassB); - float invDet = 1.0f / (jacA.Diagonal * jacB.Diagonal - nonDiag * nonDiag); - - imp0 = dv0 * jacA.Diagonal * invDet + dv1 * -nonDiag * invDet; - imp1 = dv1 * jacB.Diagonal * invDet + dv0 * -nonDiag * invDet; - - if (imp0 > 0.0f) - { - if (imp1 <= 0.0f) - { - imp1 = 0f; - - // now imp0>0 imp1<0 - imp0 = dv0 / jacA.Diagonal; - if (imp0 < 0.0f) - imp0 = 0f; - } - } - else - { - imp0 = 0f; - - imp1 = dv1 / jacB.Diagonal; - if (imp1 <= 0.0f) - { - imp1 = 0f; - // now imp0>0 imp1<0 - imp0 = dv0 / jacA.Diagonal; - if (imp0 > 0.0f) - { - } - else - { - imp0 = 0f; - } - } - } - } - - //public void ResolveAngularConstraint( - // Matrix invInertiaAWS, - // float invMassA, - // Vector3 linvelA, Vector3 angvelA, - // Vector3 rel_posA1, - // Matrix invInertiaBWS, - // float invMassB, - // Vector3 linvelB, Vector3 angvelB, - // Vector3 rel_posA2, - // float depthA, Vector3 normalA, - // Vector3 rel_posB1, Vector3 rel_posB2, - // float depthB, Vector3 normalB, - // out float imp0, out float imp1) - //{ - // imp0 = 0; - // imp1 = 0; - //} - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/SolverBody.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/SolverBody.cs deleted file mode 100644 index 2727b33b8..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/SolverBody.cs +++ /dev/null @@ -1,78 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; -using System.Runtime.InteropServices; - -namespace XnaDevRu.BulletX.Dynamics -{ - public class SolverBody - { - private Vector3 _centerOfMassPosition = new Vector3(); - private Vector3 _linearVelocity = new Vector3(); - private Vector3 _angularVelocity = new Vector3(); - private RigidBody _originalBody = null; - private float _invMass; - private float _friction; - private float _angularFactor; - - public Vector3 CenterOfMassPosition { get { return _centerOfMassPosition; } set { _centerOfMassPosition = value; } } - public Vector3 LinearVelocity { get { return _linearVelocity; } set { _linearVelocity = value; } } - public Vector3 AngularVelocity { get { return _angularVelocity; } set { _angularVelocity = value; } } - public RigidBody OriginalBody { get { return _originalBody; } set { _originalBody = value; } } - public float InvMass { get { return _invMass; } set { _invMass = value; } } - public float Friction { get { return _friction; } set { _friction = value; } } - public float AngularFactor { get { return _angularFactor; } set { _angularFactor = value; } } - - public void GetVelocityInLocalPoint(Vector3 relPos, out Vector3 velocity) - { - velocity = _linearVelocity + Vector3.Cross(_angularVelocity, relPos); - } - - public void WriteBackVelocity() - { - if (_invMass != 0) - { - _originalBody.LinearVelocity = _linearVelocity; - _originalBody.AngularVelocity = _angularVelocity; - } - } - - public void ReadVelocity() - { - if (_invMass != 0) - { - _linearVelocity = _originalBody.LinearVelocity; - _angularVelocity = _originalBody.AngularVelocity; - } - } - - //Optimization for the iterative solver: avoid calculating constant terms involving inertia, normal, relative position - internal void ApplyImpulse(Vector3 linearComponent, Vector3 angularComponent, float impulseMagnitude) - { - _linearVelocity += linearComponent * impulseMagnitude; - _angularVelocity += angularComponent * impulseMagnitude * _angularFactor; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/SolverConstraint.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/SolverConstraint.cs deleted file mode 100644 index 6ca8f3239..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/SolverConstraint.cs +++ /dev/null @@ -1,77 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; -using System.Runtime.InteropServices; - -namespace XnaDevRu.BulletX.Dynamics -{ - //1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and friction constraints. - public class SolverConstraint - { - private Vector3 _relpos1CrossNormal = new Vector3(); - private Vector3 _relpos2CrossNormal = new Vector3(); - private Vector3 _contactNormal = new Vector3(); - private Vector3 _angularComponentA = new Vector3(); - private Vector3 _angularComponentB = new Vector3(); - - private float _appliedVelocityImpulse; - private int _solverBodyIdA; - int _solverBodyIdB; - private float _friction; - private float _restitution; - private float _jacDiagABInv; - private float _penetration; - private float _appliedImpulse; - - private SolverConstraintType _constraintType = SolverConstraintType.Contact; - private int _frictionIndex; - private int[] _unusedPadding = new int[2]; - - public Vector3 RelPosACrossNormal { get { return _relpos1CrossNormal; } set { _relpos1CrossNormal = value; } } - public Vector3 RelPosBCrossNormal { get { return _relpos2CrossNormal; } set { _relpos2CrossNormal = value; } } - public Vector3 ContactNormal { get { return _contactNormal; } set { _contactNormal = value; } } - public Vector3 AngularComponentA { get { return _angularComponentA; } set { _angularComponentA = value; } } - public Vector3 AngularComponentB { get { return _angularComponentB; } set { _angularComponentB = value; } } - - public float AppliedVelocityImpulse { get { return _appliedVelocityImpulse; } set { _appliedVelocityImpulse = value; } } - public int SolverBodyIdA { get { return _solverBodyIdA; } set { _solverBodyIdA = value; } } - public int SolverBodyIdB { get { return _solverBodyIdB; } set { _solverBodyIdB = value; } } - public float Friction { get { return _friction; } set { _friction = value; } } - public float Restitution { get { return _restitution; } set { _restitution = value; } } - public float JacDiagABInv { get { return _jacDiagABInv; } set { _jacDiagABInv = value; } } - public float Penetration { get { return _penetration; } set { _penetration = value; } } - public float AppliedImpulse { get { return _appliedImpulse; } set { _appliedImpulse = value; } } - - public SolverConstraintType ConstraintType { get { return _constraintType; } set { _constraintType = value; } } - public int FrictionIndex { get { return _frictionIndex; } set { _frictionIndex = value; } } - public int[] UnusedPadding { get { return _unusedPadding; } set { _unusedPadding = value; } } - - public enum SolverConstraintType - { - Contact = 0, - Friction, - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/TypedConstraint.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/TypedConstraint.cs deleted file mode 100644 index 3d1dbcd41..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/ConstraintSolver/TypedConstraint.cs +++ /dev/null @@ -1,88 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - public abstract class TypedConstraint - { - private static RigidBody _fixed = new RigidBody(0, null, null, new Vector3(), 0, 0, 0.5f, 0); - private int _userConstraintType; - private int _userConstraintId; - - private RigidBody _rbA; - private RigidBody _rbB; - private float _appliedImpulse; - - public TypedConstraint() - : this(_fixed, _fixed) { } - - public TypedConstraint(RigidBody rbA) - : this(rbA, _fixed) { } - - public TypedConstraint(RigidBody rbA, RigidBody rbB) - { - _userConstraintType = -1; - _userConstraintId = -1; - _rbA = rbA; - _rbB = rbB; - _appliedImpulse = 0; - - _fixed.SetMassProps(0, new Vector3()); - } - - public virtual RigidBody RigidBodyA { get { return _rbA; } protected set { _rbA = value; } } - public virtual RigidBody RigidBodyB { get { return _rbB; } protected set { _rbB = value; } } - - public float AppliedImpulse { get { return _appliedImpulse; } protected set { _appliedImpulse = value; } } - public int UserConstraintId { get { return _userConstraintId; } set { _userConstraintId = value; } } - public int UserConstraintType { get { return _userConstraintType; } set { _userConstraintType = value; } } - - public abstract void BuildJacobian(); - public abstract void SolveConstraint(float timeStep); - - public static int SortConstraintOnIslandPredicate(TypedConstraint left, TypedConstraint right) - { - int rightIslandID, leftIslandID; - rightIslandID = GetConstraintIslandId(right); - leftIslandID = GetConstraintIslandId(left); - if (leftIslandID < rightIslandID) - return -1; - else - return 1; - return 0; - } - - internal static int GetConstraintIslandId(TypedConstraint lhs) - { - int islandId; - - CollisionObject colObjA = lhs.RigidBodyA; - CollisionObject colObjB = lhs.RigidBodyB; - islandId = colObjA.IslandTag >= 0 ? colObjA.IslandTag : colObjB.IslandTag; - return islandId; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/DiscreteDynamicsWorld.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/DiscreteDynamicsWorld.cs deleted file mode 100644 index 235686bf5..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/DiscreteDynamicsWorld.cs +++ /dev/null @@ -1,790 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - /// - /// DiscreteDynamicsWorld provides discrete rigid body simulation - /// those classes replace the obsolete CcdPhysicsEnvironment/CcdPhysicsController - /// - public class DiscreteDynamicsWorld : DynamicsWorld - { - private static bool _reportMe = true; - - private IConstraintSolver _constraintSolver; - private SimulationIslandManager _islandManager; - private List _constraints = new List(); - private IDebugDraw _debugDrawer; - private ContactSolverInfo _solverInfo = new ContactSolverInfo(); - private Vector3 _gravity; - //for variable timesteps - private float _localTime; - //for variable timesteps - private bool _ownsIslandManager; - private bool _ownsConstraintSolver; - private List _vehicles = new List(); - private int _profileTimings; - - public DiscreteDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache) - : this(dispatcher, pairCache, null) { } - - //this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those - public DiscreteDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache, IConstraintSolver constraintSolver) - : base(dispatcher, pairCache) - { - _constraintSolver = constraintSolver != null ? constraintSolver : new SequentialImpulseConstraintSolver(); - _debugDrawer = null; - _gravity = new Vector3(0, -10, 0); - _localTime = 1f / 60f; - _profileTimings = 0; - _islandManager = new SimulationIslandManager(); - _ownsIslandManager = true; - _ownsConstraintSolver = constraintSolver == null; - } - - public ContactSolverInfo SolverInfo { get { return _solverInfo; } } - public SimulationIslandManager SimulationIslandManager { get { return _islandManager; } } - public CollisionWorld CollisionWorld { get { return this; } } - - public override IDebugDraw DebugDrawer - { - get - { - return _debugDrawer; - } - set - { - _debugDrawer = value; - } - } - - public override Vector3 Gravity - { - set - { - _gravity = value; - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - body.Gravity = value; - } - } - } - } - - public override IConstraintSolver ConstraintSolver - { - set - { - _ownsConstraintSolver = false; - _constraintSolver = value; - } - } - - public override int ConstraintsCount - { - get - { - return _constraints.Count; - } - } - - //if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's - public override void StepSimulation(float timeStep, int maxSubSteps, float fixedTimeStep) - { - int numSimulationSubSteps = 0; - - if (maxSubSteps != 0) - { - //fixed timestep with interpolation - _localTime += timeStep; - if (_localTime >= fixedTimeStep) - { - numSimulationSubSteps = (int)(_localTime / fixedTimeStep); - _localTime -= numSimulationSubSteps * fixedTimeStep; - } - } - else - { - //variable timestep - fixedTimeStep = timeStep; - _localTime = timeStep; - if (Math.Abs(timeStep) < float.Epsilon) - { - numSimulationSubSteps = 0; - maxSubSteps = 0; - } - else - { - numSimulationSubSteps = 1; - maxSubSteps = 1; - } - } - - //process some debugging flags - if (DebugDrawer != null) - { - RigidBody.DisableDeactivation = (DebugDrawer.DebugMode & DebugDrawModes.NoDeactivation) != 0; - } - if (numSimulationSubSteps != 0) - { - - SaveKinematicState(fixedTimeStep); - - //clamp the number of substeps, to prevent simulation grinding spiralling down to a halt - int clampedSimulationSteps = (numSimulationSubSteps > maxSubSteps) ? maxSubSteps : numSimulationSubSteps; - - for (int i = 0; i < clampedSimulationSteps; i++) - { - InternalSingleStepSimulation(fixedTimeStep); - SynchronizeMotionStates(); - } - - } - - SynchronizeMotionStates(); - - //return numSimulationSubSteps; - } - - public void StepSimulation(float timeStep, int maxSubSteps) - { - StepSimulation(timeStep, maxSubSteps, 1f / 60f); - } - - public override void UpdateAabbs() - { - Vector3 colorvec = new Vector3(1, 0, 0); - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - - if (body != null) - { - // if (body->IsActive() && (!body->IsStatic())) - { - Vector3 minAabb, maxAabb; - colObj.CollisionShape.GetAabb(colObj.WorldTransform, out minAabb, out maxAabb); - OverlappingPairCache bp = BroadphasePairCache; - - //moving objects should be moderately sized, probably something wrong if not - if (colObj.IsStaticObject || ((maxAabb - minAabb).LengthSquared() < 1e12f)) - { - bp.SetAabb(body.Broadphase, minAabb, maxAabb); - } - else - { - //something went wrong, investigate - //this assert is unwanted in 3D modelers (danger of loosing work) - BulletDebug.Assert(false); - body.ActivationState = ActivationState.DisableSimulation; - - if (_reportMe) - { - _reportMe = false; - Console.WriteLine("Overflow in AABB, object removed from simulation \n"); - Console.WriteLine("If you can reproduce this, please email bugs@continuousphysics.com\n"); - Console.WriteLine("Please include above information, your Platform, version of OS.\n"); - Console.WriteLine("Thanks.\n"); - } - } - if (_debugDrawer != null && (_debugDrawer.DebugMode & DebugDrawModes.DrawAabb) != 0) - DrawAabb(_debugDrawer, minAabb, maxAabb, colorvec); - } - } - } - } - - public override void AddConstraint(TypedConstraint constraint) - { - _constraints.Add(constraint); - } - - public override void RemoveConstraint(TypedConstraint constraint) - { - _constraints.Remove(constraint); - } - - public void AddVehicle(RaycastVehicle vehicle) - { - _vehicles.Add(vehicle); - } - - public void RemoveVehicle(RaycastVehicle vehicle) - { - _vehicles.Remove(vehicle); - } - - public override void AddRigidBody(RigidBody body) - { - if (!body.IsStaticOrKinematicObject) - { - body.Gravity = _gravity; - } - - if (body.CollisionShape != null) - { - bool isDynamic = !(body.IsStaticObject || body.IsKinematicObject); - BroadphaseProxy.CollisionFilterGroups collisionFilterGroup = isDynamic ? BroadphaseProxy.CollisionFilterGroups.Default : BroadphaseProxy.CollisionFilterGroups.Static; - BroadphaseProxy.CollisionFilterGroups collisionFilterMask = isDynamic ? BroadphaseProxy.CollisionFilterGroups.All : (BroadphaseProxy.CollisionFilterGroups.All ^ BroadphaseProxy.CollisionFilterGroups.Static); - - AddCollisionObject(body, collisionFilterGroup, collisionFilterMask); - } - } - - public override void RemoveRigidBody(RigidBody body) - { - RemoveCollisionObject(body); - } - - public void DebugDrawObject(Matrix worldTransform, CollisionShape shape, Vector3 color) - { - if (shape.ShapeType == BroadphaseNativeTypes.Compound) - { - CompoundShape compoundShape = shape as CompoundShape; - for (int i = compoundShape.ChildShapeCount - 1; i >= 0; i--) - { - Matrix childTrans = compoundShape.GetChildTransform(i); - CollisionShape colShape = compoundShape.GetChildShape(i); - DebugDrawObject(worldTransform * childTrans, colShape, color); - } - - } - else - { - switch (shape.ShapeType) - { - - case BroadphaseNativeTypes.Sphere: - { - SphereShape sphereShape = shape as SphereShape; - float radius = sphereShape.Margin;//radius doesn't include the margin, so draw with margin - Vector3 start = worldTransform.Translation; - DebugDrawer.DrawLine(start, start + Vector3.TransformNormal(new Vector3(radius, 0, 0), worldTransform), color); - DebugDrawer.DrawLine(start, start + Vector3.TransformNormal(new Vector3(0, radius, 0), worldTransform), color); - DebugDrawer.DrawLine(start, start + Vector3.TransformNormal(new Vector3(0, 0, radius), worldTransform), color); - //drawSphere - break; - } - case BroadphaseNativeTypes.MultiSphere: - case BroadphaseNativeTypes.Cone: - { - ConeShape coneShape = shape as ConeShape; - float radius = coneShape.Radius;//+coneShape->getMargin(); - float height = coneShape.Height;//+coneShape->getMargin(); - Vector3 start = worldTransform.Translation; - DebugDrawer.DrawLine(start + Vector3.TransformNormal(new Vector3(0f, 0f, 0.5f * height), worldTransform), start + Vector3.TransformNormal(new Vector3(radius, 0f, -0.5f * height), worldTransform), color); - DebugDrawer.DrawLine(start + Vector3.TransformNormal(new Vector3(0f, 0f, 0.5f * height), worldTransform), start + Vector3.TransformNormal(new Vector3(-radius, 0f, -0.5f * height), worldTransform), color); - DebugDrawer.DrawLine(start + Vector3.TransformNormal(new Vector3(0f, 0f, 0.5f * height), worldTransform), start + Vector3.TransformNormal(new Vector3(0f, radius, -0.5f * height), worldTransform), color); - DebugDrawer.DrawLine(start + Vector3.TransformNormal(new Vector3(0f, 0f, 0.5f * height), worldTransform), start + Vector3.TransformNormal(new Vector3(0f, -radius, -0.5f * height), worldTransform), color); - break; - } - case BroadphaseNativeTypes.Cylinder: - { - CylinderShape cylinder = shape as CylinderShape; - int upAxis = cylinder.UpAxis; - float radius = cylinder.Radius; - float halfHeight = MathHelper.GetElement(cylinder.HalfExtents, upAxis); - Vector3 start = worldTransform.Translation; - Vector3 offsetHeight = new Vector3(); - MathHelper.SetElement(ref offsetHeight, upAxis, halfHeight); - Vector3 offsetRadius = new Vector3(); - MathHelper.SetElement(ref offsetRadius, (upAxis + 1) % 3, radius); - DebugDrawer.DrawLine(start + Vector3.TransformNormal(offsetHeight + offsetRadius, worldTransform), start + Vector3.TransformNormal(-offsetHeight + offsetRadius, worldTransform), color); - DebugDrawer.DrawLine(start + Vector3.TransformNormal(offsetHeight - offsetRadius, worldTransform), start + Vector3.TransformNormal(-offsetHeight - offsetRadius, worldTransform), color); - break; - } - default: - { - if (shape.ShapeType == BroadphaseNativeTypes.TriangleMesh) - { - TriangleMeshShape concaveMesh = shape as TriangleMeshShape; - //btVector3 aabbMax(1e30f,1e30f,1e30f); - //btVector3 aabbMax(100,100,100);//1e30f,1e30f,1e30f); - - //todo pass camera, for some culling - Vector3 aabbMax = new Vector3(1e30f, 1e30f, 1e30f); - Vector3 aabbMin = new Vector3(-1e30f, -1e30f, -1e30f); - - DebugDrawCallback drawCallback = new DebugDrawCallback(DebugDrawer, worldTransform, color); - concaveMesh.ProcessAllTriangles(drawCallback, aabbMin, aabbMax); - } - - if (shape.ShapeType == BroadphaseNativeTypes.ConvexTriangleMesh) - { - ConvexTriangleMeshShape convexMesh = shape as ConvexTriangleMeshShape; - //todo: pass camera for some culling - Vector3 aabbMax = new Vector3(1e30f, 1e30f, 1e30f); - Vector3 aabbMin = new Vector3(-1e30f, -1e30f, -1e30f); - //DebugDrawcallback drawCallback; - DebugDrawCallback drawCallback = new DebugDrawCallback(DebugDrawer, worldTransform, color); - convexMesh.getStridingMesh().InternalProcessAllTriangles(drawCallback, aabbMin, aabbMax); - } - - // for polyhedral shapes - if (shape.IsPolyhedral) - { - PolyhedralConvexShape polyshape = shape as PolyhedralConvexShape; - - for (int i = 0; i < polyshape.EdgeCount; i++) - { - Vector3 a, b; - polyshape.GetEdge(i, out a, out b); - a = Vector3.TransformNormal(a, worldTransform); - b = Vector3.TransformNormal(b, worldTransform); - DebugDrawer.DrawLine(a, b, color); - } - } - break; - } - } - } - } - - public override TypedConstraint GetConstraint(int index) - { - return _constraints[index]; - } - - public static void DrawAabb(IDebugDraw debugDrawer, Vector3 from, Vector3 to, Vector3 color) - { - Vector3 halfExtents = (to - from) * 0.5f; - Vector3 center = (to + from) * 0.5f; - - Vector3 edgecoord = new Vector3(1f, 1f, 1f), pa, pb; - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 3; j++) - { - pa = new Vector3(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, - edgecoord.Z * halfExtents.Z); - pa += center; - - int othercoord = j % 3; - MathHelper.SetElement(ref edgecoord, othercoord, MathHelper.GetElement(edgecoord, othercoord) * -1f); - pb = new Vector3(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, - edgecoord.Z * halfExtents.Z); - pb += center; - - debugDrawer.DrawLine(pa, pb, color); - } - edgecoord = new Vector3(-1f, -1f, -1f); - if (i < 3) - MathHelper.SetElement(ref edgecoord, i, MathHelper.GetElement(edgecoord, i) * -1f); - } - } - - protected void PredictUnconstraintMotion(float timeStep) - { - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - if (!body.IsStaticOrKinematicObject) - { - if (body.IsActive) - { - body.ApplyForces(timeStep); - body.IntegrateVelocities(timeStep); - Matrix temp = body.InterpolationWorldTransform; - body.PredictIntegratedTransform(timeStep, ref temp); - body.InterpolationWorldTransform = temp; - } - } - } - } - } - - protected void IntegrateTransforms(float timeStep) - { - Matrix predictedTrans = new Matrix(); - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - if (body.IsActive && (!body.IsStaticOrKinematicObject)) - { - body.PredictIntegratedTransform(timeStep, ref predictedTrans); - body.ProceedToTransform(predictedTrans); - } - } - } - } - - protected void CalculateSimulationIslands() - { - SimulationIslandManager.UpdateActivationState(this, Dispatcher); - - for (int i = 0; i < _constraints.Count; i++) - { - TypedConstraint constraint = _constraints[i]; - - RigidBody colObj0 = constraint.RigidBodyA; - RigidBody colObj1 = constraint.RigidBodyB; - - if (((colObj0 != null) && (colObj0.MergesSimulationIslands)) && - ((colObj1 != null) && (colObj1.MergesSimulationIslands))) - { - if (colObj0.IsActive || colObj1.IsActive) - { - - SimulationIslandManager.UnionFind.Unite((colObj0).IslandTag, - (colObj1).IslandTag); - } - } - } - - //Store the island id in each body - SimulationIslandManager.StoreIslandActivationState(this); - } - - //protected void SolveNonContactConstraints(ContactSolverInfo solverInfo) - //{ - // //constraint preparation: building jacobians - // for (int i = 0; i < _constraints.Count; i++) - // { - // TypedConstraint constraint = _constraints[i]; - // constraint.BuildJacobian(); - // } - - // //solve the regular non-contact constraints (point 2 point, hinge, generic d6) - // for (int g = 0; g < solverInfo.IterationsCount; g++) - // { - // for (int i = 0; i < _constraints.Count; i++) - // { - // TypedConstraint constraint = _constraints[i]; - // constraint.SolveConstraint(solverInfo.TimeStep); - // } - // } - //} - - //protected void SolveContactConstraints(ContactSolverInfo solverInfo) - //{ - // InplaceSolverIslandCallback solverCallback = new InplaceSolverIslandCallback(solverInfo, _constraintSolver, _debugDrawer); - - // // solve all the contact points and contact friction - // _islandManager.BuildAndProcessIslands(Dispatcher, CollisionObjects, solverCallback); - //} - - protected void SolveConstraints(ContactSolverInfo solverInfo) - { - //sorted version of all btTypedConstraint, based on islandId - List sortedConstraints = new List(ConstraintsCount); - - for (int i = 0; i < ConstraintsCount; i++) - { - sortedConstraints.Add(_constraints[i]); - } - - sortedConstraints.Sort(new Comparison(TypedConstraint.SortConstraintOnIslandPredicate)); - List constraintsPtr = ConstraintsCount != 0 ? sortedConstraints : new List(); - - InplaceSolverIslandCallback solverCallback = new InplaceSolverIslandCallback(solverInfo, _constraintSolver, constraintsPtr, _debugDrawer); - - // solve all the constraints for this island - _islandManager.BuildAndProcessIslands(CollisionWorld.Dispatcher, CollisionWorld.CollisionObjects, solverCallback); - } - - protected void UpdateActivationState(float timeStep) - { - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - body.UpdateDeactivation(timeStep); - - if (body.WantsSleeping()) - { - if (body.IsStaticOrKinematicObject) - { - body.ActivationState = ActivationState.IslandSleeping; - } - else - { - if (body.ActivationState == ActivationState.Active) - body.ActivationState = ActivationState.WantsDeactivation; - } - } - else - { - if (body.ActivationState != ActivationState.DisableDeactivation) - body.ActivationState = ActivationState.Active; - } - } - } - } - - protected void UpdateVehicles(float timeStep) - { - for (int i = 0; i < _vehicles.Count; i++) - { - RaycastVehicle vehicle = _vehicles[i]; - vehicle.updateVehicle(timeStep); - } - } - - protected void StartProfiling(float timeStep) { } - - protected virtual void InternalSingleStepSimulation(float timeStep) - { - StartProfiling(timeStep); - - //update aabbs information - UpdateAabbs(); - - //apply gravity, predict motion - PredictUnconstraintMotion(timeStep); - - DispatcherInfo dispatchInfo = DispatchInfo; - dispatchInfo.TimeStep = timeStep; - dispatchInfo.StepCount = 0; - dispatchInfo.DebugDraw = DebugDrawer; - - //perform collision detection - PerformDiscreteCollisionDetection(); - - CalculateSimulationIslands(); - - SolverInfo.TimeStep = timeStep; - - //solve contact and other joint constraints - SolveConstraints(SolverInfo); - - //CallbackTriggers(); - - //integrate transforms - IntegrateTransforms(timeStep); - - //update vehicle simulation - UpdateVehicles(timeStep); - - UpdateActivationState(timeStep); - } - - protected void SynchronizeMotionStates() - { - //debug vehicle wheels - { - //todo: iterate over awake simulation islands! - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - if (DebugDrawer != null && (DebugDrawer.DebugMode & DebugDrawModes.DrawWireframe) != 0) - { - Vector3 color = new Vector3(255f, 255f, 255f); - switch (colObj.ActivationState) - { - case ActivationState.Active: - color = new Vector3(255f, 255f, 255f); break; - case ActivationState.IslandSleeping: - color = new Vector3(0f, 255f, 0f); break; - case ActivationState.WantsDeactivation: - color = new Vector3(0f, 255f, 255f); break; - case ActivationState.DisableDeactivation: - color = new Vector3(255f, 0f, 0f); break; - case ActivationState.DisableSimulation: - color = new Vector3(255f, 255f, 0f); break; - default: - color = new Vector3(255f, 0f, 0f); break; - } - - DebugDrawObject(colObj.WorldTransform, colObj.CollisionShape, color); - } - RigidBody body = RigidBody.Upcast(colObj); - if (body != null && body.MotionState != null && !body.IsStaticOrKinematicObject) - { - //if (body.ActivationState != ActivationState.IslandSleeping) - { - Matrix interpolatedTransform = new Matrix(); - TransformUtil.IntegrateTransform(body.InterpolationWorldTransform, - body.InterpolationLinearVelocity, body.InterpolationAngularVelocity, _localTime, ref interpolatedTransform); - body.MotionState.SetWorldTransform(interpolatedTransform); - } - } - } - } - - if (DebugDrawer != null && (DebugDrawer.DebugMode & DebugDrawModes.DrawWireframe) != 0) - { - for (int i = 0; i < _vehicles.Count; i++) - { - for (int v = 0; v < _vehicles[i].getNumWheels(); v++) - { - Vector3 wheelColor = new Vector3(0, 255, 255); - if (_vehicles[i].getWheelInfo(v).RaycastInfo.IsInContact) - { - wheelColor = new Vector3(0, 0, 255); - } - else - { - wheelColor = new Vector3(255, 0, 255); - } - - //synchronize the wheels with the (interpolated) chassis worldtransform - _vehicles[i].updateWheelTransform(v, true); - - Vector3 wheelPosWS = _vehicles[i].getWheelInfo(v).WorldTransform.Translation; - - Vector3 axle = new Vector3( - MathHelper.GetElement(_vehicles[i].getWheelInfo(v).WorldTransform, 0, _vehicles[i].getRightAxis()), - MathHelper.GetElement(_vehicles[i].getWheelInfo(v).WorldTransform, 1, _vehicles[i].getRightAxis()), - MathHelper.GetElement(_vehicles[i].getWheelInfo(v).WorldTransform, 2, _vehicles[i].getRightAxis())); - - - //m_vehicles[i]->getWheelInfo(v).m_raycastInfo.m_wheelAxleWS - //debug wheels (cylinders) - _debugDrawer.DrawLine(wheelPosWS, wheelPosWS + axle, wheelColor); - _debugDrawer.DrawLine(wheelPosWS, _vehicles[i].getWheelInfo(v).RaycastInfo.ContactPointWS, wheelColor); - } - } - } - } - - protected void SaveKinematicState(float timeStep) - { - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - if (body.ActivationState != ActivationState.IslandSleeping) - { - if (body.IsKinematicObject) - { - //to calculate velocities next frame - body.SaveKinematicState(timeStep); - } - } - } - } - } - - internal class InplaceSolverIslandCallback : SimulationIslandManager.IIslandCallback - { - private ContactSolverInfo _solverInfo; - private IConstraintSolver _solver; - private IDebugDraw _debugDrawer; - private List _sortedConstraints; - - public InplaceSolverIslandCallback( - ContactSolverInfo solverInfo, - IConstraintSolver solver, - List sortedConstraints, - IDebugDraw debugDrawer) - { - _solverInfo = solverInfo; - _solver = solver; - _sortedConstraints = sortedConstraints; - _debugDrawer = debugDrawer; - } - - public ContactSolverInfo SolverInfo { get { return _solverInfo; } set { _solverInfo = value; } } - public IConstraintSolver Solver { get { return _solver; } set { _solver = value; } } - public List Constraints { get { return _sortedConstraints; } set { _sortedConstraints = value; } } - public IDebugDraw DebugDrawer { get { return _debugDrawer; } set { _debugDrawer = value; } } - - public void ProcessIsland(List bodies, List manifolds, int numManifolds, int islandID) - { - //also add all non-contact constraints/joints for this island - List startConstraint = new List(); - int numCurConstraints = 0; - int startIndex = 0; - int i; - - //find the first constraint for this island - for (i = 0; i < _sortedConstraints.Count; i++) - { - if (TypedConstraint.GetConstraintIslandId(_sortedConstraints[i]) == islandID) - { - //startConstraint = &m_sortedConstraints[i]; - startIndex = i; - break; - } - } - //count the number of constraints in this island - for (; i < _sortedConstraints.Count; i++) - { - if (TypedConstraint.GetConstraintIslandId(_sortedConstraints[i]) == islandID) - { - numCurConstraints++; - } - } - - for (i = startIndex; i < startIndex + numCurConstraints; i++) - { - startConstraint.Add(_sortedConstraints[i]); - } - - _solver.SolveGroup(bodies, manifolds, numManifolds, startConstraint, _solverInfo, _debugDrawer); - } - } - } - - internal class DebugDrawCallback : ITriangleIndexCallback, ITriangleCallback - { - private IDebugDraw _debugDrawer; - private Vector3 _color; - private Matrix _worldTrans; - - public DebugDrawCallback(IDebugDraw debugDrawer, Matrix worldTrans, Vector3 color) - { - _debugDrawer = debugDrawer; - _worldTrans = worldTrans; - _color = color; - } - - public void ProcessTriangleIndex(Vector3[] triangle, int partId, int triangleIndex) - { - ProcessTriangle(triangle, partId, triangleIndex); - } - - #region ITriangleCallback Members - - public void ProcessTriangle(Vector3[] triangle, int partID, int triangleIndex) - { - Vector3 wv0, wv1, wv2; - wv0 = Vector3.TransformNormal(triangle[0], _worldTrans); - wv1 = Vector3.TransformNormal(triangle[1], _worldTrans); - wv2 = Vector3.TransformNormal(triangle[2], _worldTrans); - _debugDrawer.DrawLine(wv0, wv1, _color); - _debugDrawer.DrawLine(wv1, wv2, _color); - _debugDrawer.DrawLine(wv2, wv0, _color); - } - - #endregion - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/DynamicsWorld.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/DynamicsWorld.cs deleted file mode 100644 index cf4d93e89..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/DynamicsWorld.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - public abstract class DynamicsWorld : CollisionWorld - { - public DynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache) - : base(dispatcher, pairCache) { } - - //once a rigidbody is added to the dynamics world, it will get this gravity assigned - //existing rigidbodies in the world get gravity assigned too, during this method - public abstract Vector3 Gravity { set; } - public abstract IConstraintSolver ConstraintSolver { set; } - public virtual int ConstraintsCount { get { return 0; } } - public abstract IDebugDraw DebugDrawer { get; set; } - - //stepSimulation proceeds the simulation over timeStep units - public abstract void StepSimulation(float timeStep, int numSubsteps, float fixedTimeStep); - - public void StepSimulation(float timeStep) - { - StepSimulation(timeStep, 1, 1f / 60f); - } - - public abstract void UpdateAabbs(); - - public virtual void AddConstraint(TypedConstraint constraint) { } - public virtual void RemoveConstraint(TypedConstraint constraint) { } - - public abstract void AddRigidBody(RigidBody body); - public abstract void RemoveRigidBody(RigidBody body); - - public virtual TypedConstraint GetConstraint(int index) { return null; } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/RigidBody.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/RigidBody.cs deleted file mode 100644 index 5746dc374..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/RigidBody.cs +++ /dev/null @@ -1,446 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - public class RigidBody : CollisionObject - { - private static float _linearAirDamping = 1; - //'temporarily' global variables - private static float _rigidBodyDeactivationTime = 2; - private static bool _disableDeactivation = false; - - private static float _linearSleepingThreshold = 0.8f; - private static float _angularSleepingThreshold = 1.0f; - private static int _uniqueId = 0; - - private Matrix _invInertiaTensorWorld; - private Vector3 _linearVelocity; - private Vector3 _angularVelocity; - private float _inverseMass; - private float _angularFactor; - - private Vector3 _gravity; - private Vector3 _invInertiaLocal; - private Vector3 _totalForce; - private Vector3 _totalTorque; - - private float _linearDamping; - private float _angularDamping; - - //m_optionalMotionState allows to automatic synchronize the world transform for active objects - private MotionState _optionalMotionState; - - //for experimental overriding of friction/contact solver func - private ContactSolverType _contactSolverType; - private ContactSolverType _frictionSolverType; - - private int _debugBodyId; - - //Bullet 2.20b has experimental damping code to reduce jitter just before objects fall asleep/deactivate - //doesn't work very well yet (value 0 disabled this damping) - //note there this influences deactivation thresholds! - private float _clippedAngvelThresholdSqr = 0.01f; - private float _clippedLinearThresholdSqr = 0.01f; - - private float _jitterVelocityDampingFactor = 0.7f; - - public RigidBody(float mass, MotionState motionState, CollisionShape collisionShape, Vector3 localInertia, float linearDamping, float angularDamping, float friction, float restitution) - { - _optionalMotionState = motionState; - _angularFactor = 1; - _angularDamping = 0.5f; - - if (motionState != null) - { - motionState.GetWorldTransform(out _worldTransform); - } - else - { - WorldTransform = Matrix.Identity; - } - - InterpolationWorldTransform = WorldTransform; - InterpolationLinearVelocity = new Vector3(); - InterpolationAngularVelocity = new Vector3(); - - //moved to btCollisionObject - Friction = friction; - Restitution = restitution; - - CollisionShape = collisionShape; - _debugBodyId = UniqueID++; - - //m_internalOwner is to allow upcasting from collision object to rigid body - Owner = this; - - SetMassProps(mass, localInertia); - SetDamping(linearDamping, angularDamping); - UpdateInertiaTensor(); - } - - public int DebugBodyID { get { return _debugBodyId; } set { _debugBodyId = value; } } - - public ContactSolverType ContactSolverType { get { return _contactSolverType; } set { _contactSolverType = value; } } - public ContactSolverType FrictionSolverType { get { return _frictionSolverType; } set { _frictionSolverType = value; } } - - public float AngularFactor { get { return _angularFactor; } set { _angularFactor = value; } } - - //is this rigidbody added to a btCollisionWorld/btDynamicsWorld/btBroadphase? - public bool IsInWorld { get { return Broadphase != null; } } - - public Vector3 Gravity - { - get { return _gravity; } - set - { - if (_inverseMass != 0.0f) - { - _gravity = value * (1.0f / _inverseMass); - } - } - } - public Matrix InvInertiaTensorWorld { get { return _invInertiaTensorWorld; } } - public float InverseMass { get { return _inverseMass; } } - public Vector3 InvInertiaDiagLocal { get { return _invInertiaLocal; } set { _invInertiaLocal = value; } } - public Vector3 CenterOfMassPosition { get { return WorldTransform.Translation; } } - public Quaternion Orientation { get { return Quaternion.CreateFromRotationMatrix(WorldTransform); } } - public Matrix CenterOfMassTransform - { - get { return WorldTransform; } - set - { - InterpolationWorldTransform = value; - InterpolationLinearVelocity = LinearVelocity; - InterpolationAngularVelocity = AngularVelocity; - WorldTransform = value; - UpdateInertiaTensor(); - } - } - - public Vector3 LinearVelocity - { - get { return _linearVelocity; } - set - { - if (CollisionFlags == CollisionOptions.StaticObject) - throw new BulletException("Static objects can't have linear velocity!"); - _linearVelocity = value; - } - } - - public Vector3 AngularVelocity - { - get { return _angularVelocity; } - set - { - if (CollisionFlags == CollisionOptions.StaticObject) - throw new BulletException("Static objects can't have angular velocity!"); - _angularVelocity = value; - } - } - - //MotionState allows to automatic synchronize the world transform for active objects - public MotionState MotionState - { - get { return _optionalMotionState; } - set - { - _optionalMotionState = value; - if (_optionalMotionState != null) - value.GetWorldTransform(out _worldTransform); - } - } - - public static float LinearAirDamping { get { return _linearAirDamping; } set { _linearAirDamping = value; } } - public static float RigidBodyDeactivationTime { get { return _rigidBodyDeactivationTime; } set { _rigidBodyDeactivationTime = value; } } - public static bool DisableDeactivation { get { return _disableDeactivation; } set { _disableDeactivation = value; } } - public static float LinearSleepingThreshold { get { return _linearSleepingThreshold; } set { _linearSleepingThreshold = value; } } - public static float AngularSleepingThreshold { get { return _angularSleepingThreshold; } set { _angularSleepingThreshold = value; } } - public static int UniqueID { get { return _uniqueId; } set { _uniqueId = value; } } - - public void ProceedToTransform(Matrix newTrans) - { - CenterOfMassTransform = newTrans; - } - - //to keep collision detection and dynamics separate we don't store a rigidbody pointer - //but a rigidbody is derived from btCollisionObject, so we can safely perform an upcast - public static RigidBody Upcast(CollisionObject colObj) - { - return colObj.Owner as RigidBody; - } - - // continuous collision detection needs prediction - public void PredictIntegratedTransform(float step, ref Matrix predictedTransform) - { - if ((_angularVelocity.LengthSquared() < _clippedAngvelThresholdSqr) && - (_linearVelocity.LengthSquared() < _clippedLinearThresholdSqr)) - { - _angularVelocity *= _jitterVelocityDampingFactor; - _linearVelocity *= _jitterVelocityDampingFactor; - } - - TransformUtil.IntegrateTransform(WorldTransform, _linearVelocity, _angularVelocity, step, ref predictedTransform); - } - - public void SaveKinematicState(float step) - { - //todo: clamp to some (user definable) safe minimum timestep, to limit maximum angular/linear velocities - if (step != 0) - { - //if we use motionstate to synchronize world transforms, get the new kinematic/animated world transform - if (MotionState != null) - MotionState.GetWorldTransform(out _worldTransform); - - TransformUtil.CalculateVelocity(InterpolationWorldTransform, WorldTransform, step, ref _linearVelocity, ref _angularVelocity); - InterpolationLinearVelocity = _linearVelocity; - InterpolationAngularVelocity = _angularVelocity; - InterpolationWorldTransform = WorldTransform; - } - } - - public void ApplyForces(float step) - { - if (IsStaticOrKinematicObject) - return; - - ApplyCentralForce(_gravity); - - _linearVelocity *= (1 - step * LinearAirDamping * _linearDamping) < 0.0f ? 0.0f : (1.0f < (1 - step * LinearAirDamping * _linearDamping) ? 1.0f : (1 - step * LinearAirDamping * _linearDamping)); - _angularVelocity *= (1 - step * _angularDamping) < 0.0f ? 0.0f : (1.0f < (1 - step * _angularDamping) ? 1.0f : (1 - step * _angularDamping)); - - float speed = _linearVelocity.Length(); - if (speed < _linearDamping) - { - float dampVel = 0.005f; - if (speed > dampVel) - { - Vector3 dir = _linearVelocity; - dir.Normalize(); - _linearVelocity -= dir * dampVel; - } - else - { - _linearVelocity = new Vector3(); - } - } - - float angSpeed = _angularVelocity.Length(); - if (angSpeed < _angularDamping) - { - float angDampVel = 0.005f; - if (angSpeed > angDampVel) - { - Vector3 dir = _angularVelocity; - dir.Normalize(); - _angularVelocity -= dir * angDampVel; - } - else - { - _angularVelocity = new Vector3(); - } - } - } - - public void SetDamping(float linDamping, float angDamping) - { - _linearDamping = linDamping < 0.0f ? 0.0f : (1.0f < linDamping ? 1.0f : linDamping); - _angularDamping = angDamping < 0.0f ? 0.0f : (1.0f < angDamping ? 1.0f : angDamping); - } - - public void SetMassProps(float mass, Vector3 inertia) - { - if (mass == 0) - { - CollisionFlags |= CollisionOptions.StaticObject; - _inverseMass = 0; - } - else - { - CollisionFlags &= (~CollisionOptions.StaticObject); - _inverseMass = 1.0f / mass; - } - - _invInertiaLocal = new Vector3(inertia.X != 0.0f ? 1.0f / inertia.X : 0.0f, - inertia.Y != 0.0f ? 1.0f / inertia.Y : 0.0f, - inertia.Z != 0.0f ? 1.0f / inertia.Z : 0.0f); - } - - public void IntegrateVelocities(float step) - { - if (IsStaticOrKinematicObject) - return; - - _linearVelocity += _totalForce * (_inverseMass * step); - _angularVelocity += Vector3.TransformNormal(_totalTorque, _invInertiaTensorWorld) * step; - - float MAX_ANGVEL = Microsoft.Xna.Framework.MathHelper.PiOver2; - /// clamp angular velocity. collision calculations will fail on higher angular velocities - float angvel = _angularVelocity.Length(); - if (angvel * step > MAX_ANGVEL) - { - _angularVelocity *= (MAX_ANGVEL / step) / angvel; - } - - ClearForces(); - } - - public void ApplyCentralForce(Vector3 force) - { - _totalForce += force; - } - - public void ApplyTorque(Vector3 torque) - { - _totalTorque += torque; - } - - public void ApplyForce(Vector3 force, Vector3 rel_pos) - { - ApplyCentralForce(force); - ApplyTorque(Vector3.Cross(rel_pos, force)); - } - - public void ApplyCentralImpulse(Vector3 impulse) - { - _linearVelocity += impulse * _inverseMass; - } - - public void ApplyTorqueImpulse(Vector3 torque) - { - _angularVelocity += Vector3.TransformNormal(torque, _invInertiaTensorWorld); - } - - public void ApplyImpulse(Vector3 impulse, Vector3 rel_pos) - { - if (_inverseMass != 0) - { - ApplyCentralImpulse(impulse); - if (_angularFactor != 0) - ApplyTorqueImpulse(Vector3.Cross(rel_pos, impulse) * _angularFactor); - } - } - - public void InternalApplyImpulse(Vector3 linearComponent, Vector3 angularComponent, float impulseMagnitude) - { - if (_inverseMass != 0) - { - _linearVelocity += linearComponent * impulseMagnitude; - if (_angularFactor != 0) - _angularVelocity += angularComponent * impulseMagnitude * _angularFactor; - } - } - - public void ClearForces() - { - _totalForce = new Vector3(); - _totalTorque = new Vector3(); - } - - public void UpdateInertiaTensor() - { - Matrix temp = WorldTransform; - temp.Translation = Vector3.Zero; - _invInertiaTensorWorld = MatrixOperations.Multiply(MatrixOperations.Scaled(WorldTransform, _invInertiaLocal), Matrix.Transpose(temp)); - } - - public Vector3 GetVelocityInLocalPoint(Vector3 relPos) - { - //we also calculate lin/ang velocity for kinematic objects - return _linearVelocity + Vector3.Cross(_angularVelocity, relPos); - - //for kinematic objects, we could also use use: - // return (m_worldTransform(rel_pos) - m_interpolationWorldTransform(rel_pos)) / m_kinematicTimeStep; - } - - public void Translate(Vector3 v) - { - Matrix m = WorldTransform; - m.Translation += v; - WorldTransform = m; - } - - public void GetAabb(out Vector3 aabbMin, out Vector3 aabbMax) - { - CollisionShape.GetAabb(WorldTransform, out aabbMin, out aabbMax); - } - - public float ComputeImpulseDenominator(Vector3 pos, Vector3 normal) - { - Vector3 r0 = pos - CenterOfMassPosition; - Vector3 c0 = Vector3.Cross(r0, normal); - Vector3 vec = Vector3.Cross(Vector3.TransformNormal(c0, InvInertiaTensorWorld), r0); - - return _inverseMass + Vector3.Dot(normal, vec); - - } - - public float ComputeAngularImpulseDenominator(Vector3 axis) - { - Vector3 vec = Vector3.TransformNormal(axis, InvInertiaTensorWorld); - return Vector3.Dot(axis, vec); - } - - public void UpdateDeactivation(float timeStep) - { - if ((ActivationState == ActivationState.IslandSleeping) || (ActivationState == ActivationState.DisableDeactivation)) - return; - - if ((LinearVelocity.LengthSquared() < LinearSleepingThreshold * LinearSleepingThreshold) && - (AngularVelocity.LengthSquared() < AngularSleepingThreshold * AngularSleepingThreshold)) - { - DeactivationTime += timeStep; - } - else - { - DeactivationTime = 0; - ActivationState = ActivationState.Nothing; - } - - } - - public bool WantsSleeping() - { - - if (ActivationState == ActivationState.DisableDeactivation) - return false; - - //disable deactivation - if (DisableDeactivation || (RigidBodyDeactivationTime == 0)) - return false; - - if ((ActivationState == ActivationState.IslandSleeping) || (ActivationState == ActivationState.WantsDeactivation)) - return true; - - if (DeactivationTime > RigidBodyDeactivationTime) - { - return true; - } - return false; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/SimpleDynamicsWorld.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/SimpleDynamicsWorld.cs deleted file mode 100644 index d57cee9bd..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/SimpleDynamicsWorld.cs +++ /dev/null @@ -1,211 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - public class SimpleDynamicsWorld : DynamicsWorld - { - private IConstraintSolver _constraintSolver; - private bool _ownsConstraintSolver; - private Vector3 _gravity; - private IDebugDraw _debugDrawer; - - /// - /// this btSimpleDynamicsWorld constructor creates dispatcher, broadphase pairCache and constraintSolver - /// - /// - /// - /// - public SimpleDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache, IConstraintSolver constraintSolver) - : base(dispatcher, pairCache) - { - _constraintSolver = constraintSolver; - _ownsConstraintSolver = false; - _gravity = new Vector3(0, 0, -10); - } - - public override Vector3 Gravity - { - set - { - _gravity = value; - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - body.Gravity = value; - } - } - } - } - - public override IConstraintSolver ConstraintSolver - { - set - { - _ownsConstraintSolver = false; - _constraintSolver = value; - } - } - - public override IDebugDraw DebugDrawer - { - get - { - return _debugDrawer; - } - set - { - _debugDrawer = value; - } - } - - public override void StepSimulation(float timeStep, int numSubsteps, float fixedTimeStep) - { - //apply gravity, predict motion - PredictUnconstraintMotion(timeStep); - - DispatcherInfo dispatchInfo = new DispatcherInfo(); - dispatchInfo.TimeStep = timeStep; - dispatchInfo.StepCount = 0; - dispatchInfo.DebugDraw = DebugDrawer; - //perform collision detection - PerformDiscreteCollisionDetection(); - - //solve contact constraints - int numManifolds = Dispatcher.ManifoldCount; - if (numManifolds != 0) - { - - List manifolds = (Dispatcher as CollisionDispatcher).Manifolds; - //int numManifolds = m_dispatcher1.GetNumManifolds(); - ContactSolverInfo infoGlobal = new ContactSolverInfo(); - infoGlobal.TimeStep = timeStep; - - _constraintSolver.SolveGroup(new List(), manifolds, manifolds.Count, new List(), infoGlobal, _debugDrawer); - } - //integrate transforms - IntegrateTransforms(timeStep); - - UpdateAabbs(); - - SynchronizeMotionStates(); - } - - public override void UpdateAabbs() - { - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - if (body.IsActive && (!body.IsStaticObject)) - { - Vector3 minAabb, maxAabb; - colObj.CollisionShape.GetAabb(colObj.WorldTransform, out minAabb, out maxAabb); - IBroadphase bp = Broadphase; - bp.SetAabb(body.Broadphase, minAabb, maxAabb); - } - } - } - } - - public override void AddRigidBody(RigidBody body) - { - body.Gravity = _gravity; - - if (body.CollisionShape != null) - { - AddCollisionObject(body); - } - } - - public override void RemoveRigidBody(RigidBody body) - { - RemoveCollisionObject(body); - } - - public void SynchronizeMotionStates() - { - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null && body.MotionState != null) - { - if (body.ActivationState != ActivationState.IslandSleeping) - { - body.MotionState.SetWorldTransform(body.WorldTransform); - } - } - } - } - - protected void PredictUnconstraintMotion(float timeStep) - { - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - if (!body.IsStaticObject) - { - if (body.IsActive) - { - body.ApplyForces(timeStep); - body.IntegrateVelocities(timeStep); - Matrix temp = body.InterpolationWorldTransform; - body.PredictIntegratedTransform(timeStep, ref temp); - body.InterpolationWorldTransform = temp; - } - } - } - } - } - - protected void IntegrateTransforms(float timeStep) - { - Matrix predictedTrans = Matrix.Identity; - for (int i = 0; i < CollisionObjects.Count; i++) - { - CollisionObject colObj = CollisionObjects[i]; - RigidBody body = RigidBody.Upcast(colObj); - if (body != null) - { - if (body.IsActive && (!body.IsStaticObject)) - { - body.PredictIntegratedTransform(timeStep, ref predictedTrans); - body.ProceedToTransform(predictedTrans); - } - } - } - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/Vehicle/RaycastVehicle.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/Vehicle/RaycastVehicle.cs deleted file mode 100644 index a6022c2ad..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/Vehicle/RaycastVehicle.cs +++ /dev/null @@ -1,94 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - public class RaycastVehicle : TypedConstraint - { - public override void BuildJacobian() - { - throw new Exception("The method or operation is not implemented."); - } - - public override void SolveConstraint(float timeStep) - { - throw new Exception("The method or operation is not implemented."); - } - - public int getNumWheels() - { - throw new Exception("The method or operation is not implemented."); - } - - public WheelInfo getWheelInfo(int v) - { - throw new Exception("The method or operation is not implemented."); - } - - public void updateWheelTransform(int v, bool p) - { - throw new Exception("The method or operation is not implemented."); - } - - public int getRightAxis() - { - throw new Exception("The method or operation is not implemented."); - } - - public void updateVehicle(float timeStep) - { - throw new Exception("The method or operation is not implemented."); - } - } - - public class DefaultVehicleRaycaster : IVehicleRaycaster - { - DynamicsWorld _dynamicsWorld; - - public DefaultVehicleRaycaster(DynamicsWorld world) - { - _dynamicsWorld = world; - } - - public object CastRay(Vector3 from, Vector3 to, out VehicleRaycasterResult result) - { - CollisionWorld.ClosestRayResultCallback rayCallback = new CollisionWorld.ClosestRayResultCallback(from, to); - _dynamicsWorld.RayTest(from, to, rayCallback); - - result = new VehicleRaycasterResult(); - - if (!rayCallback.HasHit) return 0; - RigidBody body = RigidBody.Upcast(rayCallback.CollisionObject); - if (body == null) return 0; - - result.HitPointInWorld = rayCallback.HitPointWorld; - result.HitNormalInWorld = rayCallback.HitNormalWorld; - result.HitNormalInWorld.Normalize(); - result.DistFraction = rayCallback.ClosestHitFraction; - return body; - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/Vehicle/VehicleRaycaster.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/Vehicle/VehicleRaycaster.cs deleted file mode 100644 index 222a52951..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/Vehicle/VehicleRaycaster.cs +++ /dev/null @@ -1,49 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - public interface IVehicleRaycaster - { - object CastRay(Vector3 from, Vector3 to, out VehicleRaycasterResult result); - } - - public class VehicleRaycasterResult - { - private Single _distFraction; - private Vector3 _hitNormalInWorld; - private Vector3 _hitPointInWorld; - - public VehicleRaycasterResult() - { - _distFraction = -1; - } - - public float DistFraction { get { return _distFraction; } set { _distFraction = value; } } - public Vector3 HitNormalInWorld { get { return _hitNormalInWorld; } set { _hitNormalInWorld = value; } } - public Vector3 HitPointInWorld { get { return _hitPointInWorld; } set { _hitPointInWorld = value; } } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/Vehicle/WheelInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/Vehicle/WheelInfo.cs deleted file mode 100644 index 23e307e86..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Dynamics/Vehicle/WheelInfo.cs +++ /dev/null @@ -1,529 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX.Dynamics -{ - public struct WheelInfoConstructionInfo - { - private Vector3 _chassicConnectionCS; - private Vector3 _wheelDirectionCS; - private Vector3 _wheelAxisCS; - - private Single _suspensionRestLength; - private Single _maxSuspensionTravelCm; - private Single _wheelRadius; - private Single _suspensionStiffness; - private Single _wheelsDampingCompression; - private Single _wheelsDampingRelaxation; - private Single _frictionSlip; - - private Boolean _isFrontWheel; - - #region Basic Properties - public Vector3 ChassicConnectionCS - { - get { return _chassicConnectionCS; } - set { _chassicConnectionCS = value; } - } - - public Vector3 WheelDirectionCS - { - get { return _wheelDirectionCS; } - set { _wheelDirectionCS = value; } - } - - public Vector3 WheelAxleCS - { - get { return _wheelAxisCS; } - set { _wheelAxisCS = value; } - } - - - public Single SuspensionRestLength - { - get { return _suspensionRestLength; } - set { _suspensionRestLength = value; } - } - - public Single MaxSuspensionTravelCm - { - get { return _maxSuspensionTravelCm; } - set { _maxSuspensionTravelCm = value; } - } - - public Single WheelRadius - { - get { return _wheelRadius; } - set { _wheelRadius = value; } - } - - - public Single SuspensionStiffness - { - get { return _suspensionStiffness; } - set { _suspensionStiffness = value; } - } - - public Single WheelsDampingCompression - { - get { return _wheelsDampingCompression; } - set { _wheelsDampingCompression = value; } - } - - public Single WheelsDampingRelaxation - { - get { return _wheelsDampingRelaxation; } - set { _wheelsDampingRelaxation = value; } - } - - public Single FrictionSlip - { - get { return _frictionSlip; } - set { _frictionSlip = value; } - } - - - public Boolean IsFrontWheel - { - get { return _isFrontWheel; } - set { _isFrontWheel = value; } - } - #endregion - } - - public struct RaycastInfo - { - private Vector3 _contractNormalWS; - private Vector3 _contractPointWS; - - private Vector3 _hardPointWS; - private Vector3 _wheelDirectionWS; - private Vector3 _wheelAxleWS; - - private Single _suspensionLength; - private Boolean _isInContract; - - #region Basic Properties - public Single SuspensionLength - { - get { return _suspensionLength; } - set { _suspensionLength = value; } - } - - public Boolean IsInContact - { - get { return _isInContract; } - set { _isInContract = value; } - } - - public Vector3 ContactNormalWS - { - get { return _contractNormalWS; } - set { _contractNormalWS = value; } - } - - public Vector3 ContactPointWS - { - get { return _contractPointWS; } - set { _contractPointWS = value; } - } - - public Vector3 HardPointWS - { - get { return _hardPointWS; } - set { _hardPointWS = value; } - } - - public Vector3 WheelDirectionWS - { - get { return _wheelDirectionWS; } - set { _wheelDirectionWS = value; } - } - - public Vector3 WheelAxleWS - { - get { return _wheelAxleWS; } - set { _wheelAxleWS = value; } - } - #endregion - } - - public struct WheelInfo - { - private RaycastInfo _raycastInfo; - - private Matrix _worldTransform; - - private Vector3 _chassicConnectionPointCS; - private Vector3 _wheelDirectionCS; - private Vector3 _wheelAxleCS; - - private Single _suspensionRestLength; - private Single _maxSuspensionTravelCm; - - private Single _wheelsRadius; - private Single _rollInfluence; - private Single _suspensionStiffness; - private Single _wheelsDampingCompression; - private Single _wheelsDampingRelaxation; - private Single _frictionSlip; - private Single _steering; - private Single _rotation; - private Single _deltaRotation; - - private Single _engineForce; - private Single _brake; - private Boolean _isFrontWheel; - - - private Single _clippedInvContactDotSuspension; - private Single _skidInfo; - private Single _wheelsSuspensionForce; - private Single _suspensionRelativeVelocity; - //can be used to store pointer to sync transforms... - private object _clientInfo; - - #region Constructor - public WheelInfo(WheelInfoConstructionInfo constructionInfo) - { - _suspensionRestLength = constructionInfo.SuspensionRestLength; - _maxSuspensionTravelCm = constructionInfo.MaxSuspensionTravelCm; - - _wheelsRadius = constructionInfo.WheelRadius; - _wheelsDampingCompression = constructionInfo.WheelsDampingCompression; - _wheelsDampingRelaxation = constructionInfo.WheelsDampingRelaxation; - _wheelDirectionCS = constructionInfo.WheelDirectionCS; - - _suspensionStiffness = constructionInfo.SuspensionStiffness; - _chassicConnectionPointCS = constructionInfo.ChassicConnectionCS; - - _wheelAxleCS = constructionInfo.WheelAxleCS; - _frictionSlip = constructionInfo.FrictionSlip; - - _clippedInvContactDotSuspension = 0; - _suspensionRelativeVelocity = 0; - _wheelsSuspensionForce = 0; - _skidInfo = 0; - - _steering = 0; - _engineForce = 0; - _rotation = 0; - _rotation = 0; - _deltaRotation = 0; - _brake = 0; - _rollInfluence = 0.1f; - _brake = 0; - _rollInfluence = 0.1f; - - _isFrontWheel = constructionInfo.IsFrontWheel; - - _raycastInfo = default(RaycastInfo); - _worldTransform = default(Matrix); - _clientInfo = null; - } - #endregion - - #region BasicProperties - public object ClientInfo { get { return _clientInfo; } set { _clientInfo = value; } } - - public RaycastInfo RaycastInfo - { - get { return _raycastInfo; } - set { _raycastInfo = value; } - } - - public Matrix WorldTransform - { - get { return _worldTransform; } - set { _worldTransform = value; } - } - - public Vector3 ChassicConnectionPointCS - { - get { return _chassicConnectionPointCS; } - set { _chassicConnectionPointCS = value; } - } - public Vector3 WheelDirectionCS - { - get { return _wheelDirectionCS; } - set { _wheelDirectionCS = value; } - } - public Vector3 WheelAxleCS - { - get { return _wheelAxleCS; } - set { _wheelAxleCS = value; } - } - - public Single SuspensionRestLength - { - get { return _suspensionRestLength; } - set { _suspensionRestLength = value; } - } - - - public Single MaxSuspensionTravelCm - { - get { return _maxSuspensionTravelCm; } - set { _maxSuspensionTravelCm = value; } - } - - public Single WheelsRadius - { - get { return _wheelsRadius; } - set { _wheelsRadius = value; } - } - - public Single SuspensionStiffness - { - get { return _suspensionStiffness; } - set { _suspensionStiffness = value; } - } - - public Single WheelsDampingCompression - { - get { return _wheelsDampingCompression; } - set { _wheelsDampingCompression = value; } - } - - public Single WheelsDampingRelaxation - { - get { return _wheelsDampingRelaxation; } - set { _wheelsDampingRelaxation = value; } - } - - public Single FrictionSlip - { - get { return _frictionSlip; } - set { _frictionSlip = value; } - } - - public Single Steering - { - get { return _steering; } - set { _steering = value; } - } - - public Single Rotation - { - get { return _rotation; } - set { _rotation = value; } - } - - public Single DeltaRotation - { - get { return _deltaRotation; } - set { _deltaRotation = value; } - } - - public Single RollInfluence - { - get { return _rollInfluence; } - set { _rollInfluence = value; } - } - - public Single EngineForce - { - get { return _engineForce; } - set { _engineForce = value; } - } - - public Single Brake - { - get { return _brake; } - set { _brake = value; } - } - - public Boolean IsFrontWheel - { - get { return _isFrontWheel; } - set { _isFrontWheel = value; } - } - - public Single ClippedInvContactDotSuspension - { - get { return _clippedInvContactDotSuspension; } - set { _clippedInvContactDotSuspension = value; } - } - - public Single SuspensionRelativeVelocity - { - get { return _suspensionRelativeVelocity; } - set { _suspensionRelativeVelocity = value; } - } - - public Single WheelsSuspensionForce - { - get { return _wheelsSuspensionForce; } - set { _wheelsSuspensionForce = value; } - } - - public Single SkidInfo - { - get { return _skidInfo; } - set { _skidInfo = value; } - } - #endregion - - /// - /// - /// - /// - /// Not used! - public void UpdateWheel(RigidBody chassis, RaycastInfo paramRaycastInfo) - { - if (_raycastInfo.IsInContact) - { - float project = Vector3.Dot(_raycastInfo.ContactNormalWS, _raycastInfo.WheelDirectionWS); - - Vector3 chassisVelocityAtContactPoint = new Vector3(); - Vector3 relpos = _raycastInfo.ContactPointWS - chassis.CenterOfMassPosition; - chassisVelocityAtContactPoint = chassis.GetVelocityInLocalPoint(relpos); - float projVel = Vector3.Dot(_raycastInfo.ContactNormalWS, chassisVelocityAtContactPoint); - - if (project >= -0.1f) - { - _suspensionRelativeVelocity = 0; - _clippedInvContactDotSuspension = 1.0f / 0.1f; - } - else - { - float inv = -1 / project; - _suspensionRelativeVelocity = projVel * inv; - _clippedInvContactDotSuspension = inv; - } - } - else - { - _raycastInfo.SuspensionLength = _suspensionRestLength; - _suspensionRelativeVelocity = 0.0f; - _raycastInfo.ContactNormalWS = -_raycastInfo.WheelDirectionWS; - _clippedInvContactDotSuspension = 1.0f; - } - } - - // if (m_raycastInfo.m_isInContact) - - //{ - // btScalar project= m_raycastInfo.m_contactNormalWS.dot( m_raycastInfo.m_wheelDirectionWS ); - // btVector3 chassis_velocity_at_contactPoint; - // btVector3 relpos = m_raycastInfo.m_contactPointWS - chassis.getCenterOfMassPosition(); - // chassis_velocity_at_contactPoint = chassis.getVelocityInLocalPoint( relpos ); - // btScalar projVel = m_raycastInfo.m_contactNormalWS.dot( chassis_velocity_at_contactPoint ); - // if ( project >= -0.1f) - // { - // m_suspensionRelativeVelocity = 0.0f; - // m_clippedInvContactDotSuspension = 1.0f / 0.1f; - // } - // else - // { - // btScalar inv = -1.f / project; - // m_suspensionRelativeVelocity = projVel * inv; - // m_clippedInvContactDotSuspension = inv; - // } - - //} - - //else // Not in contact : position wheel in a nice (rest length) position - //{ - // m_raycastInfo.m_suspensionLength = this->getSuspensionRestLength(); - // m_suspensionRelativeVelocity = 0.0f; - // m_raycastInfo.m_contactNormalWS = -m_raycastInfo.m_wheelDirectionWS; - // m_clippedInvContactDotSuspension = 1.0f; - //} - }; - - //btScalar m_clippedInvContactDotSuspension; - //btScalar m_suspensionRelativeVelocity; - //btScalar m_wheelsSuspensionForce; - //btScalar m_skidInfo; - - //void* m_clientInfo;//can be used to store pointer to sync transforms... - - //btWheelInfo(btWheelInfoConstructionInfo& ci) - - //{ - - // m_suspensionRestLength1 = ci.m_suspensionRestLength; - // m_maxSuspensionTravelCm = ci.m_maxSuspensionTravelCm; - - // m_wheelsRadius = ci.m_wheelRadius; - // m_suspensionStiffness = ci.m_suspensionStiffness; - // m_wheelsDampingCompression = ci.m_wheelsDampingCompression; - // m_wheelsDampingRelaxation = ci.m_wheelsDampingRelaxation; - // m_chassisConnectionPointCS = ci.m_chassisConnectionCS; - // m_wheelDirectionCS = ci.m_wheelDirectionCS; - // m_wheelAxleCS = ci.m_wheelAxleCS; - // m_frictionSlip = ci.m_frictionSlip; - // m_steering = 0.f; - // m_engineForce = 0.f; - // m_rotation = 0.f; - // m_deltaRotation = 0.f; - // m_brake = 0.f; - // m_rollInfluence = 0.1f; - // m_bIsFrontWheel = ci.m_bIsFrontWheel; - - //} - - //void updateWheel(const btRigidBody& chassis,RaycastInfo& raycastInfo); - - //btScalar m_clippedInvContactDotSuspension; - //btScalar m_suspensionRelativeVelocity; - ////calculated by suspension - //btScalar m_wheelsSuspensionForce; - //btScalar m_skidInfo; - - //}; - - //struct RaycastInfo - //{ - // //set by raycaster - // btVector3 m_contactNormalWS;//contactnormal - // btVector3 m_contactPointWS;//raycast hitpoint - // btScalar m_suspensionLength; - // btVector3 m_hardPointWS;//raycast starting point - // btVector3 m_wheelDirectionWS; //direction in worldspace - // btVector3 m_wheelAxleWS; // axle in worldspace - // bool m_isInContact; - // void* m_groundObject; //could be general void* ptr - //}; - - //struct btWheelInfoConstructionInfo - //{ - // btVector3 m_chassisConnectionCS; - // btVector3 m_wheelDirectionCS; - // btVector3 m_wheelAxleCS; - // btScalar m_suspensionRestLength; - // btScalar m_maxSuspensionTravelCm; - // btScalar m_wheelRadius; - - // float m_suspensionStiffness; - // float m_wheelsDampingCompression; - // float m_wheelsDampingRelaxation; - // float m_frictionSlip; - // bool m_bIsFrontWheel; - - //}; -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Exceptions/BulletException.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Exceptions/BulletException.cs deleted file mode 100644 index abd488547..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Exceptions/BulletException.cs +++ /dev/null @@ -1,53 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using System.Runtime.Serialization; - -namespace XnaDevRu.BulletX -{ - public class BulletException : Exception - { - internal BulletException() - : base("Bullet Physics Library has thrown an exception.") - { - } - - internal BulletException(string message) - : base(message) - { - } - - internal BulletException(string message, Exception innerException) - : base(message, innerException) - { - } - -#if !XBOX - internal BulletException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } -#endif - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/IDebugDraw.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/IDebugDraw.cs deleted file mode 100644 index c8e786941..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/IDebugDraw.cs +++ /dev/null @@ -1,60 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public enum DebugDrawModes - { - NoDebug = 0, - DrawWireframe = 1, - DrawAabb = 2, - DrawFeaturesText = 4, - DrawContactPoints = 8, - NoDeactivation = 16, - NoHelpText = 32, - DrawText = 64, - ProfileTimings = 128, - EnableSatComparison = 256, - DisableBulletLcp = 512, - EnableCcd = 1024, - MaxDebugDrawMode - } - - public interface IDebugDraw - { - void DrawLine(Vector3 from, Vector3 to, Vector3 color); - - void DrawContactPoint( - Vector3 pointOnB, - Vector3 normalOnB, - float distance, - int lifeTime, - Vector3 color - ); - - DebugDrawModes DebugMode { get; set; } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/DefaultMotionState.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/DefaultMotionState.cs deleted file mode 100644 index ad8759368..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/DefaultMotionState.cs +++ /dev/null @@ -1,66 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - // DefaultMotionState provides a common implementation to synchronize world transforms with offsets - public class DefaultMotionState : MotionState - { - private Matrix _graphicsWorldTransform; - private Matrix _centerOfMassOffset; - private Matrix _startWorldTransform; - private object _userData; - - public DefaultMotionState() - : this(Matrix.Identity, Matrix.Identity) { } - - public DefaultMotionState(Matrix startTransform, Matrix centerOfMassOffset) - { - _graphicsWorldTransform = startTransform; - _centerOfMassOffset = centerOfMassOffset; - _startWorldTransform = startTransform; - } - - public Matrix GraphicsWorldTransform { get { return _graphicsWorldTransform; } set { _graphicsWorldTransform = value; } } - public Matrix CenterOfMassOffset { get { return _centerOfMassOffset; } set { _centerOfMassOffset = value; } } - public Matrix StartWorldTransform { get { return _startWorldTransform; } set { _startWorldTransform = value; } } - public object UserData { get { return _userData; } set { _userData = value; } } - - // synchronizes world transform from user to physics - public override void GetWorldTransform(out Matrix centerOfMassWorldTrans) - { - centerOfMassWorldTrans = MathHelper.InvertMatrix(_centerOfMassOffset) * _graphicsWorldTransform; - } - - // synchronizes world transform from physics to user - // Bullet only calls the update of worldtransform for active objects - public override void SetWorldTransform(Matrix centerOfMassWorldTrans) - { - _graphicsWorldTransform = MatrixOperations.Multiply(centerOfMassWorldTrans, _centerOfMassOffset); - _graphicsWorldTransform.Translation = centerOfMassWorldTrans.Translation; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/MathHelper.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/MathHelper.cs deleted file mode 100644 index 20243bfa4..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/MathHelper.cs +++ /dev/null @@ -1,581 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public static class MathHelper - { - internal const float Sqrt12 = 0.7071067811865475244008443621048490f; - internal const float Infinity = 3.402823466e+38f; - internal const float Epsilon = 1.192092896e-07f; - - public static Vector3 MatrixToVector(Matrix m, Vector3 v) - { - return new Vector3( - Vector3.Dot(new Vector3(m.M11, m.M12, m.M13), v) + m.Translation.X, - Vector3.Dot(new Vector3(m.M21, m.M22, m.M23), v) + m.Translation.Y, - Vector3.Dot(new Vector3(m.M31, m.M32, m.M33), v) + m.Translation.Z - ); - } - - internal static int ClosestAxis(Vector4 v) - { - return MaxAxis(Absolute(v)); - } - - internal static Vector4 Absolute(Vector4 v) - { - return new Vector4(Math.Abs(v.X), Math.Abs(v.Y), Math.Abs(v.Z), Math.Abs(v.W)); - } - - internal static int MaxAxis(Vector4 v) - { - int maxIndex = -1; - float maxVal = float.MinValue; - if (v.X > maxVal) - { - maxIndex = 0; - maxVal = v.X; - } - if (v.Y > maxVal) - { - maxIndex = 1; - maxVal = v.Y; - } - if (v.Z > maxVal) - { - maxIndex = 2; - maxVal = v.Z; - } - if (v.W > maxVal) - { - maxIndex = 3; - maxVal = v.W; - } - - return maxIndex; - } - - internal static int MaxAxis(Vector3 v) - { - return v.X < v.Y ? (v.Y < v.Z ? 2 : 1) : (v.X < v.Z ? 2 : 0); - } - - // conservative test for overlap between two aabbs - internal static bool TestAabbAgainstAabb2(Vector3 aabbMinA, Vector3 aabbMaxA, Vector3 aabbMinB, Vector3 aabbMaxB) - { - bool overlap = true; - overlap = (aabbMinA.X > aabbMaxB.X || aabbMaxA.X < aabbMinB.X) ? false : overlap; - overlap = (aabbMinA.Z > aabbMaxB.Z || aabbMaxA.Z < aabbMinB.Z) ? false : overlap; - overlap = (aabbMinA.Y > aabbMaxB.Y || aabbMaxA.Y < aabbMinB.Y) ? false : overlap; - return overlap; - } - - internal static bool TestTriangleAgainstAabb2(Vector3[] vertices, Vector3 aabbMin, Vector3 aabbMax) - { - Vector3 p1 = vertices[0]; - Vector3 p2 = vertices[1]; - Vector3 p3 = vertices[2]; - - if (Math.Min(Math.Min(p1.X, p2.X), p3.X) > aabbMax.X) return false; - if (Math.Max(Math.Max(p1.X, p2.X), p3.X) < aabbMin.X) return false; - - if (Math.Min(Math.Min(p1.Z, p2.Z), p3.Z) > aabbMax.Z) return false; - if (Math.Max(Math.Max(p1.Z, p2.Z), p3.Z) < aabbMin.Z) return false; - - if (Math.Min(Math.Min(p1.Y, p2.Y), p3.Y) > aabbMax.Y) return false; - if (Math.Max(Math.Max(p1.Y, p2.Y), p3.Y) < aabbMin.Y) return false; - return true; - } - - internal static void SetInterpolate3(Vector3 vA, Vector3 vB, float rt, ref Vector3 interpolated) - { - float s = 1.0f - rt; - interpolated.X = s * vA.X + rt * vB.X; - interpolated.Y = s * vA.Y + rt * vB.Y; - interpolated.Z = s * vA.Z + rt * vB.Z; - } - - internal static void PlaneSpace1(Vector3 n, ref Vector3 p, ref Vector3 q) - { - if (Math.Abs(n.Z) > Sqrt12) - { - // choose p in y-z plane - float a = n.Y * n.Y + n.Z * n.Z; - float k = 1f / (float)Math.Sqrt(a); - p.X = 0; - p.Y = -n.Z * k; - p.Z = n.Y * k; - // set q = n x p - q.X = a * k; - q.Y = -n.X * p.Z; - q.Z = n.X * p.Y; - } - else - { - // choose p in x-y plane - float a = n.X * n.X + n.Y * n.Y; - float k = 1f / (float)Math.Sqrt(a); - p.X = -n.Y * k; - p.Y = n.X * k; - p.Z = 0; - // set q = n x p - q.X = -n.Z * p.Y; - q.Y = n.Z * p.X; - q.Z = a * k; - } - } - - internal static bool RayAabb(Vector3 rayFrom, - Vector3 rayTo, - Vector3 aabbMin, - Vector3 aabbMax, - float param, Vector3 normal) - { - Vector3 aabbHalfExtent = (aabbMax - aabbMin) * 0.5f; - Vector3 aabbCenter = (aabbMax + aabbMin) * 0.5f; - Vector3 source = rayFrom - aabbCenter; - Vector3 target = rayTo - aabbCenter; - int sourceOutcode = Outcode(source, aabbHalfExtent); - int targetOutcode = Outcode(target, aabbHalfExtent); - if ((sourceOutcode & targetOutcode) == 0x0) - { - float lambda_enter = 0; - float lambda_exit = param; - Vector3 r = target - source; - float normSign = 1; - Vector3 hitNormal = new Vector3(); - int bit = 1; - - for (int j = 0; j < 2; j++) - { - { - if ((sourceOutcode & bit) != 0) - { - float lambda = (-source.X - aabbHalfExtent.X * normSign) / r.X; - if (lambda_enter <= lambda) - { - lambda_enter = lambda; - hitNormal = new Vector3(); - hitNormal.X = normSign; - } - } - else if ((targetOutcode & bit) != 0) - { - float lambda = (-source.X - aabbHalfExtent.X * normSign) / r.X; - SetMin(ref lambda_exit, lambda); - } - bit <<= 1; - } - { - if ((sourceOutcode & bit) != 0) - { - float lambda = (-source.Y - aabbHalfExtent.Y * normSign) / r.Y; - if (lambda_enter <= lambda) - { - lambda_enter = lambda; - hitNormal = new Vector3(); - hitNormal.Y = normSign; - } - } - else if ((targetOutcode & bit) != 0) - { - float lambda = (-source.Y - aabbHalfExtent.Y * normSign) / r.Y; - SetMin(ref lambda_exit, lambda); - } - bit <<= 1; - } - { - if ((sourceOutcode & bit) != 0) - { - float lambda = (-source.Z - aabbHalfExtent.Z * normSign) / r.Z; - if (lambda_enter <= lambda) - { - lambda_enter = lambda; - hitNormal = new Vector3(); - hitNormal.Z = normSign; - } - } - else if ((targetOutcode & bit) != 0) - { - float lambda = (-source.Z - aabbHalfExtent.Z * normSign) / r.Z; - SetMin(ref lambda_exit, lambda); - } - bit <<= 1; - } - normSign = -1; - } - if (lambda_enter <= lambda_exit) - { - param = lambda_enter; - normal = hitNormal; - return true; - } - } - return false; - } - - internal static void SetMin(ref float a, float b) - { - if (a > b) - a = b; - } - - internal static void SetMax(ref float a, float b) - { - if (a < b) - a = b; - } - - internal static void SetMax(ref Vector3 self, Vector3 other) - { - if (other.X > self.X) - self.X = other.X; - - if (other.Y > self.Y) - self.Y = other.Y; - - if (other.Z > self.Z) - self.Z = other.Z; - } - - internal static Vector3 SetMax(Vector3 self, Vector3 other) - { - if (other.X > self.X) - self.X = other.X; - - if (other.Y > self.Y) - self.Y = other.Y; - - if (other.Z > self.Z) - self.Z = other.Z; - - return self; - } - - internal static void SetMin(ref Vector3 self, Vector3 other) - { - if (other.X < self.X) - self.X = other.X; - - if (other.Y < self.Y) - self.Y = other.Y; - - if (other.Z < self.Z) - self.Z = other.Z; - } - - internal static Vector3 SetMin(Vector3 self, Vector3 other) - { - if (other.X < self.X) - self.X = other.X; - - if (other.Y < self.Y) - self.Y = other.Y; - - if (other.Z < self.Z) - self.Z = other.Z; - - return self; - } - - internal static int Outcode(Vector3 p, Vector3 halfExtent) - { - return (p.X < -halfExtent.X ? 0x01 : 0x0) | - (p.X > halfExtent.X ? 0x08 : 0x0) | - (p.Y < -halfExtent.Y ? 0x02 : 0x0) | - (p.Y > halfExtent.Y ? 0x10 : 0x0) | - (p.Z < -halfExtent.Z ? 0x4 : 0x0) | - (p.Z > halfExtent.Z ? 0x20 : 0x0); - } - - internal static Matrix Absolute(Matrix m) - { - return new Matrix(Math.Abs(m.M11), Math.Abs(m.M12), Math.Abs(m.M13), Math.Abs(m.M14), - Math.Abs(m.M21), Math.Abs(m.M22), Math.Abs(m.M23), Math.Abs(m.M24), - Math.Abs(m.M31), Math.Abs(m.M32), Math.Abs(m.M33), Math.Abs(m.M34), - Math.Abs(m.M41), Math.Abs(m.M42), Math.Abs(m.M43), Math.Abs(m.M44)); - } - - internal static void SetValueByIndex(ref Vector3 v, int i, float value) - { - if (i == 0) - v.X = value; - else if (i == 1) - v.Y = value; - else - v.Z = value; - } - - internal static float GetValueByIndex(Vector3 v, int i) - { - if (i == 0) - return v.X; - else if (i == 1) - return v.Y; - else - return v.Z; - } - - internal static Vector3 InvXForm(Matrix m, Vector3 v) - { - v -= m.Translation; - m.Translation = new Vector3(); - return MathHelper.Transform(v, Matrix.Transpose(m)); - } - - internal static Matrix InverseTimes(Matrix m, Matrix t) - { - Vector3 v = t.Translation - m.Translation; - - Matrix mat = TransposeTimes(m, t); - mat.Translation = Vector3.Transform(v, m); - return mat; - } - - internal static Matrix TransposeTimes(Matrix mA, Matrix mB) - { - return new Matrix( - mA.M11 * mB.M11 + mA.M21 * mB.M21 + mA.M31 * mB.M31, - mA.M11 * mB.M12 + mA.M21 * mB.M22 + mA.M31 * mB.M32, - mA.M11 * mB.M13 + mA.M21 * mB.M23 + mA.M31 * mB.M33, - 0, - mA.M12 * mB.M11 + mA.M22 * mB.M21 + mA.M32 * mB.M31, - mA.M12 * mB.M12 + mA.M22 * mB.M22 + mA.M32 * mB.M32, - mA.M12 * mB.M13 + mA.M22 * mB.M23 + mA.M32 * mB.M33, - 0, - mA.M13 * mB.M11 + mA.M23 * mB.M21 + mA.M33 * mB.M31, - mA.M13 * mB.M12 + mA.M23 * mB.M22 + mA.M33 * mB.M32, - mA.M13 * mB.M13 + mA.M23 * mB.M23 + mA.M33 * mB.M33, - 0, 0, 0, 0, 1); - } - - internal static Vector3 GetColumn(Matrix m, int column) - { - switch (column) - { - case 1: - return new Vector3(m.M11, m.M21, m.M31); - case 2: - return new Vector3(m.M12, m.M22, m.M32); - case 3: - return new Vector3(m.M13, m.M23, m.M33); - default: - throw new ArgumentOutOfRangeException("column"); - } - } - - internal static Vector3 GetRow(Matrix m, int row) - { - switch (row) - { - case 1: - return new Vector3(m.M11, m.M12, m.M13); - case 2: - return new Vector3(m.M21, m.M22, m.M23); - case 3: - return new Vector3(m.M31, m.M32, m.M33); - default: - throw new ArgumentOutOfRangeException("row"); - } - } - - internal static Quaternion GetRotation(Matrix m) - { - float trace = m.M11 + m.M22 + m.M33; - Quaternion q = new Quaternion(); - - if (trace > 0) - { - float s = (float)Math.Sqrt(trace + 1.0f); - q.W = s * 0.5f; - s = 0.5f / s; - - q.X = (m.M32 - m.M23) * s; - q.Y = (m.M13 - m.M31) * s; - q.Z = (m.M21 - m.M12) * s; - } - else - { - int i = m.M11 < m.M22 ? - (m.M22 < m.M33 ? 2 : 1) : - (m.M11 < m.M33 ? 2 : 0); - int j = (i + 1) % 3; - int k = (i + 2) % 3; - - float s = (float)Math.Sqrt(GetElement(m, i, i) - GetElement(m, j, j) - GetElement(m, k, k) + 1.0f); - SetElement(ref q, i, s * 0.5f); - s = 0.5f / s; - - q.W = (GetElement(m, k, j) - GetElement(m, j, k)) * s; - SetElement(ref q, j, (GetElement(m, j, i) + GetElement(m, i, j)) * s); - SetElement(ref q, k, (GetElement(m, k, i) + GetElement(m, i, k)) * s); - } - return q; - } - - internal static float SetElement(ref Quaternion q, int index, float value) - { - switch (index) - { - case 0: - q.X = value; break; - case 1: - q.Y = value; break; - case 2: - q.Z = value; break; - case 3: - q.W = value; break; - } - - return 0; - } - - internal static float GetElement(Quaternion q, int index) - { - switch (index) - { - case 0: - return q.X; - case 1: - return q.Y; - case 2: - return q.Z; - default: - return q.W; - } - } - - internal static float GetElement(Matrix mat, int index) - { - int row = index % 3; - int col = index / 3; - - return GetElement(mat, row, col); - } - - internal static float GetElement(Matrix mat, int row, int col) - { - switch (row) - { - case 0: - switch (col) - { - case 0: - return mat.M11; - case 1: - return mat.M12; - case 2: - return mat.M13; - } break; - case 1: - switch (col) - { - case 0: - return mat.M21; - case 1: - return mat.M22; - case 2: - return mat.M23; - } break; - case 2: - switch (col) - { - case 0: - return mat.M31; - case 1: - return mat.M32; - case 2: - return mat.M33; - } break; - } - - return 0; - } - - internal static float GetElement(Vector3 v, int index) - { - if (index == 0) - return v.X; - if (index == 1) - return v.Y; - if (index == 2) - return v.Z; - - throw new ArgumentOutOfRangeException("index"); - } - - internal static void SetElement(ref Vector3 v, int index, float value) - { - if (index == 0) - v.X = value; - else if (index == 1) - v.Y = value; - else if (index == 2) - v.Z = value; - else - throw new ArgumentOutOfRangeException("index"); - } - - public static Matrix InvertMatrix(Matrix m) - { - Vector3 pos = m.Translation; - m.Translation = Vector3.Zero; - Matrix inv = Matrix.Transpose(m); - pos = Vector3.Transform(-pos, m); - inv.Translation = pos; - return inv; - } - - public static Matrix GetDisplayMatrix(Matrix m) - { - Matrix displayMatrix = m; - displayMatrix.Translation = Vector3.Zero; - displayMatrix = Matrix.Transpose(displayMatrix); - displayMatrix.Translation = m.Translation; - return displayMatrix; - } - - internal static Vector3 Transform(Vector3 position, Matrix matrix) - { - Vector3 vector = new Vector3(); - vector.X = (((position.X * matrix.M11) + (position.Y * matrix.M12)) + (position.Z * matrix.M13)) + matrix.M41; - vector.Y = (((position.X * matrix.M21) + (position.Y * matrix.M22)) + (position.Z * matrix.M23)) + matrix.M42; - vector.Z = (((position.X * matrix.M31) + (position.Y * matrix.M32)) + (position.Z * matrix.M33)) + matrix.M43; - return vector; - } - - internal static Vector3 TransformNormal(Vector3 position, Matrix matrix) - { - Vector3 vector = new Vector3(); - vector.X = (((position.X * matrix.M11) + (position.Y * matrix.M12)) + (position.Z * matrix.M13)); - vector.Y = (((position.X * matrix.M21) + (position.Y * matrix.M22)) + (position.Z * matrix.M23)); - vector.Z = (((position.X * matrix.M31) + (position.Y * matrix.M32)) + (position.Z * matrix.M33)); - return vector; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/MatrixOperations.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/MatrixOperations.cs deleted file mode 100644 index 0d649fa4a..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/MatrixOperations.cs +++ /dev/null @@ -1,116 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - internal static class MatrixOperations - { - public static void SetRotation(ref Matrix m, Quaternion q) - { - float d = q.LengthSquared(); - BulletDebug.Assert(d != 0); - float s = 2f / d; - float xs = q.X * s, ys = q.Y * s, zs = q.Z * s; - float wx = q.W * xs, wy = q.W * ys, wz = q.W * zs; - float xx = q.X * xs, xy = q.X * ys, xz = q.X * zs; - float yy = q.Y * ys, yz = q.Y * zs, zz = q.Z * zs; - m = new Matrix(1 - (yy + zz), xy - wz, xz + wy, 0, - xy + wz, 1 - (xx + zz), yz - wx, 0, - xz - wy, yz + wx, 1 - (xx + yy), 0, - m.M41, m.M42, m.M43, 1); - } - - public static Quaternion GetRotation(Matrix m) - { - Quaternion q = new Quaternion(); - - float trace = m.M11 + m.M22 + m.M33; - - if (trace > 0) - { - float s = (float)Math.Sqrt(trace + 1); - q.W = s * 0.5f; - s = 0.5f / s; - - q.X = (m.M32 - m.M23) * s; - q.Y = (m.M13 - m.M31) * s; - q.Z = (m.M21 - m.M12) * s; - } - else - { - int i = m.M11 < m.M22 ? - (m.M22 < m.M33 ? 2 : 1) : - (m.M11 < m.M33 ? 2 : 0); - int j = (i + 1) % 3; - int k = (i + 2) % 3; - - float s = (float)Math.Sqrt(MathHelper.GetElement(m, i, i) - MathHelper.GetElement(m, j, j) - MathHelper.GetElement(m, k, k) + 1); - MathHelper.SetElement(ref q, i, s * 0.5f); - s = 0.5f / s; - - q.W = (MathHelper.GetElement(m, k, j) - MathHelper.GetElement(m, j, k)) * s; - MathHelper.SetElement(ref q, j, (MathHelper.GetElement(m, j, i) + MathHelper.GetElement(m, i, j)) * s); - MathHelper.SetElement(ref q, k, (MathHelper.GetElement(m, k, i) + MathHelper.GetElement(m, i, k)) * s); - } - - return q; - } - - public static Matrix Scaled(Matrix m, Vector3 v) - { - return new Matrix( m.M11 * v.X, m.M12 * v.Y, m.M13 * v.Z, 0, - m.M21 * v.X, m.M22 * v.Y, m.M23 * v.Z, 0, - m.M31 * v.X, m.M32 * v.Y, m.M33 * v.Z, 0, - 0, 0, 0, 1); - } - - public static Matrix Multiply(Matrix a, Matrix b) - { - /*return btMatrix3x3( - m2.tdot(0, m1[0]), m2.tdot(1, m1[0]), m2.tdot(2, m1[0]), - m2.tdot(0, m1[1]), m2.tdot(1, m1[1]), m2.tdot(2, m1[1]), - m2.tdot(0, m1[2]), m2.tdot(1, m1[2]), m2.tdot(2, m1[2]));*/ - return new Matrix( - Dot(b, 0, MathHelper.GetRow(a, 1)), Dot(b, 1, MathHelper.GetRow(a, 1)), Dot(b, 2, MathHelper.GetRow(a, 1)), 0, - Dot(b, 0, MathHelper.GetRow(a, 2)), Dot(b, 1, MathHelper.GetRow(a, 2)), Dot(b, 2, MathHelper.GetRow(a, 2)), 0, - Dot(b, 0, MathHelper.GetRow(a, 3)), Dot(b, 1, MathHelper.GetRow(a, 3)), Dot(b, 2, MathHelper.GetRow(a, 3)), 0, - 0, 0, 0, 1); - } - - public static float Dot(Matrix m, int c, Vector3 v) - { - return MathHelper.GetElement(m, 0, c) * v.X + MathHelper.GetElement(m, 1, c) * v.Y + MathHelper.GetElement(m, 2, c) * v.Z; - } - - public static Matrix Transpose(Matrix m) - { - return new Matrix( m.M11, m.M21, m.M31, 0, - m.M12, m.M22, m.M32, 0, - m.M13, m.M23, m.M33, 0, - 0, 0, 0, 1); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/MotionState.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/MotionState.cs deleted file mode 100644 index b74adba02..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/MotionState.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public abstract class MotionState - { - /*public abstract Vector3 getWorldPosition(); - public abstract Vector3 getWorldScaling(); - public abstract Quaternion getWorldOrientation(); - - public abstract void setWorldPosition(Vector3 worldPos); - public abstract void setWorldOrientation(Quaternion orn); - - public abstract void calculateWorldTransformations();*/ - - public abstract void GetWorldTransform(out Matrix worldTransform); - //Bullet only calls the update of worldtransform for active objects - public abstract void SetWorldTransform(Matrix worldTransform); - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/QuadWord.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/QuadWord.cs deleted file mode 100644 index 35c9fed40..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/QuadWord.cs +++ /dev/null @@ -1,88 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX.LinearMath -{ - internal abstract class QuadWord - { - private float x; - private float y; - private float z; - private float w; - - public float X { get { return x; } set { x = value; } } - public float Y { get { return y; } set { y = value; } } - public float Z { get { return z; } set { z = value; } } - public float W { get { return w; } set { w = value; } } - - public QuadWord() { } - - public QuadWord(float x, float y, float z, float w) - { - X = x; - Y = y; - Z = z; - W = w; - } - - public QuadWord(float x, float y, float z) - { - X = x; - Y = y; - Z = z; - W = 0; - } - - public void SetMax(QuadWord other) - { - if (other.X > X) - X = other.X; - - if (other.Y > Y) - Y = other.Y; - - if (other.Z > Z) - Z = other.Z; - - if (other.W > W) - W = other.W; - } - - public void SetMin(QuadWord other) - { - if (other.X < X) - X = other.X; - - if (other.Y < Y) - Y = other.Y; - - if (other.Z < Z) - Z = other.Z; - - if (other.W < W) - W = other.W; - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/Quaternion.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/Quaternion.cs deleted file mode 100644 index 8b173ed2b..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/Quaternion.cs +++ /dev/null @@ -1,198 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX.LinearMath -{ - internal class Quaternion : QuadWord - { - public Quaternion() { } - - public Quaternion(float x, float y, float z, float w) - : base(x, y, z, w) { } - - public Quaternion(Vector3 axis, float angle) - { - SetRotation(axis, angle); - } - - public Quaternion(float yaw, float pitch, float roll) - { - SetEuler(yaw, pitch, roll); - } - - public void SetRotation(Vector3 axis, float angle) - { - float d = axis.Length(); - if (d == 0) throw new DivideByZeroException(); - float s = (float)Math.Sin(angle * 0.5f) / d; - X = axis.X * s; - Y = axis.Y * s; - Z = axis.Z * s; - W = (float)Math.Cos(angle * 0.5f); - } - - public void SetEuler(float yaw, float pitch, float roll) - { - float halfYaw = yaw * 0.5f; - float halfPitch = pitch * 0.5f; - float halfRoll = roll * 0.5f; - float cosYaw = (float)Math.Cos(halfYaw); - float sinYaw = (float)Math.Sin(halfYaw); - float cosPitch = (float)Math.Cos(halfPitch); - float sinPitch = (float)Math.Sin(halfPitch); - float cosRoll = (float)Math.Cos(halfRoll); - float sinRoll = (float)Math.Sin(halfRoll); - X = cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw; - Y = cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw; - Z = sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw; - W = cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw; - } - - public float LengthSquared() - { - return Dot(this, this); - } - - public float Length() - { - return (float)Math.Sqrt(LengthSquared()); - } - - public float Angle() - { - return 2f * (float)Math.Acos(W); - } - - public static float Angle(Quaternion a, Quaternion b) - { - float s = (float)Math.Sqrt(a.LengthSquared() * b.LengthSquared()); - if (s == 0) throw new DivideByZeroException(); - return (float)Math.Acos(Dot(a, b) / s); - } - - public static Quaternion Farthest(Quaternion a, Quaternion b) - { - Quaternion diff, sum; - diff = a - b; - sum = a + b; - if (Dot(diff, diff) > Dot(sum, sum)) - return b; - return -b; - } - - public static Quaternion Slerp(Quaternion a, Quaternion b, float c) - { - float theta = Angle(a, b); - if (theta != 0) - { - float d = 1f / (float)Math.Sin(theta); - float s0 = (float)Math.Sin((1f - c) * theta); - float s1 = (float)Math.Sin(c * theta); - return new Quaternion( - (a.X * s0 + b.X * s1) * d, - (a.Y * s0 + b.Y * s1) * d, - (a.Z * s0 + b.Z * s1) * d, - (a.W * s0 + b.W * s1) * d); - } - else - { - return a; - } - } - - public static Quaternion Inverse(Quaternion a) - { - return new Quaternion(a.X, a.Y, a.Z, -a.W); - } - - public static Quaternion Normalize(Quaternion a) - { - return a / a.Length(); - } - - public static float Dot(Quaternion a, Quaternion b) - { - return a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W; - } - - public static Quaternion operator +(Quaternion a, Quaternion b) - { - return new Quaternion(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W); - } - - public static Quaternion operator -(Quaternion a, Quaternion b) - { - return new Quaternion(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W); - } - - public static Quaternion operator -(Quaternion a) - { - return new Quaternion(-a.X, -a.Y, -a.Z, -a.W); - } - - public static Quaternion operator *(Quaternion a, float b) - { - return new Quaternion(a.X * b, a.Y * b, a.Z * b, a.W * b); - } - - public static Quaternion operator *(Quaternion a, Quaternion b) - { - return new Quaternion( - a.W * b.X + a.X * b.W + a.Y * b.Z - a.Z * b.Y, - a.W * b.Y + a.Y * b.W + a.Z * b.X - a.X * b.Z, - a.W * b.Z + a.Z * b.W + a.X * b.Y - a.Y * b.X, - a.W * b.W - a.X * b.X - a.Y * b.Y - a.Z * b.Z); - } - - public static Quaternion operator *(Quaternion a, Vector3 b) - { - return new Quaternion( - a.W * b.X + a.Y * b.Z - a.Z * b.Y, - a.W * b.Y + a.Z * b.X - a.X * b.Z, - a.W * b.Z + a.X * b.Y - a.Y * b.X, - -a.X * b.X - a.Y * b.Y - a.Z * b.Z); - } - - public static Quaternion operator *(Vector3 w, Quaternion q) - { - return new Quaternion( - w.X * q.W + w.Y * q.Z - w.Z * q.Y, - w.Y * q.W + w.Z * q.X - w.X * q.Z, - w.Z * q.W + w.X * q.Y - w.Y * q.X, - -w.X * q.X - w.Y * q.Y - w.Z * q.Z); - } - - public static Quaternion operator /(Quaternion a, float b) - { - if (b == 0) throw new DivideByZeroException(); - return new Quaternion(a.X / b, a.Y / b, a.Z / b, a.W / b); - } - - public static explicit operator Microsoft.Xna.Framework.Quaternion(Quaternion a) - { - return new Microsoft.Xna.Framework.Quaternion(a.X, a.Y, a.Z, a.W); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/TransformUtil.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/TransformUtil.cs deleted file mode 100644 index 8110b2157..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/TransformUtil.cs +++ /dev/null @@ -1,101 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.BulletX -{ - public static class TransformUtil - { - const float AngularMotionTreshold = 0.5f * Microsoft.Xna.Framework.MathHelper.PiOver2; - - public static void IntegrateTransform(Matrix currentTransform, Vector3 linearVelocity, Vector3 angularVelocity, float timeStep, ref Matrix predictedTransform) - { - predictedTransform.Translation = currentTransform.Translation + linearVelocity * timeStep; - //exponential map - Vector3 axis; - float angle = angularVelocity.Length(); - //limit the angular motion - if (angle * timeStep > AngularMotionTreshold) - { - angle = AngularMotionTreshold / timeStep; - } - - if (angle < 0.001f) - { - // use Taylor's expansions of sync function - axis = angularVelocity * (0.5f * timeStep - (timeStep * timeStep * timeStep) * (0.020833333333f) * angle * angle); - } - else - { - // sync(fAngle) = sin(c*fAngle)/t - axis = angularVelocity * ((float)Math.Sin(0.5f * angle * timeStep) / angle); - } - Quaternion dorn = new Quaternion(axis.X, axis.Y, axis.Z, (float)Math.Cos(angle * timeStep * 0.5f)); - Quaternion ornA = MatrixOperations.GetRotation(currentTransform); - - Quaternion predictedOrn = dorn * ornA; - predictedOrn.Normalize(); - - MatrixOperations.SetRotation(ref predictedTransform, predictedOrn); - - Matrix test = Matrix.CreateFromQuaternion(predictedOrn); - } - - public static void CalculateVelocity(Matrix transformA, Matrix transformB, float timeStep, ref Vector3 linearVelocity, ref Vector3 angularVelocity) - { - linearVelocity = (transformB.Translation - transformA.Translation) / timeStep; - Matrix dmat = transformB * MathHelper.InvertMatrix(transformA); - Quaternion dorn = Quaternion.CreateFromRotationMatrix(dmat); - - Vector3 axis; - float angle = 2 * (float)Math.Acos(dorn.W); - axis = new Vector3(dorn.X, dorn.Y, dorn.Z); - //axis[3] = 0.f; - //check for axis length - float len = axis.LengthSquared(); - if (len < MathHelper.Epsilon * MathHelper.Epsilon) - axis = new Vector3(1f, 0f, 0f); - else - axis /= (float)Math.Sqrt(len); - - angularVelocity = axis * angle / timeStep; - } - - public static void CalculateDiffAxisAngle(Matrix transformA, Matrix transformB, out Vector3 axis, out float angle) - { - Matrix dmat = transformB * MathHelper.InvertMatrix(transformA); - Quaternion dorn = MathHelper.GetRotation(dmat); - - angle = 2f * (float)Math.Acos(dorn.W); - axis = new Vector3(dorn.X, dorn.Y, dorn.Z); - //check for axis length - float len = axis.LengthSquared(); - if (len < MathHelper.Epsilon * MathHelper.Epsilon) - axis = new Vector3(1f, 0f, 0f); - else - axis /= (float)Math.Sqrt(len); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/Vector3.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/Vector3.cs deleted file mode 100644 index 9daed6169..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/Vector3.cs +++ /dev/null @@ -1,221 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX.LinearMath -{ - internal class Vector3 : QuadWord - { - public Vector3() { } - - public Vector3(float x, float y, float z) - : base(x, y, z) { } - - public void SetInterpolate3(Vector3 a, Vector3 b, float c) - { - float s = 1.0f - c; - X = s * a.X + c * b.X; - Y = s * a.Y + c * b.Y; - Z = s * a.Z + c * b.Z; - } - - public float LengthSquared() - { - return Dot(this, this); - } - - public float Length() - { - return (float)Math.Sqrt(LengthSquared()); - } - - public int MinAxis() - { - return X < Y ? (X < Z ? 0 : 2) : (Y < Z ? 1 : 2); - } - - public int MaxAxis() - { - return X < Y ? (Y < Z ? 2 : 1) : (X < Z ? 2 : 0); - } - - public int FurthestAxis() - { - return Absolute(this).MinAxis(); - } - - public int ClosestAxis() - { - return Absolute(this).MaxAxis(); - } - - public Vector3 Rotate(Vector3 axis, float angle) - { - Vector3 o = axis * Dot(axis, this); - Vector3 x = this - o; - Vector3 y = Cross(axis, this); - - return (o + x * (float)Math.Cos(angle) + y * (float)Math.Sin(angle)); - } - - public static Vector3 Lerp(Vector3 a, Vector3 b, float c) - { - return new Vector3( - a.X + (b.X - a.X) * c, - a.Y + (b.Y - a.Y) * c, - a.Z + (b.Z - a.Z) * c); - } - - public static float Angle(Vector3 a, Vector3 b) - { - float s = (float)Math.Sqrt(a.LengthSquared() * b.LengthSquared()); - if (s == 0) throw new DivideByZeroException(); - return (float)Math.Acos(Dot(a, b) / s); - } - - public static Vector3 Absolute(Vector3 a) - { - return new Vector3( - Math.Abs(a.X), - Math.Abs(a.Y), - Math.Abs(a.Z)); - } - - public static Vector3 Normalize(Vector3 a) - { - return a / a.Length(); - } - - public static Vector3 Cross(Vector3 a, Vector3 b) - { - return new Vector3( - a.Y * b.Z - a.Z * b.Y, - a.Z * b.X - a.X * b.Z, - a.X * b.Y - a.Y * b.X); - } - - public static float Dot(Vector3 a, Vector3 b) - { - return a.X * b.X + a.Y * b.Y + a.Z * b.Z; - } - - public static float Triple(Vector3 a, Vector3 b, Vector3 c) - { - return a.X * (b.Y * c.Z - b.Z * c.Y) + - a.Y * (b.Z * c.X - b.X * c.Z) + - a.Z * (b.X * c.Y - b.Y * c.X); - } - - public static float Distance(Vector3 a, Vector3 b) - { - return (b - a).Length(); - } - - public static float DistanceSquared(Vector3 a, Vector3 b) - { - return (b - a).LengthSquared(); - } - - public static Vector3 Rotate(Vector3 a, Vector3 axis, float angle) - { - Vector3 o = axis * Dot(axis, a); - Vector3 x = a - o; - Vector3 y = Cross(axis, a); - - return (o + x * (float)Math.Cos(angle) + y * (float)Math.Sin(angle)); - } - - public static Vector3 operator +(Vector3 a, Vector3 b) - { - return new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z); - } - - public static Vector3 operator -(Vector3 a, Vector3 b) - { - return new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z); - } - - public static Vector3 operator -(Vector3 a) - { - return new Vector3(-a.X, -a.Y, -a.Z); - } - - public static Vector3 operator *(float b, Vector3 a) - { - return new Vector3(a.X * b, a.Y * b, a.Z * b); - } - - public static Vector3 operator *(Vector3 a, float b) - { - return new Vector3(a.X * b, a.Y * b, a.Z * b); - } - - public static Vector3 operator *(Vector3 a, Vector3 b) - { - return new Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z); - } - - public static Vector3 operator /(Vector3 a, float b) - { - if (b == 0) throw new DivideByZeroException(); - return new Vector3(a.X / b, a.Y / b, a.Z / b); - } - - public static Vector3 operator /(Vector3 a, Vector3 b) - { - if (b.X == 0 || b.Y == 0 || b.Z == 0) throw new DivideByZeroException(); - return new Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z); - } - - public static bool operator ==(Vector3 a, Vector3 b) - { - return a.X == b.X && a.Y == b.Y && a.Z == b.Z; - } - - public static bool operator !=(Vector3 a, Vector3 b) - { - return a.X != b.X || a.Y != b.Y || a.Z != b.Z; - } - - public static explicit operator Microsoft.Xna.Framework.Vector3(Vector3 a) - { - return new Microsoft.Xna.Framework.Vector3(a.X, a.Y, a.Z); - } - - public override bool Equals(object obj) - { - return object.Equals(this, obj); - } - - public override int GetHashCode() - { - return X.GetHashCode() & Y.GetHashCode() & Z.GetHashCode(); - } - - public override string ToString() - { - return string.Format("{0}, {1}, {2}", X, Y, Z); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/Vector4.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/Vector4.cs deleted file mode 100644 index 416e7d796..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/LinearMath/Vector4.cs +++ /dev/null @@ -1,110 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace XnaDevRu.BulletX.LinearMath -{ - internal class Vector4 : Vector3 - { - public Vector4() { } - - public Vector4(float x, float y, float z, float w) - : base(x, y, z) { W = w; } - - public static Vector4 Absolute4(Vector4 a) - { - return new Vector4( - Math.Abs(a.X), - Math.Abs(a.Y), - Math.Abs(a.Z), - Math.Abs(a.W)); - } - - public int MaxAxis4() - { - int maxIndex = -1; - float maxVal = -1e30f; - if (X > maxVal) - { - maxIndex = 0; - maxVal = X; - } - if (Y > maxVal) - { - maxIndex = 1; - maxVal = Y; - } - if (Z > maxVal) - { - maxIndex = 2; - maxVal = Z; - } - if (W > maxVal) - { - maxIndex = 3; - maxVal = W; - } - - return maxIndex; - } - - public int MinAxis4() - { - int minIndex = -1; - float minVal = 1e30f; - if (X < minVal) - { - minIndex = 0; - minVal = X; - } - if (Y < minVal) - { - minIndex = 1; - minVal = Y; - } - if (Z < minVal) - { - minIndex = 2; - minVal = Z; - } - if (W < minVal) - { - minIndex = 3; - minVal = W; - } - - return minIndex; - } - - public int ClosestAxis4() - { - return Absolute4(this).MaxAxis4(); - } - - public static explicit operator Microsoft.Xna.Framework.Vector4(Vector4 a) - { - return new Microsoft.Xna.Framework.Vector4(a.X, a.Y, a.Z, a.W); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Properties/AssemblyInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Properties/AssemblyInfo.cs deleted file mode 100644 index 838be8852..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("XnaDevRu.BulletX")] -[assembly: AssemblyProduct("Bullet for XNA")] -[assembly: AssemblyDescription("Bullet for XNA")] -[assembly: AssemblyCompany("XNADev.ru")] -[assembly: AssemblyCopyright("Copyright © 2007 XNADev.ru")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("258138a6-4345-461c-9dcd-73cb054e07b8")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("2.50.149.21894")] diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/XnaDebugDrawer.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/XnaDebugDrawer.cs deleted file mode 100644 index 41a4b8b41..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/XnaDebugDrawer.cs +++ /dev/null @@ -1,142 +0,0 @@ -/* - Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru - Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace XnaDevRu.BulletX -{ - public class XnaDebugDraw : IDebugDraw - { - DebugDrawModes _debugDrawModes = DebugDrawModes.NoDebug; - GraphicsDevice _graphicsDevice; - List _vertices = new List(); - VertexPositionColor[] _lineVertices = new VertexPositionColor[2]; - BasicEffect _basicEffect; - - public XnaDebugDraw(GraphicsDevice device) - { - this._graphicsDevice = device; - this._basicEffect = new BasicEffect(device, null); - this._graphicsDevice.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); - } - - public void DrawAabb(Vector3 from, Vector3 to, Vector3 color) - { - Vector3 halfExtents = (to - from) * 0.5f; - Vector3 center = (to + from) * 0.5f; - - Vector3 edgecoord = new Vector3(1f, 1f, 1f), pa, pb; - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 3; j++) - { - pa = new Vector3(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, - edgecoord.Z * halfExtents.Z); - pa += center; - - int othercoord = j % 3; - MathHelper.SetElement(ref edgecoord, othercoord, MathHelper.GetElement(edgecoord, othercoord) * -1f); - pb = new Vector3(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, - edgecoord.Z * halfExtents.Z); - pb += center; - - DrawLine(pa, pb, color); - } - edgecoord = new Vector3(-1f, -1f, -1f); - if (i < 3) - MathHelper.SetElement(ref edgecoord, i, MathHelper.GetElement(edgecoord, i) * -1f); - } - } - - public void Update(Matrix view, Matrix projection) - { - this._basicEffect.AmbientLightColor = new Vector3(1, 1, 1); - - this._basicEffect.View = view; - this._basicEffect.Projection = projection; - } - - /// - /// Put this between effect. - /// - public void DrawAll() - { - this._basicEffect.Begin(); - foreach (EffectPass pass in this._basicEffect.CurrentTechnique.Passes) - { - pass.Begin(); - - if (_vertices.Count > 1) - { - _graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, _vertices.ToArray(), 0, _vertices.Count / 2); - _vertices.Clear(); - } - if (_lineVertices[0] != default(VertexPositionColor)) - _graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, _lineVertices, 0, 1); - - pass.End(); - } - this._basicEffect.End(); - } - - #region IDebugDraw Members - - public void DrawLine(Vector3 from, Vector3 to, Vector3 color) - { - if ((int)_debugDrawModes > 0) - { - this._basicEffect.Begin(); - foreach (EffectPass pass in this._basicEffect.CurrentTechnique.Passes) - { - pass.Begin(); - - _lineVertices[0] = new VertexPositionColor(from, new Color(color)); - _lineVertices[1] = new VertexPositionColor(to, new Color(color)); - - _graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, _lineVertices, 0, 1); - - pass.End(); - } - this._basicEffect.End(); - - } - } - - public void DrawContactPoint(Vector3 pointOnB, Vector3 normalOnB, float distance, int lifeTime, Vector3 color) - { - if ((_debugDrawModes & DebugDrawModes.DrawContactPoints) != 0) - { - Vector3 to = pointOnB + normalOnB * distance; - Vector3 from = pointOnB; - //device.RenderState.PointSize = 10; // TODO: Experiment with this - DrawLine(from, to, color); - } - } - - public DebugDrawModes DebugMode { get { return _debugDrawModes; } set { _debugDrawModes = value; } } - - #endregion - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/XnaDevRu.BulletX.csproj b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/XnaDevRu.BulletX.csproj deleted file mode 100644 index 07a051fc4..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/Source/XnaDevRu.BulletX/XnaDevRu.BulletX.csproj +++ /dev/null @@ -1,534 +0,0 @@ - - - {5BEE189F-47A1-42A8-A297-1960221BE20D} - {9F340DF3-2AED-4330-AC16-78AC2D9B4738};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - Library - Properties - XnaDevRu.BulletX - XnaDevRu.BulletX - v1.0 - Windows - Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll - - - false - BulletX.snk - true - - - true - full - false - ..\..\..\..\Build\x86\Debug\ - DEBUG;TRACE - prompt - 4 - true - false - x86 - - - pdbonly - true - ..\..\..\..\Build\x86\Release\ - TRACE - prompt - 4 - true - false - x86 - - - - False - - - False - - - False - - - False - - - - - false - BulletDebug - - - false - AxisSweep3 - - - false - BroadphaseNativeTypes - - - false - BroadphasePair - - - false - BroadphaseProxy - - - false - CollisionAlgorithm - - - false - CollisionAlgorithmConstructionInfo - - - false - DispatcherInfo - - - false - IBroadphase - - - false - IDispatcher - - - false - IOverlapCallback - - - false - OverlappingPairCache - - - false - SimpleBroadphase - - - false - SimpleBroadphaseProxy - - - false - BridgeTriangleRaycastCallback - - - false - CollisionAlgorithmCreateFunc - - - false - CollisionDispatcher - - - false - CollisionObject - - - false - CollisionPairCallback - - - false - CollisionWorld - - - false - CompoundCollisionAlgorithm - - - false - ConvexConcaveCollisionAlgorithm - - - false - ConvexConvexCollisionAlgorithm - - - false - ConvexTriangleCallback - - - false - EmptyAlgorithm - - - false - ManifoldResult - - - false - SimulationIslandManager - - - false - SphereBoxCollisionAlgorithm - - - false - SphereSphereCollisionAlgorithm - - - false - SphereTriangleCollisionAlgorithm - - - false - SphereTriangleDetector - - - false - UnionFind - - - false - BoxShape - - - false - BUSimplex1to4 - - - false - BvhTriangleMeshShape - - - false - CollisionShape - - - false - CompoundShape - - - false - ConcaveShape - - - false - ConeShape - - - false - ConvexHullShape - - - false - ConvexShape - - - false - ConvexTriangleMeshShape - - - false - CylinderShape - - - false - CylinderShapeX - - - false - CylinderShapeZ - - - false - EmptyShape - - - false - FilteredCallback - - - false - InternalTriangleIndexCallback - - - false - LocalSupportVertexCallback - - - false - MinkowskiSumShape - - - false - MultiSphereShape - - - false - NodeOverlapCallback - - - false - OptimizedBvh - - - false - OptimizedBvhNode - - - false - PolyhedralConvexShape - - - false - SphereShape - - - false - StaticPlaneShape - - - false - StridingMeshInterface - - - false - SupportVertexCallback - - - false - TriangleBuffer - - - false - TriangleCallback - - - false - TriangleIndexVertexArray - - - false - TriangleMesh - - - false - TriangleMeshShape - - - false - TriangleShape - - - false - SolverBody - - - false - SolverConstraint - - - false - BulletException - - - false - DefaultMotionState - - - false - MathHelper - - - false - MatrixOperations - - - false - MotionState - - - false - QuadWord - - - false - Quaternion - - - false - TransformUtil - - - false - Vector3 - - - false - Vector4 - - - false - ContinuousConvexCollision - - - false - ConvexCast - - - false - DiscreteCollisionDetectorInterface - - - false - GjkConvexCast - - - false - GjkEpa - - - false - GjkEpaPenetrationDepthSolver - - - false - GjkEpaSolver - - - false - GjkPairDetector - - - false - IConvexPenetrationDepthSolver - - - false - ISimplexSolver - - - false - ManifoldPoint - - - false - MinkowskiPenetrationDepthSolver - - - false - PersistentManifold - - - false - PointCollector - - - false - SubsimplexConvexCast - - - false - TriangleRaycastCallback - - - false - VoronoiSimplexSolver - - - false - IDebugDraw - - - false - ContactConstraint - - - false - ContactSolverInfo - - - false - Generic6DofConstraint - - - false - HingeConstraint - - - false - IConstraintSolver - - - false - JacobianEntry - - - false - Point2PointConstraint - - - false - SequentialImpulseConstraintSolver - - - false - Solve2LinearConstraint - - - false - TypedConstraint - - - false - DiscreteDynamicsWorld - - - false - DynamicsWorld - - - false - RigidBody - - - false - SimpleDynamicsWorld - - - false - RaycastVehicle - - - false - VehicleRaycaster - - - false - WheelInfo - - - false - AssemblyInfo - - - false - XnaDebugDrawer - - - - - false - BulletX - - - - - - - - - - \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/XnaDevRu.BulletX.sln b/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/XnaDevRu.BulletX.sln deleted file mode 100644 index dcbb334e4..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.BulletX/XnaDevRu.BulletX.sln +++ /dev/null @@ -1,51 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C# Express 2005 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XnaDevRu.BulletX", "Source\XnaDevRu.BulletX\XnaDevRu.BulletX.csproj", "{5BEE189F-47A1-42A8-A297-1960221BE20D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XnaDevRu.BulletX.Demos.Ccd", "Source\XnaDevRu.BulletX.Demos.Ccd\XnaDevRu.BulletX.Demos.Ccd.csproj", "{705FCCF1-44C8-430E-92A9-9987CD3D6A64}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XnaDevRu.BulletX.Demos.Constraints", "Source\XnaDevRu.BulletX.Demos.Constraints\XnaDevRu.BulletX.Demos.Constraints.csproj", "{77ABF9BD-E838-4EF0-BD76-C656C62BC517}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XnaDevRu.Demos", "..\XnaDevRu.Demos\Source\XnaDevRu.Demos\XnaDevRu.Demos.csproj", "{C54AF66D-0C55-4A84-9E7C-FC6346C78681}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XnaDevRu.BulletX.Demos.Basic", "Source\XnaDevRu.BulletX.Demos.Basic\XnaDevRu.BulletX.Demos.Basic.csproj", "{72384342-889C-47B0-B98E-C855D1CE0F41}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XnaDevRu.BulletX.Demos", "Source\XnaDevRu.BulletX.Demos\XnaDevRu.BulletX.Demos.csproj", "{2DF77065-B2FF-4DBB-96BB-A28E09A4A23A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 - Description = XNADev.ru Bullet for XNA - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5BEE189F-47A1-42A8-A297-1960221BE20D}.Debug|x86.ActiveCfg = Debug|x86 - {5BEE189F-47A1-42A8-A297-1960221BE20D}.Debug|x86.Build.0 = Debug|x86 - {5BEE189F-47A1-42A8-A297-1960221BE20D}.Release|x86.ActiveCfg = Release|x86 - {5BEE189F-47A1-42A8-A297-1960221BE20D}.Release|x86.Build.0 = Release|x86 - {705FCCF1-44C8-430E-92A9-9987CD3D6A64}.Debug|x86.ActiveCfg = Debug|x86 - {705FCCF1-44C8-430E-92A9-9987CD3D6A64}.Debug|x86.Build.0 = Debug|x86 - {705FCCF1-44C8-430E-92A9-9987CD3D6A64}.Release|x86.ActiveCfg = Release|x86 - {705FCCF1-44C8-430E-92A9-9987CD3D6A64}.Release|x86.Build.0 = Release|x86 - {77ABF9BD-E838-4EF0-BD76-C656C62BC517}.Debug|x86.ActiveCfg = Debug|x86 - {77ABF9BD-E838-4EF0-BD76-C656C62BC517}.Debug|x86.Build.0 = Debug|x86 - {77ABF9BD-E838-4EF0-BD76-C656C62BC517}.Release|x86.ActiveCfg = Release|x86 - {77ABF9BD-E838-4EF0-BD76-C656C62BC517}.Release|x86.Build.0 = Release|x86 - {C54AF66D-0C55-4A84-9E7C-FC6346C78681}.Debug|x86.ActiveCfg = Debug|x86 - {C54AF66D-0C55-4A84-9E7C-FC6346C78681}.Debug|x86.Build.0 = Debug|x86 - {C54AF66D-0C55-4A84-9E7C-FC6346C78681}.Release|x86.ActiveCfg = Release|x86 - {C54AF66D-0C55-4A84-9E7C-FC6346C78681}.Release|x86.Build.0 = Release|x86 - {72384342-889C-47B0-B98E-C855D1CE0F41}.Debug|x86.ActiveCfg = Debug|x86 - {72384342-889C-47B0-B98E-C855D1CE0F41}.Debug|x86.Build.0 = Debug|x86 - {72384342-889C-47B0-B98E-C855D1CE0F41}.Release|x86.ActiveCfg = Release|x86 - {72384342-889C-47B0-B98E-C855D1CE0F41}.Release|x86.Build.0 = Release|x86 - {2DF77065-B2FF-4DBB-96BB-A28E09A4A23A}.Debug|x86.ActiveCfg = Debug|x86 - {2DF77065-B2FF-4DBB-96BB-A28E09A4A23A}.Debug|x86.Build.0 = Debug|x86 - {2DF77065-B2FF-4DBB-96BB-A28E09A4A23A}.Release|x86.ActiveCfg = Release|x86 - {2DF77065-B2FF-4DBB-96BB-A28E09A4A23A}.Release|x86.Build.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Camera.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Camera.cs deleted file mode 100644 index fc9bce2e1..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Camera.cs +++ /dev/null @@ -1,175 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Input; - -namespace XnaDevRu.Demos -{ - /// - /// First person camera component for the demos, rotated by mouse. - /// - public class Camera : GameComponent - { - private Matrix _view; - private Matrix _projection; - - private Vector3 _position = new Vector3(130, 50, 30); - private Vector2 _angles = Vector2.Zero; - - private int _widthOver2; - private int _heightOver2; - - private float _fieldOfView = Microsoft.Xna.Framework.MathHelper.PiOver4; - private float _aspectRatio; - private float _nearPlaneDistance = 0.1f; - private float _farPlaneDistance = 1000.0f; - - private MouseState _prevMouseState = new MouseState(); - - /// - /// Initializes new camera component. - /// - /// Game to which attach this camera. - public Camera(Game game) - : base(game) - { - _widthOver2 = game.Window.ClientBounds.Width / 2; - _heightOver2 = game.Window.ClientBounds.Height / 2; - _aspectRatio = (float)game.Window.ClientBounds.Width / (float)game.Window.ClientBounds.Height; - UpdateProjection(); - Mouse.SetPosition(_widthOver2, _heightOver2); - } - - /// - /// Gets camera view matrix. - /// - public Matrix View { get { return _view; } } - /// - /// Gets or sets camera projection matrix. - /// - public Matrix Projection { get { return _projection; } set { _projection = value; } } - /// - /// Gets camera view matrix multiplied by projection matrix. - /// - public Matrix ViewProjection { get { return _view * _projection; } } - - /// - /// Gets or sets camera position. - /// - public Vector3 Position { get { return _position; } set { _position = value; } } - - /// - /// Gets or sets camera field of view. - /// - public float FieldOfView { get { return _fieldOfView; } set { _fieldOfView = value; UpdateProjection(); } } - /// - /// Gets or sets camera aspect ratio. - /// - public float AspectRatio { get { return _aspectRatio; } set { _aspectRatio = value; UpdateProjection(); } } - /// - /// Gets or sets camera near plane distance. - /// - public float NearPlaneDistance { get { return _nearPlaneDistance; } set { _nearPlaneDistance = value; UpdateProjection(); } } - /// - /// Gets or sets camera far plane distance. - /// - public float FarPlaneDistance { get { return _farPlaneDistance; } set { _farPlaneDistance = value; UpdateProjection(); } } - - /// - /// Gets or sets camera's target. - /// - public Vector3 Target - { - get - { - Matrix cameraRotation = Matrix.CreateRotationX(_angles.X) * Matrix.CreateRotationY(_angles.Y); - return _position + Vector3.Transform(Vector3.Forward, cameraRotation); - } - set - { - Vector3 forward = Vector3.Normalize(_position - value); - Vector3 right = Vector3.Normalize(Vector3.Cross(forward, Vector3.Up)); - Vector3 up = Vector3.Normalize(Vector3.Cross(right, forward)); - - Matrix test = Matrix.Identity; - test.Forward = forward; - test.Right = right; - test.Up = up; - _angles.X = -(float)Math.Asin(test.M32); - _angles.Y = -(float)Math.Asin(test.M13); - } - } - - /// - /// Updates camera with input and updates view matrix. - /// - /// - public override void Update(GameTime gameTime) - { - if (Enabled) - { - ProcessInput((float)gameTime.ElapsedGameTime.Milliseconds / 30.0f); - UpdateView(); - - base.Update(gameTime); - } - } - - private void ProcessInput(float amountOfMovement) - { - Vector3 moveVector = new Vector3(); - - KeyboardState keys = Keyboard.GetState(); - if (keys.IsKeyDown(Keys.D)) - moveVector.X += amountOfMovement; - if (keys.IsKeyDown(Keys.A)) - moveVector.X -= amountOfMovement; - if (keys.IsKeyDown(Keys.S)) - moveVector.Z += amountOfMovement; - if (keys.IsKeyDown(Keys.W)) - moveVector.Z -= amountOfMovement; - - Matrix cameraRotation = Matrix.CreateRotationX(_angles.X) * Matrix.CreateRotationY(_angles.Y); - _position += Vector3.Transform(moveVector, cameraRotation); - - MouseState currentMouseState = Mouse.GetState(); - - if (currentMouseState.RightButton == ButtonState.Pressed && _prevMouseState.RightButton == ButtonState.Released) - { - Mouse.SetPosition(_widthOver2, _heightOver2); - } - else if (currentMouseState.RightButton == ButtonState.Pressed) - { - if (currentMouseState.X != _widthOver2) - _angles.Y -= amountOfMovement / 80.0f * (currentMouseState.X - _widthOver2); - if (currentMouseState.Y != _heightOver2) - _angles.X -= amountOfMovement / 80.0f * (currentMouseState.Y - _heightOver2); - - if (_angles.X > 1.4) _angles.X = 1.4f; - if (_angles.X < -1.4) _angles.X = -1.4f; - if (_angles.Y > Math.PI) _angles.Y -= 2 * (float)Math.PI; - if (_angles.Y < -Math.PI) _angles.Y += 2 * (float)Math.PI; - - Mouse.SetPosition(_widthOver2, _heightOver2); - } - - _prevMouseState = currentMouseState; - } - - private void UpdateProjection() - { - _projection = Matrix.CreatePerspectiveFieldOfView(_fieldOfView, _aspectRatio, _nearPlaneDistance, _farPlaneDistance); - } - - private void UpdateView() - { - Matrix cameraRotation = Matrix.CreateRotationX(_angles.X) * Matrix.CreateRotationY(_angles.Y); - Vector3 targetPos = _position + Vector3.Transform(Vector3.Forward, cameraRotation); - - Vector3 upVector = Vector3.Transform(Vector3.Up, cameraRotation); - - _view = Matrix.CreateLookAt(_position, targetPos, upVector); - } - } -} diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Demos.snk b/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Demos.snk deleted file mode 100644 index 2d6c672ff..000000000 Binary files a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Demos.snk and /dev/null differ diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Framerate.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Framerate.cs deleted file mode 100644 index e389c0977..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Framerate.cs +++ /dev/null @@ -1,167 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2007, Eric Lebetsamer (http://tehone.com) // -// // -// Permission is hereby granted, free of charge, to any person obtaining a copy // -// of this software and associated documentation files (the "Software"), to deal // -// in the Software without restriction, including without limitation the rights to // -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of // -// the Software, and to permit persons to whom the Software is furnished to do so, // -// subject to the following conditions: // -// // -// The above copyright notice and this permission notice shall be included in all copies // -// or substantial portions of the Software. // -// // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // -// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // -// USE OR OTHER DEALINGS IN THE SOFTWARE. // -////////////////////////////////////////////////////////////////////////////////////////////// - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; - -namespace XnaDevRu.Demos -{ - /// - /// This is a that is used to calculate and display the current framerate (FPS, FramesPerSecond) of the game. - /// - public class Framerate : DrawableGameComponent - { - private double _fps = 0; - private float _elapsedRealTime = 0; - private string _gameWindowTitle; - private ushort _updateFrequency = 1000; - private float _updateFrequencyRatio; - - /// - /// The CurrentFramerate property represents the current frames per second (FPS) for the game. - /// - /// The CurrentFramerate property gets the data member. - public double CurrentFramerate - { - get - { - return _fps; - } - } - - /// - /// The UpdateFrequency property represents, in milliseconds, how often we are updating the count. - /// - /// The UpdateFrequency property gets/sets the data member. - /// - /// This is used to set how often we are calculating the frames per second count. - /// The default value is 1000. - /// - /// This exception will be thrown when the value is set less then 100 or when value is not divisible by 100. - public ushort UpdateFrequency - { - get - { - return _updateFrequency; - } - set - { - if(value % 100 != 0 || value < 100) - throw new ArgumentOutOfRangeException("UpdateFrequency", value, "The UpdateFrequency for the Framerate must is based on milliseconds and must be must be a positive number that is greater then or equal to 100, and the number must be divisable by 100."); - - _updateFrequency = value; - - // Figure out the new ratio, this way we are reporting the correct frames per second even when we are not calculating ever second. - _updateFrequencyRatio = 1000 / (float)_updateFrequency; - } - } - - /// - /// The main constructor for the class. - /// - /// The instance for this to use. - /// Sets the data member to the value of . - public Framerate(Game game) : base(game) - { - // Save the original game window title - _gameWindowTitle = game.Window.Title; - - // We are basing the ratio on 1 second (1000 milliseconds) - _updateFrequencyRatio = 1000 / (float)_updateFrequency; - } - - /// - /// Allows the game component to perform any initialization it needs to before starting - /// to run. This is where it can query for any required services and load content. - /// - public override void Initialize() - { - base.Initialize(); - } - - /// - /// Allows the game component to update itself. - /// - /// Provides a snapshot of timing values. - public override void Update(GameTime gameTime) - { - base.Update(gameTime); - - if (!this.Enabled) - return; - - // The total real time in milliseconds since the last Update(). - float elapsed = (float)gameTime.ElapsedRealTime.TotalMilliseconds; - - // Adds the Update() elapsed real time to the cumulative elapsed real time. - _elapsedRealTime += elapsed; - - // If the elapsed time is greater than our update frequency then: calculate the framerate, and reduce the elapsed real time count. - if(_elapsedRealTime > _updateFrequency) - { - _fps = (_updateFrequency / elapsed) * _updateFrequencyRatio; // calculate the framerate - _elapsedRealTime -= _updateFrequency; // adjust the elapsedRealTime - } - } - - /// - /// This is called when the game should draw itself. - /// - /// Provides a snapshot of timing values. - public override void Draw(GameTime gameTime) - { - base.Draw(gameTime); - - if (!this.Visible || !this.Enabled) - return; - - this.Game.Window.Title = _gameWindowTitle + " FPS: " + _fps.ToString("F"); - } - - /// - /// This method is the for the event. - /// - /// The events sender - /// The events arguments. - protected override void OnEnabledChanged(object sender, EventArgs args) - { - if(!this.Enabled) - this.Game.Window.Title = _gameWindowTitle; - - base.OnEnabledChanged(sender, args); - } - - /// - /// This method is the for the event. - /// - /// The events sender - /// The events arguments. - protected override void OnVisibleChanged(object sender, EventArgs args) - { - if (!this.Visible) - this.Game.Window.Title = _gameWindowTitle; - - base.OnVisibleChanged(sender, args); - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Properties/AssemblyInfo.cs b/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Properties/AssemblyInfo.cs deleted file mode 100644 index 106d2e5df..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("XnaDevRu.Demos")] -[assembly: AssemblyProduct("XnaDevRu.Demos")] -[assembly: AssemblyDescription("XNADev.ru Common Demo Code")] -[assembly: AssemblyCompany("XNADev.ru")] -[assembly: AssemblyCopyright("Copyright © 2007 XNADev.ru")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("73b76cdc-ea3d-46b1-895e-0b906d173b40")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.149.21894")] diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/XnaDevRu.Demos.csproj b/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/XnaDevRu.Demos.csproj deleted file mode 100644 index 6437e44c9..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/Source/XnaDevRu.Demos/XnaDevRu.Demos.csproj +++ /dev/null @@ -1,86 +0,0 @@ - - - {C54AF66D-0C55-4A84-9E7C-FC6346C78681} - {9F340DF3-2AED-4330-AC16-78AC2D9B4738};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - Library - Properties - XnaDevRu.Demos - XnaDevRu.Demos - v1.0 - Windows - Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll;Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll - - - false - Demos.snk - true - - - true - full - false - ..\..\..\..\Build\x86\Debug\ - DEBUG;TRACE - prompt - 4 - true - false - x86 - ..\..\..\..\Build\x86\Debug\XnaDevRu.Demos.XML - - - pdbonly - true - ..\..\..\..\Build\x86\Release\ - TRACE - prompt - 4 - true - false - x86 - ..\..\..\..\Build\x86\Release\XnaDevRu.Demos.XML - - - - False - - - False - - - False - - - False - - - - - false - Camera - - - false - Framerate - - - - - - false - Demos - - - - - - - \ No newline at end of file diff --git a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/XnaDevRu.Demos.sln b/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/XnaDevRu.Demos.sln deleted file mode 100644 index 3de376577..000000000 --- a/Extras/obsolete/BulletX/Source/XnaDevRu.Demos/XnaDevRu.Demos.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C# Express 2005 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XnaDevRu.Demos", "Source\XnaDevRu.Demos\XnaDevRu.Demos.csproj", "{C54AF66D-0C55-4A84-9E7C-FC6346C78681}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C54AF66D-0C55-4A84-9E7C-FC6346C78681}.Debug|x86.ActiveCfg = Debug|x86 - {C54AF66D-0C55-4A84-9E7C-FC6346C78681}.Debug|x86.Build.0 = Debug|x86 - {C54AF66D-0C55-4A84-9E7C-FC6346C78681}.Release|x86.ActiveCfg = Release|x86 - {C54AF66D-0C55-4A84-9E7C-FC6346C78681}.Release|x86.Build.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Extras/obsolete/BulletX/readme.txt b/Extras/obsolete/BulletX/readme.txt deleted file mode 100644 index 1df6f4542..000000000 --- a/Extras/obsolete/BulletX/readme.txt +++ /dev/null @@ -1,20 +0,0 @@ -BulletX is the first fully managed 3D physics engine, it supports Windows and XBox360 platforms -All original C++ code has been rewritten into C#, distributed under the same license (Zlib) - -This is a snapshot from June 6, 2007, the actual development and latest version -http://www.codeplex.com/xnadevru/Wiki/View.aspx?title=Managed%20Bullet%20Physics%20Library - -Credits: -KleMiX, aka Vsevolod Klementjev -raxxla -xnadev - -Developers -b333n -Johnnylightbulb -Knott -NeTBaPb -OSlava -perrs -SolarWind -yulius diff --git a/Extras/obsolete/CSharpWrapper/AssemblyInfo.cpp b/Extras/obsolete/CSharpWrapper/AssemblyInfo.cpp deleted file mode 100644 index 188c8dcb2..000000000 --- a/Extras/obsolete/CSharpWrapper/AssemblyInfo.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//#include "stdafx.h" - -using namespace System; -using namespace System::Reflection; -using namespace System::Runtime::CompilerServices; -using namespace System::Runtime::InteropServices; -using namespace System::Security::Permissions; - -// -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -// -[assembly:AssemblyTitleAttribute("Scea.BulletPhysics")]; -[assembly:AssemblyDescriptionAttribute("managed bullet physics engine C-API library ")]; -[assembly:AssemblyConfigurationAttribute("")]; -[assembly:AssemblyCompanyAttribute("")]; -[assembly:AssemblyProductAttribute("Scea.BulletPhysics")]; -[assembly:AssemblyCopyrightAttribute("Copyright (c) 2008")]; -[assembly:AssemblyTrademarkAttribute("")]; -[assembly:AssemblyCultureAttribute("")]; - -// -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the value or you can default the Revision and Build Numbers -// by using the '*' as shown below: - -[assembly:AssemblyVersionAttribute("1.0.*")]; - -[assembly:ComVisible(false)]; - -[assembly:CLSCompliantAttribute(true)]; - -[assembly:Guid("c3dfa120-9f17-11dd-ad8b-0800200c9a66")] - -[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Extras/obsolete/CSharpWrapper/BulletPhysics.sln b/Extras/obsolete/CSharpWrapper/BulletPhysics.sln deleted file mode 100644 index 5afd30185..000000000 --- a/Extras/obsolete/CSharpWrapper/BulletPhysics.sln +++ /dev/null @@ -1,198 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BulletPhysics", "BulletPhysics.vcproj", "{5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}" - ProjectSection(ProjectDependencies) = postProject - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE} = {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE} - {61BD1097-CF2E-B296-DAA9-73A6FE135319} = {61BD1097-CF2E-B296-DAA9-73A6FE135319} - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A} = {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BulletPhysicsapp", "BulletPhysicsapp.csproj", "{11E65486-3C29-4D36-B488-4E05D9E4B46B}" - ProjectSection(ProjectDependencies) = postProject - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239} = {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbulletmath", "..\..\msvc\8\libbulletmath.vcproj", "{7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbulletcollision", "..\..\msvc\8\libbulletcollision.vcproj", "{6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbulletdynamics", "..\..\msvc\8\libbulletdynamics.vcproj", "{61BD1097-CF2E-B296-DAA9-73A6FE135319}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|Win32 = Debug|Win32 - DebugDll|Any CPU = DebugDll|Any CPU - DebugDll|Mixed Platforms = DebugDll|Mixed Platforms - DebugDll|Win32 = DebugDll|Win32 - DebugDoublePrecision|Any CPU = DebugDoublePrecision|Any CPU - DebugDoublePrecision|Mixed Platforms = DebugDoublePrecision|Mixed Platforms - DebugDoublePrecision|Win32 = DebugDoublePrecision|Win32 - Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms - Release|Win32 = Release|Win32 - ReleaseDll|Any CPU = ReleaseDll|Any CPU - ReleaseDll|Mixed Platforms = ReleaseDll|Mixed Platforms - ReleaseDll|Win32 = ReleaseDll|Win32 - ReleaseDoublePrecision|Any CPU = ReleaseDoublePrecision|Any CPU - ReleaseDoublePrecision|Mixed Platforms = ReleaseDoublePrecision|Mixed Platforms - ReleaseDoublePrecision|Win32 = ReleaseDoublePrecision|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Debug|Win32.ActiveCfg = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Debug|Win32.Build.0 = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDll|Any CPU.ActiveCfg = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDll|Mixed Platforms.ActiveCfg = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDll|Mixed Platforms.Build.0 = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDll|Win32.ActiveCfg = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDll|Win32.Build.0 = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDoublePrecision|Any CPU.ActiveCfg = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDoublePrecision|Mixed Platforms.ActiveCfg = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDoublePrecision|Mixed Platforms.Build.0 = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDoublePrecision|Win32.ActiveCfg = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.DebugDoublePrecision|Win32.Build.0 = Debug|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Release|Any CPU.ActiveCfg = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Release|Mixed Platforms.Build.0 = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Release|Win32.ActiveCfg = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.Release|Win32.Build.0 = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDll|Any CPU.ActiveCfg = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDll|Mixed Platforms.ActiveCfg = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDll|Mixed Platforms.Build.0 = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDll|Win32.ActiveCfg = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDll|Win32.Build.0 = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDoublePrecision|Any CPU.ActiveCfg = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDoublePrecision|Mixed Platforms.ActiveCfg = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDoublePrecision|Mixed Platforms.Build.0 = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDoublePrecision|Win32.ActiveCfg = Release|Win32 - {5EE4C1C4-4C81-46BB-A1C4-416F74BF9239}.ReleaseDoublePrecision|Win32.Build.0 = Release|Win32 - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Debug|Win32.ActiveCfg = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDll|Any CPU.ActiveCfg = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDll|Any CPU.Build.0 = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDll|Mixed Platforms.ActiveCfg = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDll|Mixed Platforms.Build.0 = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDll|Win32.ActiveCfg = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDoublePrecision|Any CPU.ActiveCfg = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDoublePrecision|Any CPU.Build.0 = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDoublePrecision|Mixed Platforms.ActiveCfg = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDoublePrecision|Mixed Platforms.Build.0 = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.DebugDoublePrecision|Win32.ActiveCfg = Debug|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Release|Any CPU.Build.0 = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.Release|Win32.ActiveCfg = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDll|Any CPU.ActiveCfg = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDll|Any CPU.Build.0 = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDll|Mixed Platforms.ActiveCfg = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDll|Mixed Platforms.Build.0 = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDll|Win32.ActiveCfg = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDoublePrecision|Any CPU.ActiveCfg = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDoublePrecision|Any CPU.Build.0 = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDoublePrecision|Mixed Platforms.ActiveCfg = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDoublePrecision|Mixed Platforms.Build.0 = Release|Any CPU - {11E65486-3C29-4D36-B488-4E05D9E4B46B}.ReleaseDoublePrecision|Win32.ActiveCfg = Release|Any CPU - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Debug|Win32.ActiveCfg = Debug|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Debug|Win32.Build.0 = Debug|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDll|Any CPU.ActiveCfg = DebugDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDll|Mixed Platforms.ActiveCfg = DebugDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDll|Mixed Platforms.Build.0 = DebugDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDll|Win32.ActiveCfg = DebugDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDll|Win32.Build.0 = DebugDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDoublePrecision|Any CPU.ActiveCfg = DebugDoublePrecision|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDoublePrecision|Mixed Platforms.ActiveCfg = DebugDoublePrecision|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDoublePrecision|Mixed Platforms.Build.0 = DebugDoublePrecision|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDoublePrecision|Win32.ActiveCfg = DebugDoublePrecision|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.DebugDoublePrecision|Win32.Build.0 = DebugDoublePrecision|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Release|Any CPU.ActiveCfg = Release|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Release|Mixed Platforms.Build.0 = Release|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Release|Win32.ActiveCfg = Release|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.Release|Win32.Build.0 = Release|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDll|Any CPU.ActiveCfg = ReleaseDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDll|Mixed Platforms.ActiveCfg = ReleaseDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDll|Mixed Platforms.Build.0 = ReleaseDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDll|Win32.ActiveCfg = ReleaseDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDll|Win32.Build.0 = ReleaseDll|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDoublePrecision|Any CPU.ActiveCfg = ReleaseDoublePrecision|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDoublePrecision|Mixed Platforms.ActiveCfg = ReleaseDoublePrecision|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDoublePrecision|Mixed Platforms.Build.0 = ReleaseDoublePrecision|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDoublePrecision|Win32.ActiveCfg = ReleaseDoublePrecision|Win32 - {7D6E339F-9C2C-31DA-FDB0-5EE50973CF2A}.ReleaseDoublePrecision|Win32.Build.0 = ReleaseDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Debug|Win32.ActiveCfg = Debug|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Debug|Win32.Build.0 = Debug|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDll|Any CPU.ActiveCfg = DebugDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDll|Mixed Platforms.ActiveCfg = DebugDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDll|Mixed Platforms.Build.0 = DebugDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDll|Win32.ActiveCfg = DebugDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDll|Win32.Build.0 = DebugDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDoublePrecision|Any CPU.ActiveCfg = DebugDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDoublePrecision|Mixed Platforms.ActiveCfg = DebugDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDoublePrecision|Mixed Platforms.Build.0 = DebugDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDoublePrecision|Win32.ActiveCfg = DebugDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.DebugDoublePrecision|Win32.Build.0 = DebugDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Release|Any CPU.ActiveCfg = Release|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Release|Mixed Platforms.Build.0 = Release|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Release|Win32.ActiveCfg = Release|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.Release|Win32.Build.0 = Release|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDll|Any CPU.ActiveCfg = ReleaseDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDll|Mixed Platforms.ActiveCfg = ReleaseDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDll|Mixed Platforms.Build.0 = ReleaseDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDll|Win32.ActiveCfg = ReleaseDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDll|Win32.Build.0 = ReleaseDll|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDoublePrecision|Any CPU.ActiveCfg = ReleaseDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDoublePrecision|Mixed Platforms.ActiveCfg = ReleaseDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDoublePrecision|Mixed Platforms.Build.0 = ReleaseDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDoublePrecision|Win32.ActiveCfg = ReleaseDoublePrecision|Win32 - {6ADA430D-009C-2ED4-A787-2AC2D6FEB8CE}.ReleaseDoublePrecision|Win32.Build.0 = ReleaseDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Debug|Win32.ActiveCfg = Debug|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Debug|Win32.Build.0 = Debug|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDll|Any CPU.ActiveCfg = DebugDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDll|Mixed Platforms.ActiveCfg = DebugDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDll|Mixed Platforms.Build.0 = DebugDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDll|Win32.ActiveCfg = DebugDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDll|Win32.Build.0 = DebugDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDoublePrecision|Any CPU.ActiveCfg = DebugDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDoublePrecision|Mixed Platforms.ActiveCfg = DebugDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDoublePrecision|Mixed Platforms.Build.0 = DebugDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDoublePrecision|Win32.ActiveCfg = DebugDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.DebugDoublePrecision|Win32.Build.0 = DebugDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Release|Any CPU.ActiveCfg = Release|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Release|Mixed Platforms.Build.0 = Release|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Release|Win32.ActiveCfg = Release|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.Release|Win32.Build.0 = Release|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDll|Any CPU.ActiveCfg = ReleaseDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDll|Mixed Platforms.ActiveCfg = ReleaseDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDll|Mixed Platforms.Build.0 = ReleaseDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDll|Win32.ActiveCfg = ReleaseDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDll|Win32.Build.0 = ReleaseDll|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDoublePrecision|Any CPU.ActiveCfg = ReleaseDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDoublePrecision|Mixed Platforms.ActiveCfg = ReleaseDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDoublePrecision|Mixed Platforms.Build.0 = ReleaseDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDoublePrecision|Win32.ActiveCfg = ReleaseDoublePrecision|Win32 - {61BD1097-CF2E-B296-DAA9-73A6FE135319}.ReleaseDoublePrecision|Win32.Build.0 = ReleaseDoublePrecision|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Extras/obsolete/CSharpWrapper/BulletPhysics.vcproj b/Extras/obsolete/CSharpWrapper/BulletPhysics.vcproj deleted file mode 100644 index 87ab96699..000000000 --- a/Extras/obsolete/CSharpWrapper/BulletPhysics.vcproj +++ /dev/null @@ -1,210 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Extras/obsolete/CSharpWrapper/BulletPhysicsapp.csproj b/Extras/obsolete/CSharpWrapper/BulletPhysicsapp.csproj deleted file mode 100644 index 1b6b76158..000000000 --- a/Extras/obsolete/CSharpWrapper/BulletPhysicsapp.csproj +++ /dev/null @@ -1,73 +0,0 @@ - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {11E65486-3C29-4D36-B488-4E05D9E4B46B} - WinExe - Properties - bulletapp - bulletapp - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - debug\BulletPhysics.dll - - - - - - - - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - \ No newline at end of file diff --git a/Extras/obsolete/CSharpWrapper/BulletWrapper.cpp b/Extras/obsolete/CSharpWrapper/BulletWrapper.cpp deleted file mode 100644 index f5d68c7f5..000000000 --- a/Extras/obsolete/CSharpWrapper/BulletWrapper.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2008 SCEI - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -/* - This is a C++/CLI wrapper of the high-level generic physics C-API. - You will be able to use it in C# -*/ - -#include "BulletWrapper.h" diff --git a/Extras/obsolete/CSharpWrapper/BulletWrapper.h b/Extras/obsolete/CSharpWrapper/BulletWrapper.h deleted file mode 100644 index 67e876a69..000000000 --- a/Extras/obsolete/CSharpWrapper/BulletWrapper.h +++ /dev/null @@ -1,422 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2008 SCEI - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -/* - This is a C++/CLI wrapper of the high-level generic physics C-API. - You will be able to use it in C# -*/ - -#pragma once - -#include "Bullet-C-Api.h" - -namespace Scea -{ - namespace BulletPhysics - { - /// - /// Base Bullet Class - public __gc class Bullet; - public __gc class RigidBodyHandle; - public __gc class CollisionShapeHandle; - public __gc class MeshInterfaceHandle; - - /// - /// A Mesh Interface Handle for Bullet - public __gc class MeshInterfaceHandle - { - public: - /// - /// Constructor for Mesh Interface Handle - MeshInterfaceHandle(plMeshInterfaceHandle handle) - { - _plMeshInterfaceHandle = handle; - } - /// - /// Destructor for Mesh Interface Handle - ~MeshInterfaceHandle() - { - _plMeshInterfaceHandle = 0; - }; - plMeshInterfaceHandle _plMeshInterfaceHandle; - }; - - /// - /// A RigidBody handle for Bullet - public __gc class RigidBodyHandle - { - public: - /// - /// Constructor for RigidBody handle - RigidBodyHandle(plRigidBodyHandle handle) - { - _plRigidBodyHandle = handle; - } - /// - /// Destructor for RigidBody handle - ~RigidBodyHandle() - { - _plRigidBodyHandle = 0; - }; - plRigidBodyHandle _plRigidBodyHandle; - }; - - /// - /// A Collision Shape handle for Bullet - public __gc class CollisionShapeHandle - { - public: - /// - /// Constructor for Collision Shape handle - CollisionShapeHandle(plCollisionShapeHandle handle) - { - _plCollisionShapeHandle = handle; - } - - /// - /// Destructor for Collision Shape handle - ~CollisionShapeHandle() - { - _plCollisionShapeHandle = 0; - }; - plCollisionShapeHandle _plCollisionShapeHandle; - }; - - /// - /// A RigidBody class in Bullet - public __gc class RigidBody - { - public: - /// - /// Constructor for RigidBody - /// The mass of this RigidBody - /// The Collision Shape handle of this RigidBody - /// stationary object has mass=0.f - RigidBody(float mass, CollisionShapeHandle * shape) - { - _plCollisionShapeHandle = shape->_plCollisionShapeHandle; - _plRigidBodyHandle = plCreateRigidBody(0, mass, _plCollisionShapeHandle); - } - - /// - /// Destructor for RigidBody - ~RigidBody() - { - if (_plRigidBodyHandle != 0) - { - plDeleteRigidBody(_plRigidBodyHandle ); - _plRigidBodyHandle = 0; - } - } - - /// - /// Dispose function for RigidBody - void Dispose() - { - if (_plRigidBodyHandle != 0) - { - plDeleteRigidBody(_plRigidBodyHandle ); - _plRigidBodyHandle = 0; - } - } - - /// - /// Get the Position for this RigidBody - /// The float[3] position of this RigidBody - void GetPosition(float float_array __gc[]) - { - float position[3]; - plGetPosition(_plRigidBodyHandle, position); - for (int i=0; i<3; i++) - float_array[i] = position[i]; - } - - /// - /// Get the Open GL World Matrix for this RigidBody - /// The float[16] GL world matrix of this RigidBody - void GetOpenGLMatrix(float float_array __gc[]) - { - float matrix[16]; - plGetOpenGLMatrix(_plRigidBodyHandle, matrix); - for (int i=0; i<16; i++) - float_array[i] = matrix[i]; - } - - /// - /// Get the orientation for this RigidBody - /// The float[4] orientation of this RigidBody - void GetOrientation(float float_array __gc[]) - { - float orientation[4]; - plGetOrientation(_plRigidBodyHandle, orientation); - for (int i=0; i<4; i++) - float_array[i] = orientation[i]; - } - - /// - /// Set the position for this RigidBody - /// The float[3] position of this RigidBody - void SetPosition(float float_array __gc[]) - { - float position[3]; - for (int i=0; i<3; i++) - position[i] = float_array[i]; - plSetPosition(_plRigidBodyHandle, position); - } - - /// - /// Set the orientation for this RigidBody - /// The float[3] orientation of this RigidBody - void SetOrientation(float float_array __gc[]) - { - float orientation[3]; - for (int i=0; i<3; i++) - orientation[i] = float_array[i]; - plSetOrientation(_plRigidBodyHandle, orientation); - } - - /// - /// Set the orientation for this RigidBody - /// The yaw orientation of this RigidBody - /// The pitch orientation of this RigidBody - /// The roll orientation of this RigidBody - void SetOrientation(float yaw, float pitch, float roll) - { - float orient[4]; - plSetEuler(yaw, pitch, roll, orient); - plSetOrientation(_plRigidBodyHandle, orient); - } - - /// - /// Set the Open GL World Matrix for this RigidBody - /// The float[16] GL world matrix of this RigidBody - void SetOpenGLMatrix(float float_array __gc[]) - { - float matrix[16]; - for (int i=0; i<16; i++) - matrix[i] = float_array[i]; - plSetOpenGLMatrix(_plRigidBodyHandle, matrix); - } - - plRigidBodyHandle _plRigidBodyHandle; - plCollisionShapeHandle _plCollisionShapeHandle; - }; - - - /// - /// Base Bullet Class - public __gc class Bullet - { - public: - /// - /// Constructor for the Bullet - Bullet() - { - m_rigidbody_count = 0; - _plDynamicsWorldHandle = 0; - _plPhysicsSdkHandle = plNewBulletSdk(); - } - /// - /// Destructor for the Bullet - ~Bullet() - { - plDeletePhysicsSdk(_plPhysicsSdkHandle); - _plDynamicsWorldHandle = 0; - _plPhysicsSdkHandle = 0; - } - - /// - /// Step Simulation for Bullet - /// - /// The amount of time to step in this simulation - void StepSimulation(plReal timeStep) - { - plStepSimulation(_plDynamicsWorldHandle, timeStep); - } - - /// - /// Create collision shape handle for sphere - /// - /// The radius of the sphere - CollisionShapeHandle * CreateSphere(float radius) - { - return new CollisionShapeHandle(plNewSphereShape(radius)); - } - - /// - /// Create collision shape handle for Box - /// - /// extend x of the box - /// extend y of the box - /// extend z of the box - CollisionShapeHandle * CreateBox(float x, float y, float z) - { - return new CollisionShapeHandle( plNewBoxShape(x, y, z)); - } - - /// - /// Create collision shape handle for Capsule - /// - /// The radius of the capsule - /// The height of the capsule - CollisionShapeHandle * CreateCapsule(float radius, float height) - { - return new CollisionShapeHandle( plNewCapsuleShape(radius, height)); - } - - /// - /// Create collision shape handle for cone - /// - /// The radius of the cone - /// The height of the cone - CollisionShapeHandle * CreateCone(float radius, float height) - { - return new CollisionShapeHandle( plNewConeShape(radius, height)); - } - - /// - /// Create collision shape handle for cylinder - /// - /// The radius of the cylinder - /// The height of the cylinder - CollisionShapeHandle * CreateCylinder(float radius, float height) - { - return new CollisionShapeHandle( plNewCylinderShape(radius, height)); - } - - /// - /// Create a Compound Shape collision shape handle - /// - CollisionShapeHandle * CreateCompoundShape() - { - return new CollisionShapeHandle( plNewCompoundShape()); - } - - /// - /// Add shape to this Compound Shape collision shape handle - /// - /// compoundShape - /// childShape - /// childPos - /// childOrn - void AddCompoundShape(CollisionShapeHandle * compoundShape, CollisionShapeHandle * childShape, plVector3 childPos,plQuaternion childOrn) - { - plAddChildShape(compoundShape->_plCollisionShapeHandle, childShape->_plCollisionShapeHandle, childPos,childOrn); - } - - /// - /// Destroy a collision shape handle - /// - void DestroyShape(CollisionShapeHandle * shape) - { - plDeleteShape(shape->_plCollisionShapeHandle); - delete shape; - } - - /// - /// Create collision shape handle for Convex Meshes - /// - CollisionShapeHandle * CreateConvexHull() - { - return new CollisionShapeHandle(plNewConvexHullShape()); - } - - /// - /// Add Convex Hull Vertex to the Convex Mesh shape handle - /// - void AddConvexHullVertex(CollisionShapeHandle * handle, float x, float y, float z) - { - plAddVertex(handle->_plCollisionShapeHandle, x, y, z); - } - -/* CollisionShapeHandle * CreateTriangleMesh() - { - MeshInterfaceHandle * handle = new MeshInterfaceHandle(plNewMeshInterface()); - - return new CollisionShapeHandle(plNewStaticTriangleMeshShape(handle->_plMeshInterfaceHandle)); - } - - MeshInterfaceHandle * CreateMeshInterface() - { - - return new MeshInterfaceHandle(plNewMeshInterface()); - } -/* - void AddMeshTriangle(MeshInterfaceHandle * handle, float * v0, float * v1,float * v2) - { - plAddTriangle(handle->_plMeshInterfaceHandle, v0, v1, v2); - } -/* - CollisionShapeHandle * CreateTriangleMesh(MeshInterfaceHandle * handle) - { - return new CollisionShapeHandle(plNewStaticTriangleMeshShape(handle->_plMeshInterfaceHandle)); - } -*/ /* Concave static triangle meshes */ -/* extern void plAddTriangle(plMeshInterfaceHandle meshHandle, plVector3 v0,plVector3 v1,plVector3 v2); - extern plCollisionShapeHandle plNewStaticTriangleMeshShape(plMeshInterfaceHandle); - extern void plSetScaling(plCollisionShapeHandle shape, plVector3 scaling); -*/ - - void SetEuler(float yaw, float pitch, float roll, float * orient) - { - plSetEuler(yaw, pitch, roll, orient); - } - - /// - /// Add RigidBody, If won't haven't created a dynamic world, create one - /// - void AddRigidBody(RigidBody * body) - { - if (m_rigidbody_count == 0) - CreateDynamicsWorld(); - plAddRigidBody(_plDynamicsWorldHandle, body->_plRigidBodyHandle); - m_rigidbody_count++; - } - - /// - /// Remove RigidBody, If we remove everything in this dynamic world, we destroy the dynamic world - /// - void RemoveRigidBody(RigidBody * body) - { - plRemoveRigidBody(_plDynamicsWorldHandle, body->_plRigidBodyHandle); - m_rigidbody_count--; - if (m_rigidbody_count == 0) - DestroyDynamicsWorld(); - } - private: - /// - /// Create a Dynamic World - /// - void CreateDynamicsWorld () - { - _plDynamicsWorldHandle = plCreateDynamicsWorld(_plPhysicsSdkHandle); - } - /// - /// Destroy a Dynamic World - /// - void DestroyDynamicsWorld() - { - plDeleteDynamicsWorld(_plDynamicsWorldHandle); - } - - // The count of rigidbody in this world. - int m_rigidbody_count; - plPhysicsSdkHandle _plPhysicsSdkHandle; - - // This wrapper will let you support only one world at a time. - plDynamicsWorldHandle _plDynamicsWorldHandle; - }; - } -} \ No newline at end of file diff --git a/Extras/obsolete/CSharpWrapper/Program.cs b/Extras/obsolete/CSharpWrapper/Program.cs deleted file mode 100644 index fcd035393..000000000 --- a/Extras/obsolete/CSharpWrapper/Program.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Windows.Forms; - -using Scea.BulletPhysics; - -namespace bulletapp -{ - static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Bullet bullet = new Bullet(); - - CollisionShapeHandle s_handle = bullet.CreateSphere(1); - RigidBody body = new RigidBody(1, s_handle); - float [] position = new float[3]; - position[0] = 1.0f; position[1] = 1.1f; position[2] = 1.2f; - body.SetPosition(position); - body.SetOrientation(0.1f, 0.2f, 0.3f); - - bullet.AddRigidBody(body); - System.Console.WriteLine("Original Position (" + position[0] + ", " + position[1] + ", " + position[2] + ")"); - - float[] new_position = new float[3]; - for (int i = 0; i < 10; i++) - { - bullet.StepSimulation(0.1f); - System.Console.WriteLine("StepSimulation " + 0.1); - body.GetPosition(new_position); - System.Console.WriteLine("New Position (" + new_position[0] + ", " + new_position[1] + ", " + new_position[2] + ")"); - } - - float[] matrix = new float[16]; - body.GetOpenGLMatrix(matrix); - System.Console.WriteLine("GetOpenGLMatrix (" + - matrix[0] + ", " + matrix[1] + ", " + matrix[2] + ", " + matrix[3] + ", " + - matrix[4] + ", " + matrix[5] + ", " + matrix[6] + ", " + matrix[7] + ", " + - matrix[8] + ", " + matrix[9] + ", " + matrix[10] + ", " + matrix[11] + ", " + - matrix[12] + ", " + matrix[13] + ", " + matrix[14] + ", " + matrix[15] + ")" - ); - - float[] quot = new float[4]; - body.GetOrientation(quot); - System.Console.WriteLine("GetOrientation (" + quot[0] + ", " + quot[1] + ", " + quot[2] + ", " + quot[3] + ")"); - } - } -} \ No newline at end of file diff --git a/Extras/obsolete/CSharpWrapper/Properties/AssemblyInfo.cs b/Extras/obsolete/CSharpWrapper/Properties/AssemblyInfo.cs deleted file mode 100644 index 3821f32b1..000000000 --- a/Extras/obsolete/CSharpWrapper/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("bulletapp")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("PlayStation")] -[assembly: AssemblyProduct("bulletapp")] -[assembly: AssemblyCopyright("Copyright © PlayStation 2008")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("0cae17bf-da40-4b83-8ce2-d21c5d1ec28a")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Extras/obsolete/CSharpWrapper/Properties/Resources.Designer.cs b/Extras/obsolete/CSharpWrapper/Properties/Resources.Designer.cs deleted file mode 100644 index ee21772bd..000000000 --- a/Extras/obsolete/CSharpWrapper/Properties/Resources.Designer.cs +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:2.0.50727.1433 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace bulletapp.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("bulletapp.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - } -} diff --git a/Extras/obsolete/CSharpWrapper/Properties/Resources.resx b/Extras/obsolete/CSharpWrapper/Properties/Resources.resx deleted file mode 100644 index ffecec851..000000000 --- a/Extras/obsolete/CSharpWrapper/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Extras/obsolete/CSharpWrapper/Properties/Settings.Designer.cs b/Extras/obsolete/CSharpWrapper/Properties/Settings.Designer.cs deleted file mode 100644 index 64712a880..000000000 --- a/Extras/obsolete/CSharpWrapper/Properties/Settings.Designer.cs +++ /dev/null @@ -1,26 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:2.0.50727.1433 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace bulletapp.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "8.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - } -} diff --git a/Extras/obsolete/CSharpWrapper/Properties/Settings.settings b/Extras/obsolete/CSharpWrapper/Properties/Settings.settings deleted file mode 100644 index abf36c5d3..000000000 --- a/Extras/obsolete/CSharpWrapper/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/Extras/obsolete/EPA/Epa.cpp b/Extras/obsolete/EPA/Epa.cpp deleted file mode 100644 index 1d66540d6..000000000 --- a/Extras/obsolete/EPA/Epa.cpp +++ /dev/null @@ -1,569 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#include "LinearMath/btScalar.h" -#include "LinearMath/btVector3.h" -#include "LinearMath/btPoint3.h" -#include "LinearMath/btTransform.h" -#include "LinearMath/btMinMax.h" - -#include "BulletCollision/CollisionShapes/btConvexShape.h" - -#include -#include -#include - -#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h" - -#include "EpaCommon.h" - -#include "EpaVertex.h" -#include "EpaHalfEdge.h" -#include "EpaFace.h" -#include "EpaPolyhedron.h" -#include "Epa.h" - -const btScalar EPA_MAX_RELATIVE_ERROR = 1e-2f; -const btScalar EPA_MAX_RELATIVE_ERROR_SQRD = EPA_MAX_RELATIVE_ERROR * EPA_MAX_RELATIVE_ERROR; - -Epa::Epa( btConvexShape* pConvexShapeA, btConvexShape* pConvexShapeB, - const btTransform& transformA, const btTransform& transformB ) : m_pConvexShapeA( pConvexShapeA ), - m_pConvexShapeB( pConvexShapeB ), - m_transformA( transformA ), - m_transformB( transformB ) -{ - m_faceEntries.reserve( EPA_MAX_FACE_ENTRIES ); -} - -Epa::~Epa() -{ -} - -bool Epa::Initialize( btSimplexSolverInterface& simplexSolver ) -{ - // Run GJK on the enlarged shapes to obtain a simplex of the enlarged CSO - - btVector3 v( 1, 0, 0 ); - btScalar squaredDistance = SIMD_INFINITY; - - btScalar delta = 0.f; - - simplexSolver.reset(); - - int nbIterations = 0; - - while ( true ) - { - EPA_DEBUG_ASSERT( ( v.length2() > 0 ) ,"Warning : v has zero magnitude!" ); - - btVector3 seperatingAxisInA = -v * m_transformA.getBasis(); - btVector3 seperatingAxisInB = v * m_transformB.getBasis(); - - btVector3 pInA = m_pConvexShapeA->localGetSupportingVertex( seperatingAxisInA ); - btVector3 qInB = m_pConvexShapeB->localGetSupportingVertex( seperatingAxisInB ); - - btPoint3 pWorld = m_transformA( pInA ); - btPoint3 qWorld = m_transformB( qInB ); - - btVector3 w = pWorld - qWorld; - delta = v.dot( w ); - - EPA_DEBUG_ASSERT( ( delta <= 0 ) ,"Shapes are disjoint, EPA should have never been called!" ); - if ( delta > 0.f ) - return false; - - EPA_DEBUG_ASSERT( !simplexSolver.inSimplex( w ) ,"Shapes are disjoint, EPA should have never been called!" ); - if (simplexSolver.inSimplex( w )) - return false; - - // Add support point to simplex - simplexSolver.addVertex( w, pWorld, qWorld ); - - bool closestOk = simplexSolver.closest( v ); - EPA_DEBUG_ASSERT( closestOk ,"Shapes are disjoint, EPA should have never been called!" ); - if (!closestOk) - return false; - - btScalar prevVSqrd = squaredDistance; - squaredDistance = v.length2(); - - // Is v converging to v(A-B) ? - EPA_DEBUG_ASSERT( ( ( prevVSqrd - squaredDistance ) > SIMD_EPSILON * prevVSqrd ) , - "Shapes are disjoint, EPA should have never been called!" ); - if (( ( prevVSqrd - squaredDistance ) <= SIMD_EPSILON * prevVSqrd )) - return false; - - if ( simplexSolver.fullSimplex() || ( squaredDistance <= SIMD_EPSILON * simplexSolver.maxVertex() ) ) - { - break; - } - - ++nbIterations; - } - - btPoint3 simplexPoints[ 5 ]; - btPoint3 wSupportPointsOnA[ 5 ]; - btPoint3 wSupportPointsOnB[ 5 ]; - - int nbSimplexPoints = simplexSolver.getSimplex( wSupportPointsOnA, wSupportPointsOnB, simplexPoints ); - - // nbSimplexPoints can't be one because cases where the origin is on the boundary are handled - // by hybrid penetration depth - EPA_DEBUG_ASSERT( ( ( nbSimplexPoints > 1 ) ,( nbSimplexPoints <= 4 ) ) , - "Hybrid Penetration Depth algorithm failed!" ); - - int nbPolyhedronPoints = nbSimplexPoints; - -#ifndef EPA_POLYHEDRON_USE_PLANES - int initTetraIndices[ 4 ] = { 0, 1, 2, 3 }; -#endif - - // Prepare initial polyhedron to start EPA from - if ( nbSimplexPoints == 1 ) - { - return false; - } - else if ( nbSimplexPoints == 2 ) - { - // We have a line segment inside the CSO that contains the origin - // Create an hexahedron ( two tetrahedron glued together ) by adding 3 new points - - btVector3 d = simplexPoints[ 0 ] - simplexPoints[ 1 ]; - d.normalize(); - - btVector3 v1; - btVector3 v2; - btVector3 v3; - - btVector3 e1; - - btScalar absx = abs( d.getX() ); - btScalar absy = abs( d.getY() ); - btScalar absz = abs( d.getZ() ); - - if ( absx < absy ) - { - if ( absx < absz ) - { - e1.setX( 1 ); - } - else - { - e1.setZ( 1 ); - } - } - else - { - if ( absy < absz ) - { - e1.setY( 1 ); - } - else - { - e1.setZ( 1 ); - } - } - - v1 = d.cross( e1 ); - v1.normalize(); - - v2 = v1.rotate( d, 120 * SIMD_RADS_PER_DEG ); - v3 = v2.rotate( d, 120 * SIMD_RADS_PER_DEG ); - - nbPolyhedronPoints = 5; - - btVector3 seperatingAxisInA = v1 * m_transformA.getBasis(); - btVector3 seperatingAxisInB = -v1 * m_transformB.getBasis(); - - btVector3 p = m_pConvexShapeA->localGetSupportingVertex( seperatingAxisInA ); - btVector3 q = m_pConvexShapeB->localGetSupportingVertex( seperatingAxisInB ); - - btPoint3 pWorld = m_transformA( p ); - btPoint3 qWorld = m_transformB( q ); - - wSupportPointsOnA[ 2 ] = pWorld; - wSupportPointsOnB[ 2 ] = qWorld; - simplexPoints[ 2 ] = wSupportPointsOnA[ 2 ] - wSupportPointsOnB[ 2 ]; - - seperatingAxisInA = v2 * m_transformA.getBasis(); - seperatingAxisInB = -v2 * m_transformB.getBasis(); - - p = m_pConvexShapeA->localGetSupportingVertex( seperatingAxisInA ); - q = m_pConvexShapeB->localGetSupportingVertex( seperatingAxisInB ); - - pWorld = m_transformA( p ); - qWorld = m_transformB( q ); - - wSupportPointsOnA[ 3 ] = pWorld; - wSupportPointsOnB[ 3 ] = qWorld; - simplexPoints[ 3 ] = wSupportPointsOnA[ 3 ] - wSupportPointsOnB[ 3 ]; - - seperatingAxisInA = v3 * m_transformA.getBasis(); - seperatingAxisInB = -v3 * m_transformB.getBasis(); - - p = m_pConvexShapeA->localGetSupportingVertex( seperatingAxisInA ); - q = m_pConvexShapeB->localGetSupportingVertex( seperatingAxisInB ); - - pWorld = m_transformA( p ); - qWorld = m_transformB( q ); - - wSupportPointsOnA[ 4 ] = pWorld; - wSupportPointsOnB[ 4 ] = qWorld; - simplexPoints[ 4 ] = wSupportPointsOnA[ 4 ] - wSupportPointsOnB[ 4 ]; - -#ifndef EPA_POLYHEDRON_USE_PLANES - if ( TetrahedronContainsOrigin( simplexPoints[ 0 ], simplexPoints[ 2 ], simplexPoints[ 3 ], simplexPoints[ 4 ] ) ) - { - initTetraIndices[ 1 ] = 2; - initTetraIndices[ 2 ] = 3; - initTetraIndices[ 3 ] = 4; - } - else - { - if ( TetrahedronContainsOrigin( simplexPoints[ 1 ], simplexPoints[ 2 ], simplexPoints[ 3 ], simplexPoints[ 4 ] ) ) - { - initTetraIndices[ 0 ] = 1; - initTetraIndices[ 1 ] = 2; - initTetraIndices[ 2 ] = 3; - initTetraIndices[ 3 ] = 4; - } - else - { - // No tetrahedron contains the origin - assert( false && "Unable to find an initial tetrahedron that contains the origin!" ); - return false; - } - } -#endif - } - else if ( nbSimplexPoints == 3 ) - { - // We have a triangle inside the CSO that contains the origin - // Create an hexahedron ( two tetrahedron glued together ) by adding 2 new points - - btVector3 v0 = simplexPoints[ 2 ] - simplexPoints[ 0 ]; - btVector3 v1 = simplexPoints[ 1 ] - simplexPoints[ 0 ]; - btVector3 triangleNormal = v0.cross( v1 ); - triangleNormal.normalize(); - - nbPolyhedronPoints = 5; - - btVector3 seperatingAxisInA = triangleNormal * m_transformA.getBasis(); - btVector3 seperatingAxisInB = -triangleNormal * m_transformB.getBasis(); - - btVector3 p = m_pConvexShapeA->localGetSupportingVertex( seperatingAxisInA ); - btVector3 q = m_pConvexShapeB->localGetSupportingVertex( seperatingAxisInB ); - - btPoint3 pWorld = m_transformA( p ); - btPoint3 qWorld = m_transformB( q ); - - wSupportPointsOnA[ 3 ] = pWorld; - wSupportPointsOnB[ 3 ] = qWorld; - simplexPoints[ 3 ] = wSupportPointsOnA[ 3 ] - wSupportPointsOnB[ 3 ]; - -#ifndef EPA_POLYHEDRON_USE_PLANES - // We place this check here because if the tetrahedron contains the origin - // there is no need to sample another support point - if ( !TetrahedronContainsOrigin( simplexPoints[ 0 ], simplexPoints[ 1 ], simplexPoints[ 2 ], simplexPoints[ 3 ] ) ) - { -#endif - seperatingAxisInA = -triangleNormal * m_transformA.getBasis(); - seperatingAxisInB = triangleNormal * m_transformB.getBasis(); - - p = m_pConvexShapeA->localGetSupportingVertex( seperatingAxisInA ); - q = m_pConvexShapeB->localGetSupportingVertex( seperatingAxisInB ); - - pWorld = m_transformA( p ); - qWorld = m_transformB( q ); - - wSupportPointsOnA[ 4 ] = pWorld; - wSupportPointsOnB[ 4 ] = qWorld; - simplexPoints[ 4 ] = wSupportPointsOnA[ 4 ] - wSupportPointsOnB[ 4 ]; - -#ifndef EPA_POLYHEDRON_USE_PLANES - if ( TetrahedronContainsOrigin( simplexPoints[ 0 ], simplexPoints[ 1 ], simplexPoints[ 2 ], simplexPoints[ 4 ] ) ) - { - initTetraIndices[ 3 ] = 4; - } - else - { - // No tetrahedron contains the origin - assert( false && "Unable to find an initial tetrahedron that contains the origin!" ); - return false; - } - } -#endif - } -#ifdef _DEBUG - else if ( nbSimplexPoints == 4 ) - { - EPA_DEBUG_ASSERT( TetrahedronContainsOrigin( simplexPoints ) ,"Initial tetrahedron does not contain the origin!" ); - } -#endif - -#ifndef EPA_POLYHEDRON_USE_PLANES - btPoint3 wTetraPoints[ 4 ] = { simplexPoints[ initTetraIndices[ 0 ] ], - simplexPoints[ initTetraIndices[ 1 ] ], - simplexPoints[ initTetraIndices[ 2 ] ], - simplexPoints[ initTetraIndices[ 3 ] ] }; - - btPoint3 wTetraSupportPointsOnA[ 4 ] = { wSupportPointsOnA[ initTetraIndices[ 0 ] ], - wSupportPointsOnA[ initTetraIndices[ 1 ] ], - wSupportPointsOnA[ initTetraIndices[ 2 ] ], - wSupportPointsOnA[ initTetraIndices[ 3 ] ] }; - - btPoint3 wTetraSupportPointsOnB[ 4 ] = { wSupportPointsOnB[ initTetraIndices[ 0 ] ], - wSupportPointsOnB[ initTetraIndices[ 1 ] ], - wSupportPointsOnB[ initTetraIndices[ 2 ] ], - wSupportPointsOnB[ initTetraIndices[ 3 ] ] }; -#endif - -#ifdef EPA_POLYHEDRON_USE_PLANES - if ( !m_polyhedron.Create( simplexPoints, wSupportPointsOnA, wSupportPointsOnB, nbPolyhedronPoints ) ) -#else - if ( !m_polyhedron.Create( wTetraPoints, wTetraSupportPointsOnA, wTetraSupportPointsOnB, 4 ) ) -#endif - { - // Failed to create initial polyhedron - EPA_DEBUG_ASSERT( false ,"Failed to create initial polyhedron!" ); - return false; - } - - // Add initial faces to priority queue - -#ifdef _DEBUG - //m_polyhedron._dbgSaveToFile( "epa_start.dbg" ); -#endif - - std::list< EpaFace* >& faces = m_polyhedron.GetFaces(); - - std::list< EpaFace* >::iterator facesItr( faces.begin() ); - - while ( facesItr != faces.end() ) - { - EpaFace* pFace = *facesItr; - - if ( !pFace->m_deleted ) - { -//#ifdef EPA_POLYHEDRON_USE_PLANES -// if ( pFace->m_planeDistance >= 0 ) -// { -// m_polyhedron._dbgSaveToFile( "epa_start.dbg" ); -// assert( false && "Face's plane distance equal or greater than 0!" ); -// } -//#endif - - if ( pFace->IsAffinelyDependent() ) - { - EPA_DEBUG_ASSERT( false ,"One initial face is affinely dependent!" ); - return false; - } - - if ( pFace->m_vSqrd <= 0 ) - { - EPA_DEBUG_ASSERT( false ,"Face containing the origin!" ); - return false; - } - - if ( pFace->IsClosestPointInternal() ) - { - m_faceEntries.push_back( pFace ); - std::push_heap( m_faceEntries.begin(), m_faceEntries.end(), CompareEpaFaceEntries ); - } - } - - ++facesItr; - } - -#ifdef _DEBUG - //m_polyhedron._dbgSaveToFile( "epa_start.dbg" ); -#endif - - EPA_DEBUG_ASSERT( !m_faceEntries.empty() ,"No faces added to heap!" ); - - return true; -} - -btScalar Epa::calcPenDepth( btPoint3& wWitnessOnA, btPoint3& wWitnessOnB ) -{ - btVector3 v; - - btScalar upperBoundSqrd = SIMD_INFINITY; - btScalar vSqrd = 0; -#ifdef _DEBUG - btScalar prevVSqrd; -#endif - btScalar delta; - - bool isCloseEnough = false; - - EpaFace* pEpaFace = NULL; - - int nbIterations = 0; - //int nbMaxIterations = 1000; - - do - { - pEpaFace = m_faceEntries.front(); - std::pop_heap( m_faceEntries.begin(), m_faceEntries.end(), CompareEpaFaceEntries ); - m_faceEntries.pop_back(); - - if ( !pEpaFace->m_deleted ) - { -#ifdef _DEBUG - prevVSqrd = vSqrd; -#endif - - vSqrd = pEpaFace->m_vSqrd; - - if ( pEpaFace->m_planeDistance >= 0 ) - { - v = pEpaFace->m_planeNormal; - } - else - { - v = pEpaFace->m_v; - } - -#ifdef _DEBUG - //assert_msg( vSqrd <= upperBoundSqrd, "A triangle was falsely rejected!" ); - EPA_DEBUG_ASSERT( ( vSqrd >= prevVSqrd ) ,"vSqrd decreased!" ); -#endif //_DEBUG - EPA_DEBUG_ASSERT( ( v.length2() > 0 ) ,"Zero vector not allowed!" ); - - btVector3 seperatingAxisInA = v * m_transformA.getBasis(); - btVector3 seperatingAxisInB = -v * m_transformB.getBasis(); - - btVector3 p = m_pConvexShapeA->localGetSupportingVertex( seperatingAxisInA ); - btVector3 q = m_pConvexShapeB->localGetSupportingVertex( seperatingAxisInB ); - - btPoint3 pWorld = m_transformA( p ); - btPoint3 qWorld = m_transformB( q ); - - btPoint3 w = pWorld - qWorld; - delta = v.dot( w ); - - // Keep tighest upper bound - upperBoundSqrd = btMin( upperBoundSqrd, delta * delta / vSqrd ); - //assert_msg( vSqrd <= upperBoundSqrd, "A triangle was falsely rejected!" ); - - isCloseEnough = ( upperBoundSqrd <= ( 1 + 1e-4f ) * vSqrd ); - - if ( !isCloseEnough ) - { - std::list< EpaFace* > newFaces; - bool expandOk = m_polyhedron.Expand( w, pWorld, qWorld, pEpaFace, newFaces ); - - if ( expandOk ) - { - EPA_DEBUG_ASSERT( !newFaces.empty() ,"EPA polyhedron not expanding ?" ); - - bool check = true; - bool areEqual = false; - - while ( !newFaces.empty() ) - { - EpaFace* pNewFace = newFaces.front(); - EPA_DEBUG_ASSERT( !pNewFace->m_deleted ,"New face is deleted!" ); - - if ( !pNewFace->m_deleted ) - { - EPA_DEBUG_ASSERT( ( pNewFace->m_vSqrd > 0 ) ,"Face containing the origin!" ); - EPA_DEBUG_ASSERT( !pNewFace->IsAffinelyDependent() ,"Face is affinely dependent!" ); - -//#ifdef EPA_POLYHEDRON_USE_PLANES -//// if ( pNewFace->m_planeDistance >= 0 ) -//// { -// // assert( false && "Face's plane distance greater than 0!" ); -//#ifdef _DEBUG -//// m_polyhedron._dbgSaveToFile( "epa_beforeFix.dbg" ); -//#endif -// //pNewFace->FixOrder(); -//#ifdef _DEBUG -// //m_polyhedron._dbgSaveToFile( "epa_afterFix.dbg" ); -//#endif -//// } -//#endif -// -//#ifdef EPA_POLYHEDRON_USE_PLANES -// //assert( ( pNewFace->m_planeDistance < 0 ) && "Face's plane distance equal or greater than 0!" ); -//#endif - - if ( pNewFace->IsClosestPointInternal() && ( vSqrd <= pNewFace->m_vSqrd ) && ( pNewFace->m_vSqrd <= upperBoundSqrd ) ) - { - m_faceEntries.push_back( pNewFace ); - std::push_heap( m_faceEntries.begin(), m_faceEntries.end(), CompareEpaFaceEntries ); - } - } - - newFaces.pop_front(); - } - } - else - { - pEpaFace->CalcClosestPointOnA( wWitnessOnA ); - pEpaFace->CalcClosestPointOnB( wWitnessOnB ); - -#ifdef _DEBUG - //m_polyhedron._dbgSaveToFile( "epa_end.dbg" ); -#endif - - return v.length(); - } - } - } - - ++nbIterations; - } - while ( ( m_polyhedron.GetNbFaces() < EPA_MAX_FACE_ENTRIES ) &&/*( nbIterations < nbMaxIterations ) &&*/ - !isCloseEnough && ( m_faceEntries.size() > 0 ) && ( m_faceEntries[ 0 ]->m_vSqrd <= upperBoundSqrd ) ); - -#ifdef _DEBUG - //m_polyhedron._dbgSaveToFile( "epa_end.dbg" ); -#endif - - EPA_DEBUG_ASSERT( pEpaFace ,"Invalid epa face!" ); - - pEpaFace->CalcClosestPointOnA( wWitnessOnA ); - pEpaFace->CalcClosestPointOnB( wWitnessOnB ); - - return v.length(); -} - -bool Epa::TetrahedronContainsOrigin( const btPoint3& point0, const btPoint3& point1, - const btPoint3& point2, const btPoint3& point3 ) -{ - btVector3 facesNormals[ 4 ] = { ( point1 - point0 ).cross( point2 - point0 ), - ( point2 - point1 ).cross( point3 - point1 ), - ( point3 - point2 ).cross( point0 - point2 ), - ( point0 - point3 ).cross( point1 - point3 ) }; - - return ( ( facesNormals[ 0 ].dot( point0 ) > 0 ) != ( facesNormals[ 0 ].dot( point3 ) > 0 ) ) && - ( ( facesNormals[ 1 ].dot( point1 ) > 0 ) != ( facesNormals[ 1 ].dot( point0 ) > 0 ) ) && - ( ( facesNormals[ 2 ].dot( point2 ) > 0 ) != ( facesNormals[ 2 ].dot( point1 ) > 0 ) ) && - ( ( facesNormals[ 3 ].dot( point3 ) > 0 ) != ( facesNormals[ 3 ].dot( point2 ) > 0 ) ); -} - -bool Epa::TetrahedronContainsOrigin( btPoint3* pPoints ) -{ - return TetrahedronContainsOrigin( pPoints[ 0 ], pPoints[ 1 ], pPoints[ 2 ], pPoints[ 3 ] ); -} - -bool CompareEpaFaceEntries( EpaFace* pFaceA, EpaFace* pFaceB ) -{ - return ( pFaceA->m_vSqrd > pFaceB->m_vSqrd ); -} diff --git a/Extras/obsolete/EPA/Epa.h b/Extras/obsolete/EPA/Epa.h deleted file mode 100644 index e5cb81e86..000000000 --- a/Extras/obsolete/EPA/Epa.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef EPA_H -#define EPA_H - -#define EPA_MAX_FACE_ENTRIES 256 - - - -extern const btScalar EPA_MAX_RELATIVE_ERROR; -extern const btScalar EPA_MAX_RELATIVE_ERROR_SQRD; - -class Epa -{ - private : - - //! Prevents copying objects from this class - Epa( const Epa& epa ); - const Epa& operator = ( const Epa& epa ); - - public : - - Epa( btConvexShape* pConvexShapeA, btConvexShape* pConvexShapeB, - const btTransform& transformA, const btTransform& transformB ); - ~Epa(); - - bool Initialize( btSimplexSolverInterface& simplexSolver ); - - btScalar calcPenDepth( btPoint3& wWitnessOnA, btPoint3& wWitnessOnB ); - - private : - - bool TetrahedronContainsOrigin( btPoint3* pPoints ); - bool TetrahedronContainsOrigin( const btPoint3& point0, const btPoint3& point1, - const btPoint3& point2, const btPoint3& point3 ); - - private : - - //! Priority queue - std::vector< EpaFace* > m_faceEntries; - - btConvexShape* m_pConvexShapeA; - btConvexShape* m_pConvexShapeB; - - btTransform m_transformA; - btTransform m_transformB; - - EpaPolyhedron m_polyhedron; -}; - -extern bool CompareEpaFaceEntries( EpaFace* pFaceA, EpaFace* pFaceB ); - -#endif - diff --git a/Extras/obsolete/EPA/EpaCommon.h b/Extras/obsolete/EPA/EpaCommon.h deleted file mode 100644 index 445d7d449..000000000 --- a/Extras/obsolete/EPA/EpaCommon.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef EPA_COMMON_H -#define EPA_COMMON_H - -#define EPA_POLYHEDRON_USE_PLANES - - -//#define EPA_DEBUG_ASSERT(c,a) -//#define EPA_DEBUG_ASSERT(c,a) assert(c && a) -#define EPA_DEBUG_ASSERT(c,a) if (!c) printf(a) - -//#define EPA_USE_HYBRID - -#endif - diff --git a/Extras/obsolete/EPA/EpaFace.cpp b/Extras/obsolete/EPA/EpaFace.cpp deleted file mode 100644 index c74ae1f17..000000000 --- a/Extras/obsolete/EPA/EpaFace.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#include "LinearMath/btScalar.h" -#include "LinearMath/btVector3.h" -#include "LinearMath/btPoint3.h" - -#include "EpaCommon.h" - -#include "EpaVertex.h" -#include "EpaHalfEdge.h" -#include "EpaFace.h" - -#ifdef EPA_POLYHEDRON_USE_PLANES -btScalar PLANE_THICKNESS = 1e-5f; -#endif - -EpaFace::EpaFace() : m_pHalfEdge( 0 ), m_deleted( false ) -{ - m_pVertices[ 0 ] = m_pVertices[ 1 ] = m_pVertices[ 2 ] = 0; -} - -EpaFace::~EpaFace() -{ -} - -bool EpaFace::Initialize() -{ - assert( m_pHalfEdge && "Must setup half-edge first!" ); - - CollectVertices( m_pVertices ); - - const btVector3 e0 = m_pVertices[ 1 ]->m_point - m_pVertices[ 0 ]->m_point; - const btVector3 e1 = m_pVertices[ 2 ]->m_point - m_pVertices[ 0 ]->m_point; - - const btScalar e0Sqrd = e0.length2(); - const btScalar e1Sqrd = e1.length2(); - const btScalar e0e1 = e0.dot( e1 ); - - m_determinant = e0Sqrd * e1Sqrd - e0e1 * e0e1; - - const btScalar e0v0 = e0.dot( m_pVertices[ 0 ]->m_point ); - const btScalar e1v0 = e1.dot( m_pVertices[ 0 ]->m_point ); - - m_lambdas[ 0 ] = e0e1 * e1v0 - e1Sqrd * e0v0; - m_lambdas[ 1 ] = e0e1 * e0v0 - e0Sqrd * e1v0; - - if ( IsAffinelyDependent() ) - { - return false; - } - - CalcClosestPoint(); - -#ifdef EPA_POLYHEDRON_USE_PLANES - if ( !CalculatePlane() ) - { - return false; - } -#endif - - return true; -} - -#ifdef EPA_POLYHEDRON_USE_PLANES -bool EpaFace::CalculatePlane() -{ - assert( ( m_pVertices[ 0 ] && m_pVertices[ 1 ] && m_pVertices[ 2 ] ) - && "Must setup vertices pointers first!" ); - - // Traditional method - - const btVector3 v1 = m_pVertices[ 1 ]->m_point - m_pVertices[ 0 ]->m_point; - const btVector3 v2 = m_pVertices[ 2 ]->m_point - m_pVertices[ 0 ]->m_point; - - m_planeNormal = v2.cross( v1 ); - - if ( m_planeNormal.length2() == 0 ) - { - return false; - } - - m_planeNormal.normalize(); - - m_planeDistance = m_pVertices[ 0 ]->m_point.dot( -m_planeNormal ); - - // Robust method - - //btVector3 _v1 = m_pVertices[ 1 ]->m_point - m_pVertices[ 0 ]->m_point; - //btVector3 _v2 = m_pVertices[ 2 ]->m_point - m_pVertices[ 0 ]->m_point; - - //btVector3 n; - - //n = _v2.cross( _v1 ); - - //_v1 = m_pVertices[ 0 ]->m_point - m_pVertices[ 1 ]->m_point; - //_v2 = m_pVertices[ 2 ]->m_point - m_pVertices[ 1 ]->m_point; - - //n += ( _v1.cross( _v2 ) ); - - //_v1 = m_pVertices[ 0 ]->m_point - m_pVertices[ 2 ]->m_point; - //_v2 = m_pVertices[ 1 ]->m_point - m_pVertices[ 2 ]->m_point; - - //n += ( _v2.cross( _v1 ) ); - - //n /= 3; - //n.normalize(); - - //btVector3 c = ( m_pVertices[ 0 ]->m_point + m_pVertices[ 1 ]->m_point + m_pVertices[ 2 ]->m_point ) / 3; - //btScalar d = c.dot( -n ); - - //m_robustPlaneNormal = n; - //m_robustPlaneDistance = d; - - // Compare results from both methods and check whether they disagree - - //if ( d < 0 ) - //{ - // assert( ( m_planeDistance < 0 ) && "He he! Busted!" ); - //} - //else - //{ - // assert( ( m_planeDistance >= 0 ) && "He he! Busted!" ); - //} - - return true; -} -#endif - -void EpaFace::CalcClosestPoint() -{ - const btVector3 e0 = m_pVertices[ 1 ]->m_point - m_pVertices[ 0 ]->m_point; - const btVector3 e1 = m_pVertices[ 2 ]->m_point - m_pVertices[ 0 ]->m_point; - - m_v = m_pVertices[ 0 ]->m_point + - ( e0 * m_lambdas[ 0 ] + e1 * m_lambdas[ 1 ] ) / m_determinant; - - m_vSqrd = m_v.length2(); -} - -void EpaFace::CalcClosestPointOnA( btVector3& closestPointOnA ) -{ - const btVector3 e0 = m_pVertices[ 1 ]->m_wSupportPointOnA - m_pVertices[ 0 ]->m_wSupportPointOnA; - const btVector3 e1 = m_pVertices[ 2 ]->m_wSupportPointOnA - m_pVertices[ 0 ]->m_wSupportPointOnA; - - closestPointOnA = m_pVertices[ 0 ]->m_wSupportPointOnA + - ( e0 * m_lambdas[ 0 ] + e1 * m_lambdas[ 1 ] ) / - m_determinant; -} - -void EpaFace::CalcClosestPointOnB( btVector3& closestPointOnB ) -{ - const btVector3 e0 = m_pVertices[ 1 ]->m_wSupportPointOnB - m_pVertices[ 0 ]->m_wSupportPointOnB; - const btVector3 e1 = m_pVertices[ 2 ]->m_wSupportPointOnB - m_pVertices[ 0 ]->m_wSupportPointOnB; - - closestPointOnB = m_pVertices[ 0 ]->m_wSupportPointOnB + - ( e0 * m_lambdas[ 0 ] + e1 * m_lambdas[ 1 ] ) / - m_determinant; -} - -bool EpaFace::IsAffinelyDependent() const -{ - return ( m_determinant <= SIMD_EPSILON ); -} - -bool EpaFace::IsClosestPointInternal() const -{ - return ( ( m_lambdas[ 0 ] >= 0 ) && ( m_lambdas[ 1 ] >= 0 ) && ( ( m_lambdas[ 0 ] + m_lambdas[ 1 ] <= m_determinant ) ) ); -} - -void EpaFace::CollectVertices( EpaVertex** ppVertices ) -{ - assert( m_pHalfEdge && "Invalid half-edge pointer!" ); - - int vertexIndex = 0; - - EpaHalfEdge* pCurrentHalfEdge = m_pHalfEdge; - - do - { - assert( ( ( vertexIndex >= 0 ) && ( vertexIndex < 3 ) ) && - "Face is not a triangle!" ); - - assert( pCurrentHalfEdge->m_pVertex && "Half-edge has an invalid vertex pointer!" ); - - ppVertices[ vertexIndex++ ] = pCurrentHalfEdge->m_pVertex; - - pCurrentHalfEdge = pCurrentHalfEdge->m_pNextCCW; - - } - while( pCurrentHalfEdge != m_pHalfEdge ); -} - -//void EpaFace::FixOrder() -//{ -// EpaHalfEdge* pHalfEdges[ 3 ]; -// -// int halfEdgeIndex = 0; -// -// EpaHalfEdge* pCurrentHalfEdge = m_pHalfEdge; -// -// do -// { -// assert( ( ( halfEdgeIndex >= 0 ) && ( halfEdgeIndex < 3 ) ) && -// "Face is not a triangle!" ); -// -// pHalfEdges[ halfEdgeIndex++ ] = pCurrentHalfEdge; -// -// pCurrentHalfEdge = pCurrentHalfEdge->m_pNextCCW; -// } -// while( pCurrentHalfEdge != m_pHalfEdge ); -// -// EpaVertex* pVertices[ 3 ] = { pHalfEdges[ 0 ]->m_pVertex, -// pHalfEdges[ 1 ]->m_pVertex, -// pHalfEdges[ 2 ]->m_pVertex }; -// -// // Make them run in the opposite direction -// pHalfEdges[ 0 ]->m_pNextCCW = pHalfEdges[ 2 ]; -// pHalfEdges[ 1 ]->m_pNextCCW = pHalfEdges[ 0 ]; -// pHalfEdges[ 2 ]->m_pNextCCW = pHalfEdges[ 1 ]; -// -// // Make half-edges point to their correct origin vertices -// -// pHalfEdges[ 1 ]->m_pVertex = pVertices[ 2 ]; -// pHalfEdges[ 2 ]->m_pVertex = pVertices[ 0 ]; -// pHalfEdges[ 0 ]->m_pVertex = pVertices[ 1 ]; -// -// // Make vertices point to the correct half-edges -// -// //pHalfEdges[ 0 ]->m_pVertex->m_pHalfEdge = pHalfEdges[ 0 ]; -// //pHalfEdges[ 1 ]->m_pVertex->m_pHalfEdge = pHalfEdges[ 1 ]; -// //pHalfEdges[ 2 ]->m_pVertex->m_pHalfEdge = pHalfEdges[ 2 ]; -// -// // Flip normal and change the sign of plane distance -// -//#ifdef EPA_POLYHEDRON_USE_PLANES -// m_planeNormal = -m_planeNormal; -// m_planeDistance = -m_planeDistance; -//#endif -//} - diff --git a/Extras/obsolete/EPA/EpaFace.h b/Extras/obsolete/EPA/EpaFace.h deleted file mode 100644 index d77d0d5d4..000000000 --- a/Extras/obsolete/EPA/EpaFace.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef EPA_FACE_H -#define EPA_FACE_H - -class EpaVertex; -class EpaHalfEdge; - -#ifdef EPA_POLYHEDRON_USE_PLANES -extern btScalar PLANE_THICKNESS; -#endif - -//! Note : This class is not supposed to be a base class -class EpaFace -{ - private : - - //! Prevents copying objects from this class - EpaFace( const EpaFace& epaFace ); - const EpaFace& operator = ( const EpaFace& epaFace ); - - public : - - EpaFace(); - ~EpaFace(); - - bool Initialize(); - -#ifdef EPA_POLYHEDRON_USE_PLANES - bool CalculatePlane(); -#endif - void CalcClosestPoint(); - void CalcClosestPointOnA( btVector3& closestPointOnA ); - void CalcClosestPointOnB( btVector3& closestPointOnB ); - - bool IsAffinelyDependent() const; - bool IsClosestPointInternal() const; - - void CollectVertices( EpaVertex** ppVertices ); - - //void FixOrder(); - - public : - - EpaHalfEdge* m_pHalfEdge; - - // We keep vertices here so we don't need to call CollectVertices - // every time we need them - EpaVertex* m_pVertices[ 3 ]; - -#ifdef EPA_POLYHEDRON_USE_PLANES - btVector3 m_planeNormal; - btScalar m_planeDistance; - - //btVector3 m_robustPlaneNormal; - //btScalar m_robustPlaneDistance; -#endif - - btVector3 m_v; - btScalar m_vSqrd; - - btScalar m_determinant; - btScalar m_lambdas[ 2 ]; - - bool m_deleted; -}; - -#endif - diff --git a/Extras/obsolete/EPA/EpaHalfEdge.h b/Extras/obsolete/EPA/EpaHalfEdge.h deleted file mode 100644 index 56ba156bc..000000000 --- a/Extras/obsolete/EPA/EpaHalfEdge.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef EPA_HALF_EDGE_H -#define EPA_HALF_EDGE_H - -class EpaFace; -class EpaVertex; - -//! Note : This class is not supposed to be a base class -class EpaHalfEdge -{ - private : - - //! Prevents copying objects from this class - EpaHalfEdge( const EpaHalfEdge& epaHalfEdge ); - const EpaHalfEdge& operator = ( const EpaHalfEdge& epaHalfEdge ); - - public : - - EpaHalfEdge() : m_pTwin( 0 ), m_pNextCCW( 0 ), m_pFace( 0 ), m_pVertex( 0 ) - { - } - - ~EpaHalfEdge() - { - } - - public : - - //! Twin half-edge link - EpaHalfEdge* m_pTwin; - - //! Next half-edge in counter clock-wise ( CCW ) order - EpaHalfEdge* m_pNextCCW; - - //! Parent face link - EpaFace* m_pFace; - - //! Origin vertex link - EpaVertex* m_pVertex; -}; - -#endif - diff --git a/Extras/obsolete/EPA/EpaPenetrationDepthSolver.cpp b/Extras/obsolete/EPA/EpaPenetrationDepthSolver.cpp deleted file mode 100644 index 4cfe9ab6e..000000000 --- a/Extras/obsolete/EPA/EpaPenetrationDepthSolver.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#include "LinearMath/btScalar.h" -#include "LinearMath/btVector3.h" -#include "LinearMath/btPoint3.h" -#include "LinearMath/btTransform.h" -#include "LinearMath/btMinMax.h" - -#include - -#include "BulletCollision/CollisionShapes/btConvexShape.h" - -#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h" - -#include "EpaCommon.h" - -#include "EpaVertex.h" -#include "EpaHalfEdge.h" -#include "EpaFace.h" -#include "EpaPolyhedron.h" -#include "Epa.h" -#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h" -#include "EpaPenetrationDepthSolver.h" - -btScalar g_GJKMaxRelError = 1e-3f; -btScalar g_GJKMaxRelErrorSqrd = g_GJKMaxRelError * g_GJKMaxRelError; - -bool EpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& simplexSolver, - btConvexShape* pConvexA, btConvexShape* pConvexB, - const btTransform& transformA, const btTransform& transformB, - btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB, - class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc ) -{ - EPA_DEBUG_ASSERT( pConvexA ,"Convex shape A is invalid!" ); - EPA_DEBUG_ASSERT( pConvexB ,"Convex shape B is invalid!" ); - - btScalar penDepth; - -#ifdef EPA_USE_HYBRID - bool needsEPA = !HybridPenDepth( simplexSolver, pConvexA, pConvexB, transformA, transformB, - wWitnessOnA, wWitnessOnB, penDepth, v ); - - if ( needsEPA ) - { -#endif - penDepth = EpaPenDepth( simplexSolver, pConvexA, pConvexB, - transformA, transformB, - wWitnessOnA, wWitnessOnB ); - EPA_DEBUG_ASSERT( ( penDepth > 0 ) ,"EPA or Hybrid Technique failed to calculate penetration depth!" ); - -#ifdef EPA_USE_HYBRID - } -#endif - - return ( penDepth > 0 ); -} - -#ifdef EPA_USE_HYBRID -bool EpaPenetrationDepthSolver::HybridPenDepth( btSimplexSolverInterface& simplexSolver, - btConvexShape* pConvexA, btConvexShape* pConvexB, - const btTransform& transformA, const btTransform& transformB, - btPoint3& wWitnessOnA, btPoint3& wWitnessOnB, - btScalar& penDepth, btVector3& v ) -{ - btScalar squaredDistance = SIMD_INFINITY; - btScalar delta = 0.f; - - const btScalar margin = pConvexA->getMargin() + pConvexB->getMargin(); - const btScalar marginSqrd = margin * margin; - - simplexSolver.reset(); - - int nbIterations = 0; - - while ( true ) - { - assert( ( v.length2() > 0 ) && "Warning: v is the zero vector!" ); - - btVector3 seperatingAxisInA = -v * transformA.getBasis(); - btVector3 seperatingAxisInB = v * transformB.getBasis(); - - btVector3 pInA = pConvexA->localGetSupportingVertexWithoutMargin( seperatingAxisInA ); - btVector3 qInB = pConvexB->localGetSupportingVertexWithoutMargin( seperatingAxisInB ); - - btPoint3 pWorld = transformA( pInA ); - btPoint3 qWorld = transformB( qInB ); - - btVector3 w = pWorld - qWorld; - delta = v.dot( w ); - - // potential exit, they don't overlap - if ( ( delta > 0 ) && ( ( delta * delta / squaredDistance ) > marginSqrd ) ) - { - // Convex shapes do not overlap - // Returning true means that Hybrid's result is ok and there's no need to run EPA - penDepth = 0; - return true; - } - - //exit 0: the new point is already in the simplex, or we didn't come any closer - if ( ( squaredDistance - delta <= squaredDistance * g_GJKMaxRelErrorSqrd ) || simplexSolver.inSimplex( w ) ) - { - simplexSolver.compute_points( wWitnessOnA, wWitnessOnB ); - - assert( ( squaredDistance > 0 ) && "squaredDistance is zero!" ); - btScalar vLength = sqrt( squaredDistance ); - - wWitnessOnA -= v * ( pConvexA->getMargin() / vLength ); - wWitnessOnB += v * ( pConvexB->getMargin() / vLength ); - - penDepth = pConvexA->getMargin() + pConvexB->getMargin() - vLength; - - // Returning true means that Hybrid's result is ok and there's no need to run EPA - return true; - } - - //add current vertex to simplex - simplexSolver.addVertex( w, pWorld, qWorld ); - - //calculate the closest point to the origin (update vector v) - if ( !simplexSolver.closest( v ) ) - { - simplexSolver.compute_points( wWitnessOnA, wWitnessOnB ); - - assert( ( squaredDistance > 0 ) && "squaredDistance is zero!" ); - btScalar vLength = sqrt( squaredDistance ); - - wWitnessOnA -= v * ( pConvexA->getMargin() / vLength ); - wWitnessOnB += v * ( pConvexB->getMargin() / vLength ); - - penDepth = pConvexA->getMargin() + pConvexB->getMargin() - vLength; - - // Returning true means that Hybrid's result is ok and there's no need to run EPA - return true; - } - - btScalar previousSquaredDistance = squaredDistance; - squaredDistance = v.length2(); - - //are we getting any closer ? - if ( previousSquaredDistance - squaredDistance <= SIMD_EPSILON * previousSquaredDistance ) - { - simplexSolver.backup_closest( v ); - squaredDistance = v.length2(); - - simplexSolver.compute_points( wWitnessOnA, wWitnessOnB ); - - assert( ( squaredDistance > 0 ) && "squaredDistance is zero!" ); - btScalar vLength = sqrt( squaredDistance ); - - wWitnessOnA -= v * ( pConvexA->getMargin() / vLength ); - wWitnessOnB += v * ( pConvexB->getMargin() / vLength ); - - penDepth = pConvexA->getMargin() + pConvexB->getMargin() - vLength; - - // Returning true means that Hybrid's result is ok and there's no need to run EPA - return true; - } - - if ( simplexSolver.fullSimplex() || ( squaredDistance <= SIMD_EPSILON * simplexSolver.maxVertex() ) ) - { - // Convex Shapes intersect - we need to run EPA - // Returning false means that Hybrid couldn't do anything for us - // and that we need to run EPA to calculate the pen depth - return false; - } - - ++nbIterations; - } -} -#endif - -btScalar EpaPenetrationDepthSolver::EpaPenDepth( btSimplexSolverInterface& simplexSolver, - btConvexShape* pConvexA, btConvexShape* pConvexB, - const btTransform& transformA, const btTransform& transformB, - btPoint3& wWitnessOnA, btPoint3& wWitnessOnB ) -{ - Epa epa( pConvexA, pConvexB, transformA, transformB ); - - if ( !epa.Initialize( simplexSolver ) ) - { - EPA_DEBUG_ASSERT( false ,"Epa failed to initialize!" ); - return 0; - } - - return epa.calcPenDepth( wWitnessOnA, wWitnessOnB ); -} - diff --git a/Extras/obsolete/EPA/EpaPenetrationDepthSolver.h b/Extras/obsolete/EPA/EpaPenetrationDepthSolver.h deleted file mode 100644 index 74c8ea86e..000000000 --- a/Extras/obsolete/EPA/EpaPenetrationDepthSolver.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef EPA2_PENETRATION_DEPTH_H -#define EPA2_PENETRATION_DEPTH_H - -/** -* EpaPenetrationDepthSolver uses the Expanding Polytope Algorithm to -* calculate the penetration depth between two convex shapes. -*/ - -extern btScalar g_GJKMaxRelError; -extern btScalar g_GJKMaxRelErrorSqrd; - -//! Note : This class is not supposed to be a base class -class EpaPenetrationDepthSolver : public btConvexPenetrationDepthSolver -{ - public : - - bool calcPenDepth( btSimplexSolverInterface& simplexSolver, - btConvexShape* pConvexA, btConvexShape* pConvexB, - const btTransform& transformA, const btTransform& transformB, - btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB, - class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc ); - - private : - -#ifdef EPA_USE_HYBRID - bool HybridPenDepth( btSimplexSolverInterface& simplexSolver, - btConvexShape* pConvexA, btConvexShape* pConvexB, - const btTransform& transformA, const btTransform& transformB, - btPoint3& wWitnessOnA, btPoint3& wWitnessOnB, - btScalar& penDepth, btVector3& v ); -#endif - - btScalar EpaPenDepth( btSimplexSolverInterface& simplexSolver, - btConvexShape* pConvexA, btConvexShape* pConvexB, - const btTransform& transformA, const btTransform& transformB, - btPoint3& wWitnessOnA, btPoint3& wWitnessOnB ); -}; - -#endif // EPA_PENETRATION_DEPTH_H - diff --git a/Extras/obsolete/EPA/EpaPolyhedron.cpp b/Extras/obsolete/EPA/EpaPolyhedron.cpp deleted file mode 100644 index 9ae728c88..000000000 --- a/Extras/obsolete/EPA/EpaPolyhedron.cpp +++ /dev/null @@ -1,1026 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#include "LinearMath/btScalar.h" -#include "LinearMath/btVector3.h" -#include "LinearMath/btPoint3.h" -//#include "Memory2.h" - -#include -#ifdef _DEBUG -#include -#endif - - -#include "EpaCommon.h" - -#include "EpaVertex.h" -#include "EpaHalfEdge.h" -#include "EpaFace.h" -#include "EpaPolyhedron.h" - - -EpaPolyhedron::EpaPolyhedron() : m_nbFaces( 0 ) -{ -} - -EpaPolyhedron::~EpaPolyhedron() -{ - Destroy(); -} - -bool EpaPolyhedron::Create( btPoint3* pInitialPoints, - btPoint3* pSupportPointsOnA, btPoint3* pSupportPointsOnB, - const int nbInitialPoints ) -{ -#ifndef EPA_POLYHEDRON_USE_PLANES - EPA_DEBUG_ASSERT( ( nbInitialPoints <= 4 ) ,"nbInitialPoints greater than 4!" ); -#endif - - if ( nbInitialPoints < 4 ) - { - // Insufficient nb of points - return false; - } - - //////////////////////////////////////////////////////////////////////////////// - -#ifdef EPA_POLYHEDRON_USE_PLANES - int nbDiffCoords[ 3 ] = { 0, 0, 0 }; - - bool* pDiffCoords = new bool[ 3 * nbInitialPoints ]; - - - int i; - for (i=0;i nbDiffCoords[ i + 1 ] ) - { - int tmp = nbDiffCoords[ i ]; - nbDiffCoords[ i ] = nbDiffCoords[ i + 1 ]; - nbDiffCoords[ i + 1 ] = tmp; - - tmp = axisOrderIndices[ i ]; - axisOrderIndices[ i ] = axisOrderIndices[ i + 1 ]; - axisOrderIndices[ i + 1 ] = tmp; - } - } - - int nbSuccessfullAxis = 0; - - // The axes with less different coordinates choose first - int minsIndices[ 3 ] = { -1, -1, -1 }; - int maxsIndices[ 3 ] = { -1, -1, -1 }; - - int finalPointsIndex = 0; - - for ( axis = 0; ( axis < 3 ) && ( nbSuccessfullAxis < 2 ); ++axis ) - { - int axisIndex = axisOrderIndices[ axis ]; - - btScalar axisMin = SIMD_INFINITY; - btScalar axisMax = -SIMD_INFINITY; - - for ( int i = 0; i < 4; ++i ) - { - // Among the diff coords pick the min and max coords - - if ( pDiffCoords[ axisIndex * nbInitialPoints + i ] ) - { - if ( pInitialPoints[ i ][ axisIndex ] < axisMin ) - { - axisMin = pInitialPoints[ i ][ axisIndex ]; - minsIndices[ axisIndex ] = i; - } - - if ( pInitialPoints[ i ][ axisIndex ] > axisMax ) - { - axisMax = pInitialPoints[ i ][ axisIndex ]; - maxsIndices[ axisIndex ] = i; - } - } - } - - //assert( ( minsIndices[ axisIndex ] != maxsIndices[ axisIndex ] ) && - // "min and max have the same index!" ); - - if ( ( minsIndices[ axisIndex ] != -1 ) && ( maxsIndices[ axisIndex ] != -1 ) && - ( minsIndices[ axisIndex ] != maxsIndices[ axisIndex ] ) ) - { - ++nbSuccessfullAxis; - - finalPointsIndices[ finalPointsIndex++ ] = minsIndices[ axisIndex ]; - finalPointsIndices[ finalPointsIndex++ ] = maxsIndices[ axisIndex ]; - - // Make the choosen points to be impossible for other axes to choose - - //assert( ( minsIndices[ axisIndex ] != -1 ) && "Invalid index!" ); - //assert( ( maxsIndices[ axisIndex ] != -1 ) && "Invalid index!" ); - - for ( int i = 0; i < 3; ++i ) - { - pDiffCoords[ i * nbInitialPoints + minsIndices[ axisIndex ] ] = false; - pDiffCoords[ i * nbInitialPoints + maxsIndices[ axisIndex ] ] = false; - } - } - } - - if ( nbSuccessfullAxis <= 1 ) - { - // Degenerate input ? - EPA_DEBUG_ASSERT( false ,"nbSuccessfullAxis must be greater than 1!" ); - return false; - } - - delete[] pDiffCoords; -#endif - - ////////////////////////////////////////////////////////////////////////// - -#ifdef EPA_POLYHEDRON_USE_PLANES - btVector3 v0 = pInitialPoints[ finalPointsIndices[ 1 ] ] - pInitialPoints[ finalPointsIndices[ 0 ] ]; - btVector3 v1 = pInitialPoints[ finalPointsIndices[ 2 ] ] - pInitialPoints[ finalPointsIndices[ 0 ] ]; -#else - btVector3 v0 = pInitialPoints[ 1 ] - pInitialPoints[ 0 ]; - btVector3 v1 = pInitialPoints[ 2 ] - pInitialPoints[ 0 ]; -#endif - - btVector3 planeNormal = v1.cross( v0 ); - planeNormal.normalize(); - -#ifdef EPA_POLYHEDRON_USE_PLANES - btScalar planeDistance = pInitialPoints[ finalPointsIndices[ 0 ] ].dot( -planeNormal ); -#else - btScalar planeDistance = pInitialPoints[ 0 ].dot( -planeNormal ); -#endif - -#ifdef EPA_POLYHEDRON_USE_PLANES - bool pointOnPlane0 = btEqual( pInitialPoints[ finalPointsIndices[ 0 ] ].dot( planeNormal ) + planeDistance, PLANE_THICKNESS ); - if (!pointOnPlane0) - { - EPA_DEBUG_ASSERT(0,"Point0 should be on plane!"); - return false; - } - bool pointOnPlane1 = btEqual( pInitialPoints[ finalPointsIndices[ 1 ] ].dot( planeNormal ) + planeDistance, PLANE_THICKNESS ); - if (!pointOnPlane1) - { - EPA_DEBUG_ASSERT(0,"Point1 should be on plane!"); - return false; - } - bool pointOnPlane2 = btEqual( pInitialPoints[ finalPointsIndices[ 2 ] ].dot( planeNormal ) + planeDistance, PLANE_THICKNESS ); - if (!pointOnPlane2) - { - EPA_DEBUG_ASSERT(0,"Point2 should be on plane!"); - return false; - } -#endif - -#ifndef EPA_POLYHEDRON_USE_PLANES - { - if ( planeDistance > 0 ) - { - btVector3 tmp = pInitialPoints[ 1 ]; - pInitialPoints[ 1 ] = pInitialPoints[ 2 ]; - pInitialPoints[ 2 ] = tmp; - - tmp = pSupportPointsOnA[ 1 ]; - pSupportPointsOnA[ 1 ] = pSupportPointsOnA[ 2 ]; - pSupportPointsOnA[ 2 ] = tmp; - - tmp = pSupportPointsOnB[ 1 ]; - pSupportPointsOnB[ 1 ] = pSupportPointsOnB[ 2 ]; - pSupportPointsOnB[ 2 ] = tmp; - } - } - - EpaVertex* pVertexA = CreateVertex( pInitialPoints[ 0 ], pSupportPointsOnA[ 0 ], pSupportPointsOnB[ 0 ] ); - EpaVertex* pVertexB = CreateVertex( pInitialPoints[ 1 ], pSupportPointsOnA[ 1 ], pSupportPointsOnB[ 1 ] ); - EpaVertex* pVertexC = CreateVertex( pInitialPoints[ 2 ], pSupportPointsOnA[ 2 ], pSupportPointsOnB[ 2 ] ); - EpaVertex* pVertexD = CreateVertex( pInitialPoints[ 3 ], pSupportPointsOnA[ 3 ], pSupportPointsOnB[ 3 ] ); -#else - finalPointsIndices[ 3 ] = -1; - - btScalar absMaxDist = -SIMD_INFINITY; - btScalar maxDist; - - for ( int pointIndex = 0; pointIndex < nbInitialPoints; ++pointIndex ) - { - btScalar dist = planeNormal.dot( pInitialPoints[ pointIndex ] ) + planeDistance; - btScalar absDist = abs( dist ); - - if ( ( absDist > absMaxDist ) && - !btEqual( dist, PLANE_THICKNESS ) ) - { - absMaxDist = absDist; - maxDist = dist; - finalPointsIndices[ 3 ] = pointIndex; - } - } - - if ( finalPointsIndices[ 3 ] == -1 ) - { - Destroy(); - return false; - } - - if ( maxDist > PLANE_THICKNESS ) - { - // Can swap indices only - - btPoint3 tmp = pInitialPoints[ finalPointsIndices[ 1 ] ]; - pInitialPoints[ finalPointsIndices[ 1 ] ] = pInitialPoints[ finalPointsIndices[ 2 ] ]; - pInitialPoints[ finalPointsIndices[ 2 ] ] = tmp; - - tmp = pSupportPointsOnA[ finalPointsIndices[ 1 ] ]; - pSupportPointsOnA[ finalPointsIndices[ 1 ] ] = pSupportPointsOnA[ finalPointsIndices[ 2 ] ]; - pSupportPointsOnA[ finalPointsIndices[ 2 ] ] = tmp; - - tmp = pSupportPointsOnB[ finalPointsIndices[ 1 ] ]; - pSupportPointsOnB[ finalPointsIndices[ 1 ] ] = pSupportPointsOnB[ finalPointsIndices[ 2 ] ]; - pSupportPointsOnB[ finalPointsIndices[ 2 ] ] = tmp; - } - - EpaVertex* pVertexA = CreateVertex( pInitialPoints[ finalPointsIndices[ 0 ] ], pSupportPointsOnA[ finalPointsIndices[ 0 ] ], pSupportPointsOnB[ finalPointsIndices[ 0 ] ] ); - EpaVertex* pVertexB = CreateVertex( pInitialPoints[ finalPointsIndices[ 1 ] ], pSupportPointsOnA[ finalPointsIndices[ 1 ] ], pSupportPointsOnB[ finalPointsIndices[ 1 ] ] ); - EpaVertex* pVertexC = CreateVertex( pInitialPoints[ finalPointsIndices[ 2 ] ], pSupportPointsOnA[ finalPointsIndices[ 2 ] ], pSupportPointsOnB[ finalPointsIndices[ 2 ] ] ); - EpaVertex* pVertexD = CreateVertex( pInitialPoints[ finalPointsIndices[ 3 ] ], pSupportPointsOnA[ finalPointsIndices[ 3 ] ], pSupportPointsOnB[ finalPointsIndices[ 3 ] ] ); -#endif - - EpaFace* pFaceA = CreateFace(); - EpaFace* pFaceB = CreateFace(); - EpaFace* pFaceC = CreateFace(); - EpaFace* pFaceD = CreateFace(); - - EpaHalfEdge* pFaceAHalfEdges[ 3 ]; - EpaHalfEdge* pFaceCHalfEdges[ 3 ]; - EpaHalfEdge* pFaceBHalfEdges[ 3 ]; - EpaHalfEdge* pFaceDHalfEdges[ 3 ]; - - pFaceAHalfEdges[ 0 ] = CreateHalfEdge(); - pFaceAHalfEdges[ 1 ] = CreateHalfEdge(); - pFaceAHalfEdges[ 2 ] = CreateHalfEdge(); - - pFaceBHalfEdges[ 0 ] = CreateHalfEdge(); - pFaceBHalfEdges[ 1 ] = CreateHalfEdge(); - pFaceBHalfEdges[ 2 ] = CreateHalfEdge(); - - pFaceCHalfEdges[ 0 ] = CreateHalfEdge(); - pFaceCHalfEdges[ 1 ] = CreateHalfEdge(); - pFaceCHalfEdges[ 2 ] = CreateHalfEdge(); - - pFaceDHalfEdges[ 0 ] = CreateHalfEdge(); - pFaceDHalfEdges[ 1 ] = CreateHalfEdge(); - pFaceDHalfEdges[ 2 ] = CreateHalfEdge(); - - pFaceA->m_pHalfEdge = pFaceAHalfEdges[ 0 ]; - pFaceB->m_pHalfEdge = pFaceBHalfEdges[ 0 ]; - pFaceC->m_pHalfEdge = pFaceCHalfEdges[ 0 ]; - pFaceD->m_pHalfEdge = pFaceDHalfEdges[ 0 ]; - - pFaceAHalfEdges[ 0 ]->m_pNextCCW = pFaceAHalfEdges[ 1 ]; - pFaceAHalfEdges[ 1 ]->m_pNextCCW = pFaceAHalfEdges[ 2 ]; - pFaceAHalfEdges[ 2 ]->m_pNextCCW = pFaceAHalfEdges[ 0 ]; - - pFaceBHalfEdges[ 0 ]->m_pNextCCW = pFaceBHalfEdges[ 1 ]; - pFaceBHalfEdges[ 1 ]->m_pNextCCW = pFaceBHalfEdges[ 2 ]; - pFaceBHalfEdges[ 2 ]->m_pNextCCW = pFaceBHalfEdges[ 0 ]; - - pFaceCHalfEdges[ 0 ]->m_pNextCCW = pFaceCHalfEdges[ 1 ]; - pFaceCHalfEdges[ 1 ]->m_pNextCCW = pFaceCHalfEdges[ 2 ]; - pFaceCHalfEdges[ 2 ]->m_pNextCCW = pFaceCHalfEdges[ 0 ]; - - pFaceDHalfEdges[ 0 ]->m_pNextCCW = pFaceDHalfEdges[ 1 ]; - pFaceDHalfEdges[ 1 ]->m_pNextCCW = pFaceDHalfEdges[ 2 ]; - pFaceDHalfEdges[ 2 ]->m_pNextCCW = pFaceDHalfEdges[ 0 ]; - - - pFaceAHalfEdges[ 0 ]->m_pFace = pFaceA; - pFaceAHalfEdges[ 1 ]->m_pFace = pFaceA; - pFaceAHalfEdges[ 2 ]->m_pFace = pFaceA; - - pFaceBHalfEdges[ 0 ]->m_pFace = pFaceB; - pFaceBHalfEdges[ 1 ]->m_pFace = pFaceB; - pFaceBHalfEdges[ 2 ]->m_pFace = pFaceB; - - pFaceCHalfEdges[ 0 ]->m_pFace = pFaceC; - pFaceCHalfEdges[ 1 ]->m_pFace = pFaceC; - pFaceCHalfEdges[ 2 ]->m_pFace = pFaceC; - - pFaceDHalfEdges[ 0 ]->m_pFace = pFaceD; - pFaceDHalfEdges[ 1 ]->m_pFace = pFaceD; - pFaceDHalfEdges[ 2 ]->m_pFace = pFaceD; - - - pFaceAHalfEdges[ 0 ]->m_pVertex = pVertexA; - pFaceAHalfEdges[ 1 ]->m_pVertex = pVertexB; - pFaceAHalfEdges[ 2 ]->m_pVertex = pVertexC; - - pFaceBHalfEdges[ 0 ]->m_pVertex = pVertexB; - pFaceBHalfEdges[ 1 ]->m_pVertex = pVertexD; - pFaceBHalfEdges[ 2 ]->m_pVertex = pVertexC; - - pFaceCHalfEdges[ 0 ]->m_pVertex = pVertexD; - pFaceCHalfEdges[ 1 ]->m_pVertex = pVertexA; - pFaceCHalfEdges[ 2 ]->m_pVertex = pVertexC; - - pFaceDHalfEdges[ 0 ]->m_pVertex = pVertexB; - pFaceDHalfEdges[ 1 ]->m_pVertex = pVertexA; - pFaceDHalfEdges[ 2 ]->m_pVertex = pVertexD; - - //pVertexA->m_pHalfEdge = pFaceAHalfEdges[ 0 ]; - //pVertexB->m_pHalfEdge = pFaceAHalfEdges[ 1 ]; - //pVertexC->m_pHalfEdge = pFaceAHalfEdges[ 2 ]; - //pVertexD->m_pHalfEdge = pFaceBHalfEdges[ 1 ]; - - pFaceAHalfEdges[ 0 ]->m_pTwin = pFaceDHalfEdges[ 0 ]; - pFaceAHalfEdges[ 1 ]->m_pTwin = pFaceBHalfEdges[ 2 ]; - pFaceAHalfEdges[ 2 ]->m_pTwin = pFaceCHalfEdges[ 1 ]; - - pFaceBHalfEdges[ 0 ]->m_pTwin = pFaceDHalfEdges[ 2 ]; - pFaceBHalfEdges[ 1 ]->m_pTwin = pFaceCHalfEdges[ 2 ]; - pFaceBHalfEdges[ 2 ]->m_pTwin = pFaceAHalfEdges[ 1 ]; - - pFaceCHalfEdges[ 0 ]->m_pTwin = pFaceDHalfEdges[ 1 ]; - pFaceCHalfEdges[ 1 ]->m_pTwin = pFaceAHalfEdges[ 2 ]; - pFaceCHalfEdges[ 2 ]->m_pTwin = pFaceBHalfEdges[ 1 ]; - - pFaceDHalfEdges[ 0 ]->m_pTwin = pFaceAHalfEdges[ 0 ]; - pFaceDHalfEdges[ 1 ]->m_pTwin = pFaceCHalfEdges[ 0 ]; - pFaceDHalfEdges[ 2 ]->m_pTwin = pFaceBHalfEdges[ 0 ]; - - if ( !pFaceA->Initialize() || !pFaceB->Initialize() || - !pFaceC->Initialize() || !pFaceD->Initialize() ) - { - EPA_DEBUG_ASSERT( false, "One initial face failed to initialize!" ); - return false; - } - -#ifdef EPA_POLYHEDRON_USE_PLANES - if ( nbInitialPoints > 4 ) - { - for ( int i = 0; i < nbInitialPoints; ++i ) - { - if ( ( i != finalPointsIndices[ 0 ] ) && ( i != finalPointsIndices[ 1 ] ) && - ( i != finalPointsIndices[ 2 ] ) && ( i != finalPointsIndices[ 3 ] ) ) - { - std::list< EpaFace* >::iterator facesItr( m_faces.begin() ); - - while ( facesItr != m_faces.end() ) - { - EpaFace* pFace = *facesItr; - - btScalar dist = pFace->m_planeNormal.dot( pInitialPoints[ i ] ) + pFace->m_planeDistance; - - if ( dist > PLANE_THICKNESS ) - { - std::list< EpaFace* > newFaces; - - bool expandOk = Expand( pInitialPoints[ i ], pSupportPointsOnA[ i ], pSupportPointsOnB[ i ], - pFace, newFaces ); - - if ( !expandOk ) - { - // One or more new faces are affinely dependent - return false; - } - - EPA_DEBUG_ASSERT( !newFaces.empty() ,"Polyhedron should have expanded!" ); - - break; - } - - ++facesItr; - } - } - } - } -#endif - - return true; -} - -void EpaPolyhedron::Destroy() -{ - DestroyAllVertices(); - - DestroyAllHalfEdges(); - - DestroyAllFaces(); -} - -EpaFace* EpaPolyhedron::CreateFace() -{ - EpaFace* pNewFace = new EpaFace(); - EPA_DEBUG_ASSERT( pNewFace , "Failed to allocate memory for a new EpaFace!" ); - - m_faces.push_back( pNewFace ); - - ++m_nbFaces; - - return pNewFace; -} - -EpaHalfEdge* EpaPolyhedron::CreateHalfEdge() -{ - EpaHalfEdge* pNewHalfEdge = new EpaHalfEdge(); - EPA_DEBUG_ASSERT( pNewHalfEdge ,"Failed to allocate memory for a new EpaHalfEdge!" ); - - m_halfEdges.push_back( pNewHalfEdge ); - - return pNewHalfEdge; -} - -EpaVertex* EpaPolyhedron::CreateVertex( const btPoint3& wSupportPoint, - const btPoint3& wSupportPointOnA, - const btPoint3& wSupportPointOnB ) -{ - EpaVertex* pNewVertex = new EpaVertex( wSupportPoint, wSupportPointOnA, wSupportPointOnB ); - EPA_DEBUG_ASSERT( pNewVertex ,"Failed to allocate memory for a new EpaVertex!" ); - - m_vertices.push_back( pNewVertex ); - - return pNewVertex; -} - -void EpaPolyhedron::DeleteFace( EpaFace* pFace ) -{ - pFace->m_deleted = true; - --m_nbFaces; -} - -void EpaPolyhedron::DestroyAllFaces() -{ - while ( !m_faces.empty() ) - { - EpaFace* pFace = m_faces.front(); - - delete pFace; - - m_faces.pop_front(); - } - - m_nbFaces = 0; -} - -void EpaPolyhedron::DestroyAllHalfEdges() -{ - while ( !m_halfEdges.empty() ) - { - EpaHalfEdge* pHalfEdge = m_halfEdges.front(); - - delete pHalfEdge; - - m_halfEdges.pop_front(); - } -} - -void EpaPolyhedron::DestroyAllVertices() -{ - while ( !m_vertices.empty() ) - { - EpaVertex* pVertex = m_vertices.front(); - - delete pVertex; - - m_vertices.pop_front(); - } -} - -bool EpaPolyhedron::Expand( const btPoint3& wSupportPoint, - const btPoint3& wSupportPointOnA, - const btPoint3& wSupportPointOnB, - EpaFace* pFace, std::list< EpaFace* >& newFaces ) -{ - EPA_DEBUG_ASSERT( !pFace->m_deleted ,"Face is already deleted!" ); - EPA_DEBUG_ASSERT( newFaces.empty() ,"NewFaces list must be empty!" ); - - EPA_DEBUG_ASSERT( !pFace->m_deleted ,"Cannot expand deleted face!" ); - - // wSupportPoint must be front of face's plane used to do the expansion - -#ifdef EPA_POLYHEDRON_USE_PLANES - btScalar dist = pFace->m_planeNormal.dot( wSupportPoint ) + pFace->m_planeDistance; - if ( dist <= PLANE_THICKNESS ) - { - return false; - } -#endif - - std::list< EpaHalfEdge* > coneBaseEdges; - DeleteVisibleFaces( wSupportPoint, pFace, coneBaseEdges ); - - EPA_DEBUG_ASSERT( ( coneBaseEdges.size() >= 3 ) ,"Cone base must have at least 3 edges!" ); - - EpaVertex* pConeAppex = CreateVertex( wSupportPoint, wSupportPointOnA, wSupportPointOnB ); - EPA_DEBUG_ASSERT( pConeAppex ,"Failed to create vertex!" ); - - CreateCone( pConeAppex, coneBaseEdges, newFaces ); - - // Initialize new faces - - std::list< EpaFace* >::iterator newFacesItr( newFaces.begin() ); - - while ( newFacesItr != newFaces.end() ) - { - EpaFace* pNewFace = *newFacesItr; - - if ( !pNewFace->Initialize() ) - { - return false; - } - - ++newFacesItr; - } - - return true; -} - -std::list< EpaFace* >& EpaPolyhedron::GetFaces() -{ - return m_faces; -} - -int EpaPolyhedron::GetNbFaces() const -{ - return m_faces.size(); -} - -void EpaPolyhedron::DeleteVisibleFaces( const btPoint3& point, EpaFace* pFace, - std::list< EpaHalfEdge* >& coneBaseTwinHalfEdges ) -{ - EPA_DEBUG_ASSERT( !pFace->m_deleted ,"Face is already deleted!" ); - - DeleteFace( pFace ); - - EpaHalfEdge* pCurrentHalfEdge = pFace->m_pHalfEdge; - - do - { - EPA_DEBUG_ASSERT( pCurrentHalfEdge->m_pTwin ,"Half-edge without a twin!" ); - - EpaFace* pAdjacentFace = pCurrentHalfEdge->m_pTwin->m_pFace; - EPA_DEBUG_ASSERT( pAdjacentFace ,"Invalid adjacent face!" ); - - if ( !pAdjacentFace->m_deleted ) - { -#ifdef EPA_POLYHEDRON_USE_PLANES - EPA_DEBUG_ASSERT( ( pAdjacentFace->m_planeNormal.length2() > 0 ) ,"Invalid plane!" ); - - btScalar pointDist = pAdjacentFace->m_planeNormal.dot( point ) + - pAdjacentFace->m_planeDistance; - - if ( pointDist > PLANE_THICKNESS ) -#else - btScalar dot = pAdjacentFace->m_v.dot( point ); - if ( dot >= pAdjacentFace->m_vSqrd ) -#endif - { - DeleteVisibleFaces( point, pAdjacentFace, coneBaseTwinHalfEdges ); - } - else - { - coneBaseTwinHalfEdges.push_back( pCurrentHalfEdge->m_pTwin ); - } - } - - pCurrentHalfEdge = pCurrentHalfEdge->m_pNextCCW; - } - while( pCurrentHalfEdge != pFace->m_pHalfEdge ); -} - -void EpaPolyhedron::CreateCone( EpaVertex* pAppexVertex, std::list< EpaHalfEdge* >& baseTwinHalfEdges, - std::list< EpaFace* >& newFaces ) -{ - EPA_DEBUG_ASSERT( ( baseTwinHalfEdges.size() >= 3 ) ,"DeleteVisibleFaces method didn't do its job right!" ); - - std::list< EpaHalfEdge* >::iterator baseHalfEdgesItr( baseTwinHalfEdges.begin() ); - std::list< EpaHalfEdge* > halfEdgesToLink; - - while ( baseHalfEdgesItr != baseTwinHalfEdges.end() ) - { - EpaFace* pNewFace = CreateConeFace( pAppexVertex, *baseHalfEdgesItr, halfEdgesToLink ); - - newFaces.push_back( pNewFace ); - - ++baseHalfEdgesItr; - } - - // Connect consecutive faces by linking twin half-edges - - EPA_DEBUG_ASSERT( ( halfEdgesToLink.size() % 2 == 0 ) ,"Nb half-edges to link is odd!" ); - - int nbLinksToCreate = halfEdgesToLink.size() / 2; - int nbLinksCreated = 0; - - std::list< EpaHalfEdge* >::iterator halfEdgesItr( halfEdgesToLink.begin() ); - - for ( ; ( halfEdgesItr != halfEdgesToLink.end() ) && ( nbLinksCreated < nbLinksToCreate ); ++halfEdgesItr ) - { - std::list< EpaHalfEdge* >::iterator halfEdgesItr2( halfEdgesItr ); - ++halfEdgesItr2; - - for ( ; ( halfEdgesItr2 != halfEdgesToLink.end() ) && ( nbLinksCreated < nbLinksToCreate ); ++halfEdgesItr2 ) - { - EpaHalfEdge* pHalfEdge1 = *halfEdgesItr; - EpaHalfEdge* pHalfEdge2 = *halfEdgesItr2; - - EpaHalfEdge* pHalfEdgeNextCCW1 = pHalfEdge1->m_pNextCCW; - EpaHalfEdge* pHalfEdgeNextCCW2 = pHalfEdge2->m_pNextCCW; - - if ( ( pHalfEdge2->m_pVertex == pHalfEdgeNextCCW1->m_pVertex ) && - ( pHalfEdgeNextCCW2->m_pVertex == pHalfEdge1->m_pVertex ) ) - { - pHalfEdge1->m_pTwin = pHalfEdge2; - pHalfEdge2->m_pTwin = pHalfEdge1; - - ++nbLinksCreated; - } - } - } - - EPA_DEBUG_ASSERT( ( nbLinksCreated == nbLinksToCreate ) ,"Mesh topology not ok!" ); -} - -EpaFace* EpaPolyhedron::CreateConeFace( EpaVertex* pAppexVertex, EpaHalfEdge* pBaseTwinHalfEdge, - std::list< EpaHalfEdge* >& halfEdgesToLink ) -{ - EpaFace* pNewFace = CreateFace(); - - EpaHalfEdge* pNewHalfEdge0 = CreateHalfEdge(); - EpaHalfEdge* pNewHalfEdge1 = CreateHalfEdge(); - EpaHalfEdge* pNewHalfEdge2 = CreateHalfEdge(); - - // Let new face point to one of its new half-edges - pNewFace->m_pHalfEdge = pNewHalfEdge0; - - // Link new half-edges in a loop - - pNewHalfEdge0->m_pNextCCW = pNewHalfEdge1; - pNewHalfEdge1->m_pNextCCW = pNewHalfEdge2; - pNewHalfEdge2->m_pNextCCW = pNewHalfEdge0; - - // Let new half-edges point to new face - - pNewHalfEdge0->m_pFace = pNewFace; - pNewHalfEdge1->m_pFace = pNewFace; - pNewHalfEdge2->m_pFace = pNewFace; - - // Let new half-edge 0 and base twin half-edge point to each other - - pNewHalfEdge0->m_pTwin = pBaseTwinHalfEdge; - pBaseTwinHalfEdge->m_pTwin = pNewHalfEdge0; - - // Let new half-edges know about their origin vertex - - pNewHalfEdge0->m_pVertex = pBaseTwinHalfEdge->m_pNextCCW->m_pVertex; - pNewHalfEdge1->m_pVertex = pBaseTwinHalfEdge->m_pVertex; - pNewHalfEdge2->m_pVertex = pAppexVertex; - - // Let vertices know about one of their outgoing edges - - //pNewHalfEdge0->m_pVertex->m_pHalfEdge = pNewHalfEdge0; - //pNewHalfEdge1->m_pVertex->m_pHalfEdge = pNewHalfEdge1; - //pNewHalfEdge2->m_pVertex->m_pHalfEdge = pNewHalfEdge2; - - halfEdgesToLink.push_back( pNewHalfEdge1 ); - halfEdgesToLink.push_back( pNewHalfEdge2 ); - - return pNewFace; -} - - -#ifdef DO_SOME_DEBUGGING_ -#ifdef _DEBUG -bool EpaPolyhedron::_dbgSaveToFile( const char* pFileName ) -{ - FILE* fp = NULL; - - if ( fopen_s( &fp, pFileName, "wb" ) != 0 ) - { - return false; - } - - unsigned long int nbBytesWritten; - unsigned long int byteIndex = 0; - - unsigned long int fileID = 0xBADC0DE; - fwrite( &fileID, sizeof( fileID ), 1, fp ); - nbBytesWritten = sizeof( fileID ); - byteIndex += nbBytesWritten; - - unsigned char reservedByte = 0; - fwrite( &reservedByte, sizeof( reservedByte ), 1, fp ); - nbBytesWritten = sizeof( reservedByte ); - byteIndex += nbBytesWritten; - fwrite( &reservedByte, sizeof( reservedByte ), 1, fp ); - nbBytesWritten = sizeof( reservedByte ); - byteIndex += nbBytesWritten; - fwrite( &reservedByte, sizeof( reservedByte ), 1, fp ); - nbBytesWritten = sizeof( reservedByte ); - byteIndex += nbBytesWritten; - - fwrite( &reservedByte, sizeof( reservedByte ), 1, fp ); - nbBytesWritten = sizeof( reservedByte ); - byteIndex += nbBytesWritten; - fwrite( &reservedByte, sizeof( reservedByte ), 1, fp ); - nbBytesWritten = sizeof( reservedByte ); - byteIndex += nbBytesWritten; - fwrite( &reservedByte, sizeof( reservedByte ), 1, fp ); - nbBytesWritten = sizeof( reservedByte ); - byteIndex += nbBytesWritten; - - unsigned char stringSize = 5; - fwrite( &stringSize, sizeof( stringSize ), 1, fp ); - nbBytesWritten = sizeof( stringSize ); - byteIndex += nbBytesWritten; - - char exportedFrom[ 6 ] = "01234"; - fwrite( exportedFrom, stringSize * sizeof( char ), 1, fp ); - nbBytesWritten = stringSize * sizeof( char ); - byteIndex += nbBytesWritten; - - unsigned short int w = 0; - - fwrite( &w, sizeof( w ), 1, fp ); - nbBytesWritten = sizeof( w ); - byteIndex += nbBytesWritten; - fwrite( &w, sizeof( w ), 1, fp ); - nbBytesWritten = sizeof( w ); - byteIndex += nbBytesWritten; - fwrite( &w, sizeof( w ), 1, fp ); - nbBytesWritten = sizeof( w ); - byteIndex += nbBytesWritten; - - fwrite( &w, sizeof( w ), 1, fp ); - nbBytesWritten = sizeof( w ); - byteIndex += nbBytesWritten; - fwrite( &w, sizeof( w ), 1, fp ); - nbBytesWritten = sizeof( w ); - byteIndex += nbBytesWritten; - fwrite( &w, sizeof( w ), 1, fp ); - nbBytesWritten = sizeof( w ); - byteIndex += nbBytesWritten; - - unsigned long int geometryOffsetAtByteNb = byteIndex; - - unsigned long int geometryOffset = 0; - unsigned long int geometrySize = 0; - - fseek( fp, sizeof( geometryOffset ) + sizeof( geometrySize ), SEEK_CUR ); - byteIndex += sizeof( geometryOffset ) + sizeof( geometrySize ); - - unsigned long int mappingOffset = 0; - unsigned long int mappingSize = 0; - - fwrite( &mappingOffset, sizeof( mappingOffset ), 1, fp ); - nbBytesWritten = sizeof( mappingOffset ); - byteIndex += nbBytesWritten; - - fwrite( &mappingSize, sizeof( mappingSize ), 1, fp ); - nbBytesWritten = sizeof( mappingSize ); - byteIndex += nbBytesWritten; - - unsigned long int animationOffset = 0; - unsigned long int animationSize = 0; - - fwrite( &animationOffset, sizeof( animationOffset ), 1, fp ); - nbBytesWritten = sizeof( animationOffset ); - byteIndex += nbBytesWritten; - fwrite( &animationSize, sizeof( animationSize ), 1, fp ); - nbBytesWritten = sizeof( animationSize ); - byteIndex += nbBytesWritten; - - unsigned long int reservedDword = 0; - fwrite( &reservedDword, sizeof( reservedDword ), 1, fp ); - nbBytesWritten = sizeof( reservedDword ); - byteIndex += nbBytesWritten; - fwrite( &reservedDword, sizeof( reservedDword ), 1, fp ); - nbBytesWritten = sizeof( reservedDword ); - byteIndex += nbBytesWritten; - - geometryOffset = byteIndex; - - unsigned short int nbMeshs = 1; - fwrite( &nbMeshs, sizeof( nbMeshs ), 1, fp ); - nbBytesWritten = sizeof( nbMeshs ); - byteIndex += nbBytesWritten; - - char meshName[] = "noname mesh"; - unsigned char meshNameSize = strlen( meshName ); - - fwrite( &meshNameSize, sizeof( meshNameSize ), 1, fp ); - nbBytesWritten = sizeof( meshNameSize ); - byteIndex += nbBytesWritten; - - fwrite( meshName, meshNameSize * sizeof( char ), 1, fp ); - nbBytesWritten = meshNameSize * sizeof( char ); - byteIndex += nbBytesWritten; - - stdext::hash_map< unsigned long int, int > verticesMap; - typedef std::pair< unsigned long int, int > PR; - - int vertexIndex = 0; - - // Hash only vertices from faces that are not deleted - - std::list< EpaFace* >::iterator facesItr( m_faces.begin() ); - int nbFaces = 0; - - while ( facesItr != m_faces.end() ) - { - EpaFace* pFace = *facesItr; - - if ( !pFace->m_deleted ) - { - stdext::hash_map< unsigned long int, int >::const_iterator vertexItr; - - vertexItr = verticesMap.find( ( unsigned long int ) pFace->m_pVertices[ 0 ] ); - if ( vertexItr == verticesMap.end() ) - { - verticesMap.insert( PR( ( unsigned long int ) pFace->m_pVertices[ 0 ], vertexIndex ) ); - ++vertexIndex; - } - - vertexItr = verticesMap.find( ( unsigned long int ) pFace->m_pVertices[ 1 ] ); - if ( vertexItr == verticesMap.end() ) - { - verticesMap.insert( PR( ( unsigned long int ) pFace->m_pVertices[ 1 ], vertexIndex ) ); - ++vertexIndex; - } - - vertexItr = verticesMap.find( ( unsigned long int ) pFace->m_pVertices[ 2 ] ); - if ( vertexItr == verticesMap.end() ) - { - verticesMap.insert( PR( ( unsigned long int ) pFace->m_pVertices[ 2 ], vertexIndex ) ); - ++vertexIndex; - } - - ++nbFaces; - } - - ++facesItr; - } - - unsigned long int nbVertices = verticesMap.size(); - fwrite( &nbVertices, sizeof( nbVertices ), 1, fp ); - nbBytesWritten = sizeof( nbVertices ); - byteIndex += nbBytesWritten; - - // Collect all safe vertices - - float* pVertices = new float[ verticesMap.size() * 3 ]; - - stdext::hash_map< unsigned long int, int >::iterator verticesItr( verticesMap.begin() ); - - while ( verticesItr != verticesMap.end() ) - { - stdext::hash_map< unsigned long int, int >::const_iterator vertexItr; - - PR pr = *verticesItr; - - vertexItr = verticesMap.find( pr.first ); - assert( ( vertexItr != verticesMap.end() ) && "Vertex not found in hash table!" ); - - EpaVertex* pVertex = ( EpaVertex* ) vertexItr->first; - - pVertices[ vertexItr->second * 3 ] = pVertex->m_point.x(); - pVertices[ vertexItr->second * 3 + 1 ] = pVertex->m_point.y(); - pVertices[ vertexItr->second * 3 + 2 ] = pVertex->m_point.z(); - - ++verticesItr; - } - - unsigned long int* pIndices = new unsigned long int[ nbFaces * 3 ]; - - facesItr = m_faces.begin(); - - int facesIndex = 0; - while ( facesItr != m_faces.end() ) - { - EpaFace* pFace = *facesItr; - - if ( !pFace->m_deleted ) - { - stdext::hash_map< unsigned long int, int >::const_iterator vertexItr; - - int verticesIndices[ 3 ]; - - vertexItr = verticesMap.find( ( unsigned long int ) pFace->m_pVertices[ 0 ] ); - assert( ( vertexItr != verticesMap.end() ) && "Vertex not found in hash table!" ); - verticesIndices[ 0 ] = vertexItr->second; - - vertexItr = verticesMap.find( ( unsigned long int ) pFace->m_pVertices[ 1 ] ); - assert( ( vertexItr != verticesMap.end() ) && "Vertex not found in hash table!" ); - verticesIndices[ 1 ] = vertexItr->second; - - vertexItr = verticesMap.find( ( unsigned long int ) pFace->m_pVertices[ 2 ] ); - assert( ( vertexItr != verticesMap.end() ) && "Vertex not found in hash table!" ); - verticesIndices[ 2 ] = vertexItr->second; - - pIndices[ facesIndex * 3 ] = verticesIndices[ 0 ]; - pIndices[ facesIndex * 3 + 1 ] = verticesIndices[ 1 ]; - pIndices[ facesIndex * 3 + 2 ] = verticesIndices[ 2 ]; - - ++facesIndex; - } - - ++facesItr; - } - - fwrite( &nbFaces, sizeof( nbFaces ), 1, fp ); - nbBytesWritten = sizeof( nbFaces ); - byteIndex += nbBytesWritten; - - bool hasSmoothingGroups = false; - fwrite( &hasSmoothingGroups, sizeof( hasSmoothingGroups ), 1, fp ); - nbBytesWritten = sizeof( hasSmoothingGroups ); - byteIndex += nbBytesWritten; - - fwrite( pVertices, verticesMap.size() * 3 * sizeof( float ), 1, fp ); - nbBytesWritten = verticesMap.size() * 3 * sizeof( float ); - byteIndex += nbBytesWritten; - - // write indices - fwrite( pIndices, nbFaces * 3 * sizeof( unsigned long int ), 1, fp ); - nbBytesWritten = nbFaces * 3 * sizeof( unsigned long int ); - byteIndex += nbBytesWritten; - - delete[] pVertices; - delete[] pIndices; - - geometrySize = byteIndex - geometryOffset; - - fseek( fp, geometryOffsetAtByteNb, SEEK_SET ); - - fwrite( &geometryOffset, sizeof( geometryOffset ), 1, fp ); - nbBytesWritten = sizeof( geometryOffset ); - byteIndex += nbBytesWritten; - fwrite( &geometrySize, sizeof( geometrySize ), 1, fp ); - nbBytesWritten = sizeof( geometrySize ); - byteIndex += nbBytesWritten; - - fseek( fp, byteIndex, SEEK_SET ); - - fclose( fp ); - - return true; -} -#endif -#endif - diff --git a/Extras/obsolete/EPA/EpaPolyhedron.h b/Extras/obsolete/EPA/EpaPolyhedron.h deleted file mode 100644 index f1548aee1..000000000 --- a/Extras/obsolete/EPA/EpaPolyhedron.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef EPA_POLYHEDRON_H -#define EPA_POLYHEDRON_H - -class EpaFace; -class EpaVertex; - -//! Note : This class is not supposed to be a base class -class EpaPolyhedron -{ - private : - - //! Prevents copying objects from this class - EpaPolyhedron( const EpaPolyhedron& epaPolyhedron ); - const EpaPolyhedron& operator = ( const EpaPolyhedron& epaPolyhedron ); - - public : - - EpaPolyhedron(); - ~EpaPolyhedron(); - - bool Create( btPoint3* pInitialPoints, - btPoint3* pSupportPointsOnA, btPoint3* pSupportPointsOnB, - const int nbInitialPoints ); - void Destroy(); - - EpaFace* CreateFace(); - EpaHalfEdge* CreateHalfEdge(); - EpaVertex* CreateVertex( const btPoint3& wSupportPoint, - const btPoint3& wSupportPointOnA, - const btPoint3& wSupportPointOnB ); - - void DeleteFace( EpaFace* pFace ); - - void DestroyAllFaces(); - void DestroyAllHalfEdges(); - void DestroyAllVertices(); - - bool Expand( const btPoint3& wSupportPoint, - const btPoint3& wSupportPointOnA, - const btPoint3& wSupportPointOnB, - EpaFace* pFace, std::list< EpaFace* >& newFaces ); - - std::list< EpaFace* >& GetFaces(); - int GetNbFaces() const; - - private : - - void DeleteVisibleFaces( const btPoint3& point, EpaFace* pFace, - std::list< EpaHalfEdge* >& coneBaseTwinHalfEdges ); - - void CreateCone( EpaVertex* pAppexVertex, std::list< EpaHalfEdge* >& baseTwinHalfEdges, - std::list< EpaFace* >& newFaces ); - EpaFace* CreateConeFace( EpaVertex* pAppexVertex, EpaHalfEdge* pBaseTwinHalfEdge, - std::list< EpaHalfEdge* >& halfEdgesToLink ); - -#ifdef _DEBUG - public : - //! Please don't remove this method, it will help debugging if some problems arise in the future - bool _dbgSaveToFile( const char* pFileName ); -#endif - - private : - - //! This is the number of valid faces, m_faces list also contain deleted faces - int m_nbFaces; - - std::list< EpaFace* > m_faces; - std::list< EpaHalfEdge* > m_halfEdges; - std::list< EpaVertex* > m_vertices; -}; - -#endif - diff --git a/Extras/obsolete/EPA/EpaVertex.h b/Extras/obsolete/EPA/EpaVertex.h deleted file mode 100644 index 67eccbd29..000000000 --- a/Extras/obsolete/EPA/EpaVertex.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -EPA Copyright (c) Ricardo Padrela 2006 - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef EPA_VERTEX_H -#define EPA_VERTEX_H - -class EpaHalfEdge; - -//! Note : This class is not supposed to be a base class -class EpaVertex -{ - private : - - //! Prevents copying objects from this class - EpaVertex( const EpaVertex& epaVertex ); - const EpaVertex& operator = ( const EpaVertex& epaVertex ); - - public : - - EpaVertex( const btPoint3& point ) : /*m_pHalfEdge( 0 ),*/ m_point( point ) - { - } - - EpaVertex( const btPoint3& point, - const btPoint3& wSupportPointOnA, - const btPoint3& wSupportPointOnB ) : /*m_pHalfEdge( 0 ),*/ m_point( point ), - m_wSupportPointOnA( wSupportPointOnA ), - m_wSupportPointOnB( wSupportPointOnB ) - { - } - - ~EpaVertex() - { - } - - public : - - //! This is not necessary - //EpaHalfEdge* m_pHalfEdge; - - btPoint3 m_point; - - btPoint3 m_wSupportPointOnA; - btPoint3 m_wSupportPointOnB; -}; - -#endif - diff --git a/Extras/obsolete/ExtraSolid35/CombinedSimplexSolver.cpp b/Extras/obsolete/ExtraSolid35/CombinedSimplexSolver.cpp deleted file mode 100644 index 5168cbb9e..000000000 --- a/Extras/obsolete/ExtraSolid35/CombinedSimplexSolver.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2005 Erwin Coumans http://www.erwincoumans.com - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies. - * Erwin Coumans makes no representations about the suitability - * of this software for any purpose. - * It is provided "as is" without express or implied warranty. -*/ - -#include "CombinedSimplexSolver.h" -#include -//switch off asserts -//#define MY_ASSERT assert -#define MY_ASSERT - -bool useVoronoi = true; - -CombinedSimplexSolver::CombinedSimplexSolver() -:m_useVoronoiSolver(useVoronoi) -{ - -} - -void CombinedSimplexSolver::reset() -{ - m_voronoiSolver.reset(); - m_johnsonSolver.reset(); -} - - -void CombinedSimplexSolver::addVertex(const btVector3& w, const btPoint3& p, const btPoint3& q) -{ - printf("addVertex (%f %f %f)\n",w[0],w[1],w[2]); - m_voronoiSolver.addVertex(w,p,q); - m_johnsonSolver.addVertex(w,p,q); - int i; - i=0; - - btPoint3 vp1,vp2; - btPoint3 jp1,jp2; -/* - bool isClosest0 = m_voronoiSolver.closest(vp1); - bool isClosest1 = m_johnsonSolver.closest(vp1); - - m_voronoiSolver.compute_points(vp1, vp2); - m_johnsonSolver.compute_points(jp1,jp2); - i=0; - */ -} - - - -bool CombinedSimplexSolver::closest(btVector3& v) -{ - bool result0 = 0; - bool result1 = 0; - - btVector3 v0,v1; - - result0 = m_voronoiSolver.closest(v0); - result1 = m_johnsonSolver.closest(v1); - - if (result0 != result1) - { - result0 = m_voronoiSolver.closest(v0); - result1 = m_johnsonSolver.closest(v1); - int i; - i=0; - } - if (m_useVoronoiSolver) - { - v = v0; - return result0; - } - - v = v1; - return result1; -} - -btScalar CombinedSimplexSolver::maxVertex() -{ - btScalar maxv0 = m_voronoiSolver.maxVertex(); - btScalar maxv1 = m_johnsonSolver.maxVertex(); - MY_ASSERT(maxv0 = maxv1); - if (m_useVoronoiSolver) - return maxv0; - - return maxv1; -} - -bool CombinedSimplexSolver::fullSimplex() const -{ - bool fullSimplex0 = m_voronoiSolver.fullSimplex(); - bool fullSimplex1 = m_johnsonSolver.fullSimplex(); - MY_ASSERT(fullSimplex0 == fullSimplex1); - - if (m_useVoronoiSolver) - return fullSimplex0; - - return fullSimplex1; -} - -int CombinedSimplexSolver::getSimplex(btPoint3 *pBuf, btPoint3 *qBuf, btVector3 *yBuf) const -{ - - - int simplex0 = m_voronoiSolver.getSimplex(pBuf, qBuf, yBuf); - int simplex1 = m_johnsonSolver.getSimplex(pBuf, qBuf, yBuf); -// MY_ASSERT(simplex0 == simplex1); - if (m_useVoronoiSolver) - { - return m_voronoiSolver.getSimplex(pBuf, qBuf, yBuf); - } - - return simplex1; -} - -void CombinedSimplexSolver::debugPrint() -{ - btPoint3 pBuf0[4]; - btPoint3 qBuf0[4]; - btPoint3 yBuf0[4]; - btPoint3 pBuf1[4]; - btPoint3 qBuf1[4]; - btPoint3 yBuf1[4]; - int verts0,verts1; - - verts0 = m_voronoiSolver.getSimplex(&pBuf0[0], &qBuf0[0], &yBuf0[0]); - verts1 = m_johnsonSolver.getSimplex(&pBuf1[0], &qBuf1[0], &yBuf1[0]); - printf("numverts0 = %d, numverts1 = %d\n",verts0,verts1); - for (int i=0;i - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Extras/obsolete/ExtraSolid35/ExtraSolid35_vc8.vcproj b/Extras/obsolete/ExtraSolid35/ExtraSolid35_vc8.vcproj deleted file mode 100644 index 035432a01..000000000 --- a/Extras/obsolete/ExtraSolid35/ExtraSolid35_vc8.vcproj +++ /dev/null @@ -1,195 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Extras/obsolete/ExtraSolid35/LICENSE_QPL.txt b/Extras/obsolete/ExtraSolid35/LICENSE_QPL.txt deleted file mode 100644 index 3fca00466..000000000 --- a/Extras/obsolete/ExtraSolid35/LICENSE_QPL.txt +++ /dev/null @@ -1,110 +0,0 @@ - - The SOLID library is Copyright (C) 2001-2003 Dtecta. - - You may use, distribute and copy the SOLID library under the terms of - the Q Public License, which is displayed below. - -------------------------------------------------------------------------- - THE Q PUBLIC LICENSE - version 1.0 - - Copyright (C) 1999-2000 Trolltech AS, Norway. - Everyone is permitted to copy and - distribute this license document. - -The intent of this license is to establish freedom to share and change the -software regulated by this license under the open source model. - -This license applies to any software containing a notice placed by the -copyright holder saying that it may be distributed under the terms of -the Q Public License version 1.0. Such software is herein referred to as -the Software. This license covers modification and distribution of the -Software, use of third-party application programs based on the Software, -and development of free software which uses the Software. - - Granted Rights - -1. You are granted the non-exclusive rights set forth in this license - provided you agree to and comply with any and all conditions in this - license. Whole or partial distribution of the Software, or software - items that link with the Software, in any form signifies acceptance of - this license. - -2. You may copy and distribute the Software in unmodified form provided - that the entire package, including - but not restricted to - copyright, - trademark notices and disclaimers, as released by the initial developer - of the Software, is distributed. - -3. You may make modifications to the Software and distribute your - modifications, in a form that is separate from the Software, such as - patches. The following restrictions apply to modifications: - - a. Modifications must not alter or remove any copyright notices in - the Software. - - b. When modifications to the Software are released under this - license, a non-exclusive royalty-free right is granted to the - initial developer of the Software to distribute your modification - in future versions of the Software provided such versions remain - available under these terms in addition to any other license(s) of - the initial developer. - -4. You may distribute machine-executable forms of the Software or - machine-executable forms of modified versions of the Software, provided - that you meet these restrictions: - - a. You must include this license document in the distribution. - - b. You must ensure that all recipients of the machine-executable forms - are also able to receive the complete machine-readable source code - to the distributed Software, including all modifications, without - any charge beyond the costs of data transfer, and place prominent - notices in the distribution explaining this. - - c. You must ensure that all modifications included in the - machine-executable forms are available under the terms of this - license. - -5. You may use the original or modified versions of the Software to - compile, link and run application programs legally developed by you - or by others. - -6. You may develop application programs, reusable components and other - software items that link with the original or modified versions of the - Software. These items, when distributed, are subject to the following - requirements: - - a. You must ensure that all recipients of machine-executable forms of - these items are also able to receive and use the complete - machine-readable source code to the items without any charge - beyond the costs of data transfer. - - b. You must explicitly license all recipients of your items to use - and re-distribute original and modified versions of the items in - both machine-executable and source code forms. The recipients must - be able to do so without any charges whatsoever, and they must be - able to re-distribute to anyone they choose. - - - c. If the items are not available to the general public, and the - initial developer of the Software requests a copy of the items, - then you must supply one. - - Limitations of Liability - -In no event shall the initial developers or copyright holders be liable -for any damages whatsoever, including - but not restricted to - lost -revenue or profits or other direct, indirect, special, incidental or -consequential damages, even if they have been advised of the possibility -of such damages, except to the extent invariable law, if any, provides -otherwise. - - No Warranty - -The Software and this license document are provided AS IS with NO WARRANTY -OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE. - Choice of Law - -This license is governed by the Laws of Norway. Disputes shall be settled -by Oslo City Court. diff --git a/Extras/obsolete/ExtraSolid35/ReadMe.txt b/Extras/obsolete/ExtraSolid35/ReadMe.txt deleted file mode 100644 index e34022676..000000000 --- a/Extras/obsolete/ExtraSolid35/ReadMe.txt +++ /dev/null @@ -1,21 +0,0 @@ -======================================================================== - STATIC LIBRARY : Solid35 Project Overview -======================================================================== - -AppWizard has created this Solid35 library project for you. -No source files were created as part of your project. - - -Solid35.vcproj - This is the main project file for VC++ projects generated using an Application Wizard. - It contains information about the version of Visual C++ that generated the file, and - information about the platforms, configurations, and project features selected with the - Application Wizard. - -///////////////////////////////////////////////////////////////////////////// -Other notes: - -AppWizard uses "TODO:" comments to indicate parts of the source code you -should add to or customize. - -///////////////////////////////////////////////////////////////////////////// diff --git a/Extras/obsolete/ExtraSolid35/Solid35.vcproj b/Extras/obsolete/ExtraSolid35/Solid35.vcproj deleted file mode 100644 index 25a949f9a..000000000 --- a/Extras/obsolete/ExtraSolid35/Solid35.vcproj +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Extras/obsolete/ExtraSolid35/Solid3EpaPenetrationDepth.cpp b/Extras/obsolete/ExtraSolid35/Solid3EpaPenetrationDepth.cpp deleted file mode 100644 index ea35cda44..000000000 --- a/Extras/obsolete/ExtraSolid35/Solid3EpaPenetrationDepth.cpp +++ /dev/null @@ -1,589 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU bteral Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#include "Solid3EpaPenetrationDepth.h" -#include -#include -#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h" -#include "BulletCollision/CollisionShapes/btConvexShape.h" -#include "LinearMath/btMinMax.h" - -#define ASSERT_MESSAGE - -class ReplaceMeAccuracy { -public: - static btScalar rel_error2; // squared relative error in the computed distance - static btScalar depth_tolerance; // terminate EPA if upper_bound <= depth_tolerance * dist2 - static btScalar tol_error; // error tolerance if the distance is almost zero - - static void setAccuracy(btScalar rel_error) - { - rel_error2 = rel_error * rel_error; - depth_tolerance = btScalar(1.0f) + btScalar(2.0f) * rel_error; - } - - static void setTolerance(btScalar epsilon) - { - tol_error = epsilon; - } -}; - - -static const btScalar rel_error = btScalar(1.0e-3); - -btScalar ReplaceMeAccuracy::rel_error2 = rel_error * rel_error; -btScalar ReplaceMeAccuracy::depth_tolerance = btScalar(1.0) + btScalar(2.0) * rel_error; -btScalar ReplaceMeAccuracy::tol_error = SIMD_EPSILON; - - - - -class ReplaceMeFacet; - - -class ReplaceMeEdge { -public: - ReplaceMeEdge() {} - ReplaceMeEdge(ReplaceMeFacet *facet, int index) : - m_facet(facet), - m_index(index) {} - - ReplaceMeFacet *getFacet() const { return m_facet; } - int getIndex() const { return m_index; } - - int getSource() const; - int getTarget() const; - -private: - ReplaceMeFacet *m_facet; - int m_index; -}; - -typedef std::vector ReplaceMeEdgeBuffer; - - -class ReplaceMeFacet { -public: - ReplaceMeFacet() {} - ReplaceMeFacet(int i0, int i1, int i2) - : m_obsolete(false) - { - m_indices[0] = i0; - m_indices[1] = i1; - m_indices[2] = i2; - } - - inline int operator[](int i) const { return m_indices[i]; } - - bool link(int edge0, ReplaceMeFacet *facet, int edge1); - - - bool isObsolete() const { return m_obsolete; } - - - bool computeClosest(const btVector3 *verts); - - const btVector3& getClosest() const { return m_closest; } - - bool isClosestInternal() const - { - return m_lambda1 >= btScalar(0.0) && - m_lambda2 >= btScalar(0.0) && - m_lambda1 + m_lambda2 <= m_det; - } - - btScalar getDist2() const { return m_dist2; } - - btPoint3 getClosestPoint(const btPoint3 *points) const - { - const btPoint3& p0 = points[m_indices[0]]; - - return p0 + (m_lambda1 * (points[m_indices[1]] - p0) + - m_lambda2 * (points[m_indices[2]] - p0)) / m_det; - } - - void silhouette(const btVector3& w, ReplaceMeEdgeBuffer& edgeBuffer) - { - edgeBuffer.clear(); - m_obsolete = true; - m_adjFacets[0]->silhouette(m_adjEdges[0], w, edgeBuffer); - m_adjFacets[1]->silhouette(m_adjEdges[1], w, edgeBuffer); - m_adjFacets[2]->silhouette(m_adjEdges[2], w, edgeBuffer); - } - -private: - void silhouette(int index, const btVector3& w, ReplaceMeEdgeBuffer& edgeBuffer); - - int m_indices[3]; - bool m_obsolete; - ReplaceMeFacet *m_adjFacets[3]; - int m_adjEdges[3]; - - btScalar m_det; - btScalar m_lambda1; - btScalar m_lambda2; - btVector3 m_closest; - btScalar m_dist2; -}; - - -inline int incMod3(int i) { return ++i % 3; } - - -bool ReplaceMeFacet::link(int edge0, ReplaceMeFacet *facet, int edge1) -{ - m_adjFacets[edge0] = facet; - m_adjEdges[edge0] = edge1; - facet->m_adjFacets[edge1] = this; - facet->m_adjEdges[edge1] = edge0; - - bool b = m_indices[edge0] == facet->m_indices[incMod3(edge1)] && - m_indices[incMod3(edge0)] == facet->m_indices[edge1]; - return b; -} - - -bool ReplaceMeFacet::computeClosest(const btVector3 *verts) -{ - const btVector3& p0 = verts[m_indices[0]]; - - btVector3 v1 = verts[m_indices[1]] - p0; - btVector3 v2 = verts[m_indices[2]] - p0; - btScalar v1dv1 = v1.length2(); - btScalar v1dv2 = v1.dot(v2); - btScalar v2dv2 = v2.length2(); - btScalar p0dv1 = p0.dot(v1); - btScalar p0dv2 = p0.dot(v2); - - m_det = v1dv1 * v2dv2 - v1dv2 * v1dv2; // non-negative - //printf("m_det = %f\n",m_det); - //ASSERT(m_det >= 0.f); - - if (m_det >= (SIMD_EPSILON*SIMD_EPSILON)) { - - m_lambda1 = p0dv2 * v1dv2 - p0dv1 * v2dv2; - m_lambda2 = p0dv1 * v1dv2 - p0dv2 * v1dv1; - - m_closest = p0 + (m_lambda1 * v1 + m_lambda2 * v2) / m_det; - m_dist2 = m_closest.length2(); - return true; - } - - return false; -} - -void ReplaceMeFacet::silhouette(int index, const btVector3& w, - ReplaceMeEdgeBuffer& edgeBuffer) -{ - if (!m_obsolete) { - if (m_closest.dot(w) < m_dist2) { - edgeBuffer.push_back(ReplaceMeEdge(this, index)); - } - else { - m_obsolete = true; // Facet is visible - int next = incMod3(index); - m_adjFacets[next]->silhouette(m_adjEdges[next], w, edgeBuffer); - next = incMod3(next); - m_adjFacets[next]->silhouette(m_adjEdges[next], w, edgeBuffer); - } - } -} - - - -inline int ReplaceMeEdge::getSource() const -{ - return (*m_facet)[m_index]; -} - -inline int ReplaceMeEdge::getTarget() const -{ - return (*m_facet)[incMod3(m_index)]; -} - - -//#define DEBUG - -const int MaxSupportPoints = 100;//1000; -const int MaxFacets = 200;//b2000; - -static btPoint3 pBuf[MaxSupportPoints]; -static btPoint3 qBuf[MaxSupportPoints]; -static btVector3 yBuf[MaxSupportPoints]; - -static ReplaceMeFacet facetBuf[MaxFacets]; -static int freeFacet = 0; -static ReplaceMeFacet *facetHeap[MaxFacets]; -static int num_facets; - -class ReplaceMeFacetComp { -public: - - bool operator()(const ReplaceMeFacet *face1, const ReplaceMeFacet *face2) - { - return face1->getDist2() > face2->getDist2(); - } - -}; - -ReplaceMeFacetComp myFacetComp; - -inline ReplaceMeFacet *addFacet(int i0, int i1, int i2, - btScalar lower2, btScalar upper2) -{ - assert(i0 != i1 && i0 != i2 && i1 != i2); - if (freeFacet < MaxFacets) - { - ReplaceMeFacet *facet = new(&facetBuf[freeFacet++]) ReplaceMeFacet(i0, i1, i2); -#ifdef DEBUG - std::cout << "Facet " << i0 << ' ' << i1 << ' ' << i2; -#endif - if (facet->computeClosest(yBuf)) - { - if (facet->isClosestInternal() && - lower2 <= facet->getDist2() && facet->getDist2() <= upper2) - { - facetHeap[num_facets++] = facet; - ASSERT_MESSAGE(num_facetsisClosestInternal()) - { - std::cout << "closest point not internal"; - } - else if (lower2 > facet->getDist2()) - { - std::cout << "facet is closer than orignal facet"; - } - else - { - std::cout << "facet is further than upper bound"; - } - std::cout << std::endl; -#endif - } - - return facet; - } - } - - return 0; -} - - - -inline bool originInTetrahedron(const btVector3& p1, const btVector3& p2, - const btVector3& p3, const btVector3& p4) -{ - btVector3 normal1 = (p2 - p1).cross(p3 - p1); - btVector3 normal2 = (p3 - p2).cross(p4 - p2); - btVector3 normal3 = (p4 - p3).cross(p1 - p3); - btVector3 normal4 = (p1 - p4).cross(p2 - p4); - - return - (normal1.dot(p1) > btScalar(0.0)) != (normal1.dot(p4) > btScalar(0.0)) && - (normal2.dot(p2) > btScalar(0.0)) != (normal2.dot(p1) > btScalar(0.0)) && - (normal3.dot(p3) > btScalar(0.0)) != (normal3.dot(p2) > btScalar(0.0)) && - (normal4.dot(p4) > btScalar(0.0)) != (normal4.dot(p3) > btScalar(0.0)); -} - - - -bool Solid3EpaPenetrationDepth::calcPenDepth( btSimplexSolverInterface& simplexSolver, - btConvexShape* convexA,btConvexShape* convexB, - const btTransform& transformA,const btTransform& transformB, - btVector3& v, btPoint3& pa, btPoint3& pb, - class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc - ) -{ - - int num_verts = simplexSolver.getSimplex(pBuf, qBuf, yBuf); - - switch (num_verts) - { - case 1: - // Touching contact. Yes, we have a collision, - // but no penetration. - return false; - case 2: - { - // We have a line segment inside the Minkowski sum containing the - // origin. Blow it up by adding three additional support points. - - btVector3 dir = (yBuf[1] - yBuf[0]).normalized(); - int axis = dir.furthestAxis(); - - static btScalar sin_60 = 0.8660254037f;//84438646763723170752941.22474487f;//13915890490986420373529;// - - btQuaternion rot(dir[0] * sin_60, dir[1] * sin_60, dir[2] * sin_60, btScalar(0.5)); - btMatrix3x3 rot_mat(rot); - - btVector3 aux1 = dir.cross(btVector3(axis == 0, axis == 1, axis == 2)); - btVector3 aux2 = rot_mat * aux1; - btVector3 aux3 = rot_mat * aux2; - - pBuf[2] = transformA(convexA->localGetSupportingVertex(aux1*transformA.getBasis())); - qBuf[2] = transformB(convexB->localGetSupportingVertex((-aux1)*transformB.getBasis())); - yBuf[2] = pBuf[2] - qBuf[2]; - - pBuf[3] = transformA(convexA->localGetSupportingVertex(aux2*transformA.getBasis())); - qBuf[3] = transformB(convexB->localGetSupportingVertex((-aux2)*transformB.getBasis())); - yBuf[3] = pBuf[3] - qBuf[3]; - - pBuf[4] = transformA(convexA->localGetSupportingVertex(aux3*transformA.getBasis())); - qBuf[4] = transformB(convexB->localGetSupportingVertex((-aux3)*transformB.getBasis())); - yBuf[4] = pBuf[4] - qBuf[4]; - - if (originInTetrahedron(yBuf[0], yBuf[2], yBuf[3], yBuf[4])) - { - pBuf[1] = pBuf[4]; - qBuf[1] = qBuf[4]; - yBuf[1] = yBuf[4]; - } - else if (originInTetrahedron(yBuf[1], yBuf[2], yBuf[3], yBuf[4])) - { - pBuf[0] = pBuf[4]; - qBuf[0] = qBuf[4]; - yBuf[0] = yBuf[4]; - } - else - { - // Origin not in initial polytope - return false; - } - - num_verts = 4; - - break; - } - case 3: - { - // We have a triangle inside the Minkowski sum containing - // the origin. First blow it up. - - btVector3 v1 = yBuf[1] - yBuf[0]; - btVector3 v2 = yBuf[2] - yBuf[0]; - btVector3 vv = v1.cross(v2); - - pBuf[3] = transformA(convexA->localGetSupportingVertex(vv*transformA.getBasis())); - qBuf[3] = transformB(convexB->localGetSupportingVertex((-vv)*transformB.getBasis())); - yBuf[3] = pBuf[3] - qBuf[3]; - pBuf[4] = transformA(convexA->localGetSupportingVertex((-vv)*transformA.getBasis())); - qBuf[4] = transformB(convexB->localGetSupportingVertex(vv*transformB.getBasis())); - yBuf[4] = pBuf[4] - qBuf[4]; - - - if (originInTetrahedron(yBuf[0], yBuf[1], yBuf[2], yBuf[4])) - { - pBuf[3] = pBuf[4]; - qBuf[3] = qBuf[4]; - yBuf[3] = yBuf[4]; - } - else if (!originInTetrahedron(yBuf[0], yBuf[1], yBuf[2], yBuf[3])) - { - // Origin not in initial polytope - return false; - } - - num_verts = 4; - - break; - } - } - - // We have a tetrahedron inside the Minkowski sum containing - // the origin (if GJK did it's job right ;-) - - - if (!originInTetrahedron(yBuf[0], yBuf[1], yBuf[2], yBuf[3])) - { - // assert(false); - return false; - } - - num_facets = 0; - freeFacet = 0; - - ReplaceMeFacet *f0 = addFacet(0, 1, 2, btScalar(0.0), SIMD_INFINITY); - ReplaceMeFacet *f1 = addFacet(0, 3, 1, btScalar(0.0), SIMD_INFINITY); - ReplaceMeFacet *f2 = addFacet(0, 2, 3, btScalar(0.0), SIMD_INFINITY); - ReplaceMeFacet *f3 = addFacet(1, 3, 2, btScalar(0.0), SIMD_INFINITY); - - if (!f0 || f0->getDist2() == btScalar(0.0) || - !f1 || f1->getDist2() == btScalar(0.0) || - !f2 || f2->getDist2() == btScalar(0.0) || - !f3 || f3->getDist2() == btScalar(0.0)) - { - return false; - } - - f0->link(0, f1, 2); - f0->link(1, f3, 2); - f0->link(2, f2, 0); - f1->link(0, f2, 2); - f1->link(1, f3, 0); - f2->link(1, f3, 1); - - if (num_facets == 0) - { - return false; - } - - // at least one facet on the heap. - - ReplaceMeEdgeBuffer edgeBuffer(20); - - ReplaceMeFacet *facet = 0; - - btScalar upper_bound2 = SIMD_INFINITY; - - do { - facet = facetHeap[0]; - std::pop_heap(&facetHeap[0], &facetHeap[num_facets], myFacetComp); - --num_facets; - - if (!facet->isObsolete()) - { - assert(facet->getDist2() > btScalar(0.0)); - - if (num_verts == MaxSupportPoints) - { -#ifdef DEBUG - std::cout << "Ouch, no convergence!!!" << std::endl; -#endif - ASSERT_MESSAGE(false,"Error: pendepth calc failed"); - break; - } - - pBuf[num_verts] = transformA(convexA->localGetSupportingVertex((facet->getClosest())*transformA.getBasis())); - qBuf[num_verts] = transformB(convexB->localGetSupportingVertex((-facet->getClosest())*transformB.getBasis())); - yBuf[num_verts] = pBuf[num_verts] - qBuf[num_verts]; - - - int index = num_verts++; - btScalar far_dist2 = yBuf[index].dot(facet->getClosest()); - - - // Make sure the support mapping is OK. - //assert(far_dist2 > btScalar(0.0)); - - // - // this is to avoid problems with implicit-sphere-touching contact - // - if (far_dist2 < btScalar(0.0)) - { - return false; - } - - GEN_set_min(upper_bound2, (far_dist2 * far_dist2) / facet->getDist2()); - - if (upper_bound2 <= ReplaceMeAccuracy::depth_tolerance * facet->getDist2() -#define CHECK_NEW_SUPPORT -#ifdef CHECK_NEW_SUPPORT - || yBuf[index] == yBuf[(*facet)[0]] - || yBuf[index] == yBuf[(*facet)[1]] - || yBuf[index] == yBuf[(*facet)[2]] -#endif - ) - { - break; - } - - // Compute the silhouette cast by the new vertex - // Note that the new vertex is on the positive side - // of the current facet, so the current facet is will - // not be in the convex hull. Start local search - // from this facet. - - facet->silhouette(yBuf[index], edgeBuffer); - - if (edgeBuffer.empty()) - { - return false; - } - - ReplaceMeEdgeBuffer::const_iterator it = edgeBuffer.begin(); - ReplaceMeFacet *firstFacet = - addFacet((*it).getTarget(), (*it).getSource(), - index, facet->getDist2(), upper_bound2); - - if (!firstFacet) - { - break; - } - - firstFacet->link(0, (*it).getFacet(), (*it).getIndex()); - ReplaceMeFacet *lastFacet = firstFacet; - - ++it; - for (; it != edgeBuffer.end(); ++it) - { - ReplaceMeFacet *newFacet = - addFacet((*it).getTarget(), (*it).getSource(), - index, facet->getDist2(), upper_bound2); - - if (!newFacet) - { - break; - } - - if (!newFacet->link(0, (*it).getFacet(), (*it).getIndex())) - { - break; - } - - if (!newFacet->link(2, lastFacet, 1)) - { - break; - } - - lastFacet = newFacet; - } - if (it != edgeBuffer.end()) - { - break; - } - - firstFacet->link(2, lastFacet, 1); - } - } - while (num_facets > 0 && facetHeap[0]->getDist2() <= upper_bound2); - -#ifdef DEBUG - std::cout << "#facets left = " << num_facets << std::endl; -#endif - - v = facet->getClosest(); - pa = facet->getClosestPoint(pBuf); - pb = facet->getClosestPoint(qBuf); - return true; -} - diff --git a/Extras/obsolete/ExtraSolid35/Solid3EpaPenetrationDepth.h b/Extras/obsolete/ExtraSolid35/Solid3EpaPenetrationDepth.h deleted file mode 100644 index 6727d67a6..000000000 --- a/Extras/obsolete/ExtraSolid35/Solid3EpaPenetrationDepth.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU bteral Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#ifndef SOLID3_EPA_PENETRATION_DEPTH_H -#define SOLID3_EPA_PENETRATION_DEPTH_H - - -#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h" - -/// Solid3EpaPenetrationDepth contains the 'Expanding Polytope Algorithm' from Solid 3.5 -class Solid3EpaPenetrationDepth : public btConvexPenetrationDepthSolver -{ -public: - - virtual bool calcPenDepth( btSimplexSolverInterface& simplexSolver, - btConvexShape* convexA,btConvexShape* convexB, - const btTransform& transA,const btTransform& transB, - btVector3& v, btPoint3& pa, btPoint3& pb, - class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc - ); - -}; - -#endif //SOLID3_EPA_PENETRATION_DEPTH_H \ No newline at end of file diff --git a/Extras/obsolete/ExtraSolid35/Solid3JohnsonSimplexSolver.cpp b/Extras/obsolete/ExtraSolid35/Solid3JohnsonSimplexSolver.cpp deleted file mode 100644 index 0a4f0ad97..000000000 --- a/Extras/obsolete/ExtraSolid35/Solid3JohnsonSimplexSolver.cpp +++ /dev/null @@ -1,450 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU bteral Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#include "Solid3JohnsonSimplexSolver.h" -#include "LinearMath/btMinMax.h" - -//#define USE_BACKUP_PROCEDURE -//#define FAST_CLOSEST - -Solid3JohnsonSimplexSolver::Solid3JohnsonSimplexSolver() -: -m_bits1(0x0), -m_all_bits(0x0) -{ -} - - -Solid3JohnsonSimplexSolver::~Solid3JohnsonSimplexSolver() -{ - -} - -void Solid3JohnsonSimplexSolver::reset() -{ - m_bits1 = 0x0; - m_all_bits = 0x0; -} - - - -void Solid3JohnsonSimplexSolver::addVertex(const btVector3& w) -{ - assert(!fullSimplex()); - m_last = 0; - m_last_bit = 0x1; - while (contains(m_bits1, m_last_bit)) - { - ++m_last; - m_last_bit <<= 1; - } - m_y[m_last] = w; - m_ylen2[m_last] = w.length2(); - m_all_bits = m_bits1 | m_last_bit; - - update_cache(); - compute_det(); -} - -void Solid3JohnsonSimplexSolver::addVertex(const btVector3& w, const btPoint3& p, const btPoint3& q) -{ - addVertex(w); - m_p[m_last] = p; - m_q[m_last] = q; -} - -bool Solid3JohnsonSimplexSolver::emptySimplex() const -{ - return m_bits1 == 0x0; -} - -bool Solid3JohnsonSimplexSolver::fullSimplex() const -{ - return m_bits1 == 0xf; -} - -btScalar Solid3JohnsonSimplexSolver::maxVertex() -{ - return m_maxlen2; -} - -bool Solid3JohnsonSimplexSolver::closest(btVector3& v) -{ -#ifdef FAST_CLOSEST - T_Bits s; - for (s = m_bits1; s != 0x0; --s) - { - if (subseteq(s, m_bits1) && valid(s | m_last_bit)) - { - //update bits ! - m_bits1 = s | m_last_bit; - compute_vector(m_bits1, v); - return true; - } - } - if (valid(m_last_bit)) - { - //update bits ! - m_bits1 = m_last_bit; - m_maxlen2 = m_ylen2[m_last]; - v = m_y[m_last]; - return true; - } -#else - T_Bits s; - for (s = m_all_bits; s != 0x0; --s) - { - if (subseteq(s, m_all_bits) && valid(s)) - { - m_bits1 = s; - compute_vector(m_bits1, v); - return true; - } - } -#endif - - // Original GJK calls the backup procedure at this point. -#ifdef USE_BACKUP_PROCEDURE - backup_closest(btVector3& v); -#endif - return false; -} - - - -int Solid3JohnsonSimplexSolver::getSimplex(btPoint3 *pBuf, btPoint3 *qBuf, btVector3 *yBuf) const -{ - int num_verts = 0; - int i; - T_Bits bit; - for (i = 0, bit = 0x1; i < 4; ++i, bit <<= 1) - { - if (contains(m_bits1, bit)) - { - pBuf[num_verts] = m_p[i]; - qBuf[num_verts] = m_q[i]; - yBuf[num_verts] = m_y[i]; - -#ifdef DEBUG - std::cout << "Point " << i << " = " << m_y[i] << std::endl; -#endif - - ++num_verts; - } - } - return num_verts; -} - -bool Solid3JohnsonSimplexSolver::inSimplex(const btVector3& w) -{ - int i; - T_Bits bit; - for (i = 0, bit = 0x1; i < 4; ++i, bit <<= 1) - { - if (contains(m_all_bits, bit) && w == m_y[i]) - { - return true; - } - } - return false; -} - - - -void Solid3JohnsonSimplexSolver::backup_closest(btVector3& v) -{ - btScalar min_dist2 = SIMD_INFINITY; - - T_Bits s; - for (s = m_all_bits; s != 0x0; --s) - { - if (subseteq(s, m_all_bits) && proper(s)) - { - btVector3 u; - compute_vector(s, u); - btScalar dist2 = u.length2(); - if (dist2 < min_dist2) - { - min_dist2 = dist2; - //update bits ! - m_bits1 = s; - v = u; - } - } - } -} - - -void Solid3JohnsonSimplexSolver::compute_points(btPoint3& p1, btPoint3& p2) -{ - btScalar sum = btScalar(0.0); - p1.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); - p2.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); - int i; - T_Bits bit; - for (i = 0, bit = 0x1; i < 4; ++i, bit <<= 1) - { - if (contains(m_bits1, bit)) - { - sum += m_det[m_bits1][i]; - p1 += m_p[i] * m_det[m_bits1][i]; - p2 += m_q[i] * m_det[m_bits1][i]; - } - } - - assert(sum > btScalar(0.0)); - btScalar s = btScalar(1.0) / sum; - p1 *= s; - p2 *= s; -} - - - -int Solid3JohnsonSimplexSolver::numVertices() const -{ - int numverts = 0; - int i,bit; - for (i = 0, bit = 0x1; i < 4; ++i, bit <<= 1) - { - if (contains(m_bits1, bit)) - { - numverts++; - } - } - return numverts; -} - - - - -////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////// -//internal - -inline void Solid3JohnsonSimplexSolver::update_cache() -{ - int i; - T_Bits bit; - for (i = 0, bit = 0x1; i < 4; ++i, bit <<= 1) - { - if (contains(m_bits1, bit)) - { - m_edge[i][m_last] = m_y[i] - m_y[m_last]; - m_edge[m_last][i] = -m_edge[i][m_last]; - -#ifdef JOHNSON_ROBUST - m_norm[i][m_last] = m_norm[m_last][i] = m_edge[i][m_last].length2(); -#endif - - } - } -} - - -bool Solid3JohnsonSimplexSolver::valid(T_Bits s) -{ - int i; - T_Bits bit; - for (i = 0, bit = 0x1; i < 4; ++i, bit <<= 1) - { - if (contains(m_all_bits, bit)) - { - if (contains(s, bit)) - { - if (m_det[s][i] <= btScalar(0.0)) - { - return false; - } - } - else if (m_det[s | bit][i] > btScalar(0.0)) - { - return false; - } - } - } - return true; -} - -bool Solid3JohnsonSimplexSolver::proper(T_Bits s) -{ - int i; - T_Bits bit; - for (i = 0, bit = 0x1; i < 4; ++i, bit <<= 1) - { - if (contains(s, bit) && m_det[s][i] <= btScalar(0.0)) - { - return false; - } - } - return true; -} - -void Solid3JohnsonSimplexSolver::compute_vector(T_Bits s, btVector3& v) -{ - m_maxlen2 = btScalar(0.0); - btScalar sum = btScalar(0.0); - v .setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); - - int i; - T_Bits bit; - for (i = 0, bit = 0x1; i < 4; ++i, bit <<= 1) - { - if (contains(s, bit)) - { - sum += m_det[s][i]; - GEN_set_max(m_maxlen2, m_ylen2[i]); - v += m_y[i] * m_det[s][i]; - } - } - - assert(sum > btScalar(0.0)); - - v /= sum; -} - - - -#ifdef JOHNSON_ROBUST - -inline void Solid3JohnsonSimplexSolver::compute_det() -{ - m_det[m_last_bit][m_last] = 1; - - int i; - T_Bits si; - for (i = 0, si = 0x1; i < 4; ++i, si <<= 1) - { - if (contains(m_bits1, si)) - { - T_Bits s2 = si | m_last_bit; - m_det[s2][i] = m_edge[m_last][i].dot(m_y[m_last]); - m_det[s2][m_last] = m_edge[i][m_last].dot(m_y[i]); - - int j; - T_Bits sj; - for (j = 0, sj = 0x1; j < i; ++j, sj <<= 1) - { - if (contains(m_bits1, sj)) - { - int k; - T_Bits s3 = sj | s2; - - k = m_norm[i][j] < m_norm[m_last][j] ? i : m_last; - m_det[s3][j] = m_det[s2][i] * m_edge[k][j].dot(m_y[i]) + - m_det[s2][m_last] * m_edge[k][j].dot(m_y[m_last]); - k = m_norm[j][i] < m_norm[m_last][i] ? j : m_last; - m_det[s3][i] = m_det[sj|m_last_bit][j] * m_edge[k][i].dot(m_y[j]) + - m_det[sj|m_last_bit][m_last] * m_edge[k][i].dot(m_y[m_last]); - k = m_norm[i][m_last] < m_norm[j][m_last] ? i : j; - m_det[s3][m_last] = m_det[sj|si][j] * m_edge[k][m_last].dot(m_y[j]) + - m_det[sj|si][i] * m_edge[k][m_last].dot(m_y[i]); - } - } - } - } - - if (m_all_bits == 0xf) - { - int k; - - k = m_norm[1][0] < m_norm[2][0] ? (m_norm[1][0] < m_norm[3][0] ? 1 : 3) : (m_norm[2][0] < m_norm[3][0] ? 2 : 3); - - m_det[0xf][0] = m_det[0xe][1] * m_edge[k][0].dot(m_y[1]) + - m_det[0xe][2] * m_edge[k][0].dot(m_y[2]) + - m_det[0xe][3] * m_edge[k][0].dot(m_y[3]); - - k = m_norm[0][1] < m_norm[2][1] ? (m_norm[0][1] < m_norm[3][1] ? 0 : 3) : (m_norm[2][1] < m_norm[3][1] ? 2 : 3); - - m_det[0xf][1] = m_det[0xd][0] * m_edge[k][1].dot(m_y[0]) + - m_det[0xd][2] * m_edge[k][1].dot(m_y[2]) + - m_det[0xd][3] * m_edge[k][1].dot(m_y[3]); - - k = m_norm[0][2] < m_norm[1][2] ? (m_norm[0][2] < m_norm[3][2] ? 0 : 3) : (m_norm[1][2] < m_norm[3][2] ? 1 : 3); - - m_det[0xf][2] = m_det[0xb][0] * m_edge[k][2].dot(m_y[0]) + - m_det[0xb][1] * m_edge[k][2].dot(m_y[1]) + - m_det[0xb][3] * m_edge[k][2].dot(m_y[3]); - - k = m_norm[0][3] < m_norm[1][3] ? (m_norm[0][3] < m_norm[2][3] ? 0 : 2) : (m_norm[1][3] < m_norm[2][3] ? 1 : 2); - - m_det[0xf][3] = m_det[0x7][0] * m_edge[k][3].dot(m_y[0]) + - m_det[0x7][1] * m_edge[k][3].dot(m_y[1]) + - m_det[0x7][2] * m_edge[k][3].dot(m_y[2]); - } -} - -#else //JOHNSON_ROBUST - - -inline void Solid3JohnsonSimplexSolver::compute_det() -{ - m_det[m_last_bit][m_last] = 1; - - int i; - T_Bits si; - for (i = 0, si = 0x1; i < 4; ++i, si <<= 1) - { - if (contains(m_bits1, si)) - { - T_Bits s2 = si | m_last_bit; - m_det[s2][i] = m_edge[m_last][i].dot(m_y[m_last]); - m_det[s2][m_last] = m_edge[i][m_last].dot(m_y[i]); - - int j; - T_Bits sj; - for (j = 0, sj = 0x1; j < i; ++j, sj <<= 1) - { - if (contains(m_bits1, sj)) - { - T_Bits s3 = sj | s2; - m_det[s3][j] = m_det[s2][i] * m_edge[i][j].dot(m_y[i]) + - m_det[s2][m_last] * m_edge[i][j].dot(m_y[m_last]); - m_det[s3][i] = m_det[sj|m_last_bit][j] * m_edge[j][i].dot(m_y[j]) + - m_det[sj|m_last_bit][m_last] * m_edge[j][i].dot(m_y[m_last]); - m_det[s3][m_last] = m_det[sj|si][j] * m_edge[j][m_last].dot(m_y[j]) + - m_det[sj|si][i] * m_edge[j][m_last].dot(m_y[i]); - } - } - } - } - - if (m_all_bits == 0xf) - { - m_det[0xf][0] = m_det[0xe][1] * m_edge[1][0].dot(m_y[1]) + - m_det[0xe][2] * m_edge[1][0].dot(m_y[2]) + - m_det[0xe][3] * m_edge[1][0].dot(m_y[3]); - m_det[0xf][1] = m_det[0xd][0] * m_edge[0][1].dot(m_y[0]) + - m_det[0xd][2] * m_edge[0][1].dot(m_y[2]) + - m_det[0xd][3] * m_edge[0][1].dot(m_y[3]); - m_det[0xf][2] = m_det[0xb][0] * m_edge[0][2].dot(m_y[0]) + - m_det[0xb][1] * m_edge[0][2].dot(m_y[1]) + - m_det[0xb][3] * m_edge[0][2].dot(m_y[3]); - m_det[0xf][3] = m_det[0x7][0] * m_edge[0][3].dot(m_y[0]) + - m_det[0x7][1] * m_edge[0][3].dot(m_y[1]) + - m_det[0x7][2] * m_edge[0][3].dot(m_y[2]); - } -} - - -#endif //JOHNSON_ROBUST diff --git a/Extras/obsolete/ExtraSolid35/Solid3JohnsonSimplexSolver.h b/Extras/obsolete/ExtraSolid35/Solid3JohnsonSimplexSolver.h deleted file mode 100644 index 290719170..000000000 --- a/Extras/obsolete/ExtraSolid35/Solid3JohnsonSimplexSolver.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SOLID - Software Library for Interference Detection - * - * Copyright (C) 2001-2003 Dtecta. All rights reserved. - * - * This library may be distributed under the terms of the Q Public License - * (QPL) as defined by Trolltech AS of Norway and appearing in the file - * LICENSE.QPL included in the packaging of this file. - * - * This library may be distributed and/or modified under the terms of the - * GNU bteral Public License (GPL) version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Commercial use or any other use of this library not covered by either - * the QPL or the GPL requires an additional license from Dtecta. - * Please contact info@dtecta.com for enquiries about the terms of commercial - * use of this library. - */ - -#ifndef SOLID3JOHNSON_SIMPLEX_SOLVER_H -#define SOLID3JOHNSON_SIMPLEX_SOLVER_H - -#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h" - -//#define JOHNSON_ROBUST - - -/// Solid3JohnsonSimplexSolver contains Johnson subdistance algorithm from Solid 3.5 library -class Solid3JohnsonSimplexSolver : public btSimplexSolverInterface -{ - -private: - typedef unsigned int T_Bits; - inline static bool subseteq(T_Bits a, T_Bits b) { return (a & b) == a; } - inline static bool contains(T_Bits a, T_Bits b) { return (a & b) != 0x0; } - - void update_cache(); - void compute_det(); - bool valid(T_Bits s); - bool proper(T_Bits s); - void compute_vector(T_Bits s, btVector3& v); - - - btScalar m_det[16][4]; // cached sub-determinants - btVector3 m_edge[4][4]; - -#ifdef JOHNSON_ROBUST - btScalar m_norm[4][4]; -#endif - - btPoint3 m_p[4]; // support points of object A in local coordinates - btPoint3 m_q[4]; // support points of object B in local coordinates - btVector3 m_y[4]; // support points of A - B in world coordinates - btScalar m_ylen2[4]; // Squared lengths support points y - - btScalar m_maxlen2; // Maximum squared length to a vertex of the current - // simplex - T_Bits m_bits1; // identifies current simplex - T_Bits m_last; // identifies last found support point - T_Bits m_last_bit; // m_last_bit == 0x1 << last - T_Bits m_all_bits; // m_all_bits == m_bits | m_last_bit - - - -private: - - - void addVertex(const btVector3& w); - -public: - Solid3JohnsonSimplexSolver(); - - virtual ~Solid3JohnsonSimplexSolver(); - - virtual void reset(); - - virtual void addVertex(const btVector3& w, const btPoint3& p, const btPoint3& q); - - virtual bool closest(btVector3& v); - - virtual btScalar maxVertex(); - - virtual bool fullSimplex() const; - - virtual int getSimplex(btPoint3 *pBuf, btPoint3 *qBuf, btVector3 *yBuf) const; - - virtual bool inSimplex(const btVector3& w); - - virtual void backup_closest(btVector3& v) ; - - virtual bool emptySimplex() const ; - - virtual void compute_points(btPoint3& p1, btPoint3& p2) ; - - virtual int numVertices() const ; - - -}; - - -#endif //SOLID3JOHNSON_SIMPLEX_SOLVER_H diff --git a/Extras/obsolete/GPUphysics/CHANGES b/Extras/obsolete/GPUphysics/CHANGES deleted file mode 100644 index 27ed81b63..000000000 --- a/Extras/obsolete/GPUphysics/CHANGES +++ /dev/null @@ -1,52 +0,0 @@ -(Add new stuff at the top!) - -Sept 27th: -========== -* Added a 'collisionMap' and pre-populated it with the handles of - four of the cubes (which are coloured RED so you can see them). -* Non-red cubes are painted in shades of blue/green. -* Every cube (including the red ones) is gravitationally attracted - to all four red cubes in inverse proportion to their ranges. - -Sept 9th: -========= -* Merged in my latest changes into SVN repository. -* Arranged to avoid reading/writing textures at same time. -* Removed depth and stencil buffers from FBO's. -* Eliminated 1-component FBO that caused grief for FBO completeness test. -* Added back missing cubeShaderNoTexture.vert - -------------------- FIRST ADDITION TO SUBVERSION --------------------- -GPUphysics-0.4 -============== - -* Test for availability of vertex shader textures. -* Fixed 'status: xxxx' message. -* Added support for running the demo in the absence of vertex shader textures. - -GPUphysics-0.3 -============== - -* Use signed initial velocities so everything doesn't slide off the screen! -* The 'bounce' now slows down X/Z motion as well as Y so things actually - do stop moving eventually. -* Caught up with some portability issues for more recent versions of - GLSL. - -GPUphysics-0.2 -============== - -* Added MacOSX support. -* Added a ton of command-line debug options (see DEBUG_README) -* Changed to ZLib license. - -GPUphysics-0.1 -============== - -* Fixes for stencil buffer problems on some systems. - -GPUphysics-0.0 -============== - -* Initial release - diff --git a/Extras/obsolete/GPUphysics/CMakeLists.txt b/Extras/obsolete/GPUphysics/CMakeLists.txt deleted file mode 100644 index e3b011132..000000000 --- a/Extras/obsolete/GPUphysics/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -PROJECT(GPUphysics) - -# This is basically the overall name of the project in Visual Studio this is the name of the Solution File - - -# For every executable you have with a main method you should have an add_executable line below. -# For every add executable line you should list every .cpp and .h file you have associated with that executable. - - -# This is the variable for Windows. I use this to define the root of my directory structure. -SET(GLUT_ROOT ${GPUphysics_SOURCE_DIR}/../../Glut) - -# You shouldn't have to modify anything below this line -######################################################## - - -# This is the shortcut to finding GLU, GLUT and OpenGL if they are properly installed on your system -# This should be the case. -INCLUDE (${CMAKE_ROOT}/Modules/FindGLU.cmake) -INCLUDE (${CMAKE_ROOT}/Modules/FindGLUT.cmake) -INCLUDE (${CMAKE_ROOT}/Modules/FindOpenGL.cmake) - - - -IF (WIN32) - # This is the Windows code for which Opengl, and Glut are not properly installed - # since I can't install them I must cheat and copy libraries around - INCLUDE_DIRECTORIES(${GLUT_ROOT}) - # LINK_DIRECTORIES(${GLUT_ROOT}\\lib) - IF (${GLUT_glut_LIBRARY} MATCHES "GLUT_glut_LIBRARY-NOTFOUND") - SET(GLUT_glut_LIBRARY ${GPUphysics_SOURCE_DIR}/Glut/glut32.lib) - # LINK_LIBRARIES(${GLUT_ROOT}\\lib\\glut32 ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY}) - # TARGET_LINK_LIBRARIES(table ${GLUT_ROOT}\\lib\\glut32) -# -# ADD_CUSTOM_COMMAND(TARGET table POST_BUILD COMMAND copy ${GLUT_ROOT}\\lib\\glut32.dll ${GLUT_ROOT}\\bin\\vs2005\\Debug -# COMMAND copy ${GLUT_ROOT}\\lib\\glut32.dll ${GLUT_ROOT}\\bin\\vs2003\\Debug -# COMMAND copy ${GLUT_ROOT}\\lib\\glut32.dll ${GLUT_ROOT}\\bin\\vs6\\Debug) - ELSE (${GLUT_glut_LIBRARY} MATCHES "GLUT_glut_LIBRARY-NOTFOUND") -# LINK_LIBRARIES(${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY}) -# TARGET_LINK_LIBRARIES(table ${GLUT_glut_LIBRARY}) - ENDIF(${GLUT_glut_LIBRARY} MATCHES "GLUT_glut_LIBRARY-NOTFOUND") -# TARGET_LINK_LIBRARIES(table ${OPENGL_gl_LIBRARY}) -# TARGET_LINK_LIBRARIES(table ${OPENGL_glu_LIBRARY}) -ELSE (WIN32) - # This is the lines for linux. This should always work if everything is installed and working fine. -# SET(CMAKE_BUILD_TYPE Debug) -# SET(CMAKE_CXX_FLAGS_DEBUG "-g") - INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${GLUT_INCLUDE_DIR}) -# TARGET_LINK_LIBRARIES(table ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY}) -# TARGET_LINK_LIBRARIES(checker ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY}) -ENDIF (WIN32) - -INCLUDE_DIRECTORIES( -../../Glut/GL/include -) - -LINK_LIBRARIES( - ../../Glut/glew/lib/glew32.lib ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY} -) - -ADD_EXECUTABLE(GPUphysics - clock.cpp - fboSupport.cpp - GPU_physics_demo.cpp - shaderSupport.cpp -) - diff --git a/Extras/obsolete/GPUphysics/DEBUGGING_README b/Extras/obsolete/GPUphysics/DEBUGGING_README deleted file mode 100644 index 18fbd1bab..000000000 --- a/Extras/obsolete/GPUphysics/DEBUGGING_README +++ /dev/null @@ -1,43 +0,0 @@ - -I have added some command line options to hopefully -help with our debugging problems. - -1) Run without any shaders at all: - - GPU_physics_demo -s - - This should produce a grey screen with a neat grid of randomly - coloured cubes that are sitting completely motionless. If this - doesn't work then render-to-texture and shaders are not the - problem and we have some very basic OpenGL problem to worry - about. - -2) Run with just one shader - but no render-to-texture: - - GPU_physics_demo -p - - Just like '-s', this should produce a grey screen with a neat - grid of randomly coloured cubes that are sitting completely - motionless. This time, the vertex shader is reading the - positioning information from a texturemap. If this - doesn't work then render-to-texture isn't the problem but - something is amiss in shader-land. - - There are several possibilities - the nastiest of which might - be that your graphics card/driver doesn't support floating point - textures. (This is pretty much 'Game Over' for you because - without that, doing physics in the GPU is going to be - virtually impossible). - -3) Run without vertex texturing: - - GPU_physics_demo -v - - On hardware that doesn't support vertex texturing, this flag - is turned on by default (and things run about 5x slower!) - - Use this flag to force the software to run without vertex - texturing on hardware that does actually support it. - - You can use this flag in conjunction with any of the others. - diff --git a/Extras/obsolete/GPUphysics/GPU_physics.h b/Extras/obsolete/GPUphysics/GPU_physics.h deleted file mode 100644 index f13d3e334..000000000 --- a/Extras/obsolete/GPUphysics/GPU_physics.h +++ /dev/null @@ -1,116 +0,0 @@ - -/**********************\ -* * -* Determine OS type * -* * -\**********************/ - -#if defined(__CYGWIN__) -#define GPUP_WIN32 1 -#define GPUP_CYGWIN 1 /* Windoze AND Cygwin. */ -#elif defined(_WIN32) || defined(__WIN32__) || defined(_MSC_VER) -#define GPUP_WIN32 1 -#define GPUP_MSVC 1 /* Windoze AND MSVC. */ -#elif defined(__BEOS__) -#define GPUP_BEOS 1 -#elif defined( macintosh ) -#define GPUP_MACINTOSH 1 -#elif defined(__APPLE__) -#define GPUP_MAC_OSX 1 -#elif defined(__linux__) -#define GPUP_LINUX 1 -#elif defined(__sgi) -#define GPUP_IRIX 1 -#elif defined(_AIX) -#define GPUP_AIX 1 -#elif defined(SOLARIS) || defined(sun) -#define GPUP_SOLARIS 1 -#elif defined(hpux) -#define GPUP_HPUX 1 -#elif (defined(__unix__) || defined(unix)) && !defined(USG) -#define GPUP_BSD 1 -#endif -#if defined(BORLANDBUILDER) -#define GPUP_BB 1 -#endif - -#include -#include -#include - -/* - Add specialised includes/defines... -*/ - -#ifdef GPUP_WIN32 -#include -#include -#include -#define GPUP_WGL 1 -#endif - -#ifdef GPUP_CYGWIN -#include -#define GPUP_WGL 1 -#endif - -#ifdef GPUP_BEOS -#include -#define GPUP_GLX 1 -#endif - -#ifdef GPUP_MACINTOSH -#include -#include -#define GPUP_AGL 1 -#endif - -#ifdef GPUP_MAC_OSX -#include -#define GPUP_CGL 1 -#endif - -#if defined(GPUP_LINUX) || defined(GPUP_BSD) || defined(GPUP_IRIX) || defined(GPUP_SOLARIS) || defined(GPUP_AIX) -#include -#include -#include -#define GPUP_GLX 1 -#endif - -#if defined(GPUP_BSD) -#include -#define GPUP_GLX 1 -#endif - -#include -#include -#include -#include -#include - - -#if defined(GPUP_MAC_OSX) && !defined (VMDMESA) -#include -#include -#include -#include -#else -#include -#include -#include - - -#endif - -#ifdef DISABLE_GL_ERROR_CHECKS -inline void showGLerror ( const char * ) {} -#else -inline void showGLerror ( const char *msg ) -{ - GLenum err ; - - while ( (err = glGetError()) != GL_NO_ERROR ) - fprintf ( stderr, "%s: OpenGL Error - %s\n", msg, gluErrorString ( err ) ) ; -} -#endif - diff --git a/Extras/obsolete/GPUphysics/GPU_physics_demo.cpp b/Extras/obsolete/GPUphysics/GPU_physics_demo.cpp deleted file mode 100644 index 526d9cc98..000000000 --- a/Extras/obsolete/GPUphysics/GPU_physics_demo.cpp +++ /dev/null @@ -1,949 +0,0 @@ -#include "GPU_physics.h" -#include "fboSupport.h" -#include "shaderSupport.h" -#include "clock.h" - -#define TIMESTEP 0.016f - -enum DebugOptions -{ - DRAW_WITHOUT_SHADERS, - DRAW_WITHOUT_PHYSICS, - DRAW_ALL -} ; - - -static float *positionData = NULL ; -static float *rotationData = NULL ; -static float *collisionData = NULL ; -static bool noVertexTextureSupport = false ; -static DebugOptions debugOpt = DRAW_ALL ; - -void checkVertexTextureSupport ( bool disableVertexTextureSupport ) -{ - GLint nVertTextures ; - GLint nFragTextures ; - GLint nCombTextures ; - - glGetIntegerv ( GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, & nVertTextures ) ; - glGetIntegerv ( GL_MAX_TEXTURE_IMAGE_UNITS, & nFragTextures ) ; - glGetIntegerv ( GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, & nCombTextures ) ; - - fprintf(stderr, "INFO: This hardware supports at most:\n" - " %2d vert texture samplers\n" - " %2d frag texture samplers\n" - " %2d total texture samplers\n", - nVertTextures, nFragTextures, nCombTextures ) ; - - noVertexTextureSupport = ( nVertTextures < 2 ) ; - - if ( noVertexTextureSupport && debugOpt != DRAW_WITHOUT_SHADERS ) - { - fprintf ( stderr, "\n" - "********************************************\n" - "* *\n" - "* WARNING: This graphics card doesn't have *\n" - "* vertex shader texture support - a work- *\n" - "* around will be used - but this demo will *\n" - "* be much less impressive as a result! *\n" - "* *\n" - "********************************************\n\n" ) ; - } - - if ( ! noVertexTextureSupport && disableVertexTextureSupport ) - { - fprintf ( stderr, "WARNING: Vertex Texture Support has" - "been disabled from the command line.\n" ) ; - noVertexTextureSupport = true ; - } -} - - -int irand ( int max ) -{ - return rand() % max ; -} - - -float frand ( float max ) -{ - return (float)(rand() % 32767) * max / 32767.0f ; -} - - -static GLSL_ShaderPair *velocityGenerator ; -static GLSL_ShaderPair *positionGenerator ; -static GLSL_ShaderPair *grndCollisionGenerator ; -static GLSL_ShaderPair *collisionGenerator ; -static GLSL_ShaderPair *forceGenerator ; -static GLSL_ShaderPair *cubeShader ; - -static FrameBufferObject *position ; -static FrameBufferObject *rotation ; -static FrameBufferObject *velocity ; -static FrameBufferObject *rotvelocity ; -static FrameBufferObject *force ; -static FrameBufferObject *new_force ; -static FrameBufferObject *massSizeX ; -static FrameBufferObject *old ; -static FrameBufferObject *collisions ; - -#define TEX_SIZE 16 - -#define NUM_CUBES ( TEX_SIZE * TEX_SIZE ) -#define STRIPS_PER_CUBE 2 -#define VERTS_PER_STRIP 8 -#define NUM_VERTS ( NUM_CUBES * STRIPS_PER_CUBE * VERTS_PER_STRIP ) - -static GLuint vbo_vx = 0 ; -static GLuint vbo_tx = 0 ; -static GLuint vbo_co = 0 ; -static float vertices [ NUM_VERTS * 3 ] ; -static float texcoords [ NUM_VERTS * 2 ] ; -static float colours [ NUM_VERTS * 4 ] ; -static int starts [ NUM_CUBES * STRIPS_PER_CUBE ] ; -static int lengths [ NUM_CUBES * STRIPS_PER_CUBE ] ; - -static GLuint vbo_collvx = 0 ; -static GLuint vbo_collt0 = 0 ; -static GLuint vbo_collt1 = 0 ; -static float collvertices [ NUM_CUBES * 4 * 3 ] ; -static float colltexcoords0 [ NUM_CUBES * 4 * 2 ] ; -static float colltexcoords1 [ NUM_CUBES * 4 * 2 ] ; -static int collstart ; -static int colllength ; - -static int win_width = 640 ; -static int win_height = 480 ; - -inline int idToIndex ( int x, int y ) -{ - /* - Convert a coordinate pair within the texture to an integer - 1D array index (eg to index into the data array for that texture) - by multiplying the Y coordinate by the width of the texture and - adding the X coordinate. - */ - return y * TEX_SIZE + x ; -} - -inline float idToFloat ( int x, int y ) -{ - /* - Convert a coordinate pair within the texture to a float - by putting one coordinate into the integer part and the - other into the fraction so we can retrieve Y using floor() - and X using fract() to recover them later on inside the shader. - */ - return ((float) idToIndex ( x, y )) / (float)TEX_SIZE ; -} - - -void keybd ( unsigned char, int, int ) -{ - exit ( 0 ) ; -} - - -void reshape ( int wid, int ht ) -{ - win_width = wid ; - win_height = ht ; -} - - -void initGLcontext ( int argc, char **argv, - void (*display)(void), - bool disableVertexTextureSupport ) -{ - glutInit ( &argc, argv ) ; - glutInitDisplayMode ( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ) ; - glutInitWindowSize ( win_width, win_height ) ; - glutCreateWindow ( "Shader Math Demo" ) ; - glutDisplayFunc ( display ) ; - glutKeyboardFunc ( keybd ) ; - glutReshapeFunc ( reshape ) ; - -#if defined(GPUP_MAC_OSX) && !defined (VMDMESA) -#else - glewInit () ; -#endif - - checkVertexTextureSupport ( disableVertexTextureSupport ) ; -} - - -void initMotionTextures () -{ - if ( debugOpt == DRAW_WITHOUT_SHADERS ) return ; - - position = new FrameBufferObject ( TEX_SIZE, TEX_SIZE, 3, FBO_FLOAT ) ; - rotation = new FrameBufferObject ( TEX_SIZE, TEX_SIZE, 3, FBO_FLOAT ) ; - old = new FrameBufferObject ( TEX_SIZE, TEX_SIZE, 3, FBO_FLOAT ) ; - - if ( debugOpt == DRAW_WITHOUT_PHYSICS ) - { - velocity = NULL ; - rotvelocity = NULL ; - force = NULL ; - new_force = NULL ; - massSizeX = NULL ; - collisions = NULL ; - } - else - { - velocity = new FrameBufferObject ( TEX_SIZE, TEX_SIZE, 3, FBO_FLOAT ) ; - rotvelocity = new FrameBufferObject ( TEX_SIZE, TEX_SIZE, 3, FBO_FLOAT ) ; - force = new FrameBufferObject ( TEX_SIZE, TEX_SIZE, 3, FBO_FLOAT ) ; - new_force = new FrameBufferObject ( TEX_SIZE, TEX_SIZE, 3, FBO_FLOAT ) ; - massSizeX = new FrameBufferObject ( TEX_SIZE, TEX_SIZE, 3, FBO_FLOAT ) ; - collisions = new FrameBufferObject ( TEX_SIZE, TEX_SIZE, 3, FBO_FLOAT ) ; - } - - positionData = new float [ TEX_SIZE * TEX_SIZE * 3 ] ; - rotationData = new float [ TEX_SIZE * TEX_SIZE * 3 ] ; - - float *velocityData ; - float *rotvelocityData ; - float *forceData ; - float *massSizeXData ; - - if ( debugOpt == DRAW_WITHOUT_PHYSICS ) - { - velocityData = NULL ; - rotvelocityData = NULL ; - forceData = NULL ; - massSizeXData = NULL ; - collisionData = NULL ; - } - else - { - velocityData = new float [ TEX_SIZE * TEX_SIZE * 3 ] ; - rotvelocityData = new float [ TEX_SIZE * TEX_SIZE * 3 ] ; - forceData = new float [ TEX_SIZE * TEX_SIZE * 3 ] ; - massSizeXData = new float [ TEX_SIZE * TEX_SIZE * 3 ] ; - collisionData = new float [ TEX_SIZE * TEX_SIZE * 3 ] ; - } - - /* Give the objects some initial position, rotation, mass, force, etc */ - - for ( int y = 0 ; y < TEX_SIZE ; y++ ) - for ( int x = 0 ; x < TEX_SIZE ; x++ ) - { - /* - Start the cubes on a nice, regular 5m grid, 10m above the ground - centered around the origin - */ - - positionData [ idToIndex(x,y) * 3 + 0 ] = 5.0f * (float) (x - TEX_SIZE/2) ; - positionData [ idToIndex(x,y) * 3 + 1 ] = 0.0f ; // 10.0f ; - positionData [ idToIndex(x,y) * 3 + 2 ] = 5.0f * (float) (y - TEX_SIZE/2) ; - - /* Zero their rotations */ - rotationData [ idToIndex(x,y) * 3 + 0 ] = 0.0f ; - rotationData [ idToIndex(x,y) * 3 + 1 ] = 0.0f ; - rotationData [ idToIndex(x,y) * 3 + 2 ] = 0.0f ; - - if ( debugOpt != DRAW_WITHOUT_PHYSICS ) - { - /* Random (but predominantly upwards) velocities. */ -if(irand(2)==0) -{ - velocityData [ idToIndex(x,y) * 3 + 0 ] = frand ( 1.0f ) ; - velocityData [ idToIndex(x,y) * 3 + 1 ] = 0.0f ; - velocityData [ idToIndex(x,y) * 3 + 2 ] = frand ( 1.0f ) ; -} -else -{ - velocityData [ idToIndex(x,y) * 3 + 0 ] = 0.0f ; //frand ( 10.0f ) - 5.0f; - velocityData [ idToIndex(x,y) * 3 + 1 ] = 0.0f ; //frand ( 100.0f ) ; - velocityData [ idToIndex(x,y) * 3 + 2 ] = 0.0f ; //frand ( 10.0f ) - 5.0f; -} - - /* Random rotational velocities */ - rotvelocityData [ idToIndex(x,y) * 3 + 0 ] = 0.0f ; //frand ( 3.0f ) ; - rotvelocityData [ idToIndex(x,y) * 3 + 1 ] = 0.0f ; //frand ( 3.0f ) ; - rotvelocityData [ idToIndex(x,y) * 3 + 2 ] = 0.0f ; //frand ( 3.0f ) ; - - /* Zero forces */ - forceData [ idToIndex(x,y) * 3 + 0 ] = 0.0f ; - forceData [ idToIndex(x,y) * 3 + 1 ] = 0.0f ; - forceData [ idToIndex(x,y) * 3 + 2 ] = 0.0f ; - - /* One kg each */ - massSizeXData [ idToIndex(x,y) * 3 + 0 ] = 0.05f ; /* Mass */ - massSizeXData [ idToIndex(x,y) * 3 + 1 ] = 1.0f ; /* Radius */ - massSizeXData [ idToIndex(x,y) * 3 + 2 ] = 0.0f ; /* Unused */ - - /* Zero out collision data */ - collisionData [ idToIndex(x,y) * 3 + 0 ] = 0.0f ; - collisionData [ idToIndex(x,y) * 3 + 1 ] = 0.0f ; - collisionData [ idToIndex(x,y) * 3 + 2 ] = 0.0f ; - } - } - - if ( debugOpt != DRAW_WITHOUT_PHYSICS ) - { - /* - Object zero is the 'null' object for collision detection - so put it far away and stop it from moving around. - */ - - positionData [ 0 ] = 1000000000.0f ; - positionData [ 1 ] = 1000000000.0f ; - positionData [ 2 ] = 1000000000.0f ; - velocityData [ 0 ] = 0.0f ; - velocityData [ 1 ] = 0.0f ; - velocityData [ 2 ] = 0.0f ; - massSizeXData [ 0 ] = 10000000.0f ; /* Mass */ - massSizeXData [ 1 ] = 0.00000001f ; /* Radius */ - massSizeXData [ 2 ] = 0.0f ; /* Unused */ - collisionData [ 0 ] = 0.0f ; - collisionData [ 1 ] = 0.0f ; - collisionData [ 2 ] = 0.0f ; - } - - /* Initialise the textures */ - - position -> fillTexture ( positionData ) ; - rotation -> fillTexture ( rotationData ) ; - old -> fillTexture ( positionData ) ; // Doesn't really need it... - - if ( debugOpt != DRAW_WITHOUT_PHYSICS ) - { - velocity -> fillTexture ( velocityData ) ; - rotvelocity -> fillTexture ( rotvelocityData ) ; - force -> fillTexture ( forceData ) ; - new_force -> fillTexture ( forceData ) ; - massSizeX -> fillTexture ( massSizeXData ) ; - collisions -> fillTexture ( collisionData ) ; - } -} - - -void initPhysicsShaders () -{ - if ( debugOpt == DRAW_WITHOUT_SHADERS || - debugOpt == DRAW_WITHOUT_PHYSICS ) - return ; - - /* - The velocity generator shader calculates: - - velocity = old_velocity + delta_T * ( F / m ) ; - */ - - velocityGenerator = new GLSL_ShaderPair ( - "VelocityGenerator", - NULL, NULL, - "uniform vec4 g_dt ;" - "uniform sampler2D old_velocity ;" - "uniform sampler2D force ;" - "uniform sampler2D massSizeX ;" - "void main() {" - " gl_FragColor = vec4 (" - " texture2D ( old_velocity, gl_TexCoord[0].st ).xyz +" - " g_dt.w * ( g_dt.xyz +" - " texture2D ( force , gl_TexCoord[0].st ).xyz /" - " texture2D ( massSizeX , gl_TexCoord[0].st ).x)," - " 1.0 ) ; }", - "VelocityGenerator Frag Shader" ) ; - assert ( velocityGenerator -> compiledOK () ) ; - - /* - The position generater shader calculates: - - position = old_position + delta_T * velocity ; - - It's also used to update the rotational velocity. - */ - - positionGenerator = new GLSL_ShaderPair ( - "PositionGenerator", - NULL, NULL, - "uniform float delta_T ;" - "uniform sampler2D old_position ;" - "uniform sampler2D velocity ;" - "void main() {" - " gl_FragColor = vec4 (" - " texture2D ( old_position, gl_TexCoord[0].st ).xyz +" - " texture2D ( velocity , gl_TexCoord[0].st ).xyz *" - " delta_T," - " 1.0 ) ; }", - "PositionGenerator Frag Shader" ) ; - assert ( positionGenerator -> compiledOK () ) ; - - - collisionGenerator = new GLSL_ShaderPair ( - "CollisionGenerator", - NULL, - "collisionShader.frag" ) ; - assert ( collisionGenerator -> compiledOK () ) ; - - - forceGenerator = new GLSL_ShaderPair ( - "ForceGenerator", - NULL, NULL, - "uniform sampler2D force ;" - "uniform sampler2D position ;" - "uniform sampler2D collisions ;" - "void main() {" - " vec3 last_force = texture2D ( force , gl_TexCoord[0].st ).xyz ;" - " vec2 id = texture2D ( collisions, gl_TexCoord[0].st ).xy ;" - " vec3 pos = texture2D ( position , gl_TexCoord[0].st ).xyz ;" - " vec3 rel = pos - texture2D ( position, id ).xyz ;" - " float lrel = max ( length ( rel ), 0.001 ) ;" - " gl_FragColor = vec4 ( last_force + (rel / lrel) / lrel, 1.0 ) ;" - "}", - "ForceGenerator Frag Shader" ) ; - assert ( forceGenerator -> compiledOK () ) ; - - - grndCollisionGenerator = new GLSL_ShaderPair ( - "GroundCollisionGenerator", - NULL, NULL, - "uniform sampler2D position ;" - "uniform sampler2D old_velocity ;" - "void main() {" - " vec3 pos = texture2D ( position , gl_TexCoord[0].st ).xyz ;" - " vec3 vel = texture2D ( old_velocity, gl_TexCoord[0].st ).xyz ;" - " if ( pos [ 1 ] < 0.0 ) vel.y = abs(vel.y) ;" - " gl_FragColor = vec4 ( vel, 1.0 ) ; }", - "GroundCollisionGenerator Frag Shader" ) ; - assert ( grndCollisionGenerator -> compiledOK () ) ; -} - - -void initCollideVBO () -{ - float *p = collvertices ; - float *t0 = colltexcoords0 ; - float *t1 = colltexcoords1 ; - - collstart = 0 ; - colllength = NUM_CUBES * 4 ; - - for ( int y = 0 ; y < TEX_SIZE ; y++ ) - for ( int x = 0 ; x < TEX_SIZE ; x++ ) - { - /* Texcoord 0 data sets which corner of the texture this is. */ - - *t0++ = 0.5f /(float)TEX_SIZE ; - *t0++ = 0.5f /(float)TEX_SIZE ; - - *t0++ = ((float)TEX_SIZE-0.5f)/(float)TEX_SIZE ; - *t0++ = 0.5f /(float)TEX_SIZE ; - - *t0++ = ((float)TEX_SIZE-0.5f)/(float)TEX_SIZE ; - *t0++ = ((float)TEX_SIZE-0.5f)/(float)TEX_SIZE ; - - *t0++ = 0.5f /(float)TEX_SIZE ; - *t0++ =((float)TEX_SIZE-0.5f)/(float)TEX_SIZE ; - - /* Texcoord 1 sets which cube is which. */ - - *t1++ = ((float)x+0.5f)/(float)TEX_SIZE ; - *t1++ = ((float)y+0.5f)/(float)TEX_SIZE ; - - *t1++ = ((float)x+0.5f)/(float)TEX_SIZE ; - *t1++ = ((float)y+0.5f)/(float)TEX_SIZE ; - - *t1++ = ((float)x+0.5f)/(float)TEX_SIZE ; - *t1++ = ((float)y+0.5f)/(float)TEX_SIZE ; - - *t1++ = ((float)x+0.5f)/(float)TEX_SIZE ; - *t1++ = ((float)y+0.5f)/(float)TEX_SIZE ; - - *p++ = -1 ; *p++ = -1 ; *p++ = 0.0f ; - *p++ = +1 ; *p++ = -1 ; *p++ = 0.0f ; - *p++ = +1 ; *p++ = +1 ; *p++ = 0.0f ; - *p++ = -1 ; *p++ = +1 ; *p++ = 0.0f ; - } - - glGenBuffersARB ( 1, & vbo_collvx ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_collvx ) ; - glBufferDataARB ( GL_ARRAY_BUFFER_ARB, colllength * 3 * sizeof(float), - collvertices, GL_STATIC_DRAW_ARB ) ; - - glGenBuffersARB ( 1, & vbo_collt0 ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_collt0 ) ; - glBufferDataARB ( GL_ARRAY_BUFFER_ARB, colllength * 2 * sizeof(float), - colltexcoords0, GL_STATIC_DRAW_ARB ) ; - - glGenBuffersARB ( 1, & vbo_collt1 ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_collt1 ) ; - glBufferDataARB ( GL_ARRAY_BUFFER_ARB, colllength * 2 * sizeof(float), - colltexcoords1, GL_STATIC_DRAW_ARB ) ; - - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, 0 ) ; -} - - -void initCubeVBO () -{ - float *p = vertices ; - float *t = texcoords ; - float *c = colours ; - int nverts = 0 ; - - for ( int k = 0 ; - k < (noVertexTextureSupport ? 1 : NUM_CUBES) * STRIPS_PER_CUBE ; k++ ) - { - starts [ k ] = k * VERTS_PER_STRIP ; - lengths [ k ] = VERTS_PER_STRIP ; - } - - for ( int y = 0 ; y < (noVertexTextureSupport ? 1 : TEX_SIZE) ; y++ ) - for ( int x = 0 ; x < (noVertexTextureSupport ? 1 : TEX_SIZE) ; x++ ) - { - /* - I use the colour data to set which cube is which in - the physics textures. - */ - - for ( int k = 0 ; k < STRIPS_PER_CUBE * VERTS_PER_STRIP ; k++ ) - { - *t++ = ((float)x+0.5f)/(float)TEX_SIZE ; - *t++ = ((float)y+0.5f)/(float)TEX_SIZE ; - - if ( (x==20||x==100) && (y==20||y==100) ) - { - *c++ = 1.0f ; - *c++ = 0.0f ; - *c++ = 0.0f ; - *c++ = 1.0f ; - } - else - { - *c++ = 0.0f ; - *c++ = frand ( 1.0f ) ; - *c++ = frand ( 1.0f ) ; - *c++ = 1.0f ; - } - } - - float dx, dy, dz ; - - if ( debugOpt == DRAW_WITHOUT_SHADERS ) - { - dx = 5.0f * (float) (TEX_SIZE/2 - x) ; - dy = 10.0f ; - dz = 5.0f * (float) (TEX_SIZE/2 - y) ; - } - else - { - dx = 0.0f ; - dy = 0.0f ; - dz = 0.0f ; - } - - *p++ = -1 + dx ; *p++ = -1 + dy ; *p++ = -1 + dz ; - *p++ = +1 + dx ; *p++ = -1 + dy ; *p++ = -1 + dz ; - *p++ = -1 + dx ; *p++ = +1 + dy ; *p++ = -1 + dz ; - *p++ = +1 + dx ; *p++ = +1 + dy ; *p++ = -1 + dz ; - *p++ = -1 + dx ; *p++ = +1 + dy ; *p++ = +1 + dz ; - *p++ = +1 + dx ; *p++ = +1 + dy ; *p++ = +1 + dz ; - *p++ = -1 + dx ; *p++ = -1 + dy ; *p++ = +1 + dz ; - *p++ = +1 + dx ; *p++ = -1 + dy ; *p++ = +1 + dz ; - - *p++ = -1 + dx ; *p++ = +1 + dy ; *p++ = -1 + dz ; - *p++ = -1 + dx ; *p++ = +1 + dy ; *p++ = +1 + dz ; - *p++ = -1 + dx ; *p++ = -1 + dy ; *p++ = -1 + dz ; - *p++ = -1 + dx ; *p++ = -1 + dy ; *p++ = +1 + dz ; - *p++ = +1 + dx ; *p++ = -1 + dy ; *p++ = -1 + dz ; - *p++ = +1 + dx ; *p++ = -1 + dy ; *p++ = +1 + dz ; - *p++ = +1 + dx ; *p++ = +1 + dy ; *p++ = -1 + dz ; - *p++ = +1 + dx ; *p++ = +1 + dy ; *p++ = +1 + dz ; - - nverts += STRIPS_PER_CUBE * VERTS_PER_STRIP ; - } - - glGenBuffersARB ( 1, & vbo_vx ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_vx ) ; - glBufferDataARB ( GL_ARRAY_BUFFER_ARB, nverts * 3 * sizeof(float), - vertices, GL_STATIC_DRAW_ARB ) ; - - glGenBuffersARB ( 1, & vbo_tx ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_tx ) ; - glBufferDataARB ( GL_ARRAY_BUFFER_ARB, nverts * 2 * sizeof(float), - texcoords, GL_STATIC_DRAW_ARB ) ; - - glGenBuffersARB ( 1, & vbo_co ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_co ) ; - glBufferDataARB ( GL_ARRAY_BUFFER_ARB, nverts * 4 * sizeof(float), - colours, GL_STATIC_DRAW_ARB ) ; - - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, 0 ) ; - - if ( debugOpt == DRAW_WITHOUT_SHADERS ) - cubeShader = NULL ; - else - { - if ( noVertexTextureSupport ) - cubeShader = new GLSL_ShaderPair ( "CubeShader", - "cubeShaderNoTexture.vert", - "cubeShader.frag" ) ; - else - cubeShader = new GLSL_ShaderPair ( "CubeShader", "cubeShader.vert", - "cubeShader.frag" ) ; - assert ( cubeShader -> compiledOK () ) ; - } -} - - -void drawCubesTheHardWay () -{ - /* - Without vertex texture support, we have to read the position/rotation - data back from the hardware every frame and render each cube individually. - */ - - float p0 = positionData [ 0 ] ; - float p1 = positionData [ 1 ] ; - float p2 = positionData [ 2 ] ; - - position -> fetchTexture ( positionData ) ; - rotation -> fetchTexture ( rotationData ) ; - - //if ( positionData [ 0 ] == p0 && - // positionData [ 1 ] == p1 && - // positionData [ 2 ] == p2 ) - //{ - // fprintf ( stderr, "WARNING: If nothing seems to be working, you may\n" - // "have an old version of the nVidia driver.\n" - // "Version 76.76 is known to be bad.\n" ) ; - //} - - cubeShader -> use () ; /* Math = Cube shader */ - - glPushClientAttrib ( GL_CLIENT_VERTEX_ARRAY_BIT ) ; - - glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ; - - glEnableClientState ( GL_COLOR_ARRAY ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_co ) ; - glColorPointer ( 4, GL_FLOAT, 0, vbo_co ? NULL : colours ) ; - - glEnableClientState ( GL_VERTEX_ARRAY ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_vx ) ; - glVertexPointer ( 3, GL_FLOAT, 0, vbo_vx ? NULL : vertices ) ; - - for ( int y = 0 ; y < TEX_SIZE ; y++ ) - for ( int x = 0 ; x < TEX_SIZE ; x++ ) - { - float *pos = & positionData [ idToIndex ( x, y ) * 3 ] ; - float *rot = & rotationData [ idToIndex ( x, y ) * 3 ] ; - - glPushMatrix () ; - glTranslatef ( pos [ 0 ], pos [ 1 ], pos [ 2 ] ) ; - glRotatef ( rot [ 0 ] * 180.0f / 3.14159f, 0, 1, 0 ) ; - glRotatef ( rot [ 1 ] * 180.0f / 3.14159f, 1, 0, 0 ) ; - glRotatef ( rot [ 2 ] * 180.0f / 3.14159f, 0, 0, 1 ) ; - glMultiDrawArraysEXT ( GL_TRIANGLE_STRIP, (GLint*)starts, - (GLint*)lengths, - STRIPS_PER_CUBE ) ; - glPopMatrix () ; - } - - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, 0 ) ; - glPopClientAttrib () ; -} - - -void drawCubeVBO () -{ - /* - With vertex texture support, we can leave the position/rotation - data on the hardware and render all of the cubes in one big VBO! - */ - - if ( debugOpt != DRAW_WITHOUT_SHADERS ) - { - cubeShader -> use () ; /* Math = Cube shader */ - cubeShader -> applyTexture ( "position", position, 0 ) ; - cubeShader -> applyTexture ( "rotation", rotation, 1 ) ; - } - - glPushClientAttrib ( GL_CLIENT_VERTEX_ARRAY_BIT ) ; - - glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_tx ) ; - glTexCoordPointer ( 2, GL_FLOAT, 0, vbo_tx ? NULL : texcoords ) ; - - glEnableClientState ( GL_COLOR_ARRAY ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_co ) ; - glColorPointer ( 4, GL_FLOAT, 0, vbo_co ? NULL : colours ) ; - - glEnableClientState ( GL_VERTEX_ARRAY ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_vx ) ; - glVertexPointer ( 3, GL_FLOAT, 0, vbo_vx ? NULL : vertices ) ; - - glMultiDrawArraysEXT ( GL_TRIANGLE_STRIP, (GLint*)starts, (GLint*)lengths, - NUM_CUBES * STRIPS_PER_CUBE ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, 0 ) ; - glPopClientAttrib () ; -} - - -void drawCubes () -{ - glMatrixMode ( GL_PROJECTION ) ; - glLoadIdentity () ; - glFrustum ( -1.0f, 1.0f, - -1.0f / ((float)win_width/(float)win_height), - 1.0f / ((float)win_width/(float)win_height), - 1.0f, 1000000.0f) ; - - /* Set up camera position */ - - glMatrixMode ( GL_MODELVIEW ) ; - glLoadIdentity () ; - glTranslatef ( 10.0f * (float)TEX_SIZE/128.0f, - -100.0f * (float)TEX_SIZE/128.0f, - -500.0f * (float)TEX_SIZE/128.0f ) ; - glRotatef ( 20.0, 1.0, 0.0, 0.0 ) ; - - glEnable ( GL_DEPTH_TEST ) ; - glEnable ( GL_CULL_FACE ) ; - glCullFace ( GL_FRONT ) ; - - glClearColor ( 0.7f, 0.7f, 0.7f, 1.0f ) ; - glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; - - if ( noVertexTextureSupport ) - drawCubesTheHardWay () ; - else - drawCubeVBO () ; -} - - -void runCollisionDetection () -{ -static Clock ck ; -ck.update () ; -double tall=ck.getDeltaTime () ; - static int firsttime = true ; - static unsigned int query = 0 ; - - FrameBufferObject *tmp ; - FrameBufferObject *SCM = old ; - FrameBufferObject *DCM = collisions ; - unsigned int numHits ; - - if ( firsttime ) - { - glGenQueriesARB ( 1, (GLuint*) & query ) ; - firsttime = false ; - } - - /* Fill SCM with big numbers */ - - glClearColor ( 1.0f, 1.0f, 1.0f, 1.0f ) ; - SCM -> prepare ( true ) ; - - glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ) ; - force -> prepare ( true ) ; /* Zero out all of the forces. */ - - int numPasses = 0 ; - - glPushClientAttrib ( GL_CLIENT_VERTEX_ARRAY_BIT ) ; - - glClientActiveTexture( GL_TEXTURE1 ) ; - glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_collt1 ) ; - glTexCoordPointer ( 2, GL_FLOAT, 0, vbo_collt1 ? NULL : colltexcoords1 ) ; - - glClientActiveTexture( GL_TEXTURE0 ) ; - glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_collt0 ) ; - glTexCoordPointer ( 2, GL_FLOAT, 0, vbo_collt0 ? NULL : colltexcoords0 ) ; - - glEnableClientState ( GL_VERTEX_ARRAY ) ; - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, vbo_collvx ) ; - glVertexPointer ( 3, GL_FLOAT, 0, vbo_collvx ? NULL : collvertices ) ; - - while ( true ) - { - collisionGenerator -> use () ; - collisionGenerator -> applyTexture ( "position" , position, 0 ) ; - collisionGenerator -> applyTexture ( "old_collisions", SCM , 1 ) ; - - /* Fill DCM with zeroes */ - DCM -> prepare ( true ) ; - - glBeginQueryARB ( GL_SAMPLES_PASSED_ARB, query ) ; - - glMultiDrawArraysEXT ( GL_QUADS, (GLint*)& collstart, (GLint*)& colllength, - 1 ) ; -numPasses++ ; - - glEndQueryARB ( GL_SAMPLES_PASSED_ARB ) ; - - forceGenerator -> use () ; - forceGenerator -> applyTexture ( "position" , position , 0 ) ; - forceGenerator -> applyTexture ( "force" , force , 1 ) ; - forceGenerator -> applyTexture ( "collisions", DCM , 2 ) ; - - GLuint sampleCount ; - - glGetQueryObjectuivARB ( query, GL_QUERY_RESULT_ARB, &sampleCount ) ; - -//fprintf ( stderr, "%d ", sampleCount ) ; - - if ( sampleCount == 0 ) - break ; - - new_force -> paint () ; - - tmp = new_force ; - new_force = force ; - force = tmp ; - - tmp = DCM ; - DCM = SCM ; - SCM = tmp ; - } - - glBindBufferARB ( GL_ARRAY_BUFFER_ARB, 0 ) ; - glPopClientAttrib () ; - -ck.update () ; -double tdone=ck.getDeltaTime () ; -static int ii = 0 ; -ii++; -if (ii%100==0) -fprintf ( stderr, "Performance: %d passes %d cubes: other=%fms collisions=%fms\n", numPasses, NUM_CUBES, tall*1000.0, tdone*1000.0 ) ; -} - - -void runPhysics () -{ - FrameBufferObject *tmp ; - - /* Do some simple physics calculations in four stages */ - - /* Copy old velocity into old. */ - tmp = old ; - old = velocity ; - velocity = tmp ; - - velocityGenerator -> use () ; - velocityGenerator -> applyTexture ( "old_velocity", old , 0 ) ; - velocityGenerator -> applyTexture ( "force" , force , 1 ) ; - velocityGenerator -> applyTexture ( "massSizeX" , massSizeX, 2 ) ; - velocityGenerator -> setUniform4f ( "g_dt", 0.0f, /*-9.8f */ 0.0f, 0.0f, TIMESTEP ) ; - velocity -> paint () ; - - /* Copy old position into old. */ - tmp = old ; - old = position ; - position = tmp ; - - positionGenerator -> use () ; - positionGenerator -> applyTexture ( "old_position", old , 0 ) ; - positionGenerator -> applyTexture ( "velocity" , velocity, 1 ) ; - positionGenerator -> setUniform1f ( "delta_T", TIMESTEP ) ; - position -> paint () ; - - /* Copy old velocity into old. */ - - tmp = old ; - old = velocity ; - velocity = tmp ; - - grndCollisionGenerator -> use () ; - grndCollisionGenerator -> applyTexture ( "position" , position, 0 ) ; - grndCollisionGenerator -> applyTexture ( "old_velocity", old , 1 ) ; - velocity -> paint () ; - - /* Copy old rotation into old. */ - tmp = old ; - old = rotation ; - rotation = tmp ; - - positionGenerator -> use () ; - positionGenerator -> applyTexture ( "old_position", old , 0 ) ; - positionGenerator -> applyTexture ( "velocity" , rotvelocity, 1 ) ; - positionGenerator -> setUniform1f ( "delta_T", TIMESTEP ) ; - rotation -> paint () ; - - restoreFrameBuffer () ; -} - - - -void display ( void ) -{ - if ( debugOpt != DRAW_WITHOUT_SHADERS && - debugOpt != DRAW_WITHOUT_PHYSICS ) - { - runCollisionDetection () ; - runPhysics () ; - } - - /* Now render the scene using the results */ - - glViewport ( 0, 0, win_width, win_height ) ; - - drawCubes () ; - - /* All done! */ - - glutSwapBuffers () ; - glutPostRedisplay () ; -} - - -void help () -{ - fprintf ( stderr, "GPUphysics: Usage -\n\n" ) ; - fprintf ( stderr, " GPUphysics_demo [-c][-p][-v][-a][-v]\n\n" ) ; - fprintf ( stderr, "Where:\n" ) ; - fprintf ( stderr, " -s -- Draw with shaders at all\n" ) ; - fprintf ( stderr, " -p -- Draw with shaders but no physics\n" ) ; - fprintf ( stderr, " -a -- Draw with all features enabled [default]\n" ) ; - fprintf ( stderr, " -v -- Disable vertex textures even if " - "they are supported in hardware\n" ) ; - fprintf ( stderr, "\n" ) ; -} - - -int main ( int argc, char **argv ) -{ -#ifdef WIN32 - //until there is a first GPU that works under VertexTextureSupport under WIN32, disable it -bool disableVertexTextureSupport = true; -#else - bool disableVertexTextureSupport = false ; -#endif - debugOpt = DRAW_ALL ; - - for ( int i = 1 ; i < argc ; i++ ) - { - if ( argv [ i ][ 0 ] == '-' || argv [ i ][ 0 ] == '+' ) - for ( int j = 1 ; argv[i][j] != '\0' ; j++ ) - switch ( argv [ i ][ j ] ) - { - case 's' : debugOpt = DRAW_WITHOUT_SHADERS ; break ; - case 'p' : debugOpt = DRAW_WITHOUT_PHYSICS ; break ; - case 'a' : debugOpt = DRAW_ALL ; break ; - - case 'v' : disableVertexTextureSupport = true ; break ; - default : help () ; exit ( 0 ) ; - } - else - { - help () ; - exit ( 0 ) ; - } - } - - initGLcontext ( argc, argv, display, disableVertexTextureSupport ) ; - initMotionTextures () ; - initPhysicsShaders () ; - initCubeVBO () ; - initCollideVBO () ; - glutMainLoop () ; - return 0 ; -} - diff --git a/Extras/obsolete/GPUphysics/LICENSE b/Extras/obsolete/GPUphysics/LICENSE deleted file mode 100644 index 93ba7debb..000000000 --- a/Extras/obsolete/GPUphysics/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ - -/* GPUphysics -- A library and demo program to assist in running physics - simulations on a GPU. - - Copyright (C) 2006 Stephen J. Baker - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Steve Baker sjbaker1@airmail.net -*/ - diff --git a/Extras/obsolete/GPUphysics/Makefile b/Extras/obsolete/GPUphysics/Makefile deleted file mode 100644 index 4297adbf6..000000000 --- a/Extras/obsolete/GPUphysics/Makefile +++ /dev/null @@ -1,22 +0,0 @@ - -HDRS = fboSupport.h shaderSupport.h GPU_physics.h clock.h -OBJS = GPU_physics_demo.o fboSupport.o shaderSupport.o clock.o - -all: ${OBJS} - g++ -o GPU_physics_demo ${OBJS} -lglut -lGLEW -lGL - -clock.o : clock.cpp ${HDRS} - g++ -c clock.cpp - -shaderSupport.o : shaderSupport.cpp ${HDRS} - g++ -c shaderSupport.cpp - -fboSupport.o : fboSupport.cpp ${HDRS} - g++ -c fboSupport.cpp - -GPU_physics_demo.o : GPU_physics_demo.cpp ${HDRS} - g++ -c GPU_physics_demo.cpp - -clean: - -rm -f ${OBJS} - diff --git a/Extras/obsolete/GPUphysics/Makefile.Mac b/Extras/obsolete/GPUphysics/Makefile.Mac deleted file mode 100644 index 6bb068080..000000000 --- a/Extras/obsolete/GPUphysics/Makefile.Mac +++ /dev/null @@ -1,22 +0,0 @@ - -HDRS = fboSupport.h shaderSupport.h -OBJS = GPU_physics_demo.o fboSupport.o shaderSupport.o clock.o - -all: ${OBJS} - g++ -framework GLUT -framework OpenGL -L"/System/Library/Frameworks/OpenGL.framework/Libraries" -lGL -lGLU -o GPU_physics_demo ${OBJS} -L"/System/Library/Frameworks/OpenGL.framework/Libraries" -lGLU -lGL -lGLU -lobjc - -shaderSupport.o : shaderSupport.cpp ${HDRS} - g++ -c shaderSupport.cpp - -fboSupport.o : fboSupport.cpp ${HDRS} - g++ -c fboSupport.cpp - -GPU_physics_demo.o : GPU_physics_demo.cpp ${HDRS} - g++ -c GPU_physics_demo.cpp - -clock.o : clock.cpp - g++ -c clock.cpp - -clean: - -rm -f ${OBJS} - diff --git a/Extras/obsolete/GPUphysics/README b/Extras/obsolete/GPUphysics/README deleted file mode 100644 index d05450503..000000000 --- a/Extras/obsolete/GPUphysics/README +++ /dev/null @@ -1,106 +0,0 @@ - -Author : Steve Baker (sjbaker1@airmail.net) -Build using: 'make' -Run using: 'GPU_physics_demo' -Requires : A pretty modern graphics card - nVidia 6800 or better. - Not tested on ATI hardware. -License : zLib - see file: 'LICENSE' - ----------------------------------------------------------- -Demonstrates 16,384 cubes moving under the influence of -gravity and one other force - all with potentially different -masses, velocities, applied forces, etc. The CPU is not -involved in any of the calculations - or even in applying -those calculations to the graphics when rendering the cubes. ----------------------------------------------------------- -C++ Sources: - -shaderSupport.cxx -- A wrapper layer for OpenGL/GLSL shaders. - -fboSupport.cxx -- A wrapper layer for render-to-texture tricks. - -GPU_physics_demo.cxx -- The application code. - ----------------------------------------------------------- -GLSLShader Sources used in the Demo: - -cubeShader.vert -cubeShaderNoVertexTexture.vert -cubeShader.frag - ----------------------------------------------------------- -The objective of this library is to provide a basis for the -the Bullet physics engine to: - -* Compile shader source code into a 'class GLSL_ShaderPair' object. -* Allocate an NxM texture that you can render into. (class FrameBufferObject) -* Populate a specified texture with floating point data. -* Run a specified shader on a specified set of textures - leaving the - results in another specified texture. -* Demonstrate that this texture can be applied directly into the - graphics code without any CPU intervention whatever. - -------------------------------------------------------------- -Step 1: In initialisation code: - -* Declare some number of FrameBufferObjects. These are texture - maps that you can render to that represent the 'variables' - in the massively parallel calculations: - - eg: - - position = new FrameBufferObject ( 512, 512, 4, FBO_FLOAT ) ; - -* Declare some number of GLSL_ShaderPair objects: - - /* GLSL code read from disk */ - - teapotShaders = new GLSL_ShaderPair ( - "TeapotShader", "shader.vert", "shader.frag" ) ; - - /* ...or...Inline GLSL code */ - - textureShaders = new GLSL_ShaderPair ( - "TextureShader", - "void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }", - "Render2Texture Vert Shader", - "void main() { gl_FragColor = vec4 ( 1, 1, 0, 1 ) ; }", - "Render2Texture Frag Shader" ) ) - -* Check that they compiled OK: - - assert ( textureShaders -> compiledOK () ) ; - assert ( teapotShaders -> compiledOK () ) ; - -Step 2: In the main loop: - -* Select one shader pair to use to do the calculations: - - teapotShaders -> use () ; - -* Set any 'uniform' parameters that the shader might need to be - the same for all of the objects being calculated: - - teapotShaders -> setUniform3f ( "gravity", 0, -9.8f,0 ) ; - teapotShaders -> setUniform1f ( "delta_T", 0.016f ) ; - -* Assign slot numbers to any FBO/Textures that the shader uses as inputs - and bind them to uniforms in the shader code: - - /* Texture 'slots' 0 up to about 15 */ - teapotShaders -> applyTexture ( "velocity" , velocityFBO, 0 ) ; - teapotShaders -> applyTexture ( "accelleration", accnFBO, 1 ) ; - -* Choose a target FBO/Texture as the place to store the results and - render a polygon of suitable size to perform the calculations: - - position -> paint () ; - -* Restore the frame buffer to normal so we can go back to using the GPU - to do graphics: - - restoreFrameBuffer () ; - -Step 3: Draw stuff! - - diff --git a/Extras/obsolete/GPUphysics/clock.cpp b/Extras/obsolete/GPUphysics/clock.cpp deleted file mode 100644 index cbd8d78af..000000000 --- a/Extras/obsolete/GPUphysics/clock.cpp +++ /dev/null @@ -1,79 +0,0 @@ - -#include -#include -#include "GPU_physics.h" -#include "clock.h" - -#ifdef GPUP_CYGWIN - typedef long long _int64; - #define LARGEINTEGER _int64 -#endif - -#ifndef GPUP_WIN32 -# include -#endif - -#include - -#ifdef GPUP_WIN32 - -double Clock::res ; -int Clock::perf_timer = -1; - -void Clock::initPerformanceTimer () -{ - if ( perf_timer == -1 ) - { - /* Use Performance Timer if it's available, mmtimer if not. */ - - __int64 frequency ; - - perf_timer = QueryPerformanceFrequency ( (LARGE_INTEGER *) & frequency ) ; - - if ( perf_timer ) - { - res = 1.0 / (double) frequency ; - perf_timer = 1 ; - } - } -} -#endif - -double Clock::getRawTime () const -{ -#ifdef GPUP_WIN32 - - /* Use Performance Timer if it's available, mmtimer if not. */ - - if ( perf_timer ) - { - __int64 t ; - - QueryPerformanceCounter ( (LARGE_INTEGER *) &t ) ; - - return res * (double) t ; - } - - return (double) timeGetTime() * 0.001 ; - -#else - timeval tv ; - - gettimeofday ( & tv, NULL ) ; - - return (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0 ; -#endif -} - - -void Clock::update () -{ - now = getRawTime() - start ; - - delta = now - last_time ; - - last_time = now ; -} - - - diff --git a/Extras/obsolete/GPUphysics/clock.h b/Extras/obsolete/GPUphysics/clock.h deleted file mode 100644 index 867de808c..000000000 --- a/Extras/obsolete/GPUphysics/clock.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* - High precision clocks. -*/ - -class Clock -{ - double start ; - double now ; - double delta ; - double last_time ; - double max_delta ; - -#ifdef GPUP_WIN32 - static double res ; - static int perf_timer ; - void initPerformanceTimer () ; -#endif - - double getRawTime () const ; - -public: - - Clock () { reset () ; } - - void reset () - { -#ifdef GPUP_WIN32 - initPerformanceTimer () ; -#endif - start = getRawTime () ; - now = 0.0 ; - max_delta = 0.2 ; - delta = 0.0000001 ; /* Faked so stoopid programs won't div0 */ - last_time = 0.0 ; - } - - void setMaxDelta ( double maxDelta ) { max_delta = maxDelta ; } - double getMaxDelta () const { return max_delta ; } - void update () ; - double getAbsTime () const { return now ; } - double getDeltaTime () const { return delta ; } - double getFrameRate () const { return 1.0 / delta ; } -} ; - diff --git a/Extras/obsolete/GPUphysics/collisionShader.frag b/Extras/obsolete/GPUphysics/collisionShader.frag deleted file mode 100644 index 8e614daff..000000000 --- a/Extras/obsolete/GPUphysics/collisionShader.frag +++ /dev/null @@ -1,30 +0,0 @@ - -uniform sampler2D position ; -uniform sampler2D old_collisions ; - -void main() -{ - vec2 my_id = gl_TexCoord[0].st ; - vec2 pr_id = gl_TexCoord[1].st ; - - /* Object colliding with itself */ - - if ( length ( my_id - pr_id ) < 0.05) discard ; - - vec2 last_id = texture2D ( old_collisions, my_id ).xy ; - - /* Object collision that will already have been dealt with */ - - if ( pr_id.y >= last_id.y ) discard ; - if ( pr_id.y == last_id.y && pr_id.x >= last_id.y) discard ; - - vec3 my_pos = texture2D ( position, my_id ).xyz ; - vec3 pr_pos = texture2D ( position, pr_id ).xyz ; - - /* Objects that don't actually collide */ - - if ( length ( my_pos - pr_pos ) >= 2.0 ) discard ; - - gl_FragColor = vec4 ( pr_id, 0, 1 ) ; -} - diff --git a/Extras/obsolete/GPUphysics/cubeShader.frag b/Extras/obsolete/GPUphysics/cubeShader.frag deleted file mode 100644 index a9fb8ac02..000000000 --- a/Extras/obsolete/GPUphysics/cubeShader.frag +++ /dev/null @@ -1,6 +0,0 @@ - -void main() -{ - gl_FragColor = gl_Color ; -} - diff --git a/Extras/obsolete/GPUphysics/cubeShader.vert b/Extras/obsolete/GPUphysics/cubeShader.vert deleted file mode 100644 index b41b7e898..000000000 --- a/Extras/obsolete/GPUphysics/cubeShader.vert +++ /dev/null @@ -1,42 +0,0 @@ - -/* Use this for rendering the little cubes. */ - -/* Translation & rotation passed in texture maps */ - -uniform sampler2D position ; -uniform sampler2D rotation ; - -/* gl_Color is just the vertex colour */ -/* gl_MultiTexCoord0 selects where within the texture we - find this cubes location */ - -void main() -{ - vec4 pos = vec4 ( texture2D ( position, gl_MultiTexCoord0.st ).xyz, 1.0 ) ; - vec3 rot = texture2D ( rotation, gl_MultiTexCoord0.st ).xyz ; - - /* Build a rotation matrix */ - - float sh = sin ( rot.x ) ; float ch = cos ( rot.x ) ; - float sp = sin ( rot.y ) ; float cp = cos ( rot.y ) ; - float sr = sin ( rot.z ) ; float cr = cos ( rot.z ) ; - - mat4 mat = mat4 ( ch * cr - sh * sr * sp, - -sh * cp, - sr * ch + sh * cr * sp, - 0, - cr * sh + sr * sp * ch, - ch * cp, - sr * sh - cr * sp * ch, - 0, - -sr * cp, - sp, - cr * cp, - 0, - 0.0, 0.0, 0.0, 1.0 ) ; - - gl_FrontColor = gl_Color ; - pos.xyz += (mat * gl_Vertex).xyz ; - gl_Position = gl_ModelViewProjectionMatrix * pos ; -} - diff --git a/Extras/obsolete/GPUphysics/cubeShaderNoTexture.vert b/Extras/obsolete/GPUphysics/cubeShaderNoTexture.vert deleted file mode 100644 index 47fef79df..000000000 --- a/Extras/obsolete/GPUphysics/cubeShaderNoTexture.vert +++ /dev/null @@ -1,12 +0,0 @@ - -/* - Use this for rendering the little cubes when - there is no vertex shader texture support. -*/ - -void main() -{ - gl_FrontColor = gl_Color ; - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex ; -} - diff --git a/Extras/obsolete/GPUphysics/fboSupport.cpp b/Extras/obsolete/GPUphysics/fboSupport.cpp deleted file mode 100644 index f0eb94e91..000000000 --- a/Extras/obsolete/GPUphysics/fboSupport.cpp +++ /dev/null @@ -1,396 +0,0 @@ -#include "GPU_physics.h" - -// #define FBO_USE_NVIDIA_FLOAT_TEXTURE_EXTENSION 1 -#include "fboSupport.h" - -#ifdef FBO_USE_NVIDIA_FLOAT_TEXTURE_EXTENSION - -/* nVidia float texture extension */ -#define FBO_R_HALFFLOAT GL_FLOAT_R16_NV -#define FBO_RG_HALFFLOAT GL_FLOAT_RG16_NV -#define FBO_RGB_HALFFLOAT GL_FLOAT_RGB16_NV -#define FBO_RGBA_HALFFLOAT GL_FLOAT_RGBA16_NV - -#define FBO_R_FLOAT GL_FLOAT_R32_NV -#define FBO_RG_FLOAT GL_FLOAT_RG32_NV -#define FBO_RGB_FLOAT GL_FLOAT_RGB32_NV -#define FBO_RGBA_FLOAT GL_FLOAT_RGBA32_NV - -#else - -/* ATI float texture extension */ -#define FBO_R_HALFFLOAT GL_LUMINANCE_FLOAT16_ATI -#define FBO_RG_HALFFLOAT GL_LUMINANCE_ALPHA_FLOAT16_ATI -#define FBO_RGB_HALFFLOAT GL_RGB_FLOAT16_ATI -#define FBO_RGBA_HALFFLOAT GL_RGBA_FLOAT16_ATI - -#define FBO_R_FLOAT GL_LUMINANCE_FLOAT32_ATI -#define FBO_RG_FLOAT GL_LUMINANCE_ALPHA_FLOAT32_ATI -#define FBO_RGB_FLOAT GL_RGB_FLOAT32_ATI -#define FBO_RGBA_FLOAT GL_RGBA_FLOAT32_ATI - -#endif - -static void checkFrameBufferStatus () -{ - GLenum status ; - - status = glCheckFramebufferStatusEXT ( GL_FRAMEBUFFER_EXT ) ; - - switch ( status ) - { - case GL_FRAMEBUFFER_COMPLETE_EXT : - break ; - - case GL_FRAMEBUFFER_UNSUPPORTED_EXT : - fprintf ( stderr, "ERROR: Unsupported FBO setup.\n" ) ; - exit ( 1 ) ; - - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT : - fprintf ( stderr, "WARNING: Incomplete FBO attachment.\n" ) ; - break ; - - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT : - fprintf ( stderr, "WARNING: Incomplete FBO - missing attachment.\n" ) ; - break ; - -#ifdef GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT - case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT: - fprintf ( stderr, "WARNING: Incomplete FBO - duplicate attachment.\n" ) ; - break ; -#endif - - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT : - fprintf ( stderr, "WARNING: Incomplete FBO - improper dimensions.\n" ) ; - break ; - - case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT : - fprintf ( stderr, "WARNING: Incomplete FBO - improper formats.\n" ) ; - break ; - - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT : - fprintf ( stderr, "WARNING: Incomplete FBO draw buffer.\n" ) ; - break ; - - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT : - fprintf ( stderr, "WARNING: Incomplete FBO read buffer.\n" ) ; - break ; - - default : - fprintf ( stderr, "WARNING: Unexpected FBO status : 0x%04x\n", status ) ; - break ; - } -} - - - -FrameBufferObject::FrameBufferObject ( int _width , - int _height, - int _ncomps, - fboDataType _type ) -{ - if ( (_width & (_width-1)) == 0 ) - width = _width ; - else - { - fprintf ( stderr, "FBO: Non-power of two width!\n" ) ; - width = 512 ; - } - - if ( (_height & (_height-1)) == 0 ) - height = _height ; - else - { - fprintf ( stderr, "FBO: Non-power of two height!\n" ) ; - width = 512 ; - } - - ncomps = _ncomps ; - type = _type ; - - switch ( ncomps ) - { - case 1 : format = GL_LUMINANCE ; break ; - case 2 : format = GL_LUMINANCE_ALPHA ; break ; - case 3 : format = GL_RGB ; break ; - case 4 : format = GL_RGBA ; break ; - default: fprintf ( stderr, "Illegal number of components" - " in a FrameBufferObject.\n" ) ; - ncomps = 4 ; format = GL_RGBA ; break ; - } - - - switch ( type ) - { - case FBO_BYTE : - case FBO_UNSIGNED_BYTE : iformat = format ; break ; - - case FBO_INT : - case FBO_UNSIGNED_INT : - fprintf ( stderr, "FBO: GL_INT/GL_UINT textures are unsupported," - " truncating to 16 bits per component" ) ; - /* FALL THROUGH */ - case FBO_SHORT : - case FBO_UNSIGNED_SHORT : - switch ( ncomps ) - { - case 1 : iformat = GL_LUMINANCE16 ; break ; - case 2 : iformat = GL_LUMINANCE16_ALPHA16 ; break ; - case 3 : iformat = GL_RGB16 ; break ; - case 4 : iformat = GL_RGBA16 ; break ; - } - break ; - - case FBO_DOUBLE : - fprintf ( stderr, "FBO: GL_DOUBLE textures are unsupported," - " truncating to GL_FLOAT per component" ) ; - /* FALL THROUGH */ - case FBO_FLOAT : - switch ( ncomps ) - { - case 1 : iformat = FBO_R_FLOAT ; break ; - case 2 : iformat = FBO_RG_FLOAT ; break ; - case 3 : iformat = FBO_RGB_FLOAT ; break ; - case 4 : iformat = FBO_RGBA_FLOAT ; break ; - } - break ; - - case FBO_HALF : - switch ( ncomps ) - { - case 1 : iformat = FBO_R_HALFFLOAT ; break ; - case 2 : iformat = FBO_RG_HALFFLOAT ; break ; - case 3 : iformat = FBO_RGB_HALFFLOAT ; break ; - case 4 : iformat = FBO_RGBA_HALFFLOAT ; break ; - } - break ; - - default : - fprintf ( stderr, "FBO: Unsupported data type?!?" ) ; - break ; - } - -fprintf(stderr,"@a\n" ) ; - glGenTextures ( 1, & textureHandle ) ; -fprintf(stderr,"@b\n" ) ; - glBindTexture ( GL_TEXTURE_2D, textureHandle ) ; -fprintf(stderr,"@c\n" ) ; - glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ) ; -fprintf(stderr,"@d\n" ) ; - glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ) ; -fprintf(stderr,"@e\n" ) ; - //glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ) ; - //glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ) ; - fillTexture ( (void *) NULL ) ; -fprintf(stderr,"@f\n" ) ; - - glGenFramebuffersEXT ( 1, & fboHandle ) ; -fprintf(stderr,"@g\n" ) ; - glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT, fboHandle ) ; -fprintf(stderr,"@h\n" ) ; - - glFramebufferTexture2DEXT ( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, - GL_TEXTURE_2D, textureHandle, 0 ) ; -fprintf(stderr,"@i\n" ) ; - -#ifdef NEED_DEPTH_BUFFER - static GLuint depth_rb = 0 ; - - if ( depth_rb == 0 ) - { -fprintf(stderr,"@j\n" ) ; - glGenRenderbuffersEXT ( 1, & depth_rb ) ; - glBindRenderbufferEXT ( GL_RENDERBUFFER_EXT, depth_rb ) ; - glRenderbufferStorageEXT ( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, - width, height ) ; - glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, depth_rb ) ; - } - else -{ -fprintf(stderr,"@k\n" ) ; - glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, depth_rb ) ; -} -#else -fprintf(stderr,"@l\n" ) ; - glDisable ( GL_DEPTH_TEST ) ; - glDepthMask ( 0 ) ; -fprintf(stderr,"@m\n" ) ; - glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT , GL_DEPTH_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, 0 ) ; -fprintf(stderr,"@n\n" ) ; -#endif - -#ifdef NEED_STENCIL_BUFFER - static GLuint stencil_rb = 0 ; - - if ( stencil_rb == 0 ) - { -fprintf(stderr,"@o\n" ) ; - glGenRenderbuffersEXT ( 1, & stencil_rb ) ; - glBindRenderbufferEXT ( GL_RENDERBUFFER_EXT, stencil_rb ) ; - glRenderbufferStorageEXT ( GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, - width, height ) ; - glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT , GL_STENCIL_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, stencil_rb ) ; - } - else - glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT , GL_STENCIL_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, stencil_rb ) ; -#else -fprintf(stderr,"@p\n" ) ; - glDisable ( GL_STENCIL_TEST ) ; - glStencilMask ( 0 ) ; -fprintf(stderr,"@q\n" ) ; - glFramebufferRenderbufferEXT ( GL_FRAMEBUFFER_EXT , GL_STENCIL_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, 0 ) ; -fprintf(stderr,"@r\n" ) ; -#endif - - // Check framebuffer completeness at the end of initialization. - - checkFrameBufferStatus () ; -fprintf(stderr,"@s\n" ) ; - restoreFrameBuffer () ; -fprintf(stderr,"@t\n" ) ; -} - - - -void FrameBufferObject::fetchTexture ( void *data ) -{ - glBindTexture ( GL_TEXTURE_2D, textureHandle ) ; - glGetTexImage ( GL_TEXTURE_2D, 0, /* MIP level...zero */ - format, /* External format */ - type, /* Data type */ - data /* Image data */ ) ; -} - - - -void FrameBufferObject::fetchTexture ( unsigned char *data ) -{ - if ( type != FBO_UNSIGNED_BYTE ) - { - fprintf ( stderr, "FBO: Data format mismatch!" ) ; - return ; - } - - fetchTexture ( (void *)data ) ; -} - - - -void FrameBufferObject::fetchTexture ( unsigned short *data ) -{ - if ( type != FBO_UNSIGNED_SHORT ) - { - fprintf ( stderr, "FBO: Data format mismatch!" ) ; - return ; - } - - fetchTexture ( (void *)data ) ; -} - - - -void FrameBufferObject::fetchTexture ( float *data ) -{ - if ( type != FBO_FLOAT ) - { - fprintf ( stderr, "FBO: Data format mismatch!" ) ; - return ; - } - - fetchTexture ( (void *)data ) ; -} - - - -void FrameBufferObject::fillTexture ( void *data ) -{ - glBindTexture( GL_TEXTURE_2D, textureHandle ) ; - glTexImage2D ( GL_TEXTURE_2D, 0, /* MIP level...zero */ - iformat, /* Internal format */ - width, height, /* Size */ - 0, /* Border...false */ - format, /* External format */ - type, /* Data type */ - data /* Image data */ ) ; -} - - - -void FrameBufferObject::fillTexture ( unsigned char *data ) -{ - if ( type != FBO_UNSIGNED_BYTE ) - { - fprintf ( stderr, "FBO: Data format mismatch!" ) ; - return ; - } - - fillTexture ( (void *)data ) ; -} - -void FrameBufferObject::fillTexture ( unsigned short *data ) -{ - if ( type != FBO_UNSIGNED_SHORT ) - { - fprintf ( stderr, "FBO: Data format mismatch!" ) ; - return ; - } - - fillTexture ( (void *)data ) ; -} - - -void FrameBufferObject::fillTexture ( float *data ) -{ - if ( type != FBO_FLOAT ) - { - fprintf ( stderr, "FBO: Data format mismatch!" ) ; - return ; - } - - fillTexture ( (void *)data ) ; -} - - -void FrameBufferObject::prepare ( bool clear ) -{ - makeDestination () ; - - glViewport ( 0, 0, width, height ) ; - - if ( clear ) glClear ( GL_COLOR_BUFFER_BIT ) ; - - glMatrixMode ( GL_PROJECTION ) ; - glLoadIdentity () ; - glOrtho ( -1, 1, -1, 1, -1, 1 ) ; - - glMatrixMode ( GL_MODELVIEW ) ; - glLoadIdentity () ; - - glDisable ( GL_DEPTH_TEST ) ; - glDisable ( GL_CULL_FACE ) ; - glDisable ( GL_BLEND ) ; -} - - -void FrameBufferObject::fill () -{ - float s_min = 0.5f / (float) width ; - float s_max = (((float) width) - 0.5f) / (float) width ; - float t_min = 0.5f / (float) height ; - float t_max = (((float) height) - 0.5f) / (float) height ; - - glBegin ( GL_QUADS ) ; - glTexCoord2f ( s_min, t_min ) ; glVertex2f ( -1, -1 ) ; - glTexCoord2f ( s_max, t_min ) ; glVertex2f ( 1, -1 ) ; - glTexCoord2f ( s_max, t_max ) ; glVertex2f ( 1, 1 ) ; - glTexCoord2f ( s_min, t_max ) ; glVertex2f ( -1, 1 ) ; - glEnd () ; -} - - diff --git a/Extras/obsolete/GPUphysics/fboSupport.h b/Extras/obsolete/GPUphysics/fboSupport.h deleted file mode 100644 index d044ca934..000000000 --- a/Extras/obsolete/GPUphysics/fboSupport.h +++ /dev/null @@ -1,101 +0,0 @@ - -GLuint makeTextureTarget ( GLuint textureHandle ) ; -void renderTo2DTexture ( GLuint fboHandle ) ; -void renderToFrameBuffer () ; - -// #define NEED_STENCIL_BUFFER 1 -// #define NEED_DEPTH_BUFFER 1 - - -enum fboDataType -{ -#ifndef GL_BYTE - FBO_BYTE = 0x1400, - FBO_UNSIGNED_BYTE = 0x1401, - FBO_SHORT = 0x1402, - FBO_UNSIGNED_SHORT = 0x1403, - FBO_INT = 0x1404, - FBO_UNSIGNED_INT = 0x1405, - FBO_FLOAT = 0x1406, - FBO_DOUBLE = 0x140A, -#else - FBO_BYTE = GL_BYTE, - FBO_UNSIGNED_BYTE = GL_UNSIGNED_BYTE, - FBO_SHORT = GL_SHORT, - FBO_UNSIGNED_SHORT = GL_UNSIGNED_SHORT, - FBO_INT = GL_INT, - FBO_UNSIGNED_INT = GL_UNSIGNED_INT, - FBO_FLOAT = GL_FLOAT, - FBO_DOUBLE = GL_DOUBLE, -#endif -#ifndef GL_HALF_FLOAT_NV - FBO_HALF = 0x140B -#else - FBO_HALF = GL_HALF_FLOAT_NV -#endif -} ; - -class FrameBufferObject -{ - int width ; - int height ; - int ncomps ; - fboDataType type ; - GLenum format ; - GLenum iformat ; - - GLuint textureHandle ; - GLuint fboHandle ; - - void fillTexture ( void *data ) ; - void fetchTexture ( void *data ) ; - -public: - FrameBufferObject ( int _width, /* Must be a power of two! */ - int _height, /* Must be a power of two! */ - int _numComponents, /* 1, 2, 3 or 4 only! */ - fboDataType _type ) ; - - void makeDestination () - { -#ifndef NEED_DEPTH_BUFFER - glDepthMask ( 0 ) ; -#endif -#ifndef NEED_STENCIL_BUFFER - glStencilMask ( 0 ) ; -#endif - glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT, fboHandle ) ; - } - - void use ( int texture_unit ) - { - glActiveTexture ( GL_TEXTURE0 + texture_unit ) ; - glBindTexture ( GL_TEXTURE_2D, textureHandle ) ; - } - - void prepare ( bool clear = false ) ; - void fill () ; - - void paint ( bool clear = false ) { prepare ( clear ) ; fill () ; } - - void fillTexture ( float *data ) ; - void fillTexture ( unsigned short *data ) ; - void fillTexture ( unsigned char *data ) ; - - void fetchTexture ( float *data ) ; - void fetchTexture ( unsigned short *data ) ; - void fetchTexture ( unsigned char *data ) ; -} ; - - -inline void restoreFrameBuffer () -{ - glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT, 0 ) ; -#ifndef NEED_DEPTH_BUFFER - glDepthMask ( 1 ) ; -#endif -#ifndef NEED_STENCIL_BUFFER - glStencilMask ( 1 ) ; -#endif -} - diff --git a/Extras/obsolete/GPUphysics/shaderSupport.cpp b/Extras/obsolete/GPUphysics/shaderSupport.cpp deleted file mode 100644 index 59edd0dba..000000000 --- a/Extras/obsolete/GPUphysics/shaderSupport.cpp +++ /dev/null @@ -1,430 +0,0 @@ -#include "GPU_physics.h" -#include "shaderSupport.h" -#include "fboSupport.h" - -#define DEFAULT_VERT_SHADER \ - "void main()" \ - "{" \ - " gl_TexCoord[0] = gl_MultiTexCoord0 ;" \ - " gl_TexCoord[1] = gl_MultiTexCoord1 ;" \ - " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex ;" \ - "}" - -class FrameBufferObject ; - - -class GLSL_Shader -{ - GLenum type ; - GLhandleARB handle ; - char *name ; - char *source ; - -public: - - GLSL_Shader () - { - type = (GLenum) 0 ; - handle = 0 ; - name = NULL ; - source = NULL ; - } - - ~GLSL_Shader () - { - delete [] name ; - delete [] source ; - } - - bool compileFile ( const char *fname , GLenum type ) ; - bool compileString ( const char *source, GLenum type, - const char *name ) ; - - GLenum getType () { return type ; } - GLhandleARB getHandle () { return handle ; } -} ; - - - -static char *readShaderText ( const char *fname ) -{ - - - - FILE *fd = fopen ( fname, "r" ) ; - if (!fd) - { - //some platforms might require different path, try two additional locations - char newname[256]; - sprintf(newname,"../../Extras/GPUphysics/%s",fname); - fd = fopen( newname ,"r"); - if (!fd) - { - sprintf(newname,"Extras/GPUphysics/%s",fname); - fd = fopen( newname,"r"); - } - } - - if (!fd) - { - printf("cannot open file %s\n",fname); - exit(1); - } - - int size = 0; - /* File operations denied? ok, just close and return failure */ - if (fseek(fd, 0, SEEK_END) || (size = ftell(fd)) == EOF || fseek(fd, 0, SEEK_SET)) - { - printf("Error: cannot get filesize from %s\n", fname); - exit (1); - } - - char *shader = new char [ size + 1 ] ; - - if ( fd == NULL ) - { - fprintf ( stderr, "Cannot read shader '%s'\n", fname ) ; - exit ( 1 ) ; - } - - int count = fread ( shader, 1, size, fd ) ; - - shader [ count ] = '\0' ; - - fclose ( fd ) ; - - return shader ; -} - - -/*****************************\ -* * -* Error handling stuff * -* * -\*****************************/ - - -static void showShaderInfo ( const char *which, - GLhandleARB handle, const char *name ) -{ - int len = 0 ; - - showGLerror ( "showShaderInfo_0" ) ; - glGetObjectParameterivARB ( handle, GL_OBJECT_INFO_LOG_LENGTH_ARB, (GLint*) &len ) ; - showGLerror ( "showShaderInfo_1" ) ; - - if ( len > 0 ) - { - int trueLen ; - char *s = new char [ len ] ; - - glGetInfoLogARB ( handle, len, (GLint*)&trueLen, s ) ; - - if ( trueLen > 0 && s [ 0 ] != '\0' ) - fprintf ( stderr, "%s:%s - \n%s\n", which, name, s ) ; - - delete [] s ; - } -} - - -/************************************\ -* * -* Single Shader Stuff * -* * -\************************************/ - - - -bool GLSL_Shader::compileFile ( const char *fname, GLenum _type ) -{ - return compileString ( readShaderText ( fname ), _type, fname ) ; -} - - -bool GLSL_Shader::compileString ( const char *_source, - GLenum _type, - const char *_name ) -{ - delete [] name ; - delete [] source ; - - type = _type ; - name = strdup ( _name ) ; - source = strdup ( _source ) ; - - GLint stat ; - - handle = glCreateShaderObjectARB ( type ) ; - - glShaderSourceARB ( handle, 1, (const GLcharARB **) & source, NULL); - glCompileShaderARB ( handle ) ; - glGetObjectParameterivARB ( handle, GL_OBJECT_COMPILE_STATUS_ARB, & stat ) ; - showShaderInfo ( "Compiling", handle, name ) ; - - if ( ! stat ) - { - fprintf ( stderr, "Failed to compile shader '%s'.\n", name ) ; - return false ; - } - - return true ; -} - - - -/************************************\ -* * -* Shader Pair Stuff * -* * -\************************************/ - - - -GLint GLSL_ShaderPair::getUniformLocation ( const char *uni_name ) -{ - assert ( success ) ; - - GLint loc = glGetUniformLocationARB ( handle, uni_name ) ; - - if ( loc == -1 ) - fprintf ( stderr, "No such uniform as '%s' or" - " '%s' is unused in shader pair '%s'.\n", uni_name, - uni_name, - name ) ; - else - showGLerror ( "GLSL_ShaderPair::getUniformLocation" ) ; - - return loc ; -} - - - -void GLSL_ShaderPair::showActiveUniforms ( FILE *fd ) -{ - GLint maxlen = 0 ; - GLint maxattrs = 0 ; - - if ( fd == NULL ) fd = stderr ; - - glGetObjectParameterivARB ( handle, - GL_OBJECT_ACTIVE_UNIFORMS_ARB, - &maxattrs ) ; - - if ( maxattrs == 0 ) - { - fprintf ( fd, "No Active Uniforms.\n" ) ; - return ; - } - - glGetObjectParameterivARB ( handle, - GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB, - &maxlen ) ; - - char *name = new char [ maxlen+1 ] ; - - fprintf ( fd, "Active Uniforms:\n" ) ; - - for ( int i = 0 ; i < maxattrs ; i++ ) - { - GLsizei len ; - GLint size ; - GLenum vartype ; - char *vartypename ; - GLint location ; - - glGetActiveUniformARB ( handle, i, - maxlen+1, &len, &size, &vartype, name ) ; - - location = glGetUniformLocationARB ( handle, name ) ; - - switch ( vartype ) - { - case GL_FLOAT : vartypename = "float " ; break ; - case GL_FLOAT_VEC2_ARB : vartypename = "vec2 " ; break ; - case GL_FLOAT_VEC3_ARB : vartypename = "vec3 " ; break ; - case GL_FLOAT_VEC4_ARB : vartypename = "vec4 " ; break ; - case GL_INT : vartypename = "int " ; break ; - case GL_INT_VEC2_ARB : vartypename = "intvec2 " ; break ; - case GL_INT_VEC3_ARB : vartypename = "intvec3 " ; break ; - case GL_INT_VEC4_ARB : vartypename = "intvec4 " ; break ; - case GL_BOOL : vartypename = "bool " ; break ; - case GL_BOOL_VEC2_ARB : vartypename = "boolvec2 " ; break ; - case GL_BOOL_VEC3_ARB : vartypename = "boolvec3 " ; break ; - case GL_BOOL_VEC4_ARB : vartypename = "boolvec4 " ; break ; - case GL_FLOAT_MAT2_ARB : vartypename = "mat2 " ; break ; - case GL_FLOAT_MAT3_ARB : vartypename = "mat3 " ; break ; - case GL_FLOAT_MAT4_ARB : vartypename = "mat4 " ; break ; - case GL_SAMPLER_1D_ARB : vartypename = "sampler1D" ; break ; - case GL_SAMPLER_2D_ARB : vartypename = "sampler2D" ; break ; - case GL_SAMPLER_3D_ARB : vartypename = "sampler3D" ; break ; - default : vartypename = "?????????" ; break ; - } - - if ( size == 1 ) - fprintf ( fd, "%2d) %s %s ; // @%d\n", i, - vartypename, name, location ) ; - else - fprintf ( fd, "%2d) %s %s [ %d ] ; // @%d\n", i, - vartypename, name, size, location ) ; - } - - fprintf ( fd, "\n" ) ; - delete name ; -} - - -void GLSL_ShaderPair::showActiveAttribs ( FILE *fd ) -{ - if ( fd == NULL ) fd = stderr ; - - GLint maxlen = 0 ; - GLint maxattrs = 0 ; - - glGetObjectParameterivARB ( handle, - GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, - &maxattrs ) ; - - if ( maxattrs == 0 ) - { - fprintf ( fd, "No Active Attributes.\n" ) ; - return ; - } - - glGetObjectParameterivARB ( handle, - GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB, - &maxlen ) ; - - char *name = new char [ maxlen+1 ] ; - - fprintf ( fd, "Active Attributes:\n" ) ; - - for ( int i = 0 ; i < maxattrs ; i++ ) - { - GLsizei len ; - GLint size ; - GLenum vartype ; - char *vartypename ; - GLint location ; - - glGetActiveAttribARB ( handle, i, maxlen+1, &len, &size, &vartype, name ) ; - - location = glGetAttribLocationARB ( handle, name ) ; - - switch ( vartype ) - { - case GL_FLOAT : vartypename = "float" ; break ; - case GL_FLOAT_VEC2_ARB : vartypename = "vec2 " ; break ; - case GL_FLOAT_VEC3_ARB : vartypename = "vec3 " ; break ; - case GL_FLOAT_VEC4_ARB : vartypename = "vec4 " ; break ; - case GL_FLOAT_MAT2_ARB : vartypename = "mat2 " ; break ; - case GL_FLOAT_MAT3_ARB : vartypename = "mat3 " ; break ; - case GL_FLOAT_MAT4_ARB : vartypename = "mat4 " ; break ; - default : vartypename = "???? " ; break ; - } - - if ( size == 1 ) - fprintf ( fd, "%2d) %s %s ; // @%d\n", i, - vartypename, name, location ) ; - else - fprintf ( fd, "%2d) %s %s [ %d ] ; // @%d\n", i, - vartypename, name, size, location ) ; - } - - fprintf ( fd, "\n" ) ; - delete name ; -} - - - -bool GLSL_ShaderPair::link () -{ - GLint stat ; - - handle = glCreateProgramObjectARB () ; - - glAttachObjectARB ( handle, vertShader -> getHandle () ) ; - glAttachObjectARB ( handle, fragShader -> getHandle () ) ; - glLinkProgramARB ( handle ) ; - glGetObjectParameterivARB ( handle, GL_OBJECT_LINK_STATUS_ARB, &stat ) ; - showShaderInfo ( "Linking", handle, name ) ; - glValidateProgramARB ( handle ) ; - showShaderInfo ( "Validate", handle, name ) ; - - if ( ! stat ) - { - fprintf ( stderr, "Failed to link shader.\n" ) ; - return false ; - } - - return true ; -} - - -GLSL_ShaderPair::GLSL_ShaderPair ( const char *_name, - const char *vertFname, - const char *fragFname ) -{ - name = strdup ( _name ) ; - handle = 0 ; - - vertShader = new GLSL_Shader () ; - fragShader = new GLSL_Shader () ; - - bool res1 = ( vertFname == NULL ) ? - vertShader -> compileString ( DEFAULT_VERT_SHADER, - GL_VERTEX_SHADER_ARB, - "Default Vertex Shader" ) : - vertShader -> compileFile ( vertFname, GL_VERTEX_SHADER_ARB ) ; - - bool res2 = fragShader -> compileFile ( fragFname, GL_FRAGMENT_SHADER_ARB ) ; - - success = ( res1 && res2 && link () ) ; -} - - -GLSL_ShaderPair::GLSL_ShaderPair ( const char *_name, - const char *vertSource, - const char *vertName, - const char *fragSource, - const char *fragName ) -{ - name = strdup ( _name ) ; - handle = 0 ; - - vertShader = new GLSL_Shader () ; - fragShader = new GLSL_Shader () ; - - bool res1 = ( vertSource == NULL ) ? - vertShader -> compileString ( DEFAULT_VERT_SHADER, - GL_VERTEX_SHADER_ARB, - "Default Vertex Shader" ) : - vertShader -> compileString ( vertSource, - GL_VERTEX_SHADER_ARB, - vertName ); - - bool res2 = fragShader -> compileString ( fragSource, - GL_FRAGMENT_SHADER_ARB, - fragName ); - - success = ( res1 && res2 && link () ) ; -} - - -GLSL_ShaderPair::~GLSL_ShaderPair () -{ - delete [] name ; - delete vertShader ; - delete fragShader ; -} - - -void GLSL_ShaderPair::applyTexture ( const char *uniformName, - FrameBufferObject *fbo, - int slot ) -{ - fbo -> use ( slot ) ; - glUniform1iARB ( getUniformLocation ( uniformName ), slot ) ; -} - - diff --git a/Extras/obsolete/GPUphysics/shaderSupport.h b/Extras/obsolete/GPUphysics/shaderSupport.h deleted file mode 100644 index af4000ea3..000000000 --- a/Extras/obsolete/GPUphysics/shaderSupport.h +++ /dev/null @@ -1,76 +0,0 @@ - -class GLSL_Shader ; -class FrameBufferObject ; - -class GLSL_ShaderPair -{ - GLSL_Shader *vertShader ; - GLSL_Shader *fragShader ; - GLhandleARB handle ; - char *name ; - bool success ; - - bool link () ; - -public: - - GLSL_ShaderPair ( const char *_name, - const char *vertFname, const char *fragFname ) ; - GLSL_ShaderPair ( const char *_name, - const char *vertSource, const char *vertName, - const char *fragSource, const char *fragName ) ; - - ~GLSL_ShaderPair () ; - - bool compiledOK () { return success ; } - - /* Debug functions */ - - void showActiveUniforms ( FILE *fd = NULL ) ; - void showActiveAttribs ( FILE *fd = NULL ) ; - - GLint getUniformLocation ( const char *varname ) ; - - void applyTexture ( const char *uniformName, - FrameBufferObject *fbo, - int slot ) ; - void setUniform1f ( const char *uniformName, float valueX ) - { - glUniform1fARB ( getUniformLocation ( uniformName ), valueX ) ; - } - - void setUniform2f ( const char *uniformName, float valueX, - float valueY ) - { - glUniform2fARB ( getUniformLocation ( uniformName ), valueX, valueY ) ; - } - - void setUniform3f ( const char *uniformName, float valueX, - float valueY, - float valueZ ) - { - glUniform3fARB ( getUniformLocation ( uniformName ), valueX, valueY, - valueZ ) ; - } - - void setUniform4f ( const char *uniformName, float valueX, - float valueY, - float valueZ, - float valueW ) - { - glUniform4fARB ( getUniformLocation ( uniformName ), valueX, valueY, - valueZ, valueW ) ; - } - - - /* To apply the shaders for rendering */ - - void use () - { - assert ( success ) ; - glUseProgramObjectARB ( handle ) ; - } - -} ; - - diff --git a/Extras/obsolete/SATConvexCollision/Geometry.cpp b/Extras/obsolete/SATConvexCollision/Geometry.cpp deleted file mode 100644 index 7a5c3fff4..000000000 --- a/Extras/obsolete/SATConvexCollision/Geometry.cpp +++ /dev/null @@ -1,229 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Geometry.cpp -// -// Copyright (c) 2006 Simon Hobbs -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - - -///for now this is windows only, Intel SSE SIMD intrinsics -#ifdef WIN32 -#if _MSC_VER >= 1310 - - -#include "Geometry.h" -#include "Maths.h" -#include - - -//////////////////////////////////////////////////////////////////////////////// -// Line - - - -//////////////////////////////////////////////////////////////////////////////// -// Ray - - -// returns false if the lines are parallel -// t1 and t2 are set to the times of the nearest points on each line -bool Intersect(const Line& la, const Line& lb, float& ta, float& tb) -{ - Vector3 ea = la.m_end - la.m_start; - Vector3 eb = lb.m_end - lb.m_start; - Vector3 u = la.m_start - lb.m_start; - - float a = Dot(ea, ea); - float b = Dot(ea, eb); - float c = Dot(eb, eb); - float d = Dot(ea, u); - float e = Dot(eb, u); - - float det = (a * c - b * b); - - if (Abs(det) < 0.001f) - return false; - - float invDet = RcpNr(det); - ta = (b * e - c * d) * invDet; - tb = (a * e - b * d) * invDet; - - return true; -} - -bool IntersectSegments(const Line& la, const Line& lb, float& ta, float& tb) -{ - Vector3 ea = la.m_end - la.m_start; - Vector3 eb = lb.m_end - lb.m_start; - Vector3 u = la.m_start - lb.m_start; - - float a = Dot(ea, ea); - float b = Dot(ea, eb); - float c = Dot(eb, eb); - float d = Dot(ea, u); - float e = Dot(eb, u); - - float det = (a * c - b * b); - - if (Abs(det) < 0.001f) - return false; - - float numa = (b * e - c * d); - float numb = (a * e - b * d); - - // clip a - float dena = det, denb = det; - if (numa < 0.0f) - { - numa = 0.0f; - numb = e; - denb = c; - } - else if (numa > det) - { - numa = det; - numb = e + b; - denb = c; - } - else - denb = det; - - // clip b - if (numb < 0.0f) - { - numb = 0.0f; - if (-d < 0.0f) - { - numa = 0.0f; - } - else if (-d > a) - { - numa = dena; - } - else - { - numa = -d; - dena = a; - } - } - else if (numb > denb) - { - numb = denb; - if ((-d + b) < 0.0f) - { - numa = 0.0f; - } - else if ((-d + b) > a) - { - numa = dena; - } - else - { - numa = -d + b; - dena = a; - } - } - - // compute the times - ta = numa / dena; - tb = numb / denb; - - return true; -} - -// returns intersection of 2 rays or nearest point to it -// t1 and t2 are set to the times of the nearest points on each ray (not clamped to ray though) -// asserts if rays are parallel -bool Intersect(const Ray& ra, const Ray& rb, float& ta, float& tb) -{ - Vector3 u = ra.m_start - rb.m_start; - - Scalar a = Dot(ra.m_dir, ra.m_dir); - Scalar b = Dot(ra.m_dir, rb.m_dir); - Scalar c = Dot(rb.m_dir, rb.m_dir); - Scalar d = Dot(ra.m_dir, u); - Scalar e = Dot(rb.m_dir, u); - - Scalar det = (a * c - b * b); - - if (Abs(det) < 0.001f) - return false; - - Scalar invDet = RcpNr(det); - ta = (b * e - c * d) * invDet; - tb = (a * e - b * d) * invDet; - - return true; -} - - -//////////////////////////////////////////////////////////////////////////////// -// Plane -bool Plane::IsFinite() const -{ - if (IsNan(GetX()) || IsNan(GetY()) || IsNan(GetZ()) || IsNan(GetW())) - return false; - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -// Bounds3 - axis aligned bounding box - -Bounds3::OriginTag Bounds3::Origin; -Bounds3::EmptyTag Bounds3::Empty; - -bool Bounds3::Intersect(const Ray& ray, float& tnear, float& tfar) const -{ - Vector3 rcpDir = RcpNr(ray.m_dir); - - Vector3 v1 = (m_min - ray.m_start) * rcpDir; - Vector3 v2 = (m_max - ray.m_start) * rcpDir; - - Vector3 vmin = Min(v1, v2); - Vector3 vmax = Max(v1, v2); - - Scalar snear = MaxComp(vmin); - - // handle ray being parallel to any axis - // (most rays don't need this) - if (IsNan(snear)) - { - int inside = (ray.m_start >= m_min) & (ray.m_start <= m_max); - - for (int i = 0; i < 3; i++) - { - if (IsNan(rcpDir.Get(i))) - { - if ((inside & (1 << i)) == 0) - return false; - vmin.Set(i, Scalar::Consts::MinValue); - vmax.Set(i, Scalar::Consts::MaxValue); - } - } - - snear = MaxComp(vmin); - } - - tnear = snear; - tfar = MinComp(vmax); - - if (tnear > tfar) - return false; - - if (tfar < 0.0f) - return false; - - return true; -} - - -//////////////////////////////////////////////////////////////////////////////// -// OrientedBounds3 - oriented bounding box - -#endif -#endif //WIN32 diff --git a/Extras/obsolete/SATConvexCollision/Geometry.h b/Extras/obsolete/SATConvexCollision/Geometry.h deleted file mode 100644 index dee61e2ed..000000000 --- a/Extras/obsolete/SATConvexCollision/Geometry.h +++ /dev/null @@ -1,195 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Geometry.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. - -#ifndef BULLET_MATH_GEOMETRY_H -#define BULLET_MATH_GEOMETRY_H - - -#ifdef WIN32 - -#include "Vector.h" -#include "Matrix.h" - -class Matrix44; -class Transform; - - -//////////////////////////////////////////////////////////////////////////////// -// Line -class Line -{ -public: - Point3 m_start; - Point3 m_end; - - Line(); - Line(const Point3& start, const Point3& end); - - // returns false if the lines are parallel - friend bool Intersect(const Line& la, const Line& lb, float& ta, float& tb); - friend bool IntersectSegments(const Line& la, const Line& lb, float& ta, float& tb); - - // get projection vector between a point and a line - // (i.e. if you add the vector to the point, then the new point will lie on the line) - friend Vector3 GetProjectionVector(const Line& ln, const Point3& pt); - - // get distance from point to line (and time along line) - friend float Distance(const Line& ln, const Point3& pt, float& t); -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Ray -class Ray -{ -public: - Point3 m_start; - Vector3 m_dir; - - Ray(); - Ray(const Point3& start, const Vector3& dir); - - explicit Ray(const Line& line); - - // returns false if the rays are parallel - friend bool Intersect(const Ray& ra, const Ray& rb, float& ta, float& tb); -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Plane -class Plane : public Vector4Base -{ -public: - // constructors - Plane(); - Plane(const Plane& p); - Plane(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w); - Plane(const Vector3& xyz, const Scalar& w); - Plane(const Point3& a, const Point3& b, const Point3& c); - Plane(const Vector3& normal, const Point3& pt); - - // construction to constant - Plane(const Maths::ZeroTag&); - Plane(const Maths::UnitXTag&); - Plane(const Maths::UnitYTag&); - Plane(const Maths::UnitZTag&); - Plane(const Maths::UnitNegXTag&); - Plane(const Maths::UnitNegYTag&); - Plane(const Maths::UnitNegZTag&); - - // explicit constructors - explicit Plane(const __m128 b); - explicit Plane(const Vector3& v); - explicit Plane(const Vector4& v); - explicit Plane(const float* p); - - // assignment - const Plane& operator=(const Plane& v); - const Plane& operator=(const Maths::ZeroTag&); - const Plane& operator=(const Maths::UnitXTag&); - const Plane& operator=(const Maths::UnitYTag&); - const Plane& operator=(const Maths::UnitZTag&); - const Plane& operator=(const Maths::UnitNegXTag&); - const Plane& operator=(const Maths::UnitNegYTag&); - const Plane& operator=(const Maths::UnitNegZTag&); - - // element access - const Vector3 GetNormal() const; - const Scalar getDistance() const; - - // transformations - friend const Plane operator-(const Plane& p); - friend const Plane operator*(const Plane& p, const Transform& m); - - // operations - friend const Scalar Dot(const Plane& p, const Point3& v); - friend const Scalar Dot(const Point3& v, const Plane& p); - - friend const Scalar Dot(const Plane& p, const Vector3& v); - friend const Scalar Dot(const Vector3& v, const Plane& p); - - friend const Scalar Dot(const Plane& p, const Vector4& v); - friend const Scalar Dot(const Vector4& v, const Plane& p); - - friend const Scalar Intersect(const Plane& p, const Ray& ray); - friend const Scalar Intersect(const Plane& p, const Line& line); - - // validation - bool IsFinite() const; -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Bounds3 - axis aligned bounding box -class Bounds3 -{ -public: - Point3 m_min, m_max; - - static const enum OriginTag { } Origin; - static const enum EmptyTag { } Empty; - - // constructors - Bounds3(); - Bounds3(const Bounds3& aabb); - Bounds3(const Point3& min, const Point3& max); - - // construction to constant - Bounds3(const OriginTag&); - Bounds3(const EmptyTag&); - - // explicit constructors - explicit Bounds3(const Point3& minMax); - - // assignment - const Bounds3& operator=(const Bounds3& aabb); - const Bounds3& operator=(const Point3& pt); - - const Bounds3& operator=(const OriginTag&); - const Bounds3& operator=(const EmptyTag&); - - // in place operations - void operator+=(const Point3& pt); - void operator+=(const Bounds3& aabb); - - // operations - friend Bounds3 operator+(const Bounds3& aabb, const Point3& pt); - friend Bounds3 operator+(const Point3& pt, const Bounds3& aabb); - friend Bounds3 operator+(const Bounds3& aabb, const Bounds3& aabb2); - - bool Contains(const Point3& pt) const; - bool Contains(const Bounds3& aabb) const; - bool Touches(const Bounds3& aabb) const; - - bool Intersect(const Ray& ray, float& tnear, float& tfar) const; - bool Intersect(const Line& line, float& tnear, float& tfar) const; - - Point3 GetCenter() const; - Vector3 GetExtent() const; - Vector3 GetSize() const; - - // validation - bool IsFinite() const; - bool HasVolume() const; -}; - - -#include "Geometry.inl" - -#endif //WIN32 -#endif //BULLET_MATH_GEOMETRY_H diff --git a/Extras/obsolete/SATConvexCollision/Geometry.inl b/Extras/obsolete/SATConvexCollision/Geometry.inl deleted file mode 100644 index 703a3c51e..000000000 --- a/Extras/obsolete/SATConvexCollision/Geometry.inl +++ /dev/null @@ -1,436 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Geometry.inl -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#pragma once - - -//////////////////////////////////////////////////////////////////////////////// -// Line - -inline Line::Line() -{ -} - -inline Line::Line(const Point3& start, const Point3& end) -{ - m_start = start; - m_end = end; -} - -inline Vector3 GetProjectionVector(const Line& ln, const Point3& pt) -{ - Vector3 d = Normalize(ln.m_end - ln.m_start); - Vector3 v = pt - ln.m_start; - Scalar s = Dot(v, d); - return -(v - d * s); -} - -//////////////////////////////////////////////////////////////////////////////// -// Ray - -inline Ray::Ray() -{ -} - -inline Ray::Ray(const Point3& start, const Vector3& dir) -{ - m_start = start; - m_dir = dir; -} - -inline Ray::Ray(const Line& line) -{ - m_start = line.m_start; - m_dir = Normalize(line.m_end - line.m_start); -} - - -//////////////////////////////////////////////////////////////////////////////// -// Plane - -inline Plane::Plane() -{ -} - -inline Plane::Plane(const Plane& p) -{ - base = p.base; -} - -inline Plane::Plane(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w) -{ - Set(x.base, y.base, z.base, w.base); -} - -inline Plane::Plane(const Vector3& xyz, const Scalar& w) -{ - Set(xyz.base, w.base); -} - -inline Plane::Plane(const Point3& a, const Point3& b, const Point3& c) -{ - Vector3 normal = Normalize(Cross(c - a, b - a)); - *this = Plane(normal, -Dot(normal, Vector3(a))); -} - -inline Plane::Plane(const Vector3& normal, const Point3& pt) -{ - *this = Plane(normal, -Dot(normal, Vector3(pt))); -} - -inline Plane::Plane(const Maths::ZeroTag&) -{ - base = _mm_setzero_ps(); -} - -inline Plane::Plane(const Maths::UnitXTag&) -{ - base = Vector4Base::Consts::k1000; -} - -inline Plane::Plane(const Maths::UnitYTag&) -{ - base = Vector4Base::Consts::k0100; -} - -inline Plane::Plane(const Maths::UnitZTag&) -{ - base = Vector4Base::Consts::k0010; -} - -inline Plane::Plane(const Maths::UnitNegXTag&) -{ - base = Vector4Base::Consts::kNeg1000; -} - -inline Plane::Plane(const Maths::UnitNegYTag&) -{ - base = Vector4Base::Consts::kNeg0100; -} - -inline Plane::Plane(const Maths::UnitNegZTag&) -{ - base = Vector4Base::Consts::kNeg0010; -} - -inline Plane::Plane(const __m128 b) -{ - base = b; -} - -inline Plane::Plane(const Vector3& v) -{ - base = v.base; -} - -inline Plane::Plane(const Vector4& v) -{ - base = v.base; -} - -inline Plane::Plane(const float* p) -{ - base = _mm_load_ps(p); -} - -inline const Plane& Plane::operator=(const Plane& v) -{ - base = v.base; - return *this; -} - -inline const Plane& Plane::operator=(const Maths::ZeroTag&) -{ - base = _mm_setzero_ps(); - return *this; -} - -inline const Plane& Plane::operator=(const Maths::UnitXTag&) -{ - base = Vector4Base::Consts::k1000; - return *this; -} - -inline const Plane& Plane::operator=(const Maths::UnitYTag&) -{ - base = Vector4Base::Consts::k0100; - return *this; -} - -inline const Plane& Plane::operator=(const Maths::UnitZTag&) -{ - base = Vector4Base::Consts::k0010; - return *this; -} - -inline const Plane& Plane::operator=(const Maths::UnitNegXTag&) -{ - base = Vector4Base::Consts::kNeg1000; - return *this; -} - -inline const Plane& Plane::operator=(const Maths::UnitNegYTag&) -{ - base = Vector4Base::Consts::kNeg0100; - return *this; -} - -inline const Plane& Plane::operator=(const Maths::UnitNegZTag&) -{ - base = Vector4Base::Consts::kNeg0010; - return *this; -} - -inline const Vector3 Plane::GetNormal() const -{ - return Vector3(base); -} - -inline const Scalar Plane::getDistance() const -{ - return GetW(); -} - -inline const Plane operator-(const Plane& p) -{ - return Plane(_mm_sub_ps(_mm_setzero_ps(), p.base)); -} - -inline const Plane operator*(const Plane& p, const Transform& m) -{ - Vector3 np = Vector3(p) * m; - return Plane(np, p.GetW() - Dot(Vector3(np), Vector3(m.GetTranslation()))); -} - -inline const Scalar Dot(const Plane& p, const Point3& v) -{ - return Scalar(Vector4Base::Dot3(p.base, v.base)) + p.GetW(); -} - -inline const Scalar Dot(const Point3& v, const Plane& p) -{ - return Scalar(Vector4Base::Dot3(p.base, v.base)) + p.GetW(); -} - -inline const Scalar Dot(const Plane& p, const Vector3& v) -{ - return Scalar(Vector4Base::Dot3(p.base, v.base)); -} - -inline const Scalar Dot(const Vector3& v, const Plane& p) -{ - return Scalar(Vector4Base::Dot3(p.base, v.base)); -} - -inline const Scalar Dot(const Plane& p, const Vector4& v) -{ - return Scalar(Vector4Base::Dot4(p.base, v.base)); -} - -inline const Scalar Dot(const Vector4& v, const Plane& p) -{ - return Scalar(Vector4Base::Dot4(p.base, v.base)); -} - -// returns NaN if ray is perpendicular to ray -inline const Scalar Intersect(const Plane& p, const Ray& ray) -{ - Scalar ds = Dot(p, ray.m_start); - Scalar dd = Dot(p, ray.m_dir); - return -ds * RcpNr(dd); -} - -// returns NaN if line is perpendicular to ray -inline const Scalar Intersect(const Plane& p, const Line& line) -{ - Scalar ds = Dot(p, line.m_start); - Scalar de = Dot(p, line.m_end); - return ds * RcpNr(ds - de); -} - - -//////////////////////////////////////////////////////////////////////////////// -// Bounds3 - axis aligned bounding box - -inline Bounds3::Bounds3() -{ -} - -inline Bounds3::Bounds3(const Bounds3& aabb) -{ - *this = aabb; -} - -inline Bounds3::Bounds3(const Point3& min, const Point3& max) -{ - m_min = min; - m_max = max; -} - -inline Bounds3::Bounds3(const OriginTag&) -{ - m_min = m_max = Maths::Zero; -} - -inline Bounds3::Bounds3(const EmptyTag&) -{ - // max maximal inverted aabb - ready to have points accumulated into it - m_min = Point3(Scalar::Consts::MaxValue); - m_max = Point3(Scalar::Consts::MinValue); -} - -inline Bounds3::Bounds3(const Point3& minMax) -{ - m_min = m_max = minMax; -} - -inline const Bounds3& Bounds3::operator=(const Bounds3& aabb) -{ - m_min = aabb.m_min; - m_max = aabb.m_max; - return *this; -} - -inline const Bounds3& Bounds3::operator=(const Point3& pt) -{ - m_min = m_max = pt; - return *this; -} - -inline const Bounds3& Bounds3::operator=(const OriginTag&) -{ - m_min = m_max = Maths::Zero; -} - -inline const Bounds3& Bounds3::operator=(const EmptyTag&) -{ - // max maximal inverted aabb - ready to have points accumulated into it - m_min = Point3(Scalar::Consts::MaxValue); - m_max = Point3(Scalar::Consts::MinValue); - return *this; -} - -inline void Bounds3::operator+=(const Point3& pt) -{ - m_min = Min(m_min, pt); - m_max = Max(m_max, pt); -} - -inline void Bounds3::operator+=(const Bounds3& aabb) -{ - m_min = Min(m_min, aabb.m_min); - m_max = Max(m_max, aabb.m_max); -} - -inline Bounds3 operator+(const Bounds3& aabb, const Point3& pt) -{ - return Bounds3(Min(aabb.m_min, pt), Max(aabb.m_max, pt)); -} - -inline Bounds3 operator+(const Point3& pt, const Bounds3& aabb) -{ - return Bounds3(Min(aabb.m_min, pt), Max(aabb.m_max, pt)); -} - -inline Bounds3 operator+(const Bounds3& aabb, const Bounds3& aabb2) -{ - return Bounds3(Min(aabb.m_min, aabb2.m_min), Max(aabb.m_max, aabb2.m_max)); -} - -inline bool Bounds3::Contains(const Point3& pt) const -{ - return ((pt >= m_min) & (pt <= m_max)) == 7; -} - -inline bool Bounds3::Contains(const Bounds3& aabb) const -{ - return ((aabb.m_min >= m_min) & (aabb.m_max <= m_max)) == 7; -} - -inline bool Bounds3::Touches(const Bounds3& aabb) const -{ - return ((aabb.m_max >= m_min) & (aabb.m_min <= m_max)) == 7; -} - -// returns intersection of 2 lines or nearest point to it -// t1 and t2 are set to the times of the nearest points on each line -// asserts if rays are parallel -inline const Point3 IntersectPrev(const Line& la, const Line& lb, float& ta, float& tb) -{ - Vector3 ea = la.m_end - la.m_start; - Vector3 eb = lb.m_end - lb.m_start; - Vector3 u = la.m_start - lb.m_start; - - Scalar a = Dot(ea, ea); - Scalar b = Dot(ea, eb); - Scalar c = Dot(eb, eb); - Scalar d = Dot(ea, u); - Scalar e = Dot(eb, u); - - Scalar det = (a * c - b * b); - - // assert if rays are parallel - assert(Abs(det) > Scalar(0.0001f)); - - Scalar invDet = RcpNr(det); - ta = (b * e - c * d) * invDet; - tb = (a * e - b * d) * invDet; - - return la.m_start + ea * ta; -} - -inline const Point3 IntersectPrev(const Line& a, const Line& b) -{ - float ta, tb; - return IntersectPrev(a, b, ta, tb); -} - -inline bool Bounds3::Intersect(const Line& line, float& tnear, float& tfar) const -{ - return Intersect(Ray(line), tnear, tfar); -} - -inline Point3 Bounds3::GetCenter() const -{ - return Lerp(m_min, m_max, Scalar::Consts::Half); -} - -inline Vector3 Bounds3::GetExtent() const -{ - return (m_max - m_min) * Scalar::Consts::Half; -} - -inline Vector3 Bounds3::GetSize() const -{ - return m_max - m_min; -} - -inline bool Bounds3::IsFinite() const -{ - return m_min.IsFinite() && m_max.IsFinite(); -} - -inline bool Bounds3::HasVolume() const -{ - return (((m_min <= m_max) & 7) == 7); -} - - - -//////////////////////////////////////////////////////////////////////////////// -// OrientedBounds3 - oriented bounding box - - diff --git a/Extras/obsolete/SATConvexCollision/Hull.cpp b/Extras/obsolete/SATConvexCollision/Hull.cpp deleted file mode 100644 index 68fbd8eff..000000000 --- a/Extras/obsolete/SATConvexCollision/Hull.cpp +++ /dev/null @@ -1,1080 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// Hull.cpp -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifdef WIN32 -#if _MSC_VER >= 1310 - -#include "hull.h" -#include "Geometry.h" -#include - -#include "HullContactCollector.h" - -Hull::Hull() -{ - m_numVerts = 0; - m_numFaces = 0; - m_numEdges = 0; - - m_pVerts = 0; - m_pFaces = 0; - m_pEdges = 0; - m_pPlanes = 0; -} - -Hull::~Hull() -{ - delete[] m_pVerts; - delete[] m_pFaces; - delete[] m_pEdges; - delete[] m_pPlanes; -} - -Point3 Hull::GetFaceCentroid(short face) const -{ - short edge; - - edge = GetFaceFirstEdge(face); - Vector3 c = Vector3(getVertex(GetEdgeVertex0(face, edge))); - - for (edge = GetFaceNextEdge(face, edge); edge >= 0; edge = GetFaceNextEdge(face, edge)) - c += Vector3(getVertex(GetEdgeVertex0(face, edge))); - - c /= Scalar(GetFace(face).m_numEdges); - - return Point3(c); -} - - -// helper stuff for MakeHull -short Hull::s_firstFreeTmpFace = 0; -short Hull::s_firstUsedTmpFace = 0; -Hull::TmpFace* Hull::s_pTmpFaces = 0; - -short Hull::s_firstFreeTmpEdge = 0; -short Hull::s_firstUsedTmpEdge = 0; -Hull::TmpEdge* Hull::s_pTmpEdges = 0; - -const Point3* Hull::s_pPoints = 0; - - -short Hull::AllocTmpFace() -{ - short face = s_firstFreeTmpFace; - assert(face != -1); - - TmpFace* pFace = GetTmpFace(face); - s_firstFreeTmpFace = pFace->m_next; - - pFace->m_next = s_firstUsedTmpFace; - s_firstUsedTmpFace = face; - - for (int i = 0; i < kTmpFaceMaxVerts; i++) - pFace->m_verts[i] = pFace->m_edges[i] = -1; - - pFace->m_plane = Maths::Zero; - - return face; -} - -void Hull::FreeTmpFace(short face) -{ - assert(face >= 0); - - TmpFace* pFace = GetTmpFace(face); - - if (face == s_firstUsedTmpFace) - s_firstUsedTmpFace = pFace->m_next; - else - { - TmpFace* pPrev; - for (pPrev = GetTmpFace(s_firstUsedTmpFace); pPrev->m_next != face; pPrev = GetTmpFace(pPrev->m_next)) - { - } - pPrev->m_next = pFace->m_next; - } - - pFace->m_next = s_firstFreeTmpFace; - s_firstFreeTmpFace = face; -} - -short Hull::AllocTmpEdge() -{ - short edge = s_firstFreeTmpEdge; - assert(edge != -1); - - TmpEdge* pEdge = GetTmpEdge(edge); - s_firstFreeTmpEdge = pEdge->m_next; - - pEdge->m_next = s_firstUsedTmpEdge; - s_firstUsedTmpEdge = edge; - - pEdge->m_verts[0] = pEdge->m_verts[1] = -1; - pEdge->m_faces[0] = pEdge->m_faces[1] = -1; - - return edge; -} - -void Hull::FreeTmpEdge(short edge) -{ - assert(edge >= 0); - - TmpEdge* pEdge = GetTmpEdge(edge); - - if (edge == s_firstUsedTmpEdge) - s_firstUsedTmpEdge = pEdge->m_next; - else - { - TmpEdge* pPrev; - for ( pPrev= GetTmpEdge(s_firstUsedTmpEdge); pPrev->m_next != edge; pPrev = GetTmpEdge(pPrev->m_next)) - { - } - pPrev->m_next = pEdge->m_next; - } - - pEdge->m_next = s_firstFreeTmpEdge; - s_firstFreeTmpEdge = edge; -} - -short Hull::MatchOrAddEdge(short vert0, short vert1, short face) -{ - assert(vert0 >= 0); - assert(vert1 >= 0); - assert(vert0 != vert1); - - TmpEdge* pEdge; - - // see if edge already exists - for (pEdge = GetTmpEdge(s_firstUsedTmpEdge); pEdge; pEdge = GetTmpEdge(pEdge->m_next)) - { - if (pEdge->m_verts[0] == vert0 && pEdge->m_verts[1] == vert1) - { - assert(pEdge->m_faces[0] == -1); - pEdge->m_faces[0] = face; - return pEdge->m_index; - } - - else if (pEdge->m_verts[0] == vert1 && pEdge->m_verts[1] == vert0) - { - assert(pEdge->m_faces[1] == -1); - pEdge->m_faces[1] = face; - return pEdge->m_index; - } - } - - // doesn't exist so add new face - short edge = AllocTmpEdge(); - assert(edge >= 0); - - pEdge = GetTmpEdge(edge); - - pEdge->m_verts[0] = vert0; - pEdge->m_verts[1] = vert1; - pEdge->m_faces[0] = face; - - return edge; -} - -void Hull::UnmatchOrRemoveEdge(short edge, short face) -{ - assert(edge >= 0); - TmpEdge* pEdge = GetTmpEdge(edge); - - if (pEdge->m_faces[0] == face) - { - pEdge->m_faces[0] = -1; - } - else - { - assert(pEdge->m_faces[1] == face); - pEdge->m_faces[1] = -1; - } - - // if edge is now redundant then free it - if (pEdge->m_faces[0] == -1 && pEdge->m_faces[1] == -1) - FreeTmpEdge(edge); -} - -short Hull::AddTmpFace(short vert0, short vert1, short vert2) -{ - short verts[3] = {vert0, vert1, vert2}; - return AddTmpFace(3, verts); -} - -short Hull::AddTmpFace(short vert0, short numOtherVerts, short* pVerts) -{ - short verts[256]; - verts[0] = vert0; - for (short i = 0; i < numOtherVerts; i++) - verts[i + 1] = pVerts[i]; - return AddTmpFace(numOtherVerts + 1, verts); -} - -short Hull::AddTmpFace(short numVerts, short* pVerts) -{ - assert(numVerts >= 3); - assert(numVerts <= kTmpFaceMaxVerts); - assert(pVerts); - - short face = AllocTmpFace(); - assert(face >= 0); - - TmpFace* pFace = GetTmpFace(face); - - pFace->m_numVerts = numVerts; - - for (short i = 0; i < numVerts; i++) - { - pFace->m_verts[i] = pVerts[i]; - pFace->m_edges[i] = MatchOrAddEdge(pVerts[i], pVerts[(i + 1) % numVerts], face); - } - - pFace->m_plane = Plane(s_pPoints[pVerts[0]], s_pPoints[pVerts[1]], s_pPoints[pVerts[2]]); - - return face; -} - -void Hull::RemoveTmpFace(short face) -{ - assert(face >= 0); - - TmpFace* pFace = GetTmpFace(face); - - for (short i = 0; i < pFace->m_numVerts; i++) - UnmatchOrRemoveEdge(pFace->m_edges[i], face); - - FreeTmpFace(face); -} - -bool Hull::TmpFaceAddPoint(short point, short face) -{ - assert(face >= 0); - - TmpFace* pFace = GetTmpFace(face); - - // vertex limit reached? - if (pFace->m_numVerts == kTmpFaceMaxVerts) - return false; - - // in same plane? - if (Abs(Dot(pFace->m_plane, s_pPoints[point])) > 0.001f) - return false; - - // remove last edge - UnmatchOrRemoveEdge(pFace->m_edges[pFace->m_numVerts - 1], face); - - // add 2 new edges - MatchOrAddEdge(pFace->m_verts[pFace->m_numVerts - 1], point, face); - MatchOrAddEdge(point, pFace->m_verts[0], face); - - // add new vertex - pFace->m_verts[pFace->m_numVerts++] = point; - - return true; -} - -// The resulting hull will not contain interior points -// Note that this is a cheap and cheerful implementation that can only handle -// reasonably small point sets. However, except for the final hull it doesn't do any dynamic -// memory allocation - all the work happens on the stack. -Hull* Hull::MakeHull(int numPoints, const Point3* pPoints) -{ - assert(numPoints >= 4); - assert(pPoints); - - // check first 4 points are disjoint - // TODO: make it search points so it can cope better with this - assert(Length(pPoints[1] - pPoints[0]) > 0.01f); - assert(Length(pPoints[2] - pPoints[0]) > 0.01f); - assert(Length(pPoints[3] - pPoints[0]) > 0.01f); - assert(Length(pPoints[2] - pPoints[1]) > 0.01f); - assert(Length(pPoints[3] - pPoints[1]) > 0.01f); - assert(Length(pPoints[3] - pPoints[2]) > 0.01f); - - s_pPoints = pPoints; - - // put all temp faces on a free list - TmpFace tmpFaces[kMaxFaces]; - - s_firstFreeTmpFace = 0; - s_firstUsedTmpFace = -1; - s_pTmpFaces = tmpFaces; - - for (short i = 0; i < kMaxEdges; i++) - { - tmpFaces[i].m_index = i; - tmpFaces[i].m_next = i + 1; - } - tmpFaces[kMaxFaces - 1].m_next = -1; - - // put all temp edges on a free list - TmpEdge tmpEdges[kMaxEdges]; - - s_firstFreeTmpEdge = 0; - s_firstUsedTmpEdge = -1; - s_pTmpEdges = tmpEdges; - - for (short i = 0; i < kMaxEdges; i++) - { - tmpEdges[i].m_index = i; - tmpEdges[i].m_next = i + 1; - } - tmpEdges[kMaxEdges - 1].m_next = -1; - - // make initial tetrahedron - Plane plane = Plane(pPoints[0], pPoints[1], pPoints[2]); - - Scalar dot = Dot(plane, pPoints[3]); - assert(Abs(dot) > 0.01f); // first 4 points are co-planar - - if (IsNegative(dot)) - { - AddTmpFace(0, 1, 2); - AddTmpFace(1, 0, 3); - AddTmpFace(0, 2, 3); - AddTmpFace(2, 1, 3); - } - else - { - AddTmpFace(2, 1, (short)0); - AddTmpFace(1, 2, 3); - AddTmpFace(2, 0, 3); - AddTmpFace(0, 1, 3); - } - - // merge all remaining points - for (int i = 4; i < numPoints; i++) - if (RemoveVisibleFaces(pPoints[i]) > 0) - FillHole(i); - - return MakeHullFromTemp(); -} - -int Hull::RemoveVisibleFaces(const Point3& point) -{ - // test point for containment in current hull - int numRemoved = 0; - TmpFace* pNextFace; - for (TmpFace* pFace = GetTmpFace(s_firstUsedTmpFace); pFace; pFace = pNextFace) - { - pNextFace = GetTmpFace(pFace->m_next); - - if (Dot(pFace->m_plane, point) > -0.001f) - { - RemoveTmpFace(pFace->m_index); - numRemoved++; - } - } - - return numRemoved; -} - -void Hull::FillHole(short newVertex) -{ - // gather unmatched edges (they form the silhouette of the hole) - short edgeVert0[kMaxEdges]; - short edgeVert1[kMaxEdges]; - int numEdges = 0; - - for (TmpEdge* pEdge = GetTmpEdge(s_firstUsedTmpEdge); pEdge; pEdge = GetTmpEdge(pEdge->m_next)) - { - if (pEdge->m_faces[0] == -1) - { - assert(numEdges < kMaxEdges); - edgeVert0[numEdges] = pEdge->m_verts[0]; - edgeVert1[numEdges] = pEdge->m_verts[1]; - numEdges++; - } - else if (pEdge->m_faces[1] == -1) - { - assert(numEdges < kMaxEdges); - edgeVert0[numEdges] = pEdge->m_verts[1]; - edgeVert1[numEdges] = pEdge->m_verts[0]; - numEdges++; - } - } - - // extract vertex winding by sorting edges - short verts[kMaxEdges + 1]; // +1 for repeat of first vertex - - verts[0] = edgeVert0[0]; - verts[1] = edgeVert1[0]; - short numVerts = 2; - - while (numVerts < (numEdges + 1)) - { - for (int i = 0; i < numEdges; i++) - { - // if leading vertex of edge matches our last vertex - if (edgeVert0[i] == verts[numVerts - 1]) - { - // then add trailing vertex of edge to our vertex list - verts[numVerts++] = edgeVert1[i]; - } - } - } - - // fill the hole - int i = 1; - while (i < numVerts) - { - // make plane for first 3 vertices - Plane plane = Plane(s_pPoints[newVertex], s_pPoints[verts[i - 1]], s_pPoints[verts[i]]); - - // any subequent vertices that lie in the same plane are also added - int numFaceVerts = 2; - for (int j = i + 1; j < numVerts; j++) - { - if (Abs(Dot(plane, s_pPoints[verts[j]])) > 0.001f) - break; - numFaceVerts++; - } - - // add the polygon - AddTmpFace(newVertex, numFaceVerts, verts + i - 1); - - // skip to next - i += numFaceVerts - 1; - } -} - -// make hull from temporary working structures -Hull* Hull::MakeHullFromTemp() -{ - Hull* pHull = new Hull(); - - // count and index faces - short index = 0; - - for (TmpFace* pFace = GetTmpFace(s_firstUsedTmpFace); pFace; pFace = GetTmpFace(pFace->m_next)) - { - pFace->m_index = index++; - pHull->m_numFaces++; - } - - // count and index edges, also count and index used vertices - short vertIndexes[kMaxVerts]; - for (int i = 0; i < kMaxVerts; i++) - vertIndexes[i] = -1; - - index = 0; - for (TmpEdge* pEdge = GetTmpEdge(s_firstUsedTmpEdge); pEdge; pEdge = GetTmpEdge(pEdge->m_next)) - { - pEdge->m_index = index++; - pHull->m_numEdges++; - - if (vertIndexes[pEdge->m_verts[0]] == -1) - vertIndexes[pEdge->m_verts[0]] = pHull->m_numVerts++; - if (vertIndexes[pEdge->m_verts[1]] == -1) - vertIndexes[pEdge->m_verts[1]] = pHull->m_numVerts++; - } - - // allocate hull arrays - pHull->m_pVerts = new Point3[pHull->m_numVerts]; - pHull->m_pEdges = new Hull::Edge[pHull->m_numEdges]; - pHull->m_pFaces = new Hull::Face[pHull->m_numFaces]; - pHull->m_pPlanes = new Plane[pHull->m_numFaces]; - - // fill in hull arrays - // verts: - for (int i = 0; i < kMaxVerts; i++) - if (vertIndexes[i] != -1) - pHull->m_pVerts[vertIndexes[i]] = s_pPoints[i]; - - // edges: - index = 0; - for (TmpEdge* pEdge = GetTmpEdge(s_firstUsedTmpEdge); pEdge; pEdge = GetTmpEdge(pEdge->m_next)) - { - pHull->m_pEdges[index].m_faces[0] = GetTmpFace(pEdge->m_faces[0])->m_index; - pHull->m_pEdges[index].m_faces[1] = GetTmpFace(pEdge->m_faces[1])->m_index; - pHull->m_pEdges[index].m_verts[0] = vertIndexes[pEdge->m_verts[0]]; - pHull->m_pEdges[index].m_verts[1] = vertIndexes[pEdge->m_verts[1]]; - - index++; - } - - // faces: - index = 0; - for (TmpFace* pFace = GetTmpFace(s_firstUsedTmpFace); pFace; pFace = GetTmpFace(pFace->m_next)) - { - // set edge count - pHull->m_pFaces[index].m_numEdges = pFace->m_numVerts; - - // make linked list of face edges - short prevEdge = GetTmpEdge(pFace->m_edges[0])->m_index; - pHull->m_pFaces[index].m_firstEdge = prevEdge; - - for (int i = 1; i < pFace->m_numVerts; i++) - { - Edge& e = pHull->m_pEdges[prevEdge]; - prevEdge = GetTmpEdge(pFace->m_edges[i])->m_index; - e.m_nextEdge[pFace->m_index == e.m_faces[1]] = prevEdge; - } - - Edge& e = pHull->m_pEdges[prevEdge]; - e.m_nextEdge[pFace->m_index == e.m_faces[1]] = -1; - - // set plane - pHull->m_pPlanes[index] = pFace->m_plane; - - index++; - } - - - return pHull; -} - - - -void Hull::ProcessHullHull(btSeparation& sep,const Hull& shapeA,const Hull& shapeB,const Transform& trA,const Transform& trB,HullContactCollector* collector) -{ - Point3 vertsA[Hull::kMaxVerts]; - Point3 vertsB[Hull::kMaxVerts]; - -// const Hull& shapeA((const Hull&)*sep.m_pBodyA->GetShape()); -// const Hull& shapeB((const Hull&)*sep.m_pBodyB->GetShape()); - -// Transform trA(sep.m_pBodyA->GetTransform()); -// Transform trB(sep.m_pBodyB->GetTransform()); - - // transform verts of A to world space - Point3* pVertsA = vertsA; - for (short v = 0; v < shapeA.m_numVerts; v++) - pVertsA[v] = shapeA.m_pVerts[v] * trA; - - // transform verts of B to world space - Point3* pVertsB = vertsB; - for (short v = 0; v < shapeB.m_numVerts; v++) - pVertsB[v] = shapeB.m_pVerts[v] * trB; - -#ifdef SHAPE_COLLIDER_USE_CACHING - // update cached pair - if (sep.m_separator != btSeparation::kFeatureNone) - { - // re-use the separation - if (UpdateSeparationHullHull(sep, pVertsA, pVertsB, trA, trB) == true) - return; - - // also re-use penetration if only slight - if (sep.m_dist > -0.02f) - { - // except if no contacts were generated, in which case we continue through to full test - if (AddContactsHullHull(sep, pVertsA, pVertsB, trA, trB,shapeA,shapeB) > 0) - return; - } - } -#endif - - if (GetSeparationHullHull(sep, pVertsA, pVertsB, trA, trB,shapeA,shapeB) == false) - { - AddContactsHullHull(sep, pVertsA, pVertsB, trA, trB,shapeA,shapeB,collector); - } -} - - -void Hull::ComputeInertia(const Transform& transform, Point3& centerOfMass, Matrix33& inertia, float totalMass) const -{ - assert(totalMass > 0.0f); - - // order: 1, x, y, z, x^2, y^2, z^2, xy, yz, zx - float integral[10] = {0,0,0,0,0,0,0,0,0,0}; - - // for each triangle - for (short face = 0; face < m_numFaces; face++) - { - short edge = GetFaceFirstEdge(face); - Point3 v0 = m_pVerts[ GetEdgeVertex0(face, edge) ] * transform; - - edge = GetFaceNextEdge(face, edge); - Point3 v1 = m_pVerts[ GetEdgeVertex0(face, edge) ] * transform; - - for (edge = GetFaceNextEdge(face, edge); edge != -1; edge = GetFaceNextEdge(face, edge)) - { - Point3 v2 = m_pVerts[ GetEdgeVertex0(face, edge) ] * transform; - - // get cross product of triangle edges - Vector3 d = Cross(v2 - v0, v1 - v0); - - // compute integral terms - Vector3 w0 = Vector3(v0); - Vector3 w1 = Vector3(v1); - Vector3 w2 = Vector3(v2); - - Vector3 temp0 = w0 + w1; - Vector3 f1 = temp0 + w2; - Vector3 temp1 = w0 * w0; - Vector3 temp2 = temp1 + w1 * temp0; - Vector3 f2 = temp2 + w2 * f1; - Vector3 f3 = w0 * temp1 + w1 * temp2 + w2 * f2; - Vector3 g0 = f2 + w0 * (f1 + w0); - Vector3 g1 = f2 + w1 * (f1 + w1); - Vector3 g2 = f2 + w2 * (f1 + w2); - - // update integrals - integral[0] += d[0] * f1[0]; - integral[1] += d[0] * f2[0]; - integral[2] += d[1] * f2[1]; - integral[3] += d[2] * f2[2]; - integral[4] += d[0] * f3[0]; - integral[5] += d[1] * f3[1]; - integral[6] += d[2] * f3[2]; - integral[7] += d[0] * (v0[1] * g0[0] + v1[1] * g1[0] + v2[1] * g2[0]); - integral[8] += d[1] * (v0[2] * g0[1] + v1[2] * g1[1] + v2[2] * g2[1]); - integral[9] += d[2] * (v0[0] * g0[2] + v1[0] * g1[2] + v2[0] * g2[2]); - - // next edge - v1 = v2; - } - } - - integral[0] *= 1.0f / 6.0f; - integral[1] *= 1.0f / 24.0f; - integral[2] *= 1.0f / 24.0f; - integral[3] *= 1.0f / 24.0f; - integral[4] *= 1.0f / 60.0f; - integral[5] *= 1.0f / 60.0f; - integral[6] *= 1.0f / 60.0f; - integral[7] *= 1.0f / 120.0f; - integral[8] *= 1.0f / 120.0f; - integral[9] *= 1.0f / 120.0f; - - // scale all integrals to get desired total mass - assert(integral[0] > 0.0f); - - float invMassRatio = totalMass / integral[0]; - for (int i = 0; i < 10; i++) - integral[i] *= invMassRatio; - - // center of mass - centerOfMass = Point3(integral[1] / totalMass, integral[2] / totalMass, integral[3] / totalMass); - - // inertia relative to world - inertia[0][0] = integral[5] + integral[6]; - inertia[0][1] = -integral[7]; - inertia[0][2] = -integral[9]; - - inertia[1][0] = -integral[7]; - inertia[1][1] = integral[4] + integral[6]; - inertia[1][2] = -integral[8]; - - inertia[2][0] = -integral[9]; - inertia[2][1] = -integral[8]; - inertia[2][2] = integral[5] + integral[5]; - - // inertia relative to center of mass - inertia[0][0] -= totalMass * (centerOfMass[1] * centerOfMass[1] + centerOfMass[2] * centerOfMass[2]); - inertia[0][1] += totalMass * centerOfMass[0] * centerOfMass[1]; - inertia[0][2] += totalMass * centerOfMass[2] * centerOfMass[0]; - - inertia[1][0] += totalMass * centerOfMass[0] * centerOfMass[1]; - inertia[1][1] -= totalMass * (centerOfMass[2] * centerOfMass[2] + centerOfMass[0] * centerOfMass[0]); - inertia[1][2] += totalMass * centerOfMass[1] * centerOfMass[2]; - - inertia[2][0] += totalMass * centerOfMass[2] * centerOfMass[0]; - inertia[2][1] += totalMass * centerOfMass[1] * centerOfMass[2]; - inertia[2][2] -= totalMass * (centerOfMass[0] * centerOfMass[0] + centerOfMass[1] * centerOfMass[1]); -} - -Bounds3 Hull::ComputeBounds(const Transform& transform) const -{ - Bounds3 b(m_pVerts[0] * transform); - for (int i = 1; i < m_numVerts; i++) - b += m_pVerts[i] * transform; - return b; -} - - - - - - - -// Clips a face to the back of a plane -int Hull::ClipFace(int numVerts, Point3** ppVtxIn, Point3** ppVtxOut, const Plane& plane) -{ - int ve, numVertsOut; - Point3 *pVtxOut, *pVtxS, *pVtxE; - Scalar ds, de; - - if (numVerts == 0) - return 0; - - pVtxE = *ppVtxIn; - pVtxS = pVtxE + numVerts - 1; - pVtxOut = *ppVtxOut; - - Scalar zero(0.0f); - - ds = Dot(plane, *pVtxS); - - for (ve = 0; ve < numVerts; ve++, pVtxE++) - { - de = Dot(plane, *pVtxE); - - if (ds <= zero) - { - *pVtxOut++ = *pVtxS; - if (de > zero) - *pVtxOut++ = Lerp(*pVtxS, *pVtxE, ds * RcpNr(ds - de)); - } - else if (de <= zero) - *pVtxOut++ = Lerp(*pVtxS, *pVtxE, ds * RcpNr(ds - de)); - - if (ve == 0) - pVtxS = *ppVtxIn; - else - pVtxS++; - - ds = de; - } - - numVertsOut = pVtxOut - *ppVtxOut; - - // swap in and out arrays ready for next time - pVtxOut = *ppVtxIn; - *ppVtxIn = *ppVtxOut; - *ppVtxOut = pVtxOut; - - return numVertsOut; -} - - - - - -int Hull::AddContactsHullHull(btSeparation& sep, const Point3* pVertsA, const Point3* pVertsB, - const Transform& trA, const Transform& trB,const Hull& hullA,const Hull& hullB, - HullContactCollector* hullContactCollector) -{ - const int maxContacts = hullContactCollector->GetMaxNumContacts(); - - Vector3 normalWorld = sep.m_axis; - - // edge->edge contact is always a single point - if (sep.m_separator == btSeparation::kFeatureBoth) - { - const Hull::Edge& edgeA = hullA.getEdge(sep.m_featureA); - const Hull::Edge& edgeB = hullB.getEdge(sep.m_featureB); - - float ta, tb; - Line la(pVertsA[edgeA.m_verts[0]], pVertsA[edgeA.m_verts[1]]); - Line lb(pVertsB[edgeB.m_verts[0]], pVertsB[edgeB.m_verts[1]]); - - Intersect(la, lb, ta, tb); - -#ifdef VALIDATE_CONTACT_POINTS - AssertPointInsideHull(contact.m_points[0].m_pos, trA, hullA); - AssertPointInsideHull(contact.m_points[0].m_pos, trB, hullB); -#endif - - - Point3 posWorld = Lerp(la.m_start, la.m_end, ta); - float depth = -sep.m_dist; - Vector3 tangent = Normalize(pVertsA[edgeA.m_verts[1]] - pVertsA[edgeA.m_verts[0]]); - - sep.m_contact = hullContactCollector->BatchAddContactGroup(sep,1,normalWorld,tangent,&posWorld,&depth); - - } - // face->face contact is polygon - else - { - short faceA = sep.m_featureA; - short faceB = sep.m_featureB; - - Vector3 tangent; - - // find face of hull A that is most opposite contact axis - // TODO: avoid having to transform planes here - if (sep.m_separator == btSeparation::kFeatureB) - { - const Hull::Edge& edgeB = hullB.getEdge(hullB.GetFaceFirstEdge(faceB)); - tangent = Normalize(pVertsB[edgeB.m_verts[1]] - pVertsB[edgeB.m_verts[0]]); - - Scalar dmin = Scalar::Consts::MaxValue; - for (short face = 0; face < hullA.m_numFaces; face++) - { - Vector3 normal = hullA.getPlane(face).GetNormal() * trA; - Scalar d = Dot(normal, sep.m_axis); - if (d < dmin) - { - dmin = d; - faceA = face; - } - } - } - else - { - const Hull::Edge& edgeA = hullA.getEdge(hullA.GetFaceFirstEdge(faceA)); - tangent = Normalize(pVertsA[edgeA.m_verts[1]] - pVertsA[edgeA.m_verts[0]]); - - Scalar dmin = Scalar::Consts::MaxValue; - for (short face = 0; face < hullB.m_numFaces; face++) - { - Vector3 normal = hullB.getPlane(face).GetNormal() * trB; - Scalar d = Dot(normal, -sep.m_axis); - if (d < dmin) - { - dmin = d; - faceB = face; - } - } - } - - Point3 workspace[2][Hull::kMaxVerts]; - - // setup initial clip face (minimizing face from hull B) - int numContacts = 0; - for (short edge = hullB.GetFaceFirstEdge(faceB); edge != -1; edge = hullB.GetFaceNextEdge(faceB, edge)) - workspace[0][numContacts++] = pVertsB[ hullB.GetEdgeVertex0(faceB, edge) ]; - - // clip polygon to back of planes of all faces of hull A that are adjacent to witness face - Point3* pVtxIn = workspace[0]; - Point3* pVtxOut = workspace[1]; - -#if 0 - for (short edge = hullA.GetFaceFirstEdge(faceA); edge != -1; edge = hullA.GetFaceNextEdge(faceA, edge)) - { - Plane planeA = hullA.getPlane( hullA.GetEdgeOtherFace(edge, faceA) ) * trA; - numContacts = ClipFace(numContacts, &pVtxIn, &pVtxOut, planeA); - } -#else - for (short f = 0; f < hullA.GetNumFaces(); f++) - { - Plane planeA = hullA.getPlane(f) * trA; - numContacts = ClipFace(numContacts, &pVtxIn, &pVtxOut, planeA); - } -#endif - - // only keep points that are behind the witness face - Plane planeA = hullA.getPlane(faceA) * trA; - - float depths[Hull::kMaxVerts]; - int numPoints = 0; - for (int i = 0; i < numContacts; i++) - { - Scalar d = Dot(planeA, pVtxIn[i]); - if (IsNegative(d)) - { - depths[numPoints] = (float)-d; - pVtxIn[numPoints] = pVtxIn[i]; - -#ifdef VALIDATE_CONTACT_POINTS - AssertPointInsideHull(pVtxIn[numPoints], trA, hullA); - AssertPointInsideHull(pVtxIn[numPoints], trB, hullB); -#endif - numPoints++; - } - } - - //we can also use a persistentManifold/reducer class - // keep maxContacts points at most - if (numPoints > 0) - { - if (numPoints > maxContacts) - { - int step = (numPoints << 8) / maxContacts; - - numPoints = maxContacts; - for (int i = 0; i < numPoints; i++) - { - int nth = (step * i) >> 8; - - depths[i] = depths[nth]; - pVtxIn[i] = pVtxIn[nth]; - - -#ifdef VALIDATE_CONTACT_POINTS - AssertPointInsideHull(contact.m_points[i].m_pos, trA, hullA); - AssertPointInsideHull(contact.m_points[i].m_pos, trB, hullB); -#endif - } - } - - sep.m_contact = hullContactCollector->BatchAddContactGroup(sep,numPoints,normalWorld,tangent,pVtxIn,depths); - - } - return numPoints; - } - - // shut up compiler - return 0; -} - - - - -// returns true if a separating axis was found -// if no separating axis was found then details of least penetrating axis are returned -// resulting axis always points away from hullB -// either transform can be null in which case it is treated as identity (this avoids a bunch of work) -bool Hull::GetSeparationHullHull(btSeparation& sep, const Point3* pVertsA, const Point3* pVertsB, - const Transform& trA, const Transform& trB, - const Hull& hullA, - const Hull& hullB - ) -{ - //const Hull& hullA((const Hull&)*sep.m_pShapeA->GetShape()); - //const Hull& hullB((const Hull&)*sep.m_pShapeB->GetShape()); - - sep.m_separator = btSeparation::kFeatureNone; - sep.m_dist = MinValueF; - sep.m_featureA = sep.m_featureB = -1; - sep.m_contact = -1; - - // test verts of A to planes of B - Scalar minDistB = Scalar::Consts::MinValue; - for (short p = 0; p < hullB.m_numFaces; p++) - { - Plane planeWorld = hullB.m_pPlanes[p] * trB; - - Scalar minDist = Dot(planeWorld, pVertsA[0]); - for (short v = 1; v < hullA.m_numVerts; v++) - minDist = Min(minDist, Dot(planeWorld, pVertsA[v])); - - // keep min overlap - if (minDist > minDistB) - { - minDistB = minDist; - sep.m_featureB = p; - sep.m_dist = minDist; - sep.m_axis = planeWorld.GetNormal(); - sep.m_separator = btSeparation::kFeatureB; - } - - // got a separating plane? - if (!IsNegative(minDist)) - return true; - } - - // test verts of B to planes of A - Scalar minDistA = Scalar::Consts::MinValue; - for (short p = 0; p < hullA.m_numFaces; p++) - { - // get plane in world space - Plane planeWorld = hullA.m_pPlanes[p] * trA; - - // get min dist - Scalar minDist = Dot(planeWorld, pVertsB[0]); - for (short v = 1; v < hullB.m_numVerts; v++) - minDist = Min(minDist, Dot(planeWorld, pVertsB[v])); - - // keep min overlap - if (minDist > minDistA) - { - minDistA = minDist; - sep.m_featureA = p; - - if ((float)minDist > sep.m_dist) - { - sep.m_dist = (float)minDist; - sep.m_axis = -planeWorld.GetNormal(); - sep.m_separator = btSeparation::kFeatureA; - } - } - - // got a separating plane? - if (!IsNegative(minDist)) - return true; - } - - // test edge pairs on two minimizing faces - short faceA( sep.m_featureA ); - short faceB( sep.m_featureB ); - - Vector3 faceBnormal = Vector3(hullB.m_pPlanes[sep.m_featureB]) * trB; - -// Plane bestPlane; -// Point3 bestPlanePos; - - for (short ea = hullA.GetFaceFirstEdge(faceA); ea != -1; ea = hullA.GetFaceNextEdge(faceA, ea)) - { - const Hull::Edge& edgeA = hullA.getEdge(ea); - - for (short eb = hullB.GetFaceFirstEdge(faceB); eb != -1; eb = hullB.GetFaceNextEdge(faceB, eb)) - { - const Hull::Edge& edgeB = hullB.getEdge(eb); - - Vector3 va = pVertsA[edgeA.m_verts[1]] - pVertsA[edgeA.m_verts[0]]; - Vector3 vb = pVertsB[edgeB.m_verts[1]] - pVertsB[edgeB.m_verts[0]]; - Vector3 axis = Cross(va, vb); - Scalar rcpLen = LengthRcp(axis); - - // if the two edges have nearly equal or opposite directions then try the next pair - if (IsNan(rcpLen) || rcpLen > 10000.0f) - continue; - axis *= rcpLen; - - // if axis is very close to current best axis then don't use it - if (Abs(Dot(sep.m_axis, axis)) > 0.99f) - continue; - - // ensure the axis points away from hullB - if (Dot(faceBnormal, axis) < Scalar::Consts::Zero) - axis = -axis; - - Plane plane(axis, pVertsB[edgeB.m_verts[0]]); - - // hull B must be entirely behind plane - Scalar dmaxB = Dot(plane, pVertsB[0]); - for (short v = 1; v < hullB.m_numVerts; v++) - dmaxB = Max(dmaxB, Dot(plane, pVertsB[v])); - - if (dmaxB > 0.001f) - continue; - - // get hull A distance from plane - Scalar dminA = Dot(plane, pVertsA[0]); - for (short v = 1; v < hullA.m_numVerts; v++) - dminA = Min(dminA, Dot(plane, pVertsA[v])); - - // got a separating plane? - if (!IsNegative(dminA)) - { - sep.m_featureA = ea; - sep.m_featureB = eb; - sep.m_dist = dminA; - sep.m_axis = axis; - sep.m_separator = btSeparation::kFeatureBoth; - return true; - } - - // keep min overlap - if (dminA > sep.m_dist) - { - // if edge of A is in front of the plane, then we haven't identified the correct edge pair - if (IsNegative(Dot(plane, pVertsA[edgeA.m_verts[0]]))) - { - // bestPlane = plane; - // bestPlanePos = Lerp(pVertsB[edgeB.m_verts[0]], pVertsB[edgeB.m_verts[1]], 0.5f); - -// sep.m_featureA = ea; -// sep.m_featureB = eb; - sep.m_dist = dminA; - sep.m_axis = axis; -// sep.m_separator = btSeparation::kFeatureBoth; - } - } - - } - -// RenderPlane(bestPlane, bestPlanePos); - } - - return false; -} -#endif //MSC_VER >= 1310 -#endif //WIN32 diff --git a/Extras/obsolete/SATConvexCollision/Hull.h b/Extras/obsolete/SATConvexCollision/Hull.h deleted file mode 100644 index 8e02160de..000000000 --- a/Extras/obsolete/SATConvexCollision/Hull.h +++ /dev/null @@ -1,174 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// Hull.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifndef SAT_HULL_H -#define SAT_HULL_H - -#include "Maths.h" -#include "Shape.h" - - -class DynWorld; -class HullContactCollector; - -/// Hull implements a convex collision detection algorithm based on Separating Axis Theorem (SAT). It is an alternative to GJK. -/// It calculates the separating axis, and based on that it calculates the contact manifold (points) in one go. -/// The separating axis calculation is approximated, not all edge-edge calculations are performed (performance reasons). -/// Future idea is to combine this with GJK for polyhedra: GJK to calculate the separating axis, and Hull clipping code to calculate the full set of contacts. -class Hull : public Shape -{ - friend class ShapeCollider; - -public: - struct Edge - { - short m_verts[2]; - short m_faces[2]; - short m_nextEdge[2]; // for each m_face - }; - - struct Face - { - short m_numEdges; - short m_firstEdge; - }; - -private: - static const int kMaxVerts = 256; - static const int kMaxFaces = 256; - static const int kMaxEdges = 256; - - short m_numVerts; - short m_numFaces; - short m_numEdges; - - Point3* m_pVerts; - Face* m_pFaces; - Edge* m_pEdges; - Plane* m_pPlanes; - - // hull construction stuff - static const int kTmpFaceMaxVerts = 64; - struct TmpFace - { - short m_index; - short m_next; - short m_numVerts; - short m_verts[kTmpFaceMaxVerts]; - short m_edges[kTmpFaceMaxVerts]; - Plane m_plane; - }; - - struct TmpEdge - { - short m_index; - short m_next; - short m_verts[2]; - short m_faces[2]; - }; - - static short s_firstFreeTmpFace; - static short s_firstUsedTmpFace; - static TmpFace* s_pTmpFaces; - - static short s_firstFreeTmpEdge; - static short s_firstUsedTmpEdge; - static TmpEdge* s_pTmpEdges; - - static const Point3* s_pPoints; - - static short AllocTmpFace(); - static void FreeTmpFace(short face); - static TmpFace* GetTmpFace(short index) {if (index < 0) return 0; return s_pTmpFaces + index;} - - static short AllocTmpEdge(); - static void FreeTmpEdge(short edge); - static TmpEdge* GetTmpEdge(short index) {if (index < 0) return 0; return s_pTmpEdges + index;} - - static short MatchOrAddEdge(short vert0, short vert1, short face); - static void UnmatchOrRemoveEdge(short edge, short face); - - static short AddTmpFace(short vert0, short vert1, short vert2); - static short AddTmpFace(short numVerts, short* pVerts); - static short AddTmpFace(short vert0, short numOtherVerts, short* pVerts); - static void RemoveTmpFace(short face); - - static bool TmpFaceAddPoint(short point, short face); - - static int RemoveVisibleFaces(const Point3& point); - static void FillHole(short newVertex); - static Hull* MakeHullFromTemp(); - -public: - Hull(); - ~Hull(); - -// ObjectType GetObjectType() const {return kTypeHull;} - - short getNumVertices() const; - short GetNumFaces() const; - short getNumEdges() const; - - const Point3& getVertex(short index) const; - const Face& GetFace(short index) const; - const Edge& getEdge(short index) const; - const Plane& getPlane(short index) const; - - short GetFaceFirstEdge(short face) const; - short GetFaceNextEdge(short face, short prevEdge) const; - - short GetEdgeVertex0(short face, short edge) const; - short GetEdgeVertex1(short face, short edge) const; - - short GetEdgeOtherFace(short edge, short face) const; - - Point3 GetFaceCentroid(short face) const; - - //static void ProcessHullHull(btSeparation& sep); - static void ProcessHullHull(btSeparation& sep,const Hull& shapeA,const Hull& shapeB,const Transform& trA,const Transform& trB, HullContactCollector* collector); - - virtual void ComputeInertia(const Transform& transform, Point3& centerOfMass, Matrix33& inertia, float totalMass) const; - virtual Bounds3 ComputeBounds(const Transform& transform) const; - - static Hull* MakeHull(int numPoints, const Point3* pPoints); - - //for contact generation - - - - /// Clips a face to the back of a plane - static int ClipFace(int numVerts, Point3** ppVtxIn, Point3** ppVtxOut, const Plane& plane); - - static bool GetSeparationHullHull(btSeparation& sep, const Point3* pVertsA, const Point3* pVertsB, - const Transform& trA, const Transform& trB, - const Hull& hullA, - const Hull& hullB - ); - - static int AddContactsHullHull(btSeparation& sep, const Point3* pVertsA, const Point3* pVertsB, - const Transform& trA, const Transform& trB,const Hull& hullA,const Hull& hullB, - HullContactCollector* hullContactCollector); - - - -}; - - - -#include "hull.inl" - -#endif //SAT_HULL_H \ No newline at end of file diff --git a/Extras/obsolete/SATConvexCollision/Hull.inl b/Extras/obsolete/SATConvexCollision/Hull.inl deleted file mode 100644 index 8cf62bdf5..000000000 --- a/Extras/obsolete/SATConvexCollision/Hull.inl +++ /dev/null @@ -1,100 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// Hull.inl -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#pragma once - -#include - -inline short Hull::getNumVertices() const -{ - return m_numVerts; -} - -inline short Hull::GetNumFaces() const -{ - return m_numFaces; -} - -inline short Hull::getNumEdges() const -{ - return m_numEdges; -} - -inline const Point3& Hull::getVertex(short index) const -{ - return m_pVerts[index]; -} - -inline const Hull::Face& Hull::GetFace(short index) const -{ - return m_pFaces[index]; -} - -inline const Hull::Edge& Hull::GetEdge(short index) const -{ - return m_pEdges[index]; -} - -inline const Plane& Hull::GetPlane(short index) const -{ - return m_pPlanes[index]; -} - -inline short Hull::GetFaceFirstEdge(short face) const -{ - assert(face >= 0 && face < m_numFaces); - - return m_pFaces[face].m_firstEdge; -} - -inline short Hull::GetFaceNextEdge(short face, short prevEdge) const -{ - assert(face >= 0 && face < m_numFaces); - assert(prevEdge >= 0 && prevEdge < m_numEdges); - - const Edge& e = m_pEdges[prevEdge]; - return e.m_nextEdge[face == e.m_faces[1]]; -} - -inline short Hull::GetEdgeVertex0(short face, short edge) const -{ - assert(face >= 0 && face < m_numFaces); - assert(edge >= 0 && edge < m_numEdges); - - const Edge& e = m_pEdges[edge]; - return e.m_verts[face == e.m_faces[0]]; -} - -inline short Hull::GetEdgeVertex1(short face, short edge) const -{ - assert(face >= 0 && face < m_numFaces); - assert(edge >= 0 && edge < m_numEdges); - - const Edge& e = m_pEdges[edge]; - return e.m_verts[face == e.m_faces[1]]; -} - -inline short Hull::GetEdgeOtherFace(short edge, short face) const -{ - assert(face >= 0 && face < m_numFaces); - assert(edge >= 0 && edge < m_numEdges); - - const Edge& e = m_pEdges[edge]; - assert(e.m_faces[0] == face || e.m_faces[1] == face); - - return e.m_faces[face == e.m_faces[0]]; -} diff --git a/Extras/obsolete/SATConvexCollision/HullContactCollector.h b/Extras/obsolete/SATConvexCollision/HullContactCollector.h deleted file mode 100644 index 2d14fb5d1..000000000 --- a/Extras/obsolete/SATConvexCollision/HullContactCollector.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#ifndef HULL_CONTACT_COLLECTOR_H -#define HULL_CONTACT_COLLECTOR_H - -class Vector3; -class Point3; -class Scalar; -struct btSeparation; - -///HullContactCollector collects the Hull computation to the contact point results -class HullContactCollector -{ -public: - - virtual ~HullContactCollector() {}; - - virtual int BatchAddContactGroup(const btSeparation& sep,int numContacts,const Vector3& normalWorld,const Vector3& tangent,const Point3* positionsWorld,const float* depths)=0; - - virtual int GetMaxNumContacts() const = 0; - -}; - -#endif //HULL_CONTACT_COLLECTOR_H \ No newline at end of file diff --git a/Extras/obsolete/SATConvexCollision/Maths.h b/Extras/obsolete/SATConvexCollision/Maths.h deleted file mode 100644 index c688577b6..000000000 --- a/Extras/obsolete/SATConvexCollision/Maths.h +++ /dev/null @@ -1,175 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Maths.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifndef BULLET_MATH_H -#define BULLET_MATH_H - -#ifdef WIN32 - -#include -#include -#include - -// intrinsics headers -#include -#include - -// vector maths classes require aligned alloc -#include "Memory2.h" - -// constants -#define PI 3.141592654f - -#define Angle5 0.087266462f -#define Angle10 0.174532925f -#define Angle15 0.261799388f -#define Angle30 0.523598776f -#define Angle45 0.785398163f -#define Angle60 0.523598776f -#define Angle90 1.570796327f -#define Angle180 PI -#define Angle270 4.71238898f -#define Angle360 6.283185307f - -#define Deg2RadF 0.01745329251994329547f -#define Rad2DegF 57.29577951308232286465f - -#define MinValueF -3.402823466e+38f -#define MaxValueF 3.402823466e+38F - -#define DefaultEpsilon 0.001f - - -// float functions - -inline float Sin(const float f) -{ - return sinf(f); -} - -inline float Cos(const float f) -{ - return cosf(f); -} - -inline float Tan(const float f) -{ - return tanf(f); -} - -inline float Asin(const float f) -{ - return asinf(f); -} - -inline float Acos(const float f) -{ - return acosf(f); -} - -inline float Atan(const float f) -{ - return atanf(f); -} - -inline float Atan2(const float y, const float x) -{ - return atan2f(y, x); -} - -inline float Pow(const float x, const float y) -{ - return powf(x, y); -} - -inline float Abs(const float x) -{ - return fabsf(x); -} - -inline float Min(const float x, const float y) -{ - return (x < y) ? x : y; -} - -inline float Max(const float x, const float y) -{ - return (x > y) ? x : y; -} - -inline float Clamp(const float x, const float min, const float max) -{ - return (x >= max) ? max : Max(x, min); -} - -inline float Sgn(const float f) -{ - // TODO: replace this with something that doesn't branch - if (f < 0.0f) - return -1.0f; - if (f > 0.0f) - return 1.0f; - return 0.0f; -} - -inline float Floor(const float f) -{ - return floorf(f); -} - -inline float Ceil(const float f) -{ - return ceilf(f); -} - -inline float Mod(const float x, const float y) -{ - float n = Floor(x / y); - return x - n * y; -} - -inline float Sqrt(const float f) -{ - return sqrtf(f); -} - -inline bool Equal(const float x, const float y, const float epsilon = DefaultEpsilon) -{ - return Abs(x-y) <= epsilon; -} - -inline float Lerp(const float x, const float y, const float t) -{ - return x + (y - x) * t; -} - -inline int Min(const int x, const int y) -{ - return (x < y) ? x : y; -} - -inline int Max(const int x, const int y) -{ - return (x > y) ? x : y; -} - -#include "Vector.h" -#include "Matrix.h" -#include "Quat.h" -#include "Geometry.h" - -#endif //WIN32 -#endif //BULLET_MATH_H diff --git a/Extras/obsolete/SATConvexCollision/Matrix.cpp b/Extras/obsolete/SATConvexCollision/Matrix.cpp deleted file mode 100644 index 690b23e41..000000000 --- a/Extras/obsolete/SATConvexCollision/Matrix.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Matrix.cpp -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. - -#ifdef WIN32 -#if _MSC_VER >= 1310 - -#include "matrix.h" -#include - - -//////////////////////////////////////////////////////////////////////////////// -// Matrix33 -Matrix33::Matrix33(const Quat& q) -{ - float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2; - float *pIn = (float*)&q; - float *pOut = (float*)this; - - float x = pIn[0], y = pIn[1], z = pIn[2], w = pIn[3]; - - x2 = x + x; y2 = y + y; z2 = z + z; - xx = x * x2; yy = y * y2; zz = z * z2; - wx = w * x2; wy = w * y2; wz = w * z2; - xy = x * y2; xz = x * z2; - yz = y * z2; - - pOut[0] = 1.0f - (yy + zz); - pOut[1] = xy + wz; - pOut[2] = xz - wy; - pOut[3] = 0.0f; - - pOut[4] = xy - wz; - pOut[5] = 1.0f - (xx + zz); - pOut[6] = yz + wx; - pOut[7] = 0.0f; - - pOut[8] = xz + wy; - pOut[9] = yz - wx; - pOut[10] = 1.0f - (xx + yy); - pOut[11] = 0.0f; -} - -const Matrix33 Inv(const Matrix33& m) -{ - // TODO: do this efficiently - for now we just use the Matrix44 version - Matrix44 m44 = Inv(Matrix44(Vector4(m[0]), Vector4(m[1]), Vector4(m[2]), Vector4(Maths::UnitW))); - return Matrix33(Vector3(m44[0]), Vector3(m44[1]), Vector3(m44[2])); -} - - -//////////////////////////////////////////////////////////////////////////////// -// Matrix44 - -// calculate the inverse of a general 4x4 matrix -// -// -1 -// A = ___1__ adjoint A -// det A -// -const Matrix44 Inv(const Matrix44& src) -{ - __m128 minor0, minor1, minor2, minor3; - __m128 row0, row1 = _mm_set_ps1(0.0f), row2, row3 = row1; - __m128 det, tmp1 = row1, tmp2; - - Matrix44 tmp(src); - float *m = (float*)&tmp; - - tmp1 = _mm_loadh_pi( _mm_loadl_pi( tmp1, (__m64*)(m ) ), (__m64*)(m+ 4) ); - row1 = _mm_loadh_pi( _mm_loadl_pi( row1, (__m64*)(m+8) ), (__m64*)(m+12) ); - - row0 = _mm_shuffle_ps( tmp1, row1, 0x88 ); - row1 = _mm_shuffle_ps( row1, tmp1, 0xDD ); - - tmp1 = _mm_loadh_pi( _mm_loadl_pi( tmp1, (__m64*)(m+ 2) ), (__m64*)(m+ 6) ); - row3 = _mm_loadh_pi( _mm_loadl_pi( row3, (__m64*)(m+10) ), (__m64*)(m+14) ); - - row2 = _mm_shuffle_ps( tmp1, row3, 0x88 ); - row3 = _mm_shuffle_ps( row3, tmp1, 0xDD ); -// ----------------------------------------------- - tmp2 = _mm_mul_ps( row2, row3 ); - tmp1 = _mm_shuffle_ps( tmp2, tmp2, 0xB1); - - minor0 = _mm_mul_ps( row1, tmp1 ); - minor1 = _mm_mul_ps( row0, tmp1 ); - - tmp1 = _mm_shuffle_ps( tmp1, tmp1, 0x4E ); - - minor0 = _mm_sub_ps( _mm_mul_ps( row1, tmp1 ), minor0 ); - minor1 = _mm_sub_ps( _mm_mul_ps( row0, tmp1 ), minor1 ); - minor1 = _mm_shuffle_ps( minor1, minor1, 0x4E ); -// ----------------------------------------------- - tmp2 = _mm_mul_ps( row1, row2); - tmp1 = _mm_shuffle_ps( tmp2, tmp2, 0xB1 ); - - minor0 = _mm_add_ps( _mm_mul_ps( row3, tmp1 ), minor0 ); - minor3 = _mm_mul_ps( row0, tmp1 ); - - tmp1 = _mm_shuffle_ps( tmp1, tmp1, 0x4E ); - - minor0 = _mm_sub_ps( minor0, _mm_mul_ps( row3, tmp1 ) ); - minor3 = _mm_sub_ps( _mm_mul_ps( row0, tmp1 ), minor3 ); - minor3 = _mm_shuffle_ps( minor3, minor3, 0x4E ); -// ----------------------------------------------- - tmp2 = _mm_mul_ps( _mm_shuffle_ps( row1, row1, 0x4E ), row3 ); - tmp1 = _mm_shuffle_ps( tmp2, tmp2, 0xB1 ); - row2 = _mm_shuffle_ps( row2, row2, 0x4E ); - - minor0 = _mm_add_ps( _mm_mul_ps( row2, tmp1 ), minor0 ); - minor2 = _mm_mul_ps( row0, tmp1 ); - - tmp1 = _mm_shuffle_ps( tmp1, tmp1, 0x4E ); - - minor0 = _mm_sub_ps( minor0, _mm_mul_ps( row2, tmp1 ) ); - minor2 = _mm_sub_ps( _mm_mul_ps( row0, tmp1 ), minor2 ); - minor2 = _mm_shuffle_ps( minor2, minor2, 0x4E ); -// ----------------------------------------------- - tmp2 = _mm_mul_ps( row0, row1); - tmp1 = _mm_shuffle_ps( tmp2, tmp2, 0xB1 ); - - minor2 = _mm_add_ps( _mm_mul_ps( row3, tmp1 ), minor2 ); - minor3 = _mm_sub_ps( _mm_mul_ps( row2, tmp1 ), minor3 ); - - tmp1 = _mm_shuffle_ps( tmp1, tmp1, 0x4E ); - - minor2 = _mm_sub_ps( _mm_mul_ps( row3, tmp1 ), minor2 ); - minor3 = _mm_sub_ps( minor3, _mm_mul_ps( row2, tmp1 ) ); -// ----------------------------------------------- - tmp2 = _mm_mul_ps( row0, row3); - tmp1 = _mm_shuffle_ps( tmp2, tmp2, 0xB1 ); - - minor1 = _mm_sub_ps( minor1, _mm_mul_ps( row2, tmp1 ) ); - minor2 = _mm_add_ps( _mm_mul_ps( row1, tmp1 ), minor2 ); - - tmp1 = _mm_shuffle_ps( tmp1, tmp1, 0x4E ); - - minor1 = _mm_add_ps( _mm_mul_ps( row2, tmp1 ), minor1 ); - minor2 = _mm_sub_ps( minor2, _mm_mul_ps( row1, tmp1 ) ); -// ----------------------------------------------- - tmp2 = _mm_mul_ps( row0, row2); - tmp1 = _mm_shuffle_ps( tmp2, tmp2, 0xB1 ); - - minor1 = _mm_add_ps( _mm_mul_ps( row3, tmp1 ), minor1 ); - minor3 = _mm_sub_ps( minor3, _mm_mul_ps( row1, tmp1 ) ); - - tmp1 = _mm_shuffle_ps( tmp1, tmp1, 0x4E ); - - minor1 = _mm_sub_ps( minor1, _mm_mul_ps( row3, tmp1 ) ); - minor3 = _mm_add_ps( _mm_mul_ps( row1, tmp1 ), minor3 ); -// ----------------------------------------------- - det = _mm_mul_ps( row0, minor0 ); - det = _mm_add_ps( _mm_shuffle_ps( det, det, 0x4E ), det ); - det = _mm_add_ss( _mm_shuffle_ps( det, det, 0xB1 ), det ); - tmp1 = _mm_rcp_ss( det ); - - det = _mm_sub_ss( _mm_add_ss( tmp1, tmp1 ), _mm_mul_ss( det, _mm_mul_ss( tmp1, tmp1 ) ) ); - det = _mm_shuffle_ps( det, det, 0x00 ); - - minor0 = _mm_mul_ps( det, minor0 ); - _mm_storel_pi( (__m64*)( m ), minor0 ); - _mm_storeh_pi( (__m64*)(m+2), minor0 ); - - minor1 = _mm_mul_ps( det, minor1 ); - _mm_storel_pi( (__m64*)(m+4), minor1 ); - _mm_storeh_pi( (__m64*)(m+6), minor1 ); - - minor2 = _mm_mul_ps( det, minor2 ); - _mm_storel_pi( (__m64*)(m+ 8), minor2 ); - _mm_storeh_pi( (__m64*)(m+10), minor2 ); - - minor3 = _mm_mul_ps( det, minor3 ); - _mm_storel_pi( (__m64*)(m+12), minor3 ); - _mm_storeh_pi( (__m64*)(m+14), minor3 ); - - return tmp; -} - - - -//////////////////////////////////////////////////////////////////////////////// -// Transform - - - -//////////////////////////////////////////////////////////////////////////////// -// Matrix66 - -#endif -#endif //#ifdef WIN32 - diff --git a/Extras/obsolete/SATConvexCollision/Matrix.h b/Extras/obsolete/SATConvexCollision/Matrix.h deleted file mode 100644 index 1f25b40eb..000000000 --- a/Extras/obsolete/SATConvexCollision/Matrix.h +++ /dev/null @@ -1,208 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Matrix.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifndef BULLET_MATRIX_H -#define BULLET_MATRIX_H - -#ifdef WIN32 - -#include "Vector.h" -#include "Memory2.h" - -class Quat; - -#include - - -//////////////////////////////////////////////////////////////////////////////// -/// Matrix33 -__declspec(align(16)) class Matrix33 -{ -private: - Vector3 m_rows[3]; - -public: - - BULLET_ALIGNED_NEW_AND_DELETE - - - // constructors - Matrix33(); - Matrix33(const Vector3& x, const Vector3& y, const Vector3& z); - - // explicit constructors - explicit Matrix33(const Quat& q); - - explicit Matrix33(const Maths::ZeroTag&); - explicit Matrix33(const Maths::IdentityTag&); - explicit Matrix33(const Maths::RotateXTag&, float radians); - explicit Matrix33(const Maths::RotateYTag&, float radians); - explicit Matrix33(const Maths::RotateZTag&, float radians); - explicit Matrix33(const Maths::ScaleTag&, const Vector3& scale); - explicit Matrix33(const Maths::SkewTag&, const Vector3& v); - - // assignment - const Matrix33& operator=(const Matrix33& m); - - // assignment to constant - const Matrix33& operator=(const Maths::ZeroTag&); - const Matrix33& operator=(const Maths::IdentityTag&); - - // element access - Vector3& operator[](int row); - const Vector3& operator[](int row) const; - - Vector3& GetAxisX(); - const Vector3& GetAxisX() const; - void SetAxisX(const Vector3& v); - - Vector3& GetAxisY(); - const Vector3& GetAxisY() const; - void SetAxisY(const Vector3& v); - - Vector3& GetAxisZ(); - const Vector3& GetAxisZ() const; - void SetAxisZ(const Vector3& v); - - // operations - void operator*=(const Matrix33& a); - void operator*=(const Scalar& s); - void operator+=(const Matrix33& a); - void operator-=(const Matrix33& a); - - friend const Vector3 operator*(const Vector3& v, const Matrix33& m); - friend const Vector3 operator*(const Matrix33& m, const Vector3& vT); - friend const Matrix33 operator*(const Matrix33& a, const Matrix33& b); - friend const Matrix33 operator*(const Matrix33& m, const Scalar& s); - friend const Matrix33 operator+(const Matrix33& a, const Matrix33& b); - friend const Matrix33 operator-(const Matrix33& a, const Matrix33& b); - - friend const Matrix33 Transpose(const Matrix33& m); - friend const Matrix33 Inv(const Matrix33& m); - friend const Scalar Det(const Matrix33& m); -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Matrix44 - -__declspec(align(16)) class Matrix44 -{ -private: - Vector4 m_rows[4]; - -public: - // constructors - Matrix44(); - Matrix44(const Vector4& x, const Vector4& y, const Vector4& z, const Vector4& w); - - // explicit constructors - explicit Matrix44(const Maths::ZeroTag&); - explicit Matrix44(const Maths::IdentityTag&); - explicit Matrix44(const Maths::RotateXTag&, float radians); - explicit Matrix44(const Maths::RotateYTag&, float radians); - explicit Matrix44(const Maths::RotateZTag&, float radians); - - // assignment - const Matrix44& operator=(const Matrix44& m); - - // assignment to constant - const Matrix44& operator=(const Maths::ZeroTag&); - const Matrix44& operator=(const Maths::IdentityTag&); - - // element access - Vector4& operator[](int row); - const Vector4& operator[](int row) const; - - // operations - void operator*=(const Matrix44& a); - void operator*=(const Scalar& s); - void operator+=(const Matrix44& a); - void operator-=(const Matrix44& a); - - friend const Vector3 operator*(const Vector3& v, const Matrix44& m); - friend const Point3 operator*(const Point3& v, const Matrix44& m); - friend const Vector4 operator*(const Vector4& v, const Matrix44& m); - - friend const Matrix44 operator*(const Matrix44& a, const Matrix44& b); - friend const Matrix44 operator*(const Scalar& s, const Matrix44& m); - friend const Matrix44 operator*(const Matrix44& m, const Scalar& s); - friend const Matrix44 operator+(const Matrix44& a, const Matrix44& b); - friend const Matrix44 operator-(const Matrix44& a, const Matrix44& b); - - friend const Matrix44 Transpose(const Matrix44& m); - friend const Matrix44 Inv(const Matrix44& m); -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Transform - -__declspec(align(16)) class Transform -{ -private: - Matrix33 m_rotation; - Point3 m_translation; - -public: - // constructors - Transform(); - Transform(const Matrix33& xyz, const Point3& w); - Transform(const Vector3& x, const Vector3& y, const Vector3& z, const Point3& w); - - // explicit constructors - explicit Transform(const Maths::IdentityTag&); - - // assignment - const Transform& operator=(const Transform& m); - - // assignment to constant - const Transform& operator=(const Maths::IdentityTag&); - - // element access - Matrix33& GetRotation(); - const Matrix33& GetRotation() const; - void SetRotation(const Matrix33& m); - void SetRotation(const Quat& q); - - Point3& GetTranslation(); - const Point3& GetTranslation() const; - void SetTranslation(const Point3& p); - - Vector3& GetAxisX(); - const Vector3& GetAxisX() const; - - Vector3& GetAxisY(); - const Vector3& GetAxisY() const; - - Vector3& GetAxisZ(); - const Vector3& GetAxisZ() const; - - // operations - friend const Vector3 operator*(const Vector3& v, const Transform& m); - friend const Point3 operator*(const Point3& v, const Transform& m); - - friend const Transform operator*(const Transform& v, const Transform& m); - - friend const Transform Inv(const Transform& m); -}; - - - -#include "matrix.inl" - -#endif //#ifdef WIN32 -#endif //BULLET_MATRIX_H \ No newline at end of file diff --git a/Extras/obsolete/SATConvexCollision/Matrix.inl b/Extras/obsolete/SATConvexCollision/Matrix.inl deleted file mode 100644 index 13b836571..000000000 --- a/Extras/obsolete/SATConvexCollision/Matrix.inl +++ /dev/null @@ -1,609 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// Matrix.inl -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#pragma once - -#include -#include "math.h" - -//////////////////////////////////////////////////////////////////////////////// -// Matrix33 - -inline Matrix33::Matrix33() -{ -} - -inline Matrix33::Matrix33(const Vector3& x, const Vector3& y, const Vector3& z) -{ - m_rows[0] = x; - m_rows[1] = y; - m_rows[2] = z; -} - -inline Matrix33::Matrix33(const Maths::ZeroTag&) -{ - m_rows[0] = Maths::Zero; - m_rows[1] = Maths::Zero; - m_rows[2] = Maths::Zero; -} - -inline Matrix33::Matrix33(const Maths::IdentityTag&) -{ - m_rows[0] = Maths::UnitX; - m_rows[1] = Maths::UnitY; - m_rows[2] = Maths::UnitZ; -} - -inline Matrix33::Matrix33(const Maths::RotateXTag&, float radians) -{ - float c = cosf(radians); - float s = sinf(radians); - - m_rows[0] = Maths::UnitX; - m_rows[1] = Vector3(0.0f, c, s); - m_rows[2] = Vector3(0.0f, -s, c); -} - -inline Matrix33::Matrix33(const Maths::RotateYTag&, float radians) -{ - float c = cosf(radians); - float s = sinf(radians); - - m_rows[0] = Vector3(c, 0.0f, -s); - m_rows[1] = Maths::UnitY; - m_rows[2] = Vector3(s, 0.0f, c); -} - -inline Matrix33::Matrix33(const Maths::RotateZTag&, float radians) -{ - float c = cosf(radians); - float s = sinf(radians); - - m_rows[0] = Vector3(c, s, 0.0f); - m_rows[1] = Vector3(-s, c, 0.0f); - m_rows[2] = Maths::UnitZ; -} - -inline Matrix33::Matrix33(const Maths::ScaleTag&, const Vector3& scale) -{ - m_rows[0] = scale * Vector3(Maths::UnitX); - m_rows[1] = scale * Vector3(Maths::UnitY); - m_rows[2] = scale * Vector3(Maths::UnitZ); -} - -inline Matrix33::Matrix33(const Maths::SkewTag&, const Vector3& v) -{ - m_rows[0] = Vector3(0.0f, v[2], -v[1]); - m_rows[1] = Vector3(-v[2], 0.0f, v[0]); - m_rows[2] = Vector3(v[1], -v[0], 0.0f); -} - -inline const Matrix33& Matrix33::operator=(const Matrix33& m) -{ - m_rows[0] = m.m_rows[0]; - m_rows[1] = m.m_rows[1]; - m_rows[2] = m.m_rows[2]; - return *this; -} - -inline const Matrix33& Matrix33::operator=(const Maths::ZeroTag&) -{ - m_rows[0] = m_rows[1] = m_rows[2] = Maths::Zero; - return *this; -} - -inline const Matrix33& Matrix33::operator=(const Maths::IdentityTag&) -{ - m_rows[0] = Maths::UnitX; - m_rows[1] = Maths::UnitY; - m_rows[2] = Maths::UnitZ; - return *this; -} - -inline Vector3& Matrix33::operator[](int row) -{ - return m_rows[row]; -} - -inline const Vector3& Matrix33::operator[](int row) const -{ - return m_rows[row]; -} - -inline Vector3& Matrix33::GetAxisX() -{ - return m_rows[0]; -} - -inline const Vector3& Matrix33::GetAxisX() const -{ - return m_rows[0]; -} - -inline void Matrix33::SetAxisX(const Vector3& v) -{ - m_rows[0] = v; -} - -inline Vector3& Matrix33::GetAxisY() -{ - return m_rows[1]; -} - -inline const Vector3& Matrix33::GetAxisY() const -{ - return m_rows[1]; -} - -inline void Matrix33::SetAxisY(const Vector3& v) -{ - m_rows[1] = v; -} - -inline Vector3& Matrix33::GetAxisZ() -{ - return m_rows[2]; -} - -inline const Vector3& Matrix33::GetAxisZ() const -{ - return m_rows[2]; -} - -inline void Matrix33::SetAxisZ(const Vector3& v) -{ - m_rows[2] = v; -} - -inline const Vector3 operator*(const Vector3& v, const Matrix33& m) -{ - Scalar xxxx = v.GetX(); - Scalar yyyy = v.GetY(); - Scalar zzzz = v.GetZ(); - - return xxxx * m[0] + yyyy * m[1] + zzzz * m[2]; -} - -inline const Vector3 operator*(const Matrix33& m, const Vector3& vT) -{ - return Vector3(Dot(m[0], vT), Dot(m[1], vT), Dot(m[2], vT)); -} - -inline void Matrix33::operator*=(const Matrix33& a) -{ - *this = *this * a; -} - -inline void Matrix33::operator*=(const Scalar& s) -{ - m_rows[0] *= s; - m_rows[1] *= s; - m_rows[2] *= s; -} - -inline void Matrix33::operator+=(const Matrix33& a) -{ - m_rows[0] += a[0]; - m_rows[1] += a[1]; - m_rows[2] += a[2]; -} - -inline void Matrix33::operator-=(const Matrix33& a) -{ - m_rows[0] -= a[0]; - m_rows[1] -= a[1]; - m_rows[2] -= a[2]; -} - -inline const Matrix33 operator*(const Scalar& s, const Matrix33& m) -{ - Vector3 scale(s); - return Matrix33(scale * m[0], scale * m[1], scale * m[2]); -} - -inline const Matrix33 operator*(const Matrix33& m, const Scalar& s) -{ - Vector3 scale(s); - return Matrix33(scale * m[0], scale * m[1], scale * m[2]); -} - -inline const Matrix33 operator*(const Matrix33& a, const Matrix33& b) -{ - return Matrix33(a[0] * b, a[1] * b, a[2] * b); -} - -inline const Matrix33 operator+(const Matrix33& a, const Matrix33& b) -{ - return Matrix33(a[0] + b[0], a[1] + b[1], a[2] + b[2]); -} - -inline const Matrix33 operator-(const Matrix33& a, const Matrix33& b) -{ - return Matrix33(a[0] - b[0], a[1] - b[1], a[2] - b[2]); -} - -inline const Matrix33 Transpose(const Matrix33& m) -{ - // easiest way is to actually do a 4 * 4 transpose with an implied zero bottom row: - - // a b c d a e i 0 - // e f g h ---> b f j 0 - // i j k l c g k 0 - // 0 0 0 0 - - // shuffle the rows to make 4 quarters - __m128 abef = _mm_shuffle_ps(m[0].base, m[1].base, _MM_SHUFFLE(1, 0, 1, 0)); - __m128 cdgh = _mm_shuffle_ps(m[0].base, m[1].base, _MM_SHUFFLE(3, 2, 3, 2)); - __m128 ij00 = _mm_shuffle_ps(m[2].base, _mm_setzero_ps(), _MM_SHUFFLE(1, 0, 1, 0)); - __m128 kl00 = _mm_shuffle_ps(m[2].base, _mm_setzero_ps(), _MM_SHUFFLE(3, 2, 3, 2)); - - // shuffle the quarters to make new rows - __m128 aei0 = _mm_shuffle_ps(abef, ij00, _MM_SHUFFLE(2, 0, 2, 0)); - __m128 bfj0 = _mm_shuffle_ps(abef, ij00, _MM_SHUFFLE(3, 1, 3, 1)); - __m128 cgk0 = _mm_shuffle_ps(cdgh, kl00, _MM_SHUFFLE(2, 0, 2, 0)); - - return Matrix33(Vector3(aei0), Vector3(bfj0), Vector3(cgk0)); -} - -inline const Scalar Det(const Matrix33& m) -{ - return Dot(Cross(m.GetAxisX(), m.GetAxisY()),m.GetAxisZ()); -} - - -//////////////////////////////////////////////////////////////////////////////// -// Matrix44 - -inline Matrix44::Matrix44() -{ -} - -inline Matrix44::Matrix44(const Vector4& x, const Vector4& y, const Vector4& z, const Vector4& w) -{ - m_rows[0] = x; - m_rows[1] = y; - m_rows[2] = z; - m_rows[3] = w; -} - -inline Matrix44::Matrix44(const Maths::ZeroTag&) -{ - m_rows[0] = Maths::Zero; - m_rows[1] = Maths::Zero; - m_rows[2] = Maths::Zero; - m_rows[3] = Maths::Zero; -} - -inline Matrix44::Matrix44(const Maths::IdentityTag&) -{ - m_rows[0] = Maths::UnitX; - m_rows[1] = Maths::UnitY; - m_rows[2] = Maths::UnitZ; - m_rows[3] = Maths::UnitW; -} - -inline Matrix44::Matrix44(const Maths::RotateXTag&, float radians) -{ - float c = cosf(radians); - float s = sinf(radians); - - m_rows[0] = Maths::UnitX; - m_rows[1] = Vector4(0.0f, c, s, 0.0f); - m_rows[2] = Vector4(0.0f, -s, c, 0.0f); - m_rows[3] = Maths::UnitW; -} - -inline Matrix44::Matrix44(const Maths::RotateYTag&, float radians) -{ - float c = cosf(radians); - float s = sinf(radians); - - m_rows[0] = Vector4(c, 0.0f, -s, 0.0f); - m_rows[1] = Maths::UnitY; - m_rows[2] = Vector4(s, 0.0f, c, 0.0f); - m_rows[3] = Maths::UnitW; -} - -inline Matrix44::Matrix44(const Maths::RotateZTag&, float radians) -{ - float c = cosf(radians); - float s = sinf(radians); - - m_rows[0] = Vector4(c, s, 0.0f, 0.0f); - m_rows[1] = Vector4(-s, c, 0.0f, 0.0f); - m_rows[2] = Maths::UnitZ; - m_rows[3] = Maths::UnitW; -} - -inline const Matrix44& Matrix44::operator=(const Matrix44& m) -{ - m_rows[0] = m.m_rows[0]; - m_rows[1] = m.m_rows[1]; - m_rows[2] = m.m_rows[2]; - m_rows[3] = m.m_rows[3]; - return *this; -} - -inline const Matrix44& Matrix44::operator=(const Maths::ZeroTag&) -{ - m_rows[0] = m_rows[1] = m_rows[2] = m_rows[3] = Maths::Zero; - return *this; -} - -inline const Matrix44& Matrix44::operator=(const Maths::IdentityTag&) -{ - m_rows[0] = Maths::UnitX; - m_rows[1] = Maths::UnitY; - m_rows[2] = Maths::UnitZ; - m_rows[3] = Maths::UnitW; - return *this; -} - -inline Vector4& Matrix44::operator[](int row) -{ - return m_rows[row]; -} - -inline const Vector4& Matrix44::operator[](int row) const -{ - return m_rows[row]; -} - -inline void Matrix44::operator*=(const Matrix44& a) -{ - *this = *this * a; -} - -inline void Matrix44::operator*=(const Scalar& s) -{ - m_rows[0] *= s; - m_rows[1] *= s; - m_rows[2] *= s; - m_rows[3] *= s; -} - -inline void Matrix44::operator+=(const Matrix44& a) -{ - m_rows[0] += a[0]; - m_rows[1] += a[1]; - m_rows[2] += a[2]; - m_rows[3] += a[3]; -} - -inline void Matrix44::operator-=(const Matrix44& a) -{ - m_rows[0] -= a[0]; - m_rows[1] -= a[1]; - m_rows[2] -= a[2]; - m_rows[3] -= a[3]; -} - -inline const Vector3 operator*(const Vector3& v, const Matrix44& m) -{ - Scalar xxxx = v.GetX(); - Scalar yyyy = v.GetY(); - Scalar zzzz = v.GetZ(); - - return xxxx * Vector3(m[0]) + yyyy * Vector3(m[1]) + zzzz * Vector3(m[2]); -} - -inline const Point3 operator*(const Point3& v, const Matrix44& m) -{ - Scalar xxxx = v.GetX(); - Scalar yyyy = v.GetY(); - Scalar zzzz = v.GetZ(); - - return Point3(xxxx * m[0] + yyyy * m[1] + zzzz * m[2] + m[3]); -} - -inline const Vector4 operator*(const Vector4& v, const Matrix44& m) -{ - Scalar xxxx = v.GetX(); - Scalar yyyy = v.GetY(); - Scalar zzzz = v.GetZ(); - Scalar wwww = v.GetW(); - - return xxxx * m[0] + yyyy * m[1] + zzzz * m[2] + wwww * m[3]; -} - -inline const Matrix44 operator*(const Matrix44& a, const Matrix44& b) -{ - return Matrix44(a[0] * b, a[1] * b, a[2] * b, a[3] * b); -} - -inline const Matrix44 operator*(const Matrix44& m, const Scalar& s) -{ - Vector4 scale(s); - return Matrix44(scale * m[0], scale * m[1], scale * m[2], scale * m[3]); -} - -inline const Matrix44 operator*(const Scalar& s, const Matrix44& m) -{ - Vector4 scale(s); - return Matrix44(scale * m[0], scale * m[1], scale * m[2], scale * m[3]); -} - -inline const Matrix44 operator+(const Matrix44& a, const Matrix44& b) -{ - return Matrix44(a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]); -} - -inline const Matrix44 operator-(const Matrix44& a, const Matrix44& b) -{ - return Matrix44(a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]); -} - -inline const Matrix44 Transpose(const Matrix44& m) -{ - // a b c d a e i m - // e f g h ---> b f j n - // i j k l c g k o - // m n o p d h l p - - // shuffle the rows to make 4 quarters - __m128 abef = _mm_shuffle_ps(m[0].base, m[1].base, _MM_SHUFFLE(1, 0, 1, 0)); - __m128 cdgh = _mm_shuffle_ps(m[0].base, m[1].base, _MM_SHUFFLE(3, 2, 3, 2)); - __m128 ijmn = _mm_shuffle_ps(m[2].base, m[3].base, _MM_SHUFFLE(1, 0, 1, 0)); - __m128 klop = _mm_shuffle_ps(m[2].base, m[3].base, _MM_SHUFFLE(3, 2, 3, 2)); - - // shuffle the quarters to make new rows - __m128 aeim = _mm_shuffle_ps(abef, ijmn, _MM_SHUFFLE(2, 0, 2, 0)); - __m128 bfjn = _mm_shuffle_ps(abef, ijmn, _MM_SHUFFLE(3, 1, 3, 1)); - __m128 cgko = _mm_shuffle_ps(cdgh, klop, _MM_SHUFFLE(2, 0, 2, 0)); - __m128 dhlp = _mm_shuffle_ps(cdgh, klop, _MM_SHUFFLE(3, 1, 3, 1)); - - return Matrix44(Vector4(aeim), Vector4(bfjn), Vector4(cgko), Vector4(dhlp)); -} - - -//////////////////////////////////////////////////////////////////////////////// -// Transform - -inline Transform::Transform() -{ -} - -inline Transform::Transform(const Matrix33& xyz, const Point3& w) -{ - m_rotation = xyz; - m_translation = w; -} - -inline Transform::Transform(const Vector3& x, const Vector3& y, const Vector3& z, const Point3& w) -{ - m_rotation[0] = x; - m_rotation[1] = y; - m_rotation[2] = z; - m_translation = w; -} - -inline Transform::Transform(const Maths::IdentityTag&) -{ - m_rotation = Maths::Identity; - m_translation = Maths::Zero; -} - -inline const Transform& Transform::operator=(const Transform& m) -{ - m_rotation = m.m_rotation; - m_translation = m.m_translation; - return *this; -} - -inline const Transform& Transform::operator=(const Maths::IdentityTag&) -{ - m_rotation = Maths::Identity; - m_translation = Maths::Zero; - return *this; -} - -inline Matrix33& Transform::GetRotation() -{ - return m_rotation; -} - -inline const Matrix33& Transform::GetRotation() const -{ - return m_rotation; -} - -inline void Transform::SetRotation(const Matrix33& m) -{ - m_rotation = m; -} - -inline void Transform::SetRotation(const Quat& q) -{ - m_rotation = Matrix33(q); -} - -inline Point3& Transform::GetTranslation() -{ - return m_translation; -} - -inline const Point3& Transform::GetTranslation() const -{ - return m_translation; -} - -inline void Transform::SetTranslation(const Point3& t) -{ - m_translation = t; -} - -inline Vector3& Transform::GetAxisX() -{ - return m_rotation[0]; -} - -inline const Vector3& Transform::GetAxisX() const -{ - return m_rotation[0]; -} - -inline Vector3& Transform::GetAxisY() -{ - return m_rotation[1]; -} - -inline const Vector3& Transform::GetAxisY() const -{ - return m_rotation[1]; -} - -inline Vector3& Transform::GetAxisZ() -{ - return m_rotation[2]; -} - -inline const Vector3& Transform::GetAxisZ() const -{ - return m_rotation[2]; -} - -inline const Vector3 operator*(const Vector3& v, const Transform& m) -{ - Scalar xxxx = v.GetX(); - Scalar yyyy = v.GetY(); - Scalar zzzz = v.GetZ(); - - return xxxx * m.GetAxisX() + yyyy * m.GetAxisY() + zzzz * m.GetAxisZ(); -} - -inline const Point3 operator*(const Point3& v, const Transform& m) -{ - Scalar xxxx = v.GetX(); - Scalar yyyy = v.GetY(); - Scalar zzzz = v.GetZ(); - - return xxxx * m.GetAxisX() + yyyy * m.GetAxisY() + zzzz * m.GetAxisZ() + m.GetTranslation(); -} - -inline const Transform operator*(const Transform& a, const Transform& b) -{ - return Transform(a.GetAxisX() * b, a.GetAxisY() * b, a.GetAxisZ() * b, a.GetTranslation() * b); -} - -inline const Transform Inv(const Transform& m) -{ - Matrix33 r(Transpose(m.GetRotation())); - Point3 t = m.GetTranslation(); - t = Point3(-(t.GetX() * r.GetAxisX() + t.GetY() * r.GetAxisY() + t.GetZ() * r.GetAxisZ())); - - return Transform(r, t); -} diff --git a/Extras/obsolete/SATConvexCollision/Memory2.h b/Extras/obsolete/SATConvexCollision/Memory2.h deleted file mode 100644 index 287209e47..000000000 --- a/Extras/obsolete/SATConvexCollision/Memory2.h +++ /dev/null @@ -1,63 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Memory.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. - -#ifndef BULLET_MEMORY2_H -#define BULLET_MEMORY2_H - -#ifdef WIN32 - -//added __cdecl, thanks Jack - -// default new and delete overrides that guarantee 16 byte alignment and zero allocated memory -void* __cdecl operator new(size_t sz) throw(); -void* __cdecl operator new[](size_t sz) throw(); -void __cdecl operator delete(void* m) throw(); -void __cdecl operator delete[](void* m) throw(); - -#include - -#define BULLET_ALIGNED_NEW_AND_DELETE \ -\ -inline void* operator new(size_t sz) throw() \ -{ \ - void* mem = _aligned_malloc(sz + 64, 16); \ - return mem; \ -} \ - \ -inline void* operator new[](size_t sz) throw() \ -{ \ - void* mem = _aligned_malloc(sz + 64, 16); \ - return mem; \ -} \ - \ -inline void operator delete(void* m) throw() \ -{ \ - if (m == 0) \ - return; \ - _aligned_free(m); \ -} \ - \ -inline void operator delete[](void* m) throw() \ -{ \ - _aligned_free(m); \ -} \ - - - -#endif //WIN32 - -#endif //MEMORY2_H diff --git a/Extras/obsolete/SATConvexCollision/Quat.cpp b/Extras/obsolete/SATConvexCollision/Quat.cpp deleted file mode 100644 index f5aa91f86..000000000 --- a/Extras/obsolete/SATConvexCollision/Quat.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Quat.cpp -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. - -#ifdef WIN32 -#if _MSC_VER >= 1310 - -#include "Quat.h" -#include "Maths.h" - -bool Quat::IsFinite() const -{ - if (_finite(GetX()) && _finite(GetY()) && _finite(GetZ()) && _finite(GetW())) - return true; - return false; -} - -Quat::Quat(const Matrix33& m) -{ - float tr, s, q[4]; - int i, j, k; - int nxt[3] = {1, 2, 0}; - float x, y, z, w; - - // Check the diagonal - tr = m[0][0] + m[1][1] + m[2][2]; - if (tr >= 0.0f) - { - // Diagonal is positive - s = ::Sqrt(tr + 1.0f); - w = s * 0.5f; - s = 0.5f / s; - x = (m[1][2] - m[2][1]) * s; - y = (m[2][0] - m[0][2]) * s; - z = (m[0][1] - m[1][0]) * s; - } - else - { - // Diagonal is negative - i = 0; - if (m[1][1] > m[0][0]) i = 1; - if (m[2][2] > m[i][i]) i = 2; - j = nxt[i]; - k = nxt[j]; - - s = ::Sqrt((m[i][i] - (m[j][j] + m[k][k])) + 1.0f); - q[i] = s * 0.5f; - if (s != 0.0f) s = 0.5f / s; - - q[3] = (m[j][k] - m[k][j]) * s; - q[j] = (m[i][j] + m[j][i]) * s; - q[k] = (m[i][k] + m[k][i]) * s; - - x = q[0]; - y = q[1]; - z = q[2]; - w = q[3]; - } - - *this = Quat(x, y, z, w); -} - -const Quat Slerp(const Quat& a, const Quat& b, const Scalar& t) -{ - Quat e; - Scalar cosom, t0, t1; - - cosom = Dot(a, b); - - if (cosom < Scalar::Consts::Zero) - { - cosom = -cosom; - e = -b; - } - else - e = b; - - if (cosom < 0.9999f) - { - float omega = ::Acos(cosom); - Scalar rcpSinom = Rcp(Scalar(::Sin(omega))); - t0 = Scalar(::Sin((1.0f - (float)t) * omega)) * rcpSinom; - t1 = Scalar(::Sin((float)t * omega)) * rcpSinom; - } - else - { - t0 = Scalar(1.0f) - t; - t1 = t; - } - - return a * t0 + e * t; -} - -#endif -#endif //#ifdef WIN32 diff --git a/Extras/obsolete/SATConvexCollision/Quat.h b/Extras/obsolete/SATConvexCollision/Quat.h deleted file mode 100644 index b280b70a8..000000000 --- a/Extras/obsolete/SATConvexCollision/Quat.h +++ /dev/null @@ -1,87 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Quat.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifndef BULLET_QUAT_H -#define BULLET_QUAT_H - -#include "Vector.h" - -class Matrix33; - - -class Quat : public Vector4Base -{ -public: - BULLET_ALIGNED_NEW_AND_DELETE - - // constructors - Quat(); - Quat(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w); - Quat(const Vector3& axis, const Scalar& angle); - - // construction to constant - Quat(const Maths::IdentityTag&); - - // explicit constructors - explicit Quat(const __m128 b); - explicit Quat(const Vector3& v); - explicit Quat(const Vector4& v); - explicit Quat(const Matrix33& m); - explicit Quat(const float* p); - - // assignment - const Quat& operator=(const Quat& v); - const Quat& operator=(const Maths::IdentityTag&); - - // in place operations - void operator+=(const Quat& b); - void operator-=(const Quat& b); - void operator*=(const Quat& b); - void operator*=(const Scalar& s); - - // operations - friend const Quat operator-(const Quat& a); - friend const Quat operator+(const Quat& a, const Quat& b); - friend const Quat operator-(const Quat& a, const Quat& b); - friend const Quat operator*(const Quat& a, const Quat& b); - friend const Quat operator*(const Quat& a, const Scalar& s); - friend const Quat operator*(const Scalar& s, const Quat& a); - - friend const Quat Inv(const Quat& a); - - friend const Scalar Dot(const Quat& a, const Quat& b); - - friend const Scalar Length(const Quat& a); - friend const Quat Normalize(const Quat& a); - - friend const Scalar LengthFast(const Quat& a); - friend const Quat NormalizeFast(const Quat& a); - - friend const Quat Slerp(const Quat& a, const Quat& b, const Scalar& t); - friend const Quat Lerp(const Quat& a, const Quat& b, const Scalar& t); - - const Vector3 Rotate(const Vector3& v) const; - void GetAngleAxis(Vector3& axis, Scalar& angle) const; - - // validation - bool IsFinite() const; -}; - - -#include "Quat.inl" - - -#endif //BULLET_QUAT_H diff --git a/Extras/obsolete/SATConvexCollision/Quat.inl b/Extras/obsolete/SATConvexCollision/Quat.inl deleted file mode 100644 index ad06e600c..000000000 --- a/Extras/obsolete/SATConvexCollision/Quat.inl +++ /dev/null @@ -1,189 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Quat.inl -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#pragma once - -#include -#include "math.h" - -inline Quat::Quat() -{ -} - -inline Quat::Quat(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w) -{ - Set(x.base, y.base, z.base, w.base); -} - -inline Quat::Quat(const Vector3& axis, const Scalar& angle) -{ - assert(axis.IsFinite()); - Set((sinf(0.5f * (float)angle) * axis).base, Scalar(cosf(0.5f * (float)angle)).base); -} - -inline Quat::Quat(const Maths::IdentityTag&) -{ - base = Vector4Base::Consts::k0001; -} - -inline Quat::Quat(const Vector3& v) -{ - base = v.base; -} - -inline Quat::Quat(const Vector4& v) -{ - base = v.base; -} - -inline Quat::Quat(const __m128 b) -{ - base = b; -} - -inline Quat::Quat(const float* p) -{ - base = _mm_load_ps(p); -} - -inline const Quat& Quat::operator=(const Quat &q) -{ - base = q.base; - return *this; -} - -inline const Quat& Quat::operator=(const Maths::IdentityTag&) -{ - base = Vector4Base::Consts::k0001; - return *this; -} - -inline void Quat::operator+=(const Quat& b) -{ - base = _mm_add_ps(base, b.base); -} - -inline void Quat::operator-=(const Quat& b) -{ - base = _mm_sub_ps(base, b.base); -} - -inline void Quat::operator*=(const Quat& b) -{ - *this = (*this * b); -} - -inline void Quat::operator*=(const Scalar& s) -{ - base = _mm_mul_ps(base, _mm_shuffle_ps(s.base, s.base, _MM_SHUFFLE(0, 0, 0, 0))); -} - -inline const Quat operator-(const Quat& a) -{ - return Quat(_mm_sub_ps(_mm_setzero_ps(), a.base)); -} - -inline const Quat operator+(const Quat& a, const Quat& b) -{ - return Quat(_mm_add_ps(a.base, b.base)); -} - -inline const Quat operator-(const Quat& a, const Quat& b) -{ - return Quat(_mm_sub_ps(a.base, b.base)); -} - -inline const Quat operator*(const Quat& a, const Quat& b) -{ - // TODO: not happy with this - Vector3 va(a.base); - Vector3 vb(b.base); - Scalar wa(va.GetW()); - Scalar wb(vb.GetW()); - return Quat(Vector4(Cross(va, vb) + (va * wb) + (vb * wa), (wa * wb) - Dot(va, vb))); -} - -inline const Quat operator*(const Quat& a, const Scalar& s) -{ - return Quat(_mm_mul_ps(a.base, _mm_shuffle_ps(s.base, s.base, _MM_SHUFFLE(0, 0, 0, 0)))); -} - -inline const Quat operator*(const Scalar& s, const Quat& a) -{ - return Quat(_mm_mul_ps(a.base, _mm_shuffle_ps(s.base, s.base, _MM_SHUFFLE(0, 0, 0, 0)))); -} - -inline const Quat Inv(const Quat& a) -{ - return Quat(_mm_mul_ps(a.base, Vector4Base::Consts::kNeg111_1)); -} - -inline const Scalar Dot(const Quat& a, const Quat& b) -{ - return Scalar(Vector4Base::Dot4(a.base, b.base)); -} - -inline const Scalar Length(const Quat& a) -{ - return RsqrtNr(Dot(a, a)); -} - -inline const Quat Normalize(const Quat& a) -{ - return a * RsqrtNr(Dot(a, a)); -} - -inline const Scalar LengthFast(const Quat& a) -{ - return Rsqrt(Dot(a, a)); -} - -inline const Quat NormalizeFast(const Quat& a) -{ - return a * Rsqrt(Dot(a, a)); -} - -inline const Quat Lerp(const Quat& a, const Quat& b, const Scalar& t) -{ - Quat e; - - // go the shortest route - if (IsNegative(Dot(a, b))) - e = -b; - else - e = b; - - return Normalize(a + (e - a) * t); -} - -inline const Vector3 Quat::Rotate(const Vector3& v) const -{ - return Vector3(*this * Quat(v) * Inv(*this)); -} - -inline void Quat::GetAngleAxis(Vector3& axis, Scalar& angle) const -{ - float cosa = GetW(); - - angle = acosf(cosa); - angle += angle; // * 2; - - float sina = sqrtf(1.0f - cosa * cosa); - - // if ( fabs( sina ) < 0.0005 ) sina = 1; - - axis = RcpNr(sina) * Vector3(*this); -} diff --git a/Extras/obsolete/SATConvexCollision/Scalar.cpp b/Extras/obsolete/SATConvexCollision/Scalar.cpp deleted file mode 100644 index ddb5dda3f..000000000 --- a/Extras/obsolete/SATConvexCollision/Scalar.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Scalar.cpp -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifdef WIN32 -#if _MSC_VER >= 1310 - -#include "Scalar.h" - -const Scalar Scalar::Consts::MinusOne(-1.0f); -const Scalar Scalar::Consts::Zero(0.0f); -const Scalar Scalar::Consts::Half(0.5f); -const Scalar Scalar::Consts::One(1.0f); -const Scalar Scalar::Consts::Three(3.0f); - -const Scalar Scalar::Consts::MinValue(-3.402823466e+38f); -const Scalar Scalar::Consts::MaxValue(3.402823466e+38f); -const Scalar Scalar::Consts::Epsilon(1.192092896e-07f); - -const Scalar Scalar::Consts::PosInfinity(0x7f800000, true); -const Scalar Scalar::Consts::NegInfinity(0xff800000, true); - -const Scalar Scalar::Consts::AbsMask(0x7fffffff, true); - -#endif -#endif //WIN32 - diff --git a/Extras/obsolete/SATConvexCollision/Scalar.h b/Extras/obsolete/SATConvexCollision/Scalar.h deleted file mode 100644 index 3ad287630..000000000 --- a/Extras/obsolete/SATConvexCollision/Scalar.h +++ /dev/null @@ -1,106 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Scalar.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifndef BULLET_SCALAR_H -#define BULLET_SCALAR_H - - -#include -#include "Memory2.h" - -// resolved overload found with Koenig lookup -#pragma warning (disable : 4675) - - -__declspec(align(16)) class Scalar -{ -public: - BULLET_ALIGNED_NEW_AND_DELETE - - __m128 base; - - // constants - struct Consts{ - static const Scalar - MinusOne, - Zero, - Half, - One, - Three, - MinValue, - MaxValue, - Epsilon, - NegInfinity, - PosInfinity, - AbsMask; - }; - - // constructors - Scalar(); - Scalar(float f); - Scalar(int i, bool forceNoConvert); - - // explicit constructors - explicit Scalar(__m128 s); - explicit Scalar(int i); - - // assignment - const Scalar& operator=(const Scalar& a); - - // conversion - operator const float() const; - operator const float(); - - // in place operations - void operator+=(const Scalar& b); - void operator-=(const Scalar& b); - void operator*=(const Scalar& b); - void operator/=(const Scalar& b); - - // operations - friend const Scalar operator-(const Scalar& a); - - friend const Scalar operator+(const Scalar& a, const Scalar& b); - friend const Scalar operator-(const Scalar& a, const Scalar& b); - friend const Scalar operator*(const Scalar& a, const Scalar& b); - friend const Scalar operator/(const Scalar& a, const Scalar& b); - - friend const Scalar Abs(const Scalar& a); - friend const Scalar Rcp(const Scalar& a); - friend const Scalar Rsqrt(const Scalar& a); - friend const Scalar Sqrt(const Scalar& a); - friend const Scalar RcpNr(const Scalar& a); - friend const Scalar RsqrtNr(const Scalar& a); - - friend const Scalar Min(const Scalar& a, const Scalar& b); - friend const Scalar Max(const Scalar& a, const Scalar& b); - friend const Scalar Clamp(const Scalar& a, const Scalar& min, const Scalar& max); - - friend const Scalar Lerp(const Scalar& a, const Scalar& b, const Scalar& t); - - // comparison - friend const int IsNegative(const Scalar& a); - - friend const int IsNan(const Scalar& a); - friend const int IsInfinity(const Scalar& a); - friend const int IsPosInfinity(const Scalar& a); - friend const int IsNegInfinity(const Scalar& a); -}; - - -#include "Scalar.inl" - -#endif //BULLET_SCALAR_H diff --git a/Extras/obsolete/SATConvexCollision/Scalar.inl b/Extras/obsolete/SATConvexCollision/Scalar.inl deleted file mode 100644 index 5d7995d5d..000000000 --- a/Extras/obsolete/SATConvexCollision/Scalar.inl +++ /dev/null @@ -1,196 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// Scalar.inl -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#pragma once - - -inline Scalar::Scalar() -{ -} - -inline Scalar::Scalar(float f) -{ - base = _mm_set1_ps(f); -} - - -inline Scalar::Scalar(int i, bool forceNoConvert) -{ - __declspec(align(16)) int iv[4] = {i, i, i, i}; - *(Scalar*)&base = *(Scalar*)&iv; -} - -inline Scalar::Scalar(__m128 s) -{ - base = s; -} - -inline Scalar::Scalar(int i) -{ - base = _mm_cvtsi32_ss(base, i); - base = _mm_shuffle_ps(base, base, _MM_SHUFFLE(0, 0, 0, 0)); -} - -inline const Scalar& Scalar::operator=(const Scalar &a) -{ - base = a.base; - return *this; -} - -inline Scalar::operator const float() const -{ - float f; - _mm_store_ss(&f, base); - return f; -} - -inline Scalar::operator const float() -{ - float f; - _mm_store_ss(&f, base); - return f; -} - -inline void Scalar::operator+=(const Scalar& b) -{ - base = _mm_add_ps(base, b.base); -} - -inline void Scalar::operator-=(const Scalar& b) -{ - base = _mm_sub_ps(base, b.base); -} - -inline void Scalar::operator*=(const Scalar& b) -{ - base = _mm_mul_ps(base, b.base); -} - -inline void Scalar::operator/=(const Scalar& b) -{ - base = _mm_div_ps(base, b.base); -} - -inline const Scalar operator-(const Scalar& a) -{ - return Scalar(_mm_sub_ps(_mm_setzero_ps(), a.base)); -} - -inline const Scalar Abs(const Scalar& a) -{ - return Scalar(_mm_and_ps(a.base, Scalar::Consts::AbsMask.base)); -} - -inline const Scalar Rcp(const Scalar& a) -{ - return Scalar(_mm_rcp_ps(a.base)); -} - -inline const Scalar Rsqrt(const Scalar& a) -{ - return Scalar(_mm_rsqrt_ps(a.base)); -} - -inline const Scalar Sqrt(const Scalar& a) -{ - return Scalar(_mm_sqrt_ps(a.base)); -} - -// Newton Raphson Reciprocal -// (2 * Rcp(x)) - (x * Rcp(x) * Rcp(x))] -inline const Scalar RcpNr(const Scalar& a) -{ - Scalar rcp = Rcp(a); - return (rcp + rcp) - (a * rcp * rcp); -} - -// Newton Raphson Reciprocal Square Root -// 0.5 * Rsqrt * (3 - x * Rsqrt(x) * Rsqrt(x)) -inline const Scalar RsqrtNr(const Scalar& a) -{ - Scalar rcp = Rsqrt(a); - return (Scalar::Consts::Half * rcp) * (Scalar::Consts::Three - (a * rcp) * rcp); -} - -// binary -inline const Scalar operator+(const Scalar& a, const Scalar& b) -{ - return Scalar(_mm_add_ps(a.base, b.base)); -} - -inline const Scalar operator-(const Scalar& a, const Scalar& b) -{ - return Scalar(_mm_sub_ps(a.base, b.base)); -} - -inline const Scalar operator*(const Scalar& a, const Scalar& b) -{ - return Scalar(_mm_mul_ps(a.base, b.base)); -} - -inline const Scalar operator/(const Scalar& a, const Scalar& b) -{ - return Scalar(_mm_div_ps(a.base, b.base)); -} - -inline const Scalar Min(const Scalar& a, const Scalar& b) -{ - return Scalar(_mm_min_ps(a.base, b.base)); -} - -inline const Scalar Max(const Scalar& a, const Scalar& b) -{ - return Scalar(_mm_max_ps(a.base, b.base)); -} - -inline const Scalar Clamp(const Scalar& a, const Scalar& min, const Scalar& max) -{ - return Scalar(_mm_min_ps(max.base, _mm_max_ps(min.base, a.base))); -} - -inline const Scalar Lerp(const Scalar& a, const Scalar& b, const Scalar& t) -{ - return Scalar(a + (b - a) * t); -} - -inline const int IsNegative(const Scalar& a) -{ - return _mm_movemask_ps(a.base) & 1; -} - -// warning. this only checks for quiet nan -inline const int IsNan(const Scalar& a) -{ - int aInt = *(int*)&a; - return ((aInt & 0x7fc00000) == 0x7fc00000); -} - -inline const int IsInfinity(const Scalar& a) -{ - return (a == Scalar::Consts::PosInfinity || a == Scalar::Consts::NegInfinity); -} - -inline const int IsPosInfinity(const Scalar& a) -{ - return (a == Scalar::Consts::PosInfinity); -} - -inline const int IsNegInfinity(const Scalar& a) -{ - return (a == Scalar::Consts::NegInfinity); -} - diff --git a/Extras/obsolete/SATConvexCollision/Shape.cpp b/Extras/obsolete/SATConvexCollision/Shape.cpp deleted file mode 100644 index 54cb6ad6d..000000000 --- a/Extras/obsolete/SATConvexCollision/Shape.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// Shape.cpp -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. - - -#ifdef WIN32 -#if _MSC_VER >= 1310 - -#include "shape.h" - -Shape::Shape() -{ -} - -Shape::~Shape() -{ -} - -#endif -#endif //WIN32 diff --git a/Extras/obsolete/SATConvexCollision/Shape.h b/Extras/obsolete/SATConvexCollision/Shape.h deleted file mode 100644 index e63150d76..000000000 --- a/Extras/obsolete/SATConvexCollision/Shape.h +++ /dev/null @@ -1,67 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// Shape.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -// Shape.h -// -#ifndef BULLET_SHAPE_H -#define BULLET_SHAPE_H - -#include "Maths.h" - - - - -struct btSeparation -{ - - short m_featureA; - short m_featureB; - float m_dist; - Vector3 m_axis; // in world space - - // separators - enum - { - kFeatureNone, // not separated - kFeatureA, - kFeatureB, - kFeatureBoth - }; - short m_separator; - - // contact between the 2 bodies (-1 if none) - short m_contact; -}; - -///Shape provides a interface for Hull class (convex hull calculation). -class Shape -{ -public: - Shape(); - virtual ~Shape(); - - //virtual void ComputeInertia(Point3& centerOfMass, Matrix33& inertia, float totalMass) const = 0; - virtual void ComputeInertia(const Transform& transform, Point3& centerOfMass, Matrix33& inertia, float totalMass) const = 0; - - - virtual Bounds3 ComputeBounds(const Transform& transform) const = 0; -}; - - - -#endif //BULLET_SHAPE_H diff --git a/Extras/obsolete/SATConvexCollision/Vector.cpp b/Extras/obsolete/SATConvexCollision/Vector.cpp deleted file mode 100644 index 29505d857..000000000 --- a/Extras/obsolete/SATConvexCollision/Vector.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// Vector.cpp -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifdef WIN32 -#if _MSC_VER >= 1310 -#include "Vector.h" -#include - -//////////////////////////////////////////////////////////////////////////////// -// Vector3 - -bool Vector3::IsFinite() const -{ - if (_finite(GetX()) && _finite(GetY()) && _finite(GetZ())) - return true; - return false; -} - - -//////////////////////////////////////////////////////////////////////////////// -// Point3 - -bool Point3::IsFinite() const -{ - if (_finite(GetX()) && _finite(GetY()) && _finite(GetZ())) - return true; - return false; -} - - -//////////////////////////////////////////////////////////////////////////////// -// Vector4 -bool Vector4::IsFinite() const -{ - if (_finite(GetX()) && _finite(GetY()) && _finite(GetZ()) && _finite(GetW())) - return true; - return false; -} - -#endif -#endif //WIN32 diff --git a/Extras/obsolete/SATConvexCollision/Vector.h b/Extras/obsolete/SATConvexCollision/Vector.h deleted file mode 100644 index 9b2b289f1..000000000 --- a/Extras/obsolete/SATConvexCollision/Vector.h +++ /dev/null @@ -1,349 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// Vector.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifndef BULLET_VECTOR_H -#define BULLET_VECTOR_H - -#include "VectorBase.h" - -class Point3; -class Vector4; - -//////////////////////////////////////////////////////////////////////////////// -// Vector3 -__declspec(align(16)) class Vector3 : public Vector4Base -{ -public: - BULLET_ALIGNED_NEW_AND_DELETE - - // constructors - Vector3(); - Vector3(const Vector3& v); - Vector3(float x, float y, float z); - Vector3(const Scalar& x, const Scalar& y, const Scalar& z); - - // construction to constant - Vector3(const Maths::ZeroTag&); - Vector3(const Maths::UnitXTag&); - Vector3(const Maths::UnitYTag&); - Vector3(const Maths::UnitZTag&); - Vector3(const Maths::UnitNegXTag&); - Vector3(const Maths::UnitNegYTag&); - Vector3(const Maths::UnitNegZTag&); - - // explicit constructors - explicit Vector3(const __m128 b); - explicit Vector3(const Vector4Base& v); - explicit Vector3(const Scalar& v); - explicit Vector3(const Point3& v); - explicit Vector3(const Vector4& v); - explicit Vector3(const float* p); - - // assignment - const Vector3& operator=(const Vector3& v); - - // assignment to constant - const Vector3& operator=(const Maths::ZeroTag&); - const Vector3& operator=(const Maths::UnitXTag&); - const Vector3& operator=(const Maths::UnitYTag&); - const Vector3& operator=(const Maths::UnitZTag&); - const Vector3& operator=(const Maths::UnitNegXTag&); - const Vector3& operator=(const Maths::UnitNegYTag&); - const Vector3& operator=(const Maths::UnitNegZTag&); - - // in place operations - void operator+=(const Vector3& b); - void operator-=(const Vector3& b); - void operator*=(const Vector3& b); - void operator/=(const Vector3& b); - void operator*=(const Scalar& s); - void operator/=(const Scalar& s); - - // operations - friend const Vector3 operator-(const Vector3& a); - - friend const Vector3 operator+(const Vector3& a, const Vector3& b); - friend const Vector3 operator-(const Vector3& a, const Vector3& b); - friend const Vector3 operator*(const Vector3& a, const Vector3& b); - friend const Vector3 operator/(const Vector3& a, const Vector3& b); - friend const Vector3 operator*(const Vector3& a, const Scalar& s); - friend const Vector3 operator*(const Scalar& s, const Vector3& a); - friend const Vector3 operator/(const Vector3& a, const Scalar& s); - - friend const Vector3 Abs(const Vector3& a); - friend const Vector3 Rcp(const Vector3& a); - friend const Vector3 Rsqrt(const Vector3& a); - friend const Vector3 Sqrt(const Vector3& a); - friend const Vector3 RcpNr(const Vector3& a); - friend const Vector3 RsqrtNr(const Vector3& a); - - friend const Scalar Sum(const Vector3& a); - friend const Scalar Dot(const Vector3& a, const Vector3& b); - - friend const Vector3 Cross(const Vector3& a, const Vector3& b); - - friend const Vector3 Min(const Vector3& a, const Vector3& b); - friend const Vector3 Max(const Vector3& a, const Vector3& b); - friend const Vector3 Clamp(const Vector3& v, const Vector3& min, const Vector3& max); - - friend const Scalar MinComp(const Vector3& a); - friend const Scalar MaxComp(const Vector3& a); - friend const int MinCompIndex(const Vector3& a); - friend const int MaxCompIndex(const Vector3& a); - - friend const Scalar Length(const Vector3& a); - friend const Scalar LengthSqr(const Vector3& a); - friend const Scalar LengthRcp(const Vector3& a); - friend const Vector3 Normalize(const Vector3& a); - - friend const Scalar LengthFast(const Vector3& a); - friend const Scalar LengthRcpFast(const Vector3& a); - friend const Vector3 NormalizeFast(const Vector3& a); - - friend const Vector3 Lerp(const Vector3& a, const Vector3& b, const Scalar& t); - - // returns an arbitrary perpendicular vector (not normalized) - friend const Vector3 Perp(const Vector3& v); - - // comparisons (return 1 bit per component) - friend int operator==(const Vector3& a, const Vector3& b); - friend int operator!=(const Vector3& a, const Vector3& b); - friend int operator<(const Vector3& a, const Vector3& b); - friend int operator<=(const Vector3& a, const Vector3& b); - friend int operator>(const Vector3& a, const Vector3& b); - friend int operator>=(const Vector3& a, const Vector3& b); - - // validation - bool IsFinite() const; -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Point3 -__declspec(align(16)) class Point3 : public Vector4Base -{ -public: - // constructors - Point3(); - Point3(const Point3& v); - Point3(float x, float y, float z); - Point3(const Scalar& x, const Scalar& y, const Scalar& z); - - // construction to constant - Point3(const Maths::ZeroTag&); - Point3(const Maths::UnitXTag&); - Point3(const Maths::UnitYTag&); - Point3(const Maths::UnitZTag&); - Point3(const Maths::UnitNegXTag&); - Point3(const Maths::UnitNegYTag&); - Point3(const Maths::UnitNegZTag&); - - // explicit constructors - explicit Point3(const __m128 b); - explicit Point3(const Vector4Base& v); - explicit Point3(const Scalar& v); - explicit Point3(const Vector3& v); - explicit Point3(const Vector4& v); - explicit Point3(const float* p); - - // assignment - const Point3& operator=(const Point3& v); - - // assignment to constant - const Point3& operator=(const Maths::ZeroTag&); - const Point3& operator=(const Maths::UnitXTag&); - const Point3& operator=(const Maths::UnitYTag&); - const Point3& operator=(const Maths::UnitZTag&); - const Point3& operator=(const Maths::UnitNegXTag&); - const Point3& operator=(const Maths::UnitNegYTag&); - const Point3& operator=(const Maths::UnitNegZTag&); - - // in place operations - void operator+=(const Vector3& b); - void operator-=(const Vector3& b); - - // operations - friend const Point3 operator-(const Point3& a); - - friend const Point3 operator+(const Point3& a, const Vector3& b); - friend const Point3 operator+(const Vector3& a, const Point3& b); - - friend const Point3 operator-(const Point3& a, const Vector3& b); - friend const Vector3 operator-(const Point3& a, const Point3& b); - - friend const Vector3 operator*(const Point3& a, const Vector3& b); - friend const Vector3 operator*(const Vector3& a, const Point3& b); - - friend const Point3 Abs(const Point3& a); - - friend const Scalar Sum(const Point3& a); - friend const Scalar Dot(const Point3& a, const Point3& b); - friend const Scalar Dot(const Vector3& a, const Point3& b); - friend const Scalar Dot(const Point3& a, const Vector3& b); - - friend const Point3 Min(const Point3& a, const Point3& b); - friend const Point3 Max(const Point3& a, const Point3& b); - friend const Point3 Clamp(const Point3& v, const Point3& min, const Point3& max); - - friend const Scalar Dist(const Point3& a, const Point3& b); - friend const Scalar DistSqr(const Point3& a, const Point3& b); - friend const Scalar DistRcp(const Point3& a, const Point3& b); - - friend const Scalar DistFast(const Point3& a, const Point3& b); - friend const Scalar DistRcpFast(const Point3& a, const Point3& b); - - friend const Point3 Lerp(const Point3& a, const Point3& b, const Scalar& t); - - friend const Point3 Homogenize(const Vector4& v); - friend const Point3 HomogenizeFast(const Vector4& v); - - // comparisons (return 1 bit per component) - friend int operator==(const Point3& a, const Point3& b); - friend int operator!=(const Point3& a, const Point3& b); - friend int operator<(const Point3& a, const Point3& b); - friend int operator<=(const Point3& a, const Point3& b); - friend int operator>(const Point3& a, const Point3& b); - friend int operator>=(const Point3& a, const Point3& b); - - // validation - bool IsFinite() const; -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Vector4 -__declspec(align(16)) class Vector4 : public Vector4Base -{ -public: - // constructors - Vector4(); - Vector4(const Vector4& v); - Vector4(float x, float y, float z, float w); - Vector4(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w); - Vector4(const Vector3& xyz, const Scalar& w); - - // construction to constant - Vector4(const Maths::ZeroTag&); - Vector4(const Maths::UnitXTag&); - Vector4(const Maths::UnitYTag&); - Vector4(const Maths::UnitZTag&); - Vector4(const Maths::UnitWTag&); - Vector4(const Maths::UnitNegXTag&); - Vector4(const Maths::UnitNegYTag&); - Vector4(const Maths::UnitNegZTag&); - Vector4(const Maths::UnitNegWTag&); - - // explicit constructors - explicit Vector4(const __m128 b); - explicit Vector4(const Vector4Base& v); - explicit Vector4(const Scalar& v); - explicit Vector4(const Vector3& v); - explicit Vector4(const Point3& v); - explicit Vector4(const float* p); - - // assignment - const Vector4& operator=(const Vector4& v); - - // assignment to constant - const Vector4& operator=(const Maths::ZeroTag&); - const Vector4& operator=(const Maths::UnitXTag&); - const Vector4& operator=(const Maths::UnitYTag&); - const Vector4& operator=(const Maths::UnitZTag&); - const Vector4& operator=(const Maths::UnitWTag&); - const Vector4& operator=(const Maths::UnitNegXTag&); - const Vector4& operator=(const Maths::UnitNegYTag&); - const Vector4& operator=(const Maths::UnitNegZTag&); - const Vector4& operator=(const Maths::UnitNegWTag&); - - // in place operations - void operator+=(const Vector4& b); - void operator-=(const Vector4& b); - void operator*=(const Vector4& b); - void operator/=(const Vector4& b); - void operator*=(const Scalar& s); - void operator/=(const Scalar& s); - - // operations - friend const Vector4 operator-(const Vector4& a); - - friend const Vector4 operator+(const Vector4& a, const Vector4& b); - friend const Vector4 operator-(const Vector4& a, const Vector4& b); - friend const Vector4 operator*(const Vector4& a, const Vector4& b); - friend const Vector4 operator/(const Vector4& a, const Vector4& b); - friend const Vector4 operator*(const Vector4& a, const Scalar& s); - friend const Vector4 operator*(const Scalar& s, const Vector4& a); - friend const Vector4 operator/(const Vector4& a, const Scalar& s); - - friend const Vector4 Abs(const Vector4& a); - friend const Vector4 Rcp(const Vector4& a); - friend const Vector4 Rsqrt(const Vector4& a); - friend const Vector4 Sqrt(const Vector4& a); - friend const Vector4 RcpNr(const Vector4& a); - friend const Vector4 RsqrtNr(const Vector4& a); - - friend const Scalar Sum(const Vector4& a); - friend const Scalar Dot(const Vector4& a, const Vector4& b); - - friend const Vector4 Min(const Vector4& a, const Vector4& b); - friend const Vector4 Max(const Vector4& a, const Vector4& b); - friend const Vector4 Clamp(const Vector4& v, const Vector4& min, const Vector4& max); - - friend const Scalar MinComp(const Vector4& a); - friend const Scalar MaxComp(const Vector4& a); - - friend const Scalar Length(const Vector4& a); - friend const Scalar LengthSqr(const Vector4& a); - friend const Scalar LengthRcp(const Vector4& a); - friend const Vector4 Normalize(const Vector4& a); - - friend const Scalar LengthFast(const Vector4& a); - friend const Scalar LengthRcpFast(const Vector4& a); - friend const Vector4 NormalizeFast(const Vector4& a); - - friend const Vector4 Lerp(const Vector4& a, const Vector4& b, const Scalar& t); - - // comparisons (return 1 bit per component) - friend int operator==(const Vector4& a, const Vector4& b); - friend int operator!=(const Vector4& a, const Vector4& b); - friend int operator<(const Vector4& a, const Vector4& b); - friend int operator<=(const Vector4& a, const Vector4& b); - friend int operator>(const Vector4& a, const Vector4& b); - friend int operator>=(const Vector4& a, const Vector4& b); - - // validation - bool IsFinite() const; -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Vector2 -class Vector2 : public Vector2Base -{ -public: -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Point2 -class Point2 : public Vector2Base -{ -public: - -}; - - -#include "Vector.inl" -#endif //BULLET_VECTOR_H diff --git a/Extras/obsolete/SATConvexCollision/Vector.inl b/Extras/obsolete/SATConvexCollision/Vector.inl deleted file mode 100644 index f0bdd6f9e..000000000 --- a/Extras/obsolete/SATConvexCollision/Vector.inl +++ /dev/null @@ -1,1110 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// Vector.inl -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#pragma once - - -//////////////////////////////////////////////////////////////////////////////// -// Vector3 - -inline Vector3::Vector3() -{ -} - -inline Vector3::Vector3(const Vector3& v) -{ - base = v.base; -} - -inline Vector3::Vector3(float x, float y, float z) -{ - base = _mm_setr_ps(x, y, z, z); -} - -inline Vector3::Vector3(const Scalar& x, const Scalar& y, const Scalar& z) -{ - __m128 xy = _mm_unpacklo_ps(x.base, y.base); - base = _mm_shuffle_ps(xy, z.base, _MM_SHUFFLE(1, 0, 1, 0)); -} - -inline Vector3::Vector3(const Maths::ZeroTag&) -{ - base = _mm_setzero_ps(); -} - -inline Vector3::Vector3(const Maths::UnitXTag&) -{ - base = Vector4Base::Consts::k1000; -} - -inline Vector3::Vector3(const Maths::UnitYTag&) -{ - base = Vector4Base::Consts::k0100; -} - -inline Vector3::Vector3(const Maths::UnitZTag&) -{ - base = Vector4Base::Consts::k0010; -} - -inline Vector3::Vector3(const Maths::UnitNegXTag&) -{ - base = Vector4Base::Consts::kNeg1000; -} - -inline Vector3::Vector3(const Maths::UnitNegYTag&) -{ - base = Vector4Base::Consts::kNeg0100; -} - -inline Vector3::Vector3(const Maths::UnitNegZTag&) -{ - base = Vector4Base::Consts::kNeg0010; -} - -inline Vector3::Vector3(const Vector4Base& v) -{ - base = v.base; -} - -inline Vector3::Vector3(const __m128 b) -{ - base = b; -} - -inline Vector3::Vector3(const Scalar& v) -{ - base = v.base; -} - -inline Vector3::Vector3(const Point3& v) -{ - base = v.base; -} - -inline Vector3::Vector3(const Vector4& v) -{ - base = v.base; -} - -inline Vector3::Vector3(const float* p) -{ - base = _mm_load_ps(p); -} - -inline const Vector3& Vector3::operator=(const Vector3& v) -{ - base = v.base; - return *this; -} - -inline const Vector3& Vector3::operator=(const Maths::ZeroTag&) -{ - base = _mm_setzero_ps(); - return *this; -} - -inline const Vector3& Vector3::operator=(const Maths::UnitXTag&) -{ - base = Vector4Base::Consts::k1000; - return *this; -} - -inline const Vector3& Vector3::operator=(const Maths::UnitYTag&) -{ - base = Vector4Base::Consts::k0100; - return *this; -} - -inline const Vector3& Vector3::operator=(const Maths::UnitZTag&) -{ - base = Vector4Base::Consts::k0010; - return *this; -} - -inline const Vector3& Vector3::operator=(const Maths::UnitNegXTag&) -{ - base = Vector4Base::Consts::kNeg1000; - return *this; -} - -inline const Vector3& Vector3::operator=(const Maths::UnitNegYTag&) -{ - base = Vector4Base::Consts::kNeg0100; - return *this; -} - -inline const Vector3& Vector3::operator=(const Maths::UnitNegZTag&) -{ - base = Vector4Base::Consts::kNeg0010; - return *this; -} - -inline void Vector3::operator+=(const Vector3& b) -{ - base = _mm_add_ps(base, b.base); -} - -inline void Vector3::operator-=(const Vector3& b) -{ - base = _mm_sub_ps(base, b.base); -} - -inline void Vector3::operator*=(const Vector3& b) -{ - base = _mm_mul_ps(base, b.base); -} - -inline void Vector3::operator/=(const Vector3& b) -{ - base = _mm_div_ps(base, b.base); -} - -inline void Vector3::operator*=(const Scalar& s) -{ - base = _mm_mul_ps(base, s.base); -} - -inline void Vector3::operator/=(const Scalar& s) -{ - base = _mm_div_ps(base, s.base); -} - -inline const Vector3 operator-(const Vector3& a) -{ - return Vector3(_mm_sub_ps(_mm_setzero_ps(), a.base)); -} - -inline const Vector3 operator+(const Vector3& a, const Vector3& b) -{ - return Vector3(_mm_add_ps(a.base, b.base)); -} - -inline const Vector3 operator-(const Vector3& a, const Vector3& b) -{ - return Vector3(_mm_sub_ps(a.base, b.base)); -} - -inline const Vector3 operator*(const Vector3& a, const Vector3& b) -{ - return Vector3(_mm_mul_ps(a.base, b.base)); -} - -inline const Vector3 operator/(const Vector3& a, const Vector3& b) -{ - return Vector3(_mm_div_ps(a.base, b.base)); -} - -inline const Vector3 operator*(const Vector3& a, const Scalar& s) -{ - return Vector3(_mm_mul_ps(a.base, s.base)); -} - -inline const Vector3 operator*(const Scalar& s, const Vector3& a) -{ - return Vector3(_mm_mul_ps(a.base, s.base)); -} - -inline const Vector3 operator/(const Vector3& a, const Scalar& s) -{ - return Vector3(_mm_div_ps(a.base, s.base)); -} - - -inline const Vector3 SplatX(const Vector3& v) -{ - return Vector3(_mm_shuffle_ps(v.base, v.base, _MM_SHUFFLE(3, 0, 0, 0))); -} - -inline const Vector3 SplatY(const Vector3& v) -{ - return Vector3(_mm_shuffle_ps(v.base, v.base, _MM_SHUFFLE(3, 1, 1, 1))); -} - -inline const Vector3 SplatZ(const Vector3& v) -{ - return Vector3(_mm_shuffle_ps(v.base, v.base, _MM_SHUFFLE(3, 2, 2, 2))); -} - -inline const Vector3 Abs(const Vector3& a) -{ - return Vector3(_mm_and_ps(a.base, Vector4Base::Consts::kMaskAbs)); -} - -inline const Vector3 Rcp(const Vector3& a) -{ - return Vector3(_mm_rcp_ps(a.base)); -} - -inline const Vector3 Rsqrt(const Vector3& a) -{ - return Vector3(_mm_rsqrt_ps(a.base)); -} - -inline const Vector3 Sqrt(const Vector3& a) -{ - return Vector3(_mm_sqrt_ps(a.base)); -} - -inline const Vector3 RcpNr(const Vector3& a) -{ - Vector3 rcp = Rcp(a); - return (rcp + rcp) - (a * rcp * rcp); -} - -inline const Vector3 RsqrtNr(const Vector3& a) -{ - Vector3 rcp = Rsqrt(a); - return (Vector3(Vector4Base::Consts::kHalf) * rcp) * (Vector3(Vector4Base::Consts::kThree) - (a * rcp) * rcp); -} - -inline const Scalar Sum(const Vector3& a) -{ - return Scalar(Vector4Base::Sum3(a.base)); -} - -inline const Scalar Dot(const Vector3& a, const Vector3& b) -{ - return Scalar(Vector4Base::Dot3(a.base, b.base)); -} - -inline const Vector3 Cross(const Vector3& a, const Vector3& b) -{ - __m128 va = a.base; - __m128 vb = b.base; - __m128 v0yzx = _mm_shuffle_ps(va, va, _MM_SHUFFLE(3, 0, 2, 1)); - __m128 v1zxy = _mm_shuffle_ps(vb, vb, _MM_SHUFFLE(3, 1, 0, 2)); - __m128 v0zxy = _mm_shuffle_ps(va, va, _MM_SHUFFLE(3, 1, 0, 2)); - __m128 v1yzx = _mm_shuffle_ps(vb, vb, _MM_SHUFFLE(3, 0, 2, 1)); - return Vector3(_mm_sub_ps(_mm_mul_ps(v0yzx, v1zxy), _mm_mul_ps(v0zxy, v1yzx))); -} - -inline const Vector3 Min(const Vector3& a, const Vector3& b) -{ - return Vector3(_mm_min_ps(a.base, b.base)); -} - -inline const Vector3 Max(const Vector3& a, const Vector3& b) -{ - return Vector3(_mm_max_ps(a.base, b.base)); -} - -inline const Vector3 Clamp(const Vector3& v, const Vector3& min, const Vector3& max) -{ - return Vector3(_mm_min_ps(max.base, _mm_max_ps(min.base, v.base))); -} - -inline const Scalar MinComp(const Vector3& a) -{ - return Scalar(Vector4Base::MinComp3(a.base)); -} - -inline const Scalar MaxComp(const Vector3& a) -{ - return Scalar(Vector4Base::MaxComp3(a.base)); -} - -inline const int MinCompIndex(const Vector3& a) -{ - int index = 0; - - if (a[2] < a[1]) - { - if (a[2] < a[0]) - index = 2; - } - else if (a[1] < a[0]) - index = 1; - - return index; -} - -inline const int MaxCompIndex(const Vector3& a) -{ - int index = 0; - - if (a[2] > a[1]) - { - if (a[2] > a[0]) - index = 2; - } - else if (a[1] > a[0]) - index = 1; - - return index; -} - - -inline const Scalar Length(const Vector3& a) -{ - return Sqrt(Dot(a, a)); -} - -inline const Scalar LengthSqr(const Vector3& a) -{ - return Dot(a, a); -} - -inline const Scalar LengthRcp(const Vector3& a) -{ - return RsqrtNr(Dot(a, a)); -} - -inline const Vector3 Normalize(const Vector3& a) -{ - return RsqrtNr(Dot(a, a)) * a; -} - -inline const Vector3 Lerp(const Vector3& a, const Vector3& b, const Scalar& t) -{ - return a + (b - a) * t; -} - -inline const Vector3 Perp(const Vector3& v) -{ - Vector3 vtmp; - if ((float)Abs(v[1]) < 0.707f) - vtmp = Vector3(0.0f, 1.0f, 0.0f); - else - vtmp = Vector3(1.0f, 0.0f, 0.0f); - return Cross(v, vtmp); -} - - -inline const Scalar LengthFast(const Vector3& a) -{ - return Rcp(Rsqrt(Dot(a, a))); -} - -inline const Scalar LengthRcpFast(const Vector3& a) -{ - return Rsqrt(Dot(a, a)); -} - -inline const Vector3 NormalizeFast(const Vector3& a) -{ - return Rsqrt(Dot(a, a)) * a; -} - -// comparisons return 1 bit per element -inline int operator==(const Vector3& a, const Vector3& b) -{ - return (_mm_movemask_ps(_mm_cmpeq_ps(a.base, b.base)) & 7); -} - -inline int operator!=(const Vector3& a, const Vector3& b) -{ - return (_mm_movemask_ps(_mm_cmpneq_ps(a.base, b.base)) & 7); -} - -inline int operator<(const Vector3& a, const Vector3& b) -{ - return (_mm_movemask_ps(_mm_cmplt_ps(a.base, b.base)) & 7); -} - -inline int operator<=(const Vector3& a, const Vector3& b) -{ - return (_mm_movemask_ps(_mm_cmple_ps(a.base, b.base)) & 7); -} - -inline int operator>(const Vector3& a, const Vector3& b) -{ - return (_mm_movemask_ps(_mm_cmpgt_ps(a.base, b.base)) & 7); -} - -inline int operator>=(const Vector3& a, const Vector3& b) -{ - return (_mm_movemask_ps(_mm_cmpge_ps(a.base, b.base)) & 7); -} - -//////////////////////////////////////////////////////////////////////////////// -// Point3 - -inline Point3::Point3() -{ -} - -inline Point3::Point3(const Point3& v) -{ - base = v.base; -} - -inline Point3::Point3(float x, float y, float z) -{ - base = _mm_setr_ps(x, y, z, 1.f); -} - -inline Point3::Point3(const Scalar& x, const Scalar& y, const Scalar& z) -{ - __m128 xy = _mm_unpacklo_ps(x.base, y.base); - base = _mm_shuffle_ps(xy, z.base, _MM_SHUFFLE(1, 0, 1, 0)); -} - -inline Point3::Point3(const Maths::ZeroTag&) -{ - base = _mm_setzero_ps(); -} - -inline Point3::Point3(const Maths::UnitXTag&) -{ - base = Vector4Base::Consts::k1000; -} - -inline Point3::Point3(const Maths::UnitYTag&) -{ - base = Vector4Base::Consts::k0100; -} - -inline Point3::Point3(const Maths::UnitZTag&) -{ - base = Vector4Base::Consts::k0010; -} - -inline Point3::Point3(const Maths::UnitNegXTag&) -{ - base = Vector4Base::Consts::kNeg1000; -} - -inline Point3::Point3(const Maths::UnitNegYTag&) -{ - base = Vector4Base::Consts::kNeg0100; -} - -inline Point3::Point3(const Maths::UnitNegZTag&) -{ - base = Vector4Base::Consts::kNeg0010; -} - -inline Point3::Point3(const Vector4Base& v) -{ - base = v.base; -} - -inline Point3::Point3(const __m128 b) -{ - base = b; -} - -inline Point3::Point3(const Scalar& v) -{ - base = v.base; -} - -inline Point3::Point3(const Vector3& v) -{ - base = v.base; -} - -inline Point3::Point3(const Vector4& v) -{ - base = v.base; -} - -inline Point3::Point3(const float* p) -{ - base = _mm_load_ps(p); -} - -inline const Point3& Point3::operator=(const Point3& v) -{ - base = v.base; - return *this; -} - -inline const Point3& Point3::operator=(const Maths::ZeroTag&) -{ - base = _mm_setzero_ps(); - return *this; -} - -inline const Point3& Point3::operator=(const Maths::UnitXTag&) -{ - base = Vector4Base::Consts::k1000; - return *this; -} - -inline const Point3& Point3::operator=(const Maths::UnitYTag&) -{ - base = Vector4Base::Consts::k0100; - return *this; -} - -inline const Point3& Point3::operator=(const Maths::UnitZTag&) -{ - base = Vector4Base::Consts::k0010; - return *this; -} - -inline const Point3& Point3::operator=(const Maths::UnitNegXTag&) -{ - base = Vector4Base::Consts::kNeg1000; - return *this; -} - -inline const Point3& Point3::operator=(const Maths::UnitNegYTag&) -{ - base = Vector4Base::Consts::kNeg0100; - return *this; -} - -inline const Point3& Point3::operator=(const Maths::UnitNegZTag&) -{ - base = Vector4Base::Consts::kNeg0010; - return *this; -} - -inline void Point3::operator+=(const Vector3& b) -{ - base = _mm_add_ps(base, b.base); -} - -inline void Point3::operator-=(const Vector3& b) -{ - base = _mm_sub_ps(base, b.base); -} - -inline const Point3 operator-(const Point3& a) -{ - return Point3(_mm_sub_ps(_mm_setzero_ps(), a.base)); -} - -inline const Point3 operator+(const Point3& a, const Vector3& b) -{ - return Point3(_mm_add_ps(a.base, b.base)); -} - -inline const Point3 operator+(const Vector3& a, const Point3& b) -{ - return Point3(_mm_add_ps(a.base, b.base)); -} - -inline const Point3 operator-(const Point3& a, const Vector3& b) -{ - return Point3(_mm_sub_ps(a.base, b.base)); -} - -inline const Vector3 operator-(const Point3& a, const Point3& b) -{ - return Vector3(_mm_sub_ps(a.base, b.base)); -} - -inline const Vector3 operator*(const Point3& a, const Vector3& b) -{ - return Vector3(_mm_mul_ps(a.base, b.base)); -} - -inline const Vector3 operator*(const Vector3& a, const Point3& b) -{ - return Vector3(_mm_mul_ps(a.base, b.base)); -} - -inline const Point3 SplatX(const Point3& v) -{ - return Point3(_mm_shuffle_ps(v.base, v.base, _MM_SHUFFLE(3, 0, 0, 0))); -} - -inline const Point3 SplatY(const Point3& v) -{ - return Point3(_mm_shuffle_ps(v.base, v.base, _MM_SHUFFLE(3, 1, 1, 1))); -} - -inline const Point3 SplatZ(const Point3& v) -{ - return Point3(_mm_shuffle_ps(v.base, v.base, _MM_SHUFFLE(3, 2, 2, 2))); -} - -inline const Point3 Abs(const Point3& a) -{ - return Point3(_mm_and_ps(a.base, Vector4Base::Consts::kMaskAbs)); -} - -inline const Scalar Sum(const Point3& a) -{ - return Scalar(Vector4Base::Sum3(a.base)); -} - -inline const Scalar Dot(const Point3& a, const Point3& b) -{ - return Scalar(Vector4Base::Dot3(a.base, b.base)); -} - -inline const Scalar Dot(const Vector3& a, const Point3& b) -{ - return Scalar(Vector4Base::Dot3(a.base, b.base)); -} - -inline const Scalar Dot(const Point3& a, const Vector3& b) -{ - return Scalar(Vector4Base::Dot3(a.base, b.base)); -} - -inline const Point3 Min(const Point3& a, const Point3& b) -{ - return Point3(_mm_min_ps(a.base, b.base)); -} - -inline const Point3 Max(const Point3& a, const Point3& b) -{ - return Point3(_mm_max_ps(a.base, b.base)); -} - -inline const Point3 Clamp(const Point3& v, const Point3& min, const Point3& max) -{ - return Point3(_mm_min_ps(max.base, _mm_max_ps(min.base, v.base))); -} - -inline const Scalar Dist(const Point3& a, const Point3& b) -{ - return Length(a - b); -} - -inline const Scalar DistSqr(const Point3& a, const Point3& b) -{ - return LengthSqr(a - b); -} - -inline const Scalar DistRcp(const Point3& a, const Point3& b) -{ - return LengthRcp(a - b); -} - -inline const Scalar DistFast(const Point3& a, const Point3& b) -{ - return LengthFast(a - b); -} - -inline const Scalar DistRcpFast(const Point3& a, const Point3& b) -{ - return LengthRcpFast(a - b); -} - -inline const Point3 Lerp(const Point3& a, const Point3& b, const Scalar& t) -{ - return a + (b - a) * t; -} - -inline const Point3 Homogenize(const Vector4& v) -{ - return Point3(v * RcpNr(v.GetW())); -} - -inline const Point3 HomogenizeFast(const Vector4& v) -{ - return Point3(v * Rcp(v.GetW())); -} - -// comparisons return 1 bit per element -inline int operator==(const Point3& a, const Point3& b) -{ - return (_mm_movemask_ps(_mm_cmpeq_ps(a.base, b.base)) & 7); -} - -inline int operator!=(const Point3& a, const Point3& b) -{ - return (_mm_movemask_ps(_mm_cmpneq_ps(a.base, b.base)) & 7); -} - -inline int operator<(const Point3& a, const Point3& b) -{ - return (_mm_movemask_ps(_mm_cmplt_ps(a.base, b.base)) & 7); -} - -inline int operator<=(const Point3& a, const Point3& b) -{ - return (_mm_movemask_ps(_mm_cmple_ps(a.base, b.base)) & 7); -} - -inline int operator>(const Point3& a, const Point3& b) -{ - return (_mm_movemask_ps(_mm_cmpgt_ps(a.base, b.base)) & 7); -} - -inline int operator>=(const Point3& a, const Point3& b) -{ - return (_mm_movemask_ps(_mm_cmpge_ps(a.base, b.base)) & 7); -} - - -//////////////////////////////////////////////////////////////////////////////// -// Vector4 - -inline Vector4::Vector4() -{ -} - -inline Vector4::Vector4(const Vector4& v) -{ - base = v.base; -} - -inline Vector4::Vector4(float x, float y, float z, float w) -{ - base = _mm_setr_ps(x, y, z, w); -} - -inline Vector4::Vector4(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w) -{ - Set(x.base, y.base, z.base, w.base); -} - -inline Vector4::Vector4(const Point3& v) -{ - Set(v.base, Vector4Base::Consts::k1000); -} - -inline Vector4::Vector4(const Vector3& v) -{ - Set(v.base, _mm_setzero_ps()); -} - -inline Vector4::Vector4(const Vector3& xyz, const Scalar& w) -{ - Set(xyz.base, w.base); -} - -inline Vector4::Vector4(const Maths::ZeroTag&) -{ - base = _mm_setzero_ps(); -} - -inline Vector4::Vector4(const Maths::UnitXTag&) -{ - base = Vector4Base::Consts::k1000; -} - -inline Vector4::Vector4(const Maths::UnitYTag&) -{ - base = Vector4Base::Consts::k0100; -} - -inline Vector4::Vector4(const Maths::UnitZTag&) -{ - base = Vector4Base::Consts::k0010; -} - -inline Vector4::Vector4(const Maths::UnitWTag&) -{ - base = Vector4Base::Consts::k0001; -} - -inline Vector4::Vector4(const Maths::UnitNegXTag&) -{ - base = Vector4Base::Consts::kNeg1000; -} - -inline Vector4::Vector4(const Maths::UnitNegYTag&) -{ - base = Vector4Base::Consts::kNeg0100; -} - -inline Vector4::Vector4(const Maths::UnitNegZTag&) -{ - base = Vector4Base::Consts::kNeg0010; -} - -inline Vector4::Vector4(const Maths::UnitNegWTag&) -{ - base = Vector4Base::Consts::kNeg0001; -} - -inline Vector4::Vector4(const Vector4Base& v) -{ - base = v.base; -} - -inline Vector4::Vector4(const __m128 b) -{ - base = b; -} - -inline Vector4::Vector4(const Scalar& v) -{ - base = v.base; -} - -inline Vector4::Vector4(const float* p) -{ - base = _mm_load_ps(p); -} - -inline const Vector4& Vector4::operator=(const Vector4& v) -{ - base = v.base; - return *this; -} - -inline const Vector4& Vector4::operator=(const Maths::ZeroTag&) -{ - base = _mm_setzero_ps(); - return *this; -} - -inline const Vector4& Vector4::operator=(const Maths::UnitXTag&) -{ - base = Vector4Base::Consts::k1000; - return *this; -} - -inline const Vector4& Vector4::operator=(const Maths::UnitYTag&) -{ - base = Vector4Base::Consts::k0100; - return *this; -} - -inline const Vector4& Vector4::operator=(const Maths::UnitZTag&) -{ - base = Vector4Base::Consts::k0010; - return *this; -} - -inline const Vector4& Vector4::operator=(const Maths::UnitWTag&) -{ - base = Vector4Base::Consts::k0001; - return *this; -} - -inline const Vector4& Vector4::operator=(const Maths::UnitNegXTag&) -{ - base = Vector4Base::Consts::kNeg1000; - return *this; -} - -inline const Vector4& Vector4::operator=(const Maths::UnitNegYTag&) -{ - base = Vector4Base::Consts::kNeg0100; - return *this; -} - -inline const Vector4& Vector4::operator=(const Maths::UnitNegZTag&) -{ - base = Vector4Base::Consts::kNeg0010; - return *this; -} - -inline const Vector4& Vector4::operator=(const Maths::UnitNegWTag&) -{ - base = Vector4Base::Consts::kNeg0001; - return *this; -} - -inline void Vector4::operator+=(const Vector4& b) -{ - base = _mm_add_ps(base, b.base); -} - -inline void Vector4::operator-=(const Vector4& b) -{ - base = _mm_sub_ps(base, b.base); -} - -inline void Vector4::operator*=(const Vector4& b) -{ - base = _mm_mul_ps(base, b.base); -} - -inline void Vector4::operator/=(const Vector4& b) -{ - base = _mm_div_ps(base, b.base); -} - -inline void Vector4::operator*=(const Scalar& s) -{ - base = _mm_mul_ps(base, s.base); -} - -inline void Vector4::operator/=(const Scalar& s) -{ - base = _mm_div_ps(base, s.base); -} - -inline const Vector4 operator-(const Vector4& a) -{ - return Vector4(_mm_sub_ps(_mm_setzero_ps(), a.base)); -} - -inline const Vector4 operator+(const Vector4& a, const Vector4& b) -{ - return Vector4(_mm_add_ps(a.base, b.base)); -} - -inline const Vector4 operator-(const Vector4& a, const Vector4& b) -{ - return Vector4(_mm_sub_ps(a.base, b.base)); -} - -inline const Vector4 operator*(const Vector4& a, const Vector4& b) -{ - return Vector4(_mm_mul_ps(a.base, b.base)); -} - -inline const Vector4 operator/(const Vector4& a, const Vector4& b) -{ - return Vector4(_mm_div_ps(a.base, b.base)); -} - -inline const Vector4 operator*(const Vector4& a, const Scalar& s) -{ - return Vector4(_mm_mul_ps(a.base, s.base)); -} - -inline const Vector4 operator*(const Scalar& s, const Vector4& a) -{ - return Vector4(_mm_mul_ps(a.base, s.base)); -} - -inline const Vector4 operator/(const Vector4& a, const Scalar& s) -{ - return Vector4(_mm_div_ps(a.base, s.base)); -} - -inline const Vector4 Abs(const Vector4& a) -{ - return Vector4(_mm_and_ps(a.base, Vector4Base::Consts::kMaskAbs)); -} - -inline const Vector4 Rcp(const Vector4& a) -{ - return Vector4(_mm_rcp_ps(a.base)); -} - -inline const Vector4 Rsqrt(const Vector4& a) -{ - return Vector4(_mm_rsqrt_ps(a.base)); -} - -inline const Vector4 Sqrt(const Vector4& a) -{ - return Vector4(_mm_sqrt_ps(a.base)); -} - -inline const Vector4 RcpNr(const Vector4& a) -{ - Vector4 rcp = Rcp(a); - return (rcp + rcp) - (a * rcp * rcp); -} - -inline const Vector4 RsqrtNr(const Vector4& a) -{ - Vector4 rcp = Rsqrt(a); - return (Vector4(Vector4Base::Consts::kHalf) * rcp) * (Vector4(Vector4Base::Consts::kThree) - (a * rcp) * rcp); -} - -inline const Scalar Sum(const Vector4& a) -{ - return Scalar(Vector4Base::Sum4(a.base)); -} - -inline const Scalar Dot(const Vector4& a, const Vector4& b) -{ - return Scalar(Vector4Base::Dot4(a.base, b.base)); -} - -inline const Vector4 Min(const Vector4& a, const Vector4& b) -{ - return Vector4(_mm_min_ps(a.base, b.base)); -} - -inline const Vector4 Max(const Vector4& a, const Vector4& b) -{ - return Vector4(_mm_max_ps(a.base, b.base)); -} - -inline const Vector4 Clamp(const Vector4& v, const Vector4& min, const Vector4& max) -{ - return Vector4(_mm_min_ps(max.base, _mm_max_ps(min.base, v.base))); -} - -inline const Scalar MinComp(const Vector4& a) -{ - return Scalar(Vector4Base::MinComp4(a.base)); -} - -inline const Scalar MaxComp(const Vector4& a) -{ - return Scalar(Vector4Base::MaxComp4(a.base)); -} - -inline const Scalar Length(const Vector4& a) -{ - return Sqrt(Dot(a, a)); -} - -inline const Scalar LengthSqr(const Vector4& a) -{ - return Dot(a, a); -} - -inline const Scalar LengthRcp(const Vector4& a) -{ - return RsqrtNr(Dot(a, a)); -} - -inline const Vector4 Normalize(const Vector4& a) -{ - return RsqrtNr(Dot(a, a)) * a; -} - -inline const Vector4 Lerp(const Vector4& a, const Vector4& b, const Scalar& t) -{ - return a + (b - a) * t; -} - -inline const Scalar LengthFast(const Vector4& a) -{ - return Rcp(Rsqrt(Dot(a, a))); -} - -inline const Scalar LengthRcpFast(const Vector4& a) -{ - return Rsqrt(Dot(a, a)); -} - -inline const Vector4 NormalizeFast(const Vector4& a) -{ - return Rsqrt(Dot(a, a)) * a; -} - -// comparisons return 1 bit per element -inline int operator==(const Vector4& a, const Vector4& b) -{ - return _mm_movemask_ps(_mm_cmpeq_ps(a.base, b.base)); -} - -inline int operator!=(const Vector4& a, const Vector4& b) -{ - return _mm_movemask_ps(_mm_cmpneq_ps(a.base, b.base)); -} - -inline int operator<(const Vector4& a, const Vector4& b) -{ - return _mm_movemask_ps(_mm_cmplt_ps(a.base, b.base)); -} - -inline int operator<=(const Vector4& a, const Vector4& b) -{ - return _mm_movemask_ps(_mm_cmple_ps(a.base, b.base)); -} - -inline int operator>(const Vector4& a, const Vector4& b) -{ - return _mm_movemask_ps(_mm_cmpgt_ps(a.base, b.base)); -} - -inline int operator>=(const Vector4& a, const Vector4& b) -{ - return _mm_movemask_ps(_mm_cmpge_ps(a.base, b.base)); -} diff --git a/Extras/obsolete/SATConvexCollision/VectorBase.cpp b/Extras/obsolete/SATConvexCollision/VectorBase.cpp deleted file mode 100644 index 0233b07f1..000000000 --- a/Extras/obsolete/SATConvexCollision/VectorBase.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// VectorBase.cpp -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifdef WIN32 -#if _MSC_VER >= 1310 - -#include "VectorBase.h" - -const __m128 Vector4Base::Consts::kZero = _mm_set1_ps(0.0f); -const __m128 Vector4Base::Consts::kHalf = _mm_set1_ps(0.5f); -const __m128 Vector4Base::Consts::kThree = _mm_set1_ps(3.0f); - -const __m128 Vector4Base::Consts::k1000 = _mm_setr_ps(1.0f, 0.0f, 0.0f, 0.0f); -const __m128 Vector4Base::Consts::k0100 = _mm_setr_ps(0.0f, 1.0f, 0.0f, 0.0f); -const __m128 Vector4Base::Consts::k0010 = _mm_setr_ps(0.0f, 0.0f, 1.0f, 0.0f); -const __m128 Vector4Base::Consts::k0001 = _mm_setr_ps(0.0f, 0.0f, 0.0f, 1.0f); - -const __m128 Vector4Base::Consts::kNeg1000 = _mm_setr_ps(-1.0f, 0.0f, 0.0f, 0.0f); -const __m128 Vector4Base::Consts::kNeg0100 = _mm_setr_ps(0.0f, -1.0f, 0.0f, 0.0f); -const __m128 Vector4Base::Consts::kNeg0010 = _mm_setr_ps(0.0f, 0.0f, -1.0f, 0.0f); -const __m128 Vector4Base::Consts::kNeg0001 = _mm_setr_ps(0.0f, 0.0f, 0.0f, -1.0f); - -const __m128 Vector4Base::Consts::kNeg111_1 = _mm_setr_ps(-1.0f, -1.0f, -1.0f, 1.0f); -const __m128 Vector4Base::Consts::k1110 = _mm_setr_ps(1.0f, 1.0f, 1.0f, 0.0f); - -const unsigned int Vector4Base::Consts::maskAbs = 0x7fffffff; -const __m128 Vector4Base::Consts::kMaskAbs = _mm_load1_ps((float*)&Vector4Base::Consts::maskAbs); - -const unsigned int Vector4Base::Consts::mask1110[4] = {0xffffffff, 0xffffffff, 0xffffffff, 0x00000000}; -const unsigned int Vector4Base::Consts::mask0001[4] = {0x00000000, 0x00000000, 0x00000000, 0xffffffff}; - -const __m128 Vector4Base::Consts::kMask1110 = _mm_loadu_ps((float*)Vector4Base::Consts::mask1110); -const __m128 Vector4Base::Consts::kMask0001 = _mm_loadu_ps((float*)Vector4Base::Consts::mask0001); - -#endif -#endif //WIN32 diff --git a/Extras/obsolete/SATConvexCollision/VectorBase.h b/Extras/obsolete/SATConvexCollision/VectorBase.h deleted file mode 100644 index af5237c60..000000000 --- a/Extras/obsolete/SATConvexCollision/VectorBase.h +++ /dev/null @@ -1,142 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// VectorBase.h -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#ifndef BULLET_VECTOR_BASE_H -#define BULLET_VECTOR_BASE_H - -#include "Scalar.h" -#include "Memory2.h" - -// vector constants -namespace Maths -{ - static const enum ZeroTag { } Zero; - static const enum UnitXTag { } UnitX; - static const enum UnitYTag { } UnitY; - static const enum UnitZTag { } UnitZ; - static const enum UnitWTag { } UnitW; - static const enum UnitNegXTag { } UnitNegX; - static const enum UnitNegYTag { } UnitNegY; - static const enum UnitNegZTag { } UnitNegZ; - static const enum UnitNegWTag { } UnitNegW; - - static const enum IdentityTag { } Identity; - static const enum RotateXTag { } RotateX; - static const enum RotateYTag { } RotateY; - static const enum RotateZTag { } RotateZ; - static const enum ScaleTag { } Scale; - static const enum SkewTag { } Skew; -}; - -//////////////////////////////////////////////////////////////////////////////// -// Vector4Base -__declspec(align(16)) class Vector4Base -{ -public: - BULLET_ALIGNED_NEW_AND_DELETE - - __m128 base; - -//protected: - // useful constants for internal use - struct Consts - { - static const unsigned int maskAbs; - static const unsigned int mask1110[4]; - static const unsigned int mask0001[4]; - - static const __m128 - kZero, - kHalf, - kThree, - - k1000, - k0100, - k0010, - k0001, - - kNeg1000, - kNeg0100, - kNeg0010, - kNeg0001, - - kNeg111_1, - - k1110, - kMaskAbs, - kMask1110, - kMask0001; - }; - - // can't construct a Vector4Base - Vector4Base(); - - // compound operations helpers for use by derived classes - void Set(const __m128& x, const __m128& y, const __m128& z, const __m128& w); - void Set(const __m128& xyz, const __m128& w); - - static __m128 Dot3(const __m128& v0, const __m128& v1); - static __m128 Dot4(const __m128& v0, const __m128& v1); - - static __m128 Sum3(const __m128& a); - static __m128 Sum4(const __m128& a); - - static __m128 MinComp3(const __m128& a); - static __m128 MinComp4(const __m128& a); - - static __m128 MaxComp3(const __m128& a); - static __m128 MaxComp4(const __m128& a); - -public: - // element access - const float& operator[](int i) const; - float& operator[](int i); - - // get/set elements - const Scalar GetX() const; - const Scalar GetY() const; - const Scalar GetZ() const; - const Scalar GetW() const; - const Scalar Get(int i) const; - - void SetX(const Scalar& s); - void SetY(const Scalar& s); - void SetZ(const Scalar& s); - void SetW(const Scalar& s); - void Set(int i, const Scalar& s); - - // unaligned load/store - void LoadUnaligned3(const float* p); - void LoadUnaligned4(const float* p); - - void StoreUnaligned3(float* p) const; - void StoreUnaligned4(float* p) const; -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Vector2Base -class __declspec(align(8)) Vector2Base -{ -public: - float x, y; -}; - - -#include "VectorBase.inl" - -#endif //BULLET_VECTOR_BASE_H diff --git a/Extras/obsolete/SATConvexCollision/VectorBase.inl b/Extras/obsolete/SATConvexCollision/VectorBase.inl deleted file mode 100644 index d744ebfa7..000000000 --- a/Extras/obsolete/SATConvexCollision/VectorBase.inl +++ /dev/null @@ -1,213 +0,0 @@ -// Bullet Continuous Collision Detection and Physics Library -// Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ -// -// -// VectorBase.inl -// -// Copyright (c) 2006 Simon Hobbs -// -// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -#pragma once - - -//////////////////////////////////////////////////////////////////////////////// -// Vector4Base - -inline Vector4Base::Vector4Base() -{ -} - -inline const float& Vector4Base::operator[](int i) const -{ - return *(((float*)&base) + i); -} - -inline float& Vector4Base::operator[](int i) -{ - return *(((float*)&base) + i); -} - -inline const Scalar Vector4Base::GetX() const -{ - return Scalar(_mm_shuffle_ps(base, base, _MM_SHUFFLE(0, 0, 0, 0))); -} - -inline const Scalar Vector4Base::GetY() const -{ - return Scalar(_mm_shuffle_ps(base, base, _MM_SHUFFLE(1, 1, 1, 1))); -} - -inline const Scalar Vector4Base::GetZ() const -{ - return Scalar(_mm_shuffle_ps(base, base, _MM_SHUFFLE(2, 2, 2, 2))); -} - -inline const Scalar Vector4Base::GetW() const -{ - return Scalar(_mm_shuffle_ps(base, base, _MM_SHUFFLE(3, 3, 3, 3))); -} - -inline const Scalar Vector4Base::Get(int i) const -{ - __m128 res; - - switch (i) - { - case 0: res = _mm_shuffle_ps(base, base, _MM_SHUFFLE(0, 0, 0, 0)); break; - case 1: res = _mm_shuffle_ps(base, base, _MM_SHUFFLE(1, 1, 1, 1)); break; - case 2: res = _mm_shuffle_ps(base, base, _MM_SHUFFLE(2, 2, 2, 2)); break; - case 3: res = _mm_shuffle_ps(base, base, _MM_SHUFFLE(3, 3, 3, 3)); break; - } - - return Scalar(res); -} - -inline void Vector4Base::SetX(const Scalar& s) -{ - __m128 xxyy = _mm_shuffle_ps(s.base, base, _MM_SHUFFLE(1, 1, 0, 0)); - base = _mm_shuffle_ps(xxyy, base, _MM_SHUFFLE(3, 2, 2, 0)); -} - -inline void Vector4Base::SetY(const Scalar& s) -{ - __m128 xxyy = _mm_shuffle_ps(base, s.base, _MM_SHUFFLE(0, 0, 0, 0)); - base = _mm_shuffle_ps(xxyy, base, _MM_SHUFFLE(3, 2, 2, 0)); -} - -inline void Vector4Base::SetZ(const Scalar& s) -{ - __m128 zzww = _mm_shuffle_ps(s.base, base, _MM_SHUFFLE(3, 3, 0, 0)); - base = _mm_shuffle_ps(base, zzww, _MM_SHUFFLE(2, 0, 1, 0)); -} - -inline void Vector4Base::SetW(const Scalar& s) -{ - __m128 zzww = _mm_shuffle_ps(base, s.base, _MM_SHUFFLE(0, 0, 2, 2)); - base = _mm_shuffle_ps(base, zzww, _MM_SHUFFLE(2, 0, 1, 0)); -} - -inline void Vector4Base::Set(int i, const Scalar& s) -{ - switch (i) - { - case 0: SetX(s); break; - case 1: SetY(s); break; - case 2: SetZ(s); break; - case 3: SetW(s); break; - } -} - -inline void Vector4Base::LoadUnaligned3(const float* p) -{ - int* dst = (int*)this; - dst[0] = ((const int*)p)[0]; - dst[1] = ((const int*)p)[1]; - dst[2] = ((const int*)p)[2]; -} - -inline void Vector4Base::LoadUnaligned4(const float* p) -{ - base = _mm_loadu_ps(p); -} - -inline void Vector4Base::StoreUnaligned3(float* p) const -{ - const int* src = (const int*)this; - ((int*)p)[0] = src[0]; - ((int*)p)[1] = src[1]; - ((int*)p)[2] = src[2]; -} - -inline void Vector4Base::StoreUnaligned4(float* p) const -{ - _mm_storeu_ps(p, base); -} - -__forceinline void Vector4Base::Set(const __m128& x, const __m128& y, const __m128& z, const __m128& w) -{ - __m128 xy = _mm_unpacklo_ps(x, y); - __m128 zw = _mm_unpacklo_ps(z, w); - base = _mm_shuffle_ps(xy, zw, _MM_SHUFFLE(1, 0, 1, 0)); -} - -__forceinline void Vector4Base::Set(const __m128& xyz, const __m128& w) -{ - base = _mm_shuffle_ps(xyz, xyz, _MM_SHUFFLE(0, 1, 2, 3)); - base = _mm_move_ss(base, w); - base = _mm_shuffle_ps(base, base, _MM_SHUFFLE(0, 1, 2, 3)); -} - -__forceinline __m128 Vector4Base::Dot3(const __m128& v0, const __m128& v1) -{ - __m128 a = _mm_mul_ps(v0, v1); - __m128 b = _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 0, 0, 0)); - __m128 c = _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 1, 1, 1)); - __m128 d = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 2, 2, 2)); - return _mm_add_ps(b, _mm_add_ps(c, d)); -} - -__forceinline __m128 Vector4Base::Dot4(const __m128& v0, const __m128& v1) -{ - __m128 a = _mm_mul_ps(v0, v1); - __m128 b = _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 3, 2, 1)); - __m128 c = _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 0, 3, 2)); - __m128 d = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 1, 0, 3)); - return _mm_add_ps(a, _mm_add_ps(b, _mm_add_ps(c, d))); -} - -__forceinline __m128 Vector4Base::Sum3(const __m128& a) -{ - __m128 b = _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 0, 0, 0)); - __m128 c = _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 1, 1, 1)); - __m128 d = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 2, 2, 2)); - return _mm_add_ps(b, _mm_add_ps(c, d)); -} - -__forceinline __m128 Vector4Base::Sum4(const __m128& a) -{ - __m128 b = _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 3, 2, 1)); - __m128 c = _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 0, 3, 2)); - __m128 d = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 1, 0, 3)); - return _mm_add_ps(a, _mm_add_ps(b, _mm_add_ps(c, d))); -} - -__forceinline __m128 Vector4Base::MinComp3(const __m128& a) -{ - __m128 b = _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 0, 0, 0)); - __m128 c = _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 1, 1, 1)); - __m128 d = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 2, 2, 2)); - return _mm_min_ps(b, _mm_min_ps(c, d)); -} - -__forceinline __m128 Vector4Base::MinComp4(const __m128& a) -{ - __m128 b = _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 3, 2, 1)); - __m128 c = _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 0, 3, 2)); - __m128 d = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 1, 0, 3)); - return _mm_min_ps(a, _mm_min_ps(b, _mm_min_ps(c, d))); -} - -__forceinline __m128 Vector4Base::MaxComp3(const __m128& a) -{ - __m128 b = _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 0, 0, 0)); - __m128 c = _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 1, 1, 1)); - __m128 d = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 2, 2, 2)); - return _mm_max_ps(b, _mm_max_ps(c, d)); -} - -__forceinline __m128 Vector4Base::MaxComp4(const __m128& a) -{ - __m128 b = _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 3, 2, 1)); - __m128 c = _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 0, 3, 2)); - __m128 d = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 1, 0, 3)); - return _mm_max_ps(a, _mm_max_ps(b, _mm_max_ps(c, d))); -} - diff --git a/Extras/obsolete/test_BulletOde.cpp b/Extras/obsolete/test_BulletOde.cpp deleted file mode 100644 index 14823f355..000000000 --- a/Extras/obsolete/test_BulletOde.cpp +++ /dev/null @@ -1,531 +0,0 @@ -/************************************************************************* - * * - * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * - * All rights reserved. Email: russ@q12.org Web: www.q12.org * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of EITHER: * - * (1) The GNU Lesser bteral Public License as published by the Free * - * Software Foundation; either version 2.1 of the License, or (at * - * your option) any later version. The text of the GNU Lesser * - * bteral Public License is included with this library in the * - * file LICENSE.TXT. * - * (2) The BSD-style license that is included with this library in * - * the file LICENSE-BSD.TXT. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * - * LICENSE.TXT and LICENSE-BSD.TXT for more details. * - * * - *************************************************************************/ - -///Bullet Continuous Collision Detection and Physics Engine: - - - - - -#include -#include -//#include -#include "BulletCollision/CollisionDispatch/btCollisionObject.h" -#include "BulletCollision/CollisionDispatch/btCollisionWorld.h" -#include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h" -#include "BulletCollision/BroadphaseCollision/btAxisSweep3.h" - - -#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h" - -#include "BulletCollision/CollisionShapes/btBoxShape.h" -#include "BulletCollision/CollisionShapes/btSphereShape.h" -#include "BulletCollision/CollisionShapes/btCylinderShape.h" - - - -#ifdef _MSC_VER -#pragma warning(disable:4244 4305) // for VC++, no precision loss complaints -#endif - -// select correct drawing functions - -#ifdef dDOUBLE -#define dsDrawBox dsDrawBoxD -#define dsDrawSphere dsDrawSphereD -#define dsDrawCylinder dsDrawCylinderD -#define dsDrawCappedCylinder dsDrawCappedCylinderD -#endif - - -// some constants - -#define NUM 100 // max number of objects -#define DENSITY (5.0) // density of all objects -#define GPB 3 // maximum number of geometries per body -#define MAX_CONTACTS 4 // maximum number of contact points per body - - -// dynamics and collision objects - -struct MyObject { - dBodyID body; // the body - btCollisionObject collider; //the collisionShape -}; - -static int num=0; // number of objects in simulation -static int nextobj=0; // next object to recycle if num==NUM -static dWorldID world; - -btCollisionWorld* collisionWorld = 0; - -static MyObject obj[NUM]; -static dJointGroupID contactgroup; -static int selected = -1; // selected object -static int show_aabb = 0; // show geom AABBs? -static int show_contacts = 0; // show contact points? -static int random_pos = 1; // drop objects from random position? -static int write_world = 0; - - - -btTransform GetTransformFromOde(const dReal* pos,const dReal* rot) -{ - btTransform trans; - trans.setIdentity(); - -// rot is pointer to object's rotation matrix, 4*3 format! - - btMatrix3x3 orn(rot[0],rot[1],rot[2], - rot[4],rot[5],rot[6], - rot[8],rot[9],rot[10]); - - trans.setOrigin(btVector3(pos[0],pos[1],pos[2])); - trans.setBasis(orn); - - return trans; -} - -void GetOdeFromTransform(const btTransform& trans,dReal* pos,dReal* rot) -{ - pos[0] = trans.getOrigin().x(); - pos[1] = trans.getOrigin().y(); - pos[2] = trans.getOrigin().z(); - - rot[0] = trans.getBasis()[0][0]; - rot[1] = trans.getBasis()[0][1]; - rot[2] = trans.getBasis()[0][2]; - - rot[4] = trans.getBasis()[1][0]; - rot[5] = trans.getBasis()[1][1]; - rot[6] = trans.getBasis()[1][2]; - - rot[8] = trans.getBasis()[2][0]; - rot[9] = trans.getBasis()[2][1]; - rot[10] = trans.getBasis()[2][2]; - -} - - - -// start simulation - set viewpoint - -static void start() -{ - static float xyz[3] = {2.1640f,-1.3079f,1.7600f}; - static float hpr[3] = {125.5000f,-17.0000f,0.0000f}; - dsSetViewpoint (xyz,hpr); - printf ("To drop another object, press:\n"); - printf (" b for box.\n"); - printf (" s for sphere.\n"); - printf (" c for cylinder.\n"); - printf (" x for a composite object.\n"); - printf ("To select an object, press space.\n"); - printf ("To disable the selected object, press d.\n"); - printf ("To enable the selected object, press e.\n"); - printf ("To toggle showing the geom AABBs, press a.\n"); - printf ("To toggle showing the contact points, press t.\n"); - printf ("To toggle dropping from random position/orientation, press r.\n"); - printf ("To save the current state to 'state.dif', press 1.\n"); -} - - -char locase (char c) -{ - if (c >= 'A' && c <= 'Z') return c - ('a'-'A'); - else return c; -} - - -// called when a key pressed - -static void command (int cmd) -{ - size_t i; - int j,k; - dReal sides[3]; - dMass m; - - cmd = locase (cmd); - if (cmd == 'b' || cmd == 's' || cmd == 'c' - /* || cmd == 'l' */) { - if (num < NUM) { - i = num; - num++; - } - else { - i = nextobj; - nextobj++; - if (nextobj >= num) nextobj = 0; - - // destroy the body and geoms for slot i - dBodyDestroy (obj[i].body); - collisionWorld->removeCollisionObject(&obj[i].collider); - obj[i].collider.m_broadphaseHandle = (btBroadphaseProxy*)(-1); - - - //todo: destroy collider - } - - obj[i].body = dBodyCreate (world); - for (k=0; k<3; k++) sides[k] = dRandReal()*0.2+0.1; - - dMatrix3 R; - if (random_pos) { - dBodySetPosition (obj[i].body, - dRandReal()*2-1,dRandReal()*2-1,dRandReal()+2); - dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, - dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); - } - else { - dReal maxheight = 0; - for (k=0; k maxheight) maxheight = pos[2]; - } - dBodySetPosition (obj[i].body, 0,0,maxheight+0.3); - dRFromAxisAndAngle (R,0,0,1,dRandReal()*10.0-5.0); - } - dBodySetRotation (obj[i].body,R); - dBodySetData (obj[i].body,(void*) i); - - if (cmd == 'b') { - dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]); - obj[i].collider.m_collisionShape = new btBoxShape(btVector3(0.5*sides[0],0.5*sides[1],0.5*sides[2])); - obj[i].collider.m_worldTransform = GetTransformFromOde(dBodyGetPosition(obj[i].body),dBodyGetRotation(obj[i].body)); - collisionWorld->addCollisionObject(&obj[i].collider); - obj[i].collider.m_userPointer = obj[i].body; - - } - else if (cmd == 'c') { - sides[0] *= 0.2; - sides[1] *= 0.2; - sides[2] *= 0.2; - dMassSetCappedCylinder (&m,DENSITY,3,sides[0],sides[1]); - obj[i].collider.m_collisionShape = new btCylinderShapeZ(btVector3(sides[0],sides[1],sides[1])); - obj[i].collider.m_worldTransform = GetTransformFromOde(dBodyGetPosition(obj[i].body),dBodyGetRotation(obj[i].body)); - collisionWorld->addCollisionObject(&obj[i].collider); - obj[i].collider.m_userPointer = obj[i].body; - //obj[i].geom[0] = dCreateCCylinder (space,sides[0],sides[1]); - } -/* - // cylinder option not yet implemented - else if (cmd == 'l') { - sides[1] *= 0.5; - dMassSetCappedCylinder (&m,DENSITY,3,sides[0],sides[1]); - obj[i].geom[0] = dCreateCylinder (space,sides[0],sides[1]); - } -*/ - else if (cmd == 's') { - sides[0] *= 0.5; - dMassSetSphere (&m,DENSITY,sides[0]); - obj[i].collider.m_collisionShape = new btSphereShape(sides[0]); - - - obj[i].collider.m_worldTransform = GetTransformFromOde(dBodyGetPosition(obj[i].body),dBodyGetRotation(obj[i].body)); - collisionWorld->addCollisionObject(&obj[i].collider); - obj[i].collider.m_userPointer = obj[i].body; - - //obj[i].geom[0] = dCreateSphere (space,sides[0]); - } - else if (cmd == 'x') { - - - - } - - for (k=0; k < GPB; k++) { - //if (obj[i].geom[k]) - // dGeomSetBody (obj[i].geom[k],obj[i].body); - } - - dBodySetMass (obj[i].body,&m); - } - - if (cmd == ' ') { - selected++; - if (selected >= num) selected = 0; - if (selected < 0) selected = 0; - } - else if (cmd == 'd' && selected >= 0 && selected < num) { - dBodyDisable (obj[selected].body); - } - else if (cmd == 'e' && selected >= 0 && selected < num) { - dBodyEnable (obj[selected].body); - } - else if (cmd == 'a') { - show_aabb ^= 1; - } - else if (cmd == 't') { - show_contacts ^= 1; - } - else if (cmd == 'r') { - random_pos ^= 1; - } - else if (cmd == '1') { - write_world = 1; - } -} - - -// draw a geom - -void drawGeom (btCollisionObject& collider)//, const dReal *pos, const dReal *R, int show_aabb) -{ - dReal pos[4]; - dReal R[16]; - - GetOdeFromTransform(collider.m_worldTransform,&pos[0],&R[0]); - - int i; - - if (!collider.m_collisionShape) return; - - int type = collider.m_collisionShape->getShapeType(); - - if (type == BOX_SHAPE_PROXYTYPE) { - dVector3 sides; - btBoxShape* boxShape = static_cast(collider.m_collisionShape); - sides[0] = 2.f*boxShape->getHalfExtents().x(); - sides[1] = 2.f*boxShape->getHalfExtents().y(); - sides[2] = 2.f*boxShape->getHalfExtents().z(); - ///boxshape already has margins 'inside' - dsDrawBox (pos,R,sides); - - } - else if (type == SPHERE_SHAPE_PROXYTYPE) { - btSphereShape* sphereShape = static_cast(collider.m_collisionShape); - dReal radius = sphereShape->getMargin(); - - dsDrawSphere (pos,R,radius); - - } - - else if (type == CYLINDER_SHAPE_PROXYTYPE) { - - btCylinderShapeZ* cylinder = static_cast(collider.m_collisionShape); - dReal radius = cylinder->getHalfExtents()[0]; - dReal length = 2.f*cylinder->getHalfExtents()[1]; - radius += cylinder->getMargin(); - length += 2.f*cylinder->getMargin(); - - //dGeomCCylinderGetParams (g,&radius,&length); - dsDrawCylinder (pos,R,length,radius); - } -/* - // cylinder option not yet implemented - else if (type == dCylinderClass) { - dReal radius,length; - dGeomCylinderGetParams (g,&radius,&length); - dsDrawCylinder (pos,R,length,radius); - } - - else if (type == dGeomTransformClass) { - dGeomID g2 = dGeomTransformGetGeom (g); - const dReal *pos2 = dGeomGetPosition (g2); - const dReal *R2 = dGeomGetRotation (g2); - dVector3 actual_pos; - dMatrix3 actual_R; - dMULTIPLY0_331 (actual_pos,R,pos2); - actual_pos[0] += pos[0]; - actual_pos[1] += pos[1]; - actual_pos[2] += pos[2]; - dMULTIPLY0_333 (actual_R,R,R2); - drawGeom (g2,actual_pos,actual_R,0); - } - - if (show_aabb) { - // draw the bounding box for this geom - dReal aabb[6]; - dGeomGetAABB (g,aabb); - dVector3 bbpos; - for (i=0; i<3; i++) bbpos[i] = 0.5*(aabb[i*2] + aabb[i*2+1]); - dVector3 bbsides; - for (i=0; i<3; i++) bbsides[i] = aabb[i*2+1] - aabb[i*2]; - dMatrix3 RI; - dRSetIdentity (RI); - dsSetColorAlpha (1,0,0,0.5); - dsDrawBox (bbpos,RI,bbsides); - } -*/ -} - - -// simulation loop - -static void simLoop (int pause) -{ - dsSetColor (0,0,2); - //dSpaceCollide (space,0,&nearCallback); - collisionWorld->performDiscreteCollisionDetection(); - //now the collisionWorld contains all contact points... just copy them over to ODE and that's it - - for (int i=0;igetDispatcher()->getNumManifolds();i++) - { - btPersistentManifold* manifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i); - btCollisionObject* obj0 = static_cast(manifold->getBody0()); - btCollisionObject* obj1 = static_cast(manifold->getBody1()); - - //refreshContactPoints will update and/or remove existing contactpoints from previous frames - manifold->refreshContactPoints(obj0->m_worldTransform,obj1->m_worldTransform); - for (int j=0;jgetNumContacts();j++) - { - btManifoldPoint& pt = manifold->getContactPoint(j); - if (pt.getDistance()<0.f) - { - //report point to ODE - - dContact contact; - contact.surface.mode = dContactBounce | dContactSoftCFM; - contact.surface.mu = 10.f;//dInfinity; - contact.surface.mu2 = 0; - contact.surface.bounce = 0.1; - contact.surface.bounce_vel = 0.1; - contact.surface.soft_cfm = 0.01; - contact.geom.depth = -pt.getDistance(); - - - contact.geom.normal[0] = pt.m_normalWorldOnB.x(); - contact.geom.normal[1] = pt.m_normalWorldOnB.y(); - contact.geom.normal[2] = pt.m_normalWorldOnB.z(); - //contact.geom.g1 does it really need this? - contact.geom.g1 = 0; - contact.geom.g2 = 0; - contact.geom.pos[0] = pt.getPositionWorldOnB().x(); - contact.geom.pos[1] = pt.getPositionWorldOnB().y(); - contact.geom.pos[2] = pt.getPositionWorldOnB().z(); - - contact.fdir1[0] = 0.f; - contact.fdir1[1] = 0.f; - contact.fdir1[2] = 0.f; - - - dJointID c = dJointCreateContact (world,contactgroup,&contact); - dBodyID b1 = (dBodyID)obj0->m_userPointer; - dBodyID b2 = (dBodyID)obj1->m_userPointer; - dJointAttach (c,b1,b2); - if (show_contacts) - { - dMatrix3 RI; - dRSetIdentity (RI); - const dReal ss[3] = {0.02,0.02,0.02}; - dsDrawBox (contact.geom.pos,RI,ss); - } - - } - - - - - - } - } - - - - if (!pause) dWorldQuickStep (world,0.05); - - if (write_world) { - FILE *f = fopen ("state.dif","wt"); - if (f) { - dWorldExportDIF (world,f,"X"); - fclose (f); - } - write_world = 0; - } - - // remove all contact joints - dJointGroupEmpty (contactgroup); - - dsSetColor (1,1,0); - dsSetTexture (DS_WOOD); - for (int i=0; isetMargin(0.005f); - collisionWorld->addCollisionObject(&groundPlane); - groundPlane.m_userPointer = 0; - - memset (obj,0,sizeof(obj)); - - // run simulation - dsSimulationLoop (argc,argv,352,288,&fn); - - dJointGroupDestroy (contactgroup); - - delete collisionWorld; - dWorldDestroy (world); - - return 0; -} diff --git a/Extras/quickstep/btOdeContactJoint.cpp b/Extras/quickstep/btOdeContactJoint.cpp deleted file mode 100644 index 312f7c290..000000000 --- a/Extras/quickstep/btOdeContactJoint.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#include "btOdeContactJoint.h" -#include "btOdeSolverBody.h" -#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" - - -//this constant needs to be set up so different solvers give 'similar' results -#define FRICTION_CONSTANT 120.f - - -btOdeContactJoint::btOdeContactJoint(btPersistentManifold* manifold,int index,bool swap,btOdeSolverBody* body0,btOdeSolverBody* body1) -:m_manifold(manifold), -m_index(index), -m_swapBodies(swap), -m_body0(body0), -m_body1(body1) -{ -} - -int m_numRows = 3; - - -void btOdeContactJoint::GetInfo1(Info1 *info) -{ - info->m_numConstraintRows = m_numRows; - //friction adds another 2... - - info->nub = 0; -} - -#define dCROSS(a,op,b,c) \ - (a)[0] op ((b)[1]*(c)[2] - (b)[2]*(c)[1]); \ - (a)[1] op ((b)[2]*(c)[0] - (b)[0]*(c)[2]); \ - (a)[2] op ((b)[0]*(c)[1] - (b)[1]*(c)[0]); - -#define M_SQRT12 btScalar(0.7071067811865475244008443621048490) - -#define dRecipSqrt(x) ((float)(1.0f/btSqrt(float(x)))) /* reciprocal square root */ - - - -void dPlaneSpace1 (const dVector3 n, dVector3 p, dVector3 q); -void dPlaneSpace1 (const dVector3 n, dVector3 p, dVector3 q) -{ - if (btFabs(n[2]) > M_SQRT12) { - // choose p in y-z plane - btScalar a = n[1]*n[1] + n[2]*n[2]; - btScalar k = dRecipSqrt (a); - p[0] = 0; - p[1] = -n[2]*k; - p[2] = n[1]*k; - // set q = n x p - q[0] = a*k; - q[1] = -n[0]*p[2]; - q[2] = n[0]*p[1]; - } - else { - // choose p in x-y plane - btScalar a = n[0]*n[0] + n[1]*n[1]; - btScalar k = dRecipSqrt (a); - p[0] = -n[1]*k; - p[1] = n[0]*k; - p[2] = 0; - // set q = n x p - q[0] = -n[2]*p[1]; - q[1] = n[2]*p[0]; - q[2] = a*k; - } -} - - - -void btOdeContactJoint::GetInfo2(Info2 *info) -{ - - int s = info->rowskip; - int s2 = 2*s; - - float swapFactor = m_swapBodies ? -1.f : 1.f; - - // get normal, with sign adjusted for body1/body2 polarity - dVector3 normal; - - - btManifoldPoint& point = m_manifold->getContactPoint(m_index); - - normal[0] = swapFactor*point.m_normalWorldOnB.x(); - normal[1] = swapFactor*point.m_normalWorldOnB.y(); - normal[2] = swapFactor*point.m_normalWorldOnB.z(); - normal[3] = 0; // @@@ hmmm - - assert(m_body0); - // if (GetBody0()) - btVector3 relativePositionA; - { - relativePositionA = point.getPositionWorldOnA() - m_body0->m_centerOfMassPosition; - - // set jacobian for normal - info->m_J1linearAxis[0] = normal[0]; - info->m_J1linearAxis[1] = normal[1]; - info->m_J1linearAxis[2] = normal[2]; - dCROSS (info->m_J1angularAxis,=,relativePositionA,normal); - - } - - btVector3 relativePositionB(0,0,0); - if (m_body1) - { - // if (GetBody1()) - - { - btVector3 posBody1 = m_body1 ? m_body1->m_centerOfMassPosition : btVector3(0,0,0); - relativePositionB = point.getPositionWorldOnB() - posBody1; - - // for (i=0; i<3; i++) c2[i] = j->contact.geom.pos[i] - - // j->node[1].body->pos[i]; - - info->m_J2linearAxis[0] = -normal[0]; - info->m_J2linearAxis[1] = -normal[1]; - info->m_J2linearAxis[2] = -normal[2]; - dCROSS (info->m_J2angularAxis,= -,relativePositionB,normal); - } - } - - float depth = -point.getDistance(); -// if (depth < 0.f) -// depth = 0.f; - - info->m_constraintError[0] = depth * info->fps * info->erp ; - //float maxvel = .2f; - -// if (info->c[0] > maxvel) -// info->c[0] = maxvel; - - - //can override it, not necessary -// info->cfm[0] = 0.f; -// info->cfm[1] = 0.f; -// info->cfm[2] = 0.f; - - - - // set LCP limits for normal - info->m_lowerLimit[0] = 0; - info->m_higherLimit[0] = BT_LARGE_FLOAT;//dInfinity; - info->m_lowerLimit[1] = 0; - info->m_higherLimit[1] = 0.f; - info->m_lowerLimit[2] = 0.f; - info->m_higherLimit[2] = 0.f; - -#define DO_THE_FRICTION_2 -#ifdef DO_THE_FRICTION_2 - // now do jacobian for tangential forces - dVector3 t1,t2; // two vectors tangential to normal - - dVector3 c1; - c1[0] = relativePositionA.x(); - c1[1] = relativePositionA.y(); - c1[2] = relativePositionA.z(); - - dVector3 c2; - c2[0] = relativePositionB.x(); - c2[1] = relativePositionB.y(); - c2[2] = relativePositionB.z(); - - //combined friction is available in the contact point - //float friction = 0.25;//FRICTION_CONSTANT ;//* m_body0->m_friction * m_body1->m_friction; - float friction = 1.0f; - if (m_body0 != 0) - friction *= m_body0->m_friction; - if (m_body1 != 0) - friction *= m_body1->m_friction; - - // first friction direction - if (m_numRows >= 2) - { - - - - dPlaneSpace1 (normal,t1,t2); - - info->m_J1linearAxis[s+0] = t1[0]; - info->m_J1linearAxis[s+1] = t1[1]; - info->m_J1linearAxis[s+2] = t1[2]; - dCROSS (info->m_J1angularAxis+s,=,c1,t1); -// if (1) { //j->node[1].body) { - info->m_J2linearAxis[s+0] = -t1[0]; - info->m_J2linearAxis[s+1] = -t1[1]; - info->m_J2linearAxis[s+2] = -t1[2]; - dCROSS (info->m_J2angularAxis+s,= -,c2,t1); -// } - // set right hand side -// if (0) {//j->contact.surface.mode & dContactMotion1) { - //info->c[1] = j->contact.surface.motion1; -// } - // set LCP bounds and friction index. this depends on the approximation - // mode - //BT_LARGE_FLOAT - - - info->m_lowerLimit[1] = -friction;//-j->contact.surface.mu; - info->m_higherLimit[1] = friction;//j->contact.surface.mu; -// if (1)//j->contact.surface.mode & dContactApprox1_1) - info->findex[1] = 0; - - // set slip (constraint force mixing) -// if (0)//j->contact.surface.mode & dContactSlip1) -// { -// // info->cfm[1] = j->contact.surface.slip1; -// } else -// { -// //info->cfm[1] = 0.f; -// } - } - - // second friction direction - if (m_numRows >= 3) { - info->m_J1linearAxis[s2+0] = t2[0]; - info->m_J1linearAxis[s2+1] = t2[1]; - info->m_J1linearAxis[s2+2] = t2[2]; - dCROSS (info->m_J1angularAxis+s2,=,c1,t2); -// if (1) { //j->node[1].body) { - info->m_J2linearAxis[s2+0] = -t2[0]; - info->m_J2linearAxis[s2+1] = -t2[1]; - info->m_J2linearAxis[s2+2] = -t2[2]; - dCROSS (info->m_J2angularAxis+s2,= -,c2,t2); -// } - - // set right hand side -// if (0){//j->contact.surface.mode & dContactMotion2) { - //info->c[2] = j->contact.surface.motion2; -// } - // set LCP bounds and friction index. this depends on the approximation - // mode -// if (0){//j->contact.surface.mode & dContactMu2) { - //info->m_lowerLimit[2] = -j->contact.surface.mu2; - //info->m_higherLimit[2] = j->contact.surface.mu2; -// } -// else { - info->m_lowerLimit[2] = -friction; - info->m_higherLimit[2] = friction; -// } - if (1)//j->contact.surface.mode & dContactApprox1_2) - - { - info->findex[2] = 0; - } - // set slip (constraint force mixing) -// if (0) //j->contact.surface.mode & dContactSlip2) - -// { - //info->cfm[2] = j->contact.surface.slip2; - -// } - } - -#endif //DO_THE_FRICTION_2 - -} - diff --git a/Extras/quickstep/btOdeContactJoint.h b/Extras/quickstep/btOdeContactJoint.h deleted file mode 100644 index 10a6f7684..000000000 --- a/Extras/quickstep/btOdeContactJoint.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef CONTACT_JOINT_H -#define CONTACT_JOINT_H - -#include "btOdeJoint.h" -struct btOdeSolverBody; -class btPersistentManifold; - -class btOdeContactJoint : public btOdeJoint -{ - btPersistentManifold* m_manifold; - int m_index; - bool m_swapBodies; - btOdeSolverBody* m_body0; - btOdeSolverBody* m_body1; - - -public: - - btOdeContactJoint() {}; - - btOdeContactJoint(btPersistentManifold* manifold,int index,bool swap,btOdeSolverBody* body0,btOdeSolverBody* body1); - - //btOdeJoint interface for solver - - virtual void GetInfo1(Info1 *info); - - virtual void GetInfo2(Info2 *info); - - - - -}; - -#endif //CONTACT_JOINT_H - diff --git a/Extras/quickstep/btOdeJoint.cpp b/Extras/quickstep/btOdeJoint.cpp deleted file mode 100644 index b8bcc0f40..000000000 --- a/Extras/quickstep/btOdeJoint.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#include "btOdeJoint.h" - -btOdeJoint::btOdeJoint() -{ - -} -btOdeJoint::~btOdeJoint() -{ - -} diff --git a/Extras/quickstep/btOdeJoint.h b/Extras/quickstep/btOdeJoint.h deleted file mode 100644 index 34a1811e7..000000000 --- a/Extras/quickstep/btOdeJoint.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef btOdeJoint_H -#define btOdeJoint_H - -struct btOdeSolverBody; -class btOdeJoint; - -#include "LinearMath/btScalar.h" - -struct BU_ContactJointNode { - btOdeJoint *joint; // pointer to enclosing btOdeJoint object - btOdeSolverBody* body; // *other* body this joint is connected to -}; -typedef btScalar dVector3[4]; - - -class btOdeJoint { - -public: - // naming convention: the "first" body this is connected to is node[0].body, - // and the "second" body is node[1].body. if this joint is only connected - // to one body then the second body is 0. - - // info returned by getInfo1 function. the constraint dimension is m (<=6). - // i.e. that is the total number of rows in the jacobian. `nub' is the - // number of unbounded variables (which have lo,hi = -/+ infinity). - - btOdeJoint(); - virtual ~btOdeJoint(); - - - struct Info1 { - int m_numConstraintRows,nub; - }; - - // info returned by getInfo2 function - - struct Info2 { - // integrator parameters: frames per second (1/stepsize), default error - // reduction parameter (0..1). - btScalar fps,erp; - - // for the first and second body, pointers to two (linear and angular) - // n*3 jacobian sub matrices, stored by rows. these matrices will have - // been initialized to 0 on entry. if the second body is zero then the - // J2xx pointers may be 0. - btScalar *m_J1linearAxis,*m_J1angularAxis,*m_J2linearAxis,*m_J2angularAxis; - - // elements to jump from one row to the next in J's - int rowskip; - - // right hand sides of the equation J*v = c + cfm * lambda. cfm is the - // "constraint force mixing" vector. c is set to zero on entry, cfm is - // set to a constant value (typically very small or zero) value on entry. - btScalar *m_constraintError,*cfm; - - // lo and hi limits for variables (set to -/+ infinity on entry). - btScalar *m_lowerLimit,*m_higherLimit; - - // findex vector for variables. see the LCP solver interface for a - // description of what this does. this is set to -1 on entry. - // note that the returned indexes are relative to the first index of - // the constraint. - int *findex; - }; - - // virtual function table: size of the joint structure, function pointers. - // we do it this way instead of using C++ virtual functions because - // sometimes we need to allocate joints ourself within a memory pool. - - virtual void GetInfo1 (Info1 *info)=0; - virtual void GetInfo2 (Info2 *info)=0; - - int flags; // dJOINT_xxx flags - BU_ContactJointNode node[2]; // connections to bodies. node[1].body can be 0 - btScalar lambda[6]; // lambda generated by last step -}; - - -#endif //btOdeJoint_H diff --git a/Extras/quickstep/btOdeMacros.h b/Extras/quickstep/btOdeMacros.h deleted file mode 100644 index f9bdca4cc..000000000 --- a/Extras/quickstep/btOdeMacros.h +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Quickstep constraint solver re-distributed under the ZLib license with permission from Russell L. Smith - * Original version is from Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. - * All rights reserved. Email: russ@q12.org Web: www.q12.org - Bullet Continuous Collision Detection and Physics Library - Bullet is Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#define ODE_MACROS -#ifdef ODE_MACROS - -#include "LinearMath/btScalar.h" - -typedef btScalar dVector4[4]; -typedef btScalar dMatrix3[4*3]; -#define dInfinity FLT_MAX - - - -#define dRecip(x) ((float)(1.0f/(x))) /* reciprocal */ - - - -#define dMULTIPLY0_331NEW(A,op,B,C) \ -{\ - btScalar tmp[3];\ - tmp[0] = C.getX();\ - tmp[1] = C.getY();\ - tmp[2] = C.getZ();\ - dMULTIPLYOP0_331(A,op,B,tmp);\ -} - -#define dMULTIPLY0_331(A,B,C) dMULTIPLYOP0_331(A,=,B,C) -#define dMULTIPLYOP0_331(A,op,B,C) \ - (A)[0] op dDOT1((B),(C)); \ - (A)[1] op dDOT1((B+4),(C)); \ - (A)[2] op dDOT1((B+8),(C)); - -#define dAASSERT btAssert -#define dIASSERT btAssert - -#define REAL float -#define dDOTpq(a,b,p,q) ((a)[0]*(b)[0] + (a)[p]*(b)[q] + (a)[2*(p)]*(b)[2*(q)]) -inline btScalar dDOT1 (const btScalar *a, const btScalar *b) -{ return dDOTpq(a,b,1,1); } -#define dDOT14(a,b) dDOTpq(a,b,1,4) - -#define dCROSS(a,op,b,c) \ - (a)[0] op ((b)[1]*(c)[2] - (b)[2]*(c)[1]); \ - (a)[1] op ((b)[2]*(c)[0] - (b)[0]*(c)[2]); \ - (a)[2] op ((b)[0]*(c)[1] - (b)[1]*(c)[0]); - -/* - * set a 3x3 submatrix of A to a matrix such that submatrix(A)*b = a x b. - * A is stored by rows, and has `skip' elements per row. the matrix is - * assumed to be already zero, so this does not write zero elements! - * if (plus,minus) is (+,-) then a positive version will be written. - * if (plus,minus) is (-,+) then a negative version will be written. - */ - -#define dCROSSMAT(A,a,skip,plus,minus) \ -{ \ - (A)[1] = minus (a)[2]; \ - (A)[2] = plus (a)[1]; \ - (A)[(skip)+0] = plus (a)[2]; \ - (A)[(skip)+2] = minus (a)[0]; \ - (A)[2*(skip)+0] = minus (a)[1]; \ - (A)[2*(skip)+1] = plus (a)[0]; \ -} - - -#define dMULTIPLYOP2_333(A,op,B,C) \ - (A)[0] op dDOT1((B),(C)); \ - (A)[1] op dDOT1((B),(C+4)); \ - (A)[2] op dDOT1((B),(C+8)); \ - (A)[4] op dDOT1((B+4),(C)); \ - (A)[5] op dDOT1((B+4),(C+4)); \ - (A)[6] op dDOT1((B+4),(C+8)); \ - (A)[8] op dDOT1((B+8),(C)); \ - (A)[9] op dDOT1((B+8),(C+4)); \ - (A)[10] op dDOT1((B+8),(C+8)); - -#define dMULTIPLYOP0_333(A,op,B,C) \ - (A)[0] op dDOT14((B),(C)); \ - (A)[1] op dDOT14((B),(C+1)); \ - (A)[2] op dDOT14((B),(C+2)); \ - (A)[4] op dDOT14((B+4),(C)); \ - (A)[5] op dDOT14((B+4),(C+1)); \ - (A)[6] op dDOT14((B+4),(C+2)); \ - (A)[8] op dDOT14((B+8),(C)); \ - (A)[9] op dDOT14((B+8),(C+1)); \ - (A)[10] op dDOT14((B+8),(C+2)); - -#define dMULTIPLY2_333(A,B,C) dMULTIPLYOP2_333(A,=,B,C) -#define dMULTIPLY0_333(A,B,C) dMULTIPLYOP0_333(A,=,B,C) -#define dMULTIPLYADD0_331(A,B,C) dMULTIPLYOP0_331(A,+=,B,C) - - -//////////////////////////////////////////////////////////////////// -#define EFFICIENT_ALIGNMENT 16 -#define dEFFICIENT_SIZE(x) ((((x)-1)|(EFFICIENT_ALIGNMENT-1))+1) -/* alloca aligned to the EFFICIENT_ALIGNMENT. note that this can waste - * up to 15 bytes per allocation, depending on what alloca() returns. - */ - -#define dALLOCA16(n) \ - ((char*)dEFFICIENT_SIZE(((size_t)(alloca((n)+(EFFICIENT_ALIGNMENT-1)))))) - -//#define ALLOCA dALLOCA16 - -typedef const btScalar *dRealPtr; -typedef btScalar *dRealMutablePtr; -//#define dRealArray(name,n) btScalar name[n]; -//#define dRealAllocaArray(name,n) btScalar *name = (btScalar*) ALLOCA ((n)*sizeof(btScalar)); - -/////////////////////////////////////////////////////////////////////////////// - - //Remotion: 10.10.2007 -#define ALLOCA(size) stackAlloc->allocate( dEFFICIENT_SIZE(size) ); - -//#define dRealAllocaArray(name,size) btScalar *name = (btScalar*) stackAlloc->allocate(dEFFICIENT_SIZE(size)*sizeof(btScalar)); -#define dRealAllocaArray(name,size) btScalar *name = NULL; \ - unsigned int memNeeded_##name = dEFFICIENT_SIZE(size)*sizeof(btScalar); \ - if (memNeeded_##name < static_cast(stackAlloc->getAvailableMemory())) name = (btScalar*) stackAlloc->allocate(memNeeded_##name); \ - else{ btAssert(memNeeded_##name < static_cast(stackAlloc->getAvailableMemory())); name = (btScalar*) alloca(memNeeded_##name); } - - - - - -/////////////////////////////////////////////////////////////////////////////// -#if 0 -inline void dSetZero1 (btScalar *a, int n) -{ - dAASSERT (a && n >= 0); - while (n > 0) { - *(a++) = 0; - n--; - } -} - -inline void dSetValue1 (btScalar *a, int n, btScalar value) -{ - dAASSERT (a && n >= 0); - while (n > 0) { - *(a++) = value; - n--; - } -} -#else - -/// This macros are for MSVC and XCode compilers. Remotion. - - -#include //for memset - -//Remotion: 10.10.2007 -//------------------------------------------------------------------------------ -#define IS_ALIGNED_16(x) ((size_t(x)&15)==0) -//------------------------------------------------------------------------------ -inline void dSetZero1 (btScalar *dest, int size) -{ - dAASSERT (dest && size >= 0); - memset(dest, 0, size * sizeof(btScalar)); -} -//------------------------------------------------------------------------------ -inline void dSetValue1 (btScalar *dest, int size, btScalar val) -{ - dAASSERT (dest && size >= 0); - int n_mod4 = size & 3; - int n4 = size - n_mod4; -/*#ifdef __USE_SSE__ -//it is not supported on double precision, todo... - if(IS_ALIGNED_16(dest)){ - __m128 xmm0 = _mm_set_ps1(val); - for (int i=0; i -#include "LinearMath/btQuickprof.h" - -#include "LinearMath/btIDebugDraw.h" - -#define USE_SOR_SOLVER - -#include "btSorLcp.h" - -#include -#include //FLT_MAX -#ifdef WIN32 -#include -#endif -#include -#include - -#if defined (WIN32) -#include -#else -#if defined (__FreeBSD__) -#include -#else -#include -#endif -#endif - -class btOdeJoint; - -//see below -//to bridge with ODE quickstep, we make a temp copy of the rigidbodies in each simultion island - - -btOdeQuickstepConstraintSolver::btOdeQuickstepConstraintSolver() -{ -} - - -//iterative lcp and penalty method -btScalar btOdeQuickstepConstraintSolver::solveGroup(btCollisionObject** /*bodies*/,int numBulletBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc,btDispatcher* /*dispatcher*/) -{ - - m_CurBody = 0; - m_CurJoint = 0; - m_CurTypedJoint = 0; - int j; - - int max_contacts = 0; /// should be 4 //Remotion - for ( j=0;jgetNumContacts() > max_contacts) max_contacts = manifold->getNumContacts(); - } - //if(max_contacts > 4) - // printf(" max_contacts > 4"); - - int numBodies = 0; - m_odeBodies.clear(); - m_odeBodies.reserve(numBulletBodies + 1); //??? - // btOdeSolverBody* odeBodies [ODE_MAX_SOLVER_BODIES]; - - int numJoints = 0; - m_joints.clear(); - m_joints.reserve(numManifolds * max_contacts + 4 + numConstraints + 1); //??? - // btOdeJoint* joints [ODE_MAX_SOLVER_JOINTS*2]; - - m_SolverBodyArray.resize(numBulletBodies + 1); - m_JointArray.resize(numManifolds * max_contacts + 4); - m_TypedJointArray.resize(numConstraints + 1); - - - //capture contacts - int body0=-1,body1=-1; - for (j=0;jgetNumContacts() > 0) - { - body0 = ConvertBody((btRigidBody*)manifold->getBody0(),m_odeBodies,numBodies); - body1 = ConvertBody((btRigidBody*)manifold->getBody1(),m_odeBodies,numBodies); - ConvertConstraint(manifold,m_joints,numJoints,m_odeBodies,body0,body1,debugDrawer); - } - } - - //capture constraints - for (j=0;jgetRigidBodyA(),m_odeBodies,numBodies); - body1 = ConvertBody((btRigidBody*)&typedconstraint->getRigidBodyB(),m_odeBodies,numBodies); - ConvertTypedConstraint(typedconstraint,m_joints,numJoints,m_odeBodies,body0,body1,debugDrawer); - } - //if(numBodies > numBulletBodies) - // printf(" numBodies > numBulletBodies"); - //if(numJoints > numManifolds * 4 + numConstraints) - // printf(" numJoints > numManifolds * 4 + numConstraints"); - - - m_SorLcpSolver.SolveInternal1(m_odeBodies,numBodies,m_joints,numJoints,infoGlobal,stackAlloc); ///do - - //write back resulting velocities - for (int i=0;im_invMass) - { - m_odeBodies[i]->m_originalBody->setLinearVelocity(m_odeBodies[i]->m_linearVelocity); - m_odeBodies[i]->m_originalBody->setAngularVelocity(m_odeBodies[i]->m_angularVelocity); - } - } - - - /// Remotion, just free all this here - m_odeBodies.clear(); - m_joints.clear(); - - m_SolverBodyArray.clear(); - m_JointArray.clear(); - m_TypedJointArray.clear(); - - return 0.f; - -} - -///////////////////////////////////////////////////////////////////////////////// - - -typedef btScalar dQuaternion[4]; -#define _R(i,j) R[(i)*4+(j)] - -void dRfromQ1 (dMatrix3 R, const dQuaternion q); -void dRfromQ1 (dMatrix3 R, const dQuaternion q) -{ - // q = (s,vx,vy,vz) - btScalar qq1 = 2.f*q[1]*q[1]; - btScalar qq2 = 2.f*q[2]*q[2]; - btScalar qq3 = 2.f*q[3]*q[3]; - _R(0,0) = 1.f - qq2 - qq3; - _R(0,1) = 2*(q[1]*q[2] - q[0]*q[3]); - _R(0,2) = 2*(q[1]*q[3] + q[0]*q[2]); - _R(0,3) = 0.f; - - _R(1,0) = 2*(q[1]*q[2] + q[0]*q[3]); - _R(1,1) = 1.f - qq1 - qq3; - _R(1,2) = 2*(q[2]*q[3] - q[0]*q[1]); - _R(1,3) = 0.f; - - _R(2,0) = 2*(q[1]*q[3] - q[0]*q[2]); - _R(2,1) = 2*(q[2]*q[3] + q[0]*q[1]); - _R(2,2) = 1.f - qq1 - qq2; - _R(2,3) = 0.f; - -} - - - -//int btOdeQuickstepConstraintSolver::ConvertBody(btRigidBody* orgBody,btOdeSolverBody** bodies,int& numBodies) -int btOdeQuickstepConstraintSolver::ConvertBody(btRigidBody* orgBody,btAlignedObjectArray< btOdeSolverBody*> &bodies,int& numBodies) -{ - assert(orgBody); - if (!orgBody || (orgBody->getInvMass() == 0.f) ) - { - return -1; - } - - if (orgBody->getCompanionId()>=0) - { - return orgBody->getCompanionId(); - } - //first try to find - int i,j; - - //if not found, create a new body - // btOdeSolverBody* body = bodies[numBodies] = &gSolverBodyArray[numBodies]; - btOdeSolverBody* body = &m_SolverBodyArray[numBodies]; - bodies.push_back(body); // Remotion 10.10.07: - - orgBody->setCompanionId(numBodies); - - numBodies++; - - body->m_originalBody = orgBody; - - body->m_facc.setValue(0,0,0); - body->m_tacc.setValue(0,0,0); - - body->m_linearVelocity = orgBody->getLinearVelocity(); - body->m_angularVelocity = orgBody->getAngularVelocity(); - body->m_invMass = orgBody->getInvMass(); - body->m_centerOfMassPosition = orgBody->getCenterOfMassPosition(); - body->m_friction = orgBody->getFriction(); - - //are the indices the same ? - for (i=0;i<4;i++) - { - for ( j=0;j<3;j++) - { - body->m_invI[i+4*j] = 0.f; - body->m_I[i+4*j] = 0.f; - } - } - body->m_invI[0+4*0] = orgBody->getInvInertiaDiagLocal().x(); - body->m_invI[1+4*1] = orgBody->getInvInertiaDiagLocal().y(); - body->m_invI[2+4*2] = orgBody->getInvInertiaDiagLocal().z(); - - body->m_I[0+0*4] = 1.f/orgBody->getInvInertiaDiagLocal().x(); - body->m_I[1+1*4] = 1.f/orgBody->getInvInertiaDiagLocal().y(); - body->m_I[2+2*4] = 1.f/orgBody->getInvInertiaDiagLocal().z(); - - - - - dQuaternion q; - - q[1] = orgBody->getOrientation().x(); - q[2] = orgBody->getOrientation().y(); - q[3] = orgBody->getOrientation().z(); - q[0] = orgBody->getOrientation().w(); - - dRfromQ1(body->m_R,q); - - return numBodies-1; -} - - - - - - - - - -void btOdeQuickstepConstraintSolver::ConvertConstraint(btPersistentManifold* manifold, - btAlignedObjectArray &joints,int& numJoints, - const btAlignedObjectArray< btOdeSolverBody*> &bodies, - int _bodyId0,int _bodyId1,btIDebugDraw* debugDrawer) -{ - - - /* manifold->refreshContactPoints(((btRigidBody*)manifold->getBody0())->getCenterOfMassTransform(), - ((btRigidBody*)manifold->getBody1())->getCenterOfMassTransform()); -*/ - - int bodyId0 = _bodyId0,bodyId1 = _bodyId1; - - int i,numContacts = manifold->getNumContacts(); - - bool swapBodies = (bodyId0 < 0); - - - btOdeSolverBody* body0,*body1; - - if (swapBodies) - { - bodyId0 = _bodyId1; - bodyId1 = _bodyId0; - - body0 = bodyId0>=0 ? bodies[bodyId0] : 0;//(btRigidBody*)manifold->getBody1(); - body1 = bodyId1>=0 ? bodies[bodyId1] : 0;//(btRigidBody*)manifold->getBody0(); - - } - else - { - body0 = bodyId0>=0 ? bodies[bodyId0] : 0;//(btRigidBody*)manifold->getBody0(); - body1 = bodyId1>=0 ? bodies[bodyId1] : 0;//(btRigidBody*)manifold->getBody1(); - } - - assert(bodyId0 >= 0); - - btVector3 color(0,1,0); - for (i=0;igetContactPoint(i).getDistance() < 0.0f) - { - - btOdeContactJoint* cont = new (&m_JointArray[m_CurJoint++]) btOdeContactJoint( manifold ,i, swapBodies,body0,body1); - //btOdeContactJoint* cont = new (&gJointArray[m_CurJoint++]) btOdeContactJoint( manifold ,i, swapBodies,body0,body1); - - cont->node[0].joint = cont; - cont->node[0].body = bodyId0 >= 0 ? bodies[bodyId0] : 0; - - cont->node[1].joint = cont; - cont->node[1].body = bodyId1 >= 0 ? bodies[bodyId1] : 0; - - // joints[numJoints++] = cont; - joints.push_back(cont); // Remotion 10.10.07: - numJoints++; - - for (int i=0;i<6;i++) - cont->lambda[i] = 0.f; - - cont->flags = 0; - } - } - - //create a new contact constraint -} - -void btOdeQuickstepConstraintSolver::ConvertTypedConstraint( - btTypedConstraint * constraint, - btAlignedObjectArray &joints,int& numJoints, - const btAlignedObjectArray< btOdeSolverBody*> &bodies,int _bodyId0,int _bodyId1,btIDebugDraw* /*debugDrawer*/) -{ - - int bodyId0 = _bodyId0,bodyId1 = _bodyId1; - bool swapBodies = (bodyId0 < 0); - - - btOdeSolverBody* body0,*body1; - - if (swapBodies) - { - bodyId0 = _bodyId1; - bodyId1 = _bodyId0; - - body0 = bodyId0>=0 ? bodies[bodyId0] : 0;//(btRigidBody*)manifold->getBody1(); - body1 = bodyId1>=0 ? bodies[bodyId1] : 0;//(btRigidBody*)manifold->getBody0(); - - } - else - { - body0 = bodyId0>=0 ? bodies[bodyId0] : 0;//(btRigidBody*)manifold->getBody0(); - body1 = bodyId1>=0 ? bodies[bodyId1] : 0;//(btRigidBody*)manifold->getBody1(); - } - - assert(bodyId0 >= 0); - - - //assert (m_CurTypedJoint < ODE_MAX_SOLVER_JOINTS); - - - btOdeTypedJoint * cont = NULL; - - // Determine constraint type - int joint_type = constraint->getConstraintType(); - switch(joint_type) - { - case POINT2POINT_CONSTRAINT_TYPE: - case D6_CONSTRAINT_TYPE: - cont = new (&m_TypedJointArray[m_CurTypedJoint ++]) btOdeTypedJoint(constraint,0, swapBodies,body0,body1); - //cont = new (&gTypedJointArray[m_CurTypedJoint ++]) btOdeTypedJoint(constraint,0, swapBodies,body0,body1); - break; - - }; - - if(cont) - { - cont->node[0].joint = cont; - cont->node[0].body = bodyId0 >= 0 ? bodies[bodyId0] : 0; - - cont->node[1].joint = cont; - cont->node[1].body = bodyId1 >= 0 ? bodies[bodyId1] : 0; - - // joints[numJoints++] = cont; - joints.push_back(cont); // Remotion 10.10.07: - numJoints++; - - for (int i=0;i<6;i++) - cont->lambda[i] = 0.f; - - cont->flags = 0; - } - -} diff --git a/Extras/quickstep/btOdeQuickstepConstraintSolver.h b/Extras/quickstep/btOdeQuickstepConstraintSolver.h deleted file mode 100644 index bc044b292..000000000 --- a/Extras/quickstep/btOdeQuickstepConstraintSolver.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Quickstep constraint solver re-distributed under the ZLib license with permission from Russell L. Smith - * Original version is from Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. - * All rights reserved. Email: russ@q12.org Web: www.q12.org - Bullet Continuous Collision Detection and Physics Library - Bullet is Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef ODE_CONSTRAINT_SOLVER_H -#define ODE_CONSTRAINT_SOLVER_H - -#include "BulletDynamics/ConstraintSolver/btConstraintSolver.h" - -#include "LinearMath/btAlignedObjectArray.h" -#include "btOdeContactJoint.h" -#include "btOdeTypedJoint.h" -#include "btOdeSolverBody.h" -#include "btSorLcp.h" - -class btRigidBody; -struct btOdeSolverBody; -class btOdeJoint; - -/// btOdeQuickstepConstraintSolver is one of the available solvers for Bullet dynamics framework -/// It uses an adapted version quickstep solver from the Open Dynamics Engine project -class btOdeQuickstepConstraintSolver : public btConstraintSolver -{ -private: - int m_CurBody; - int m_CurJoint; - int m_CurTypedJoint; - - btSorLcpSolver m_SorLcpSolver; - - btAlignedObjectArray m_odeBodies; - btAlignedObjectArray m_joints; - - btAlignedObjectArray m_SolverBodyArray; - btAlignedObjectArray m_JointArray; - btAlignedObjectArray m_TypedJointArray; - - -private: - int ConvertBody(btRigidBody* body,btAlignedObjectArray< btOdeSolverBody*> &bodies,int& numBodies); - void ConvertConstraint(btPersistentManifold* manifold, - btAlignedObjectArray &joints,int& numJoints, - const btAlignedObjectArray< btOdeSolverBody*> &bodies, - int _bodyId0,int _bodyId1,btIDebugDraw* debugDrawer); - - void ConvertTypedConstraint( - btTypedConstraint * constraint, - btAlignedObjectArray &joints,int& numJoints, - const btAlignedObjectArray< btOdeSolverBody*> &bodies,int _bodyId0,int _bodyId1,btIDebugDraw* debugDrawer); - - -public: - - btOdeQuickstepConstraintSolver(); - - virtual ~btOdeQuickstepConstraintSolver() {} - - virtual btScalar solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& info,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc,btDispatcher* dispatcher); - - - ///clear internal cached data and reset random seed - void reset() - { - m_SorLcpSolver.dRand2_seed = 0; - } - - void setRandSeed(unsigned long seed) - { - m_SorLcpSolver.dRand2_seed = seed; - } - unsigned long getRandSeed() const - { - return m_SorLcpSolver.dRand2_seed; - } -}; - - - - -#endif //ODE_CONSTRAINT_SOLVER_H diff --git a/Extras/quickstep/btOdeSolverBody.h b/Extras/quickstep/btOdeSolverBody.h deleted file mode 100644 index fc47a0932..000000000 --- a/Extras/quickstep/btOdeSolverBody.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef ODE_SOLVER_BODY_H -#define ODE_SOLVER_BODY_H - -class btRigidBody; -#include "LinearMath/btVector3.h" -typedef btScalar dMatrix3[4*3]; - -///ODE's quickstep needs just a subset of the rigidbody data in its own layout, so make a temp copy -struct btOdeSolverBody -{ - btRigidBody* m_originalBody; - - btVector3 m_centerOfMassPosition; - /// for ode solver-binding - dMatrix3 m_R;//temp - dMatrix3 m_I; - dMatrix3 m_invI; - - int m_odeTag; - float m_invMass; - float m_friction; - - btVector3 m_tacc;//temp - btVector3 m_facc; - - btVector3 m_linearVelocity; - btVector3 m_angularVelocity; - -}; - - -#endif //#ifndef ODE_SOLVER_BODY_H - diff --git a/Extras/quickstep/btOdeTypedJoint.cpp b/Extras/quickstep/btOdeTypedJoint.cpp deleted file mode 100644 index 74dc003eb..000000000 --- a/Extras/quickstep/btOdeTypedJoint.cpp +++ /dev/null @@ -1,860 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -#include "btOdeTypedJoint.h" -#include "btOdeSolverBody.h" -#include "btOdeMacros.h" -#include - -void btOdeTypedJoint::GetInfo1(Info1 *info) -{ - int joint_type = m_constraint->getConstraintType(); - switch (joint_type) - { - case POINT2POINT_CONSTRAINT_TYPE: - { - OdeP2PJoint p2pjoint(m_constraint,m_index,m_swapBodies,m_body0,m_body1); - p2pjoint.GetInfo1(info); - } - break; - case D6_CONSTRAINT_TYPE: - { - OdeD6Joint d6joint(m_constraint,m_index,m_swapBodies,m_body0,m_body1); - d6joint.GetInfo1(info); - } - break; - case SLIDER_CONSTRAINT_TYPE: - { - OdeSliderJoint sliderjoint(m_constraint,m_index,m_swapBodies,m_body0,m_body1); - sliderjoint.GetInfo1(info); - } - break; - }; -} - -void btOdeTypedJoint::GetInfo2(Info2 *info) -{ - int joint_type = m_constraint->getConstraintType(); - switch (joint_type) - { - case POINT2POINT_CONSTRAINT_TYPE: - { - OdeP2PJoint p2pjoint(m_constraint,m_index,m_swapBodies,m_body0,m_body1); - p2pjoint.GetInfo2(info); - } - break; - case D6_CONSTRAINT_TYPE: - { - OdeD6Joint d6joint(m_constraint,m_index,m_swapBodies,m_body0,m_body1); - d6joint.GetInfo2(info); - } - break; - case SLIDER_CONSTRAINT_TYPE: - { - OdeSliderJoint sliderjoint(m_constraint,m_index,m_swapBodies,m_body0,m_body1); - sliderjoint.GetInfo2(info); - } - break; - }; -} - - -OdeP2PJoint::OdeP2PJoint( - btTypedConstraint * constraint, - int index,bool swap,btOdeSolverBody* body0,btOdeSolverBody* body1): - btOdeTypedJoint(constraint,index,swap,body0,body1) -{ -} - - -void OdeP2PJoint::GetInfo1(Info1 *info) -{ - info->m_numConstraintRows = 3; - info->nub = 3; -} - - -void OdeP2PJoint::GetInfo2(Info2 *info) -{ - - btPoint2PointConstraint * p2pconstraint = this->getP2PConstraint(); - - //retrieve matrices - btTransform body0_trans; - if (m_body0) - { - body0_trans = m_body0->m_originalBody->getCenterOfMassTransform(); - } - - btTransform body1_trans; - - if (m_body1) - { - body1_trans = m_body1->m_originalBody->getCenterOfMassTransform(); - } - - // anchor points in global coordinates with respect to body PORs. - int s = info->rowskip; - - // set jacobian - info->m_J1linearAxis[0] = 1; - info->m_J1linearAxis[s+1] = 1; - info->m_J1linearAxis[2*s+2] = 1; - - - btVector3 a1,a2; - - a1 = body0_trans.getBasis()*p2pconstraint->getPivotInA(); - //dMULTIPLY0_331 (a1, body0_mat,m_constraint->m_pivotInA); - dCROSSMAT (info->m_J1angularAxis,a1,s,-,+); - if (m_body1) - { - info->m_J2linearAxis[0] = -1; - info->m_J2linearAxis[s+1] = -1; - info->m_J2linearAxis[2*s+2] = -1; - a2 = body1_trans.getBasis()*p2pconstraint->getPivotInB(); - //dMULTIPLY0_331 (a2,body1_mat,m_constraint->m_pivotInB); - dCROSSMAT (info->m_J2angularAxis,a2,s,+,-); - } - - - // set right hand side - btScalar k = info->fps * info->erp; - if (m_body1) - { - for (int j=0; j<3; j++) - { - info->m_constraintError[j] = k * (a2[j] + body1_trans.getOrigin()[j] - a1[j] - body0_trans.getOrigin()[j]); - printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]); - } - } - else - { - for (int j=0; j<3; j++) - { - info->m_constraintError[j] = k * (p2pconstraint->getPivotInB()[j] - a1[j] - body0_trans.getOrigin()[j]); - printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]); - - } - } -} - - -///////////////////limit motor support - -/*! \pre testLimitValue must be called on limot*/ -int bt_get_limit_motor_info2( - btRotationalLimitMotor * limot, - btRigidBody * body0, btRigidBody * body1, - btOdeJoint::Info2 *info, int row, btVector3& ax1, int rotational) -{ - - - int srow = row * info->rowskip; - - // if the joint is powered, or has joint limits, add in the extra row - int powered = limot->m_enableMotor; - int limit = limot->m_currentLimit; - - if (powered || limit) - { - btScalar *J1 = rotational ? info->m_J1angularAxis : info->m_J1linearAxis; - btScalar *J2 = rotational ? info->m_J2angularAxis : info->m_J2linearAxis; - - J1[srow+0] = ax1[0]; - J1[srow+1] = ax1[1]; - J1[srow+2] = ax1[2]; - if (body1) - { - J2[srow+0] = -ax1[0]; - J2[srow+1] = -ax1[1]; - J2[srow+2] = -ax1[2]; - } - - // linear limot torque decoupling step: - // - // if this is a linear limot (e.g. from a slider), we have to be careful - // that the linear constraint forces (+/- ax1) applied to the two bodies - // do not create a torque couple. in other words, the points that the - // constraint force is applied at must lie along the same ax1 axis. - // a torque couple will result in powered or limited slider-jointed free - // bodies from gaining angular momentum. - // the solution used here is to apply the constraint forces at the point - // halfway between the body centers. there is no penalty (other than an - // extra tiny bit of computation) in doing this adjustment. note that we - // only need to do this if the constraint connects two bodies. - - btVector3 ltd; // Linear Torque Decoupling vector (a torque) - if (!rotational && body1) - { - btVector3 c; - c[0]=btScalar(0.5)*(body1->getCenterOfMassPosition()[0] - -body0->getCenterOfMassPosition()[0]); - c[1]=btScalar(0.5)*(body1->getCenterOfMassPosition()[1] - -body0->getCenterOfMassPosition()[1]); - c[2]=btScalar(0.5)*(body1->getCenterOfMassPosition()[2] - -body0->getCenterOfMassPosition()[2]); - - ltd = c.cross(ax1); - - info->m_J1angularAxis[srow+0] = ltd[0]; - info->m_J1angularAxis[srow+1] = ltd[1]; - info->m_J1angularAxis[srow+2] = ltd[2]; - info->m_J2angularAxis[srow+0] = ltd[0]; - info->m_J2angularAxis[srow+1] = ltd[1]; - info->m_J2angularAxis[srow+2] = ltd[2]; - } - - // if we're limited low and high simultaneously, the joint motor is - // ineffective - - if (limit && (limot->m_loLimit == limot->m_hiLimit)) powered = 0; - - if (powered) - { - info->cfm[row] = 0.0f;//limot->m_normalCFM; - if (! limit) - { - info->m_constraintError[row] = limot->m_targetVelocity; - info->m_lowerLimit[row] = -limot->m_maxMotorForce; - info->m_higherLimit[row] = limot->m_maxMotorForce; - } - } - - if (limit) - { - btScalar k = info->fps * limot->m_ERP; - info->m_constraintError[row] = -k * limot->m_currentLimitError; - info->cfm[row] = 0.0f;//limot->m_stopCFM; - - if (limot->m_loLimit == limot->m_hiLimit) - { - // limited low and high simultaneously - info->m_lowerLimit[row] = -dInfinity; - info->m_higherLimit[row] = dInfinity; - } - else - { - if (limit == 1) - { - // low limit - info->m_lowerLimit[row] = 0; - info->m_higherLimit[row] = SIMD_INFINITY; - } - else - { - // high limit - info->m_lowerLimit[row] = -SIMD_INFINITY; - info->m_higherLimit[row] = 0; - } - - // deal with bounce - if (limot->m_bounce > 0) - { - // calculate joint velocity - btScalar vel; - if (rotational) - { - vel = body0->getAngularVelocity().dot(ax1); - if (body1) - vel -= body1->getAngularVelocity().dot(ax1); - } - else - { - vel = body0->getLinearVelocity().dot(ax1); - if (body1) - vel -= body1->getLinearVelocity().dot(ax1); - } - - // only apply bounce if the velocity is incoming, and if the - // resulting c[] exceeds what we already have. - if (limit == 1) - { - // low limit - if (vel < 0) - { - btScalar newc = -limot->m_bounce* vel; - if (newc > info->m_constraintError[row]) - info->m_constraintError[row] = newc; - } - } - else - { - // high limit - all those computations are reversed - if (vel > 0) - { - btScalar newc = -limot->m_bounce * vel; - if (newc < info->m_constraintError[row]) - info->m_constraintError[row] = newc; - } - } - } - } - } - return 1; - } - else return 0; -} - - -///////////////////OdeD6Joint - - - - - -OdeD6Joint::OdeD6Joint( - btTypedConstraint * constraint, - int index,bool swap,btOdeSolverBody* body0,btOdeSolverBody* body1): - btOdeTypedJoint(constraint,index,swap,body0,body1) -{ -} - - -void OdeD6Joint::GetInfo1(Info1 *info) -{ - btGeneric6DofConstraint * d6constraint = this->getD6Constraint(); - //prepare constraint - d6constraint->calculateTransforms(); - info->m_numConstraintRows = 3; - info->nub = 3; - - //test angular limits - for (int i=0;i<3 ;i++ ) - { - //if(i==2) continue; - if(d6constraint->testAngularLimitMotor(i)) - { - info->m_numConstraintRows++; - } - } - - -} - - -int OdeD6Joint::setLinearLimits(Info2 *info) -{ - - btGeneric6DofConstraint * d6constraint = this->getD6Constraint(); - - //retrieve matrices - btTransform body0_trans; - if (m_body0) - { - body0_trans = m_body0->m_originalBody->getCenterOfMassTransform(); - } - - btTransform body1_trans; - - if (m_body1) - { - body1_trans = m_body1->m_originalBody->getCenterOfMassTransform(); - } - - // anchor points in global coordinates with respect to body PORs. - - int s = info->rowskip; - - // set jacobian - info->m_J1linearAxis[0] = 1; - info->m_J1linearAxis[s+1] = 1; - info->m_J1linearAxis[2*s+2] = 1; - - - btVector3 a1,a2; - - a1 = body0_trans.getBasis()*d6constraint->getFrameOffsetA().getOrigin(); - //dMULTIPLY0_331 (a1, body0_mat,m_constraint->m_pivotInA); - dCROSSMAT (info->m_J1angularAxis,a1,s,-,+); - if (m_body1) - { - info->m_J2linearAxis[0] = -1; - info->m_J2linearAxis[s+1] = -1; - info->m_J2linearAxis[2*s+2] = -1; - a2 = body1_trans.getBasis()*d6constraint->getFrameOffsetB().getOrigin(); - - //dMULTIPLY0_331 (a2,body1_mat,m_constraint->m_pivotInB); - dCROSSMAT (info->m_J2angularAxis,a2,s,+,-); - } - - - // set right hand side - btScalar k = info->fps * info->erp; - if (m_body1) - { - for (int j=0; j<3; j++) - { - info->m_constraintError[j] = k * (a2[j] + body1_trans.getOrigin()[j] - - a1[j] - body0_trans.getOrigin()[j]); - } - } - else - { - for (int j=0; j<3; j++) - { - info->m_constraintError[j] = k * (d6constraint->getCalculatedTransformB().getOrigin()[j] - a1[j] - - body0_trans.getOrigin()[j]); - } - } - - return 3; - -} - -int OdeD6Joint::setAngularLimits(Info2 *info, int row_offset) -{ - btGeneric6DofConstraint * d6constraint = this->getD6Constraint(); - int row = row_offset; - //solve angular limits - for (int i=0;i<3 ;i++ ) - { - //if(i==2) continue; - if(d6constraint->getRotationalLimitMotor(i)->needApplyTorques()) - { - btVector3 axis = d6constraint->getAxis(i); - row += bt_get_limit_motor_info2( - d6constraint->getRotationalLimitMotor(i), - m_body0->m_originalBody, - m_body1 ? m_body1->m_originalBody : NULL, - info,row,axis,1); - } - } - - return row; -} - -void OdeD6Joint::GetInfo2(Info2 *info) -{ - int row = setLinearLimits(info); - setAngularLimits(info, row); -} - -//---------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------- -/* -OdeSliderJoint -Ported from ODE by Roman Ponomarev (rponom@gmail.com) -April 24, 2008 -*/ - -OdeSliderJoint::OdeSliderJoint( - btTypedConstraint * constraint, - int index,bool swap, btOdeSolverBody* body0, btOdeSolverBody* body1): - btOdeTypedJoint(constraint,index,swap,body0,body1) -{ -} // OdeSliderJoint::OdeSliderJoint() - -//---------------------------------------------------------------------------------- - -void OdeSliderJoint::GetInfo1(Info1* info) -{ - info->nub = 4; - info->m_numConstraintRows = 4; // Fixed 2 linear + 2 angular - btSliderConstraint * slider = this->getSliderConstraint(); - //prepare constraint - slider->calculateTransforms(); - slider->testLinLimits(); - if(slider->getSolveLinLimit() || slider->getPoweredLinMotor()) - { - info->m_numConstraintRows++; // limit 3rd linear as well - } - slider->testAngLimits(); - if(slider->getSolveAngLimit() || slider->getPoweredAngMotor()) - { - info->m_numConstraintRows++; // limit 3rd angular as well - } -} // OdeSliderJoint::GetInfo1() - -//---------------------------------------------------------------------------------- - -void OdeSliderJoint::GetInfo2(Info2 *info) -{ - int i, s = info->rowskip; - btSliderConstraint * slider = this->getSliderConstraint(); - const btTransform& trA = slider->getCalculatedTransformA(); - const btTransform& trB = slider->getCalculatedTransformB(); - // make rotations around Y and Z equal - // the slider axis should be the only unconstrained - // rotational axis, the angular velocity of the two bodies perpendicular to - // the slider axis should be equal. thus the constraint equations are - // p*w1 - p*w2 = 0 - // q*w1 - q*w2 = 0 - // where p and q are unit vectors normal to the slider axis, and w1 and w2 - // are the angular velocity vectors of the two bodies. - // get slider axis (X) - btVector3 ax1 = trA.getBasis().getColumn(0); - // get 2 orthos to slider axis (Y, Z) - btVector3 p = trA.getBasis().getColumn(1); - btVector3 q = trA.getBasis().getColumn(2); - // set the two slider rows - info->m_J1angularAxis[0] = p[0]; - info->m_J1angularAxis[1] = p[1]; - info->m_J1angularAxis[2] = p[2]; - info->m_J1angularAxis[s+0] = q[0]; - info->m_J1angularAxis[s+1] = q[1]; - info->m_J1angularAxis[s+2] = q[2]; - if(m_body1) - { - info->m_J2angularAxis[0] = -p[0]; - info->m_J2angularAxis[1] = -p[1]; - info->m_J2angularAxis[2] = -p[2]; - info->m_J2angularAxis[s+0] = -q[0]; - info->m_J2angularAxis[s+1] = -q[1]; - info->m_J2angularAxis[s+2] = -q[2]; - } - // compute the right hand side of the constraint equation. set relative - // body velocities along p and q to bring the slider back into alignment. - // if ax1,ax2 are the unit length slider axes as computed from body1 and - // body2, we need to rotate both bodies along the axis u = (ax1 x ax2). - // if "theta" is the angle between ax1 and ax2, we need an angular velocity - // along u to cover angle erp*theta in one step : - // |angular_velocity| = angle/time = erp*theta / stepsize - // = (erp*fps) * theta - // angular_velocity = |angular_velocity| * (ax1 x ax2) / |ax1 x ax2| - // = (erp*fps) * theta * (ax1 x ax2) / sin(theta) - // ...as ax1 and ax2 are unit length. if theta is smallish, - // theta ~= sin(theta), so - // angular_velocity = (erp*fps) * (ax1 x ax2) - // ax1 x ax2 is in the plane space of ax1, so we project the angular - // velocity to p and q to find the right hand side. - btScalar k = info->fps * info->erp * slider->getSoftnessOrthoAng(); - btVector3 ax2 = trB.getBasis().getColumn(0); - btVector3 u; - if(m_body1) - { - u = ax1.cross(ax2); - } - else - { - u = ax2.cross(ax1); - } - info->m_constraintError[0] = k * u.dot(p); - info->m_constraintError[1] = k * u.dot(q); - // pull out pos and R for both bodies. also get the connection - // vector c = pos2-pos1. - // next two rows. we want: vel2 = vel1 + w1 x c ... but this would - // result in three equations, so we project along the planespace vectors - // so that sliding along the slider axis is disregarded. for symmetry we - // also substitute (w1+w2)/2 for w1, as w1 is supposed to equal w2. - btTransform bodyA_trans = m_body0->m_originalBody->getCenterOfMassTransform(); - btTransform bodyB_trans; - if(m_body1) - { - bodyB_trans = m_body1->m_originalBody->getCenterOfMassTransform(); - } - int s2 = 2 * s, s3 = 3 * s; - btVector3 c; - if(m_body1) - { - c = bodyB_trans.getOrigin() - bodyA_trans.getOrigin(); - btVector3 tmp = btScalar(0.5) * c.cross(p); - - for (i=0; i<3; i++) info->m_J1angularAxis[s2+i] = tmp[i]; - for (i=0; i<3; i++) info->m_J2angularAxis[s2+i] = tmp[i]; - - tmp = btScalar(0.5) * c.cross(q); - - for (i=0; i<3; i++) info->m_J1angularAxis[s3+i] = tmp[i]; - for (i=0; i<3; i++) info->m_J2angularAxis[s3+i] = tmp[i]; - - for (i=0; i<3; i++) info->m_J2linearAxis[s2+i] = -p[i]; - for (i=0; i<3; i++) info->m_J2linearAxis[s3+i] = -q[i]; - } - for (i=0; i<3; i++) info->m_J1linearAxis[s2+i] = p[i]; - for (i=0; i<3; i++) info->m_J1linearAxis[s3+i] = q[i]; - // compute two elements of right hand side. we want to align the offset - // point (in body 2's frame) with the center of body 1. - btVector3 ofs; // offset point in global coordinates - if(m_body1) - { - ofs = trB.getOrigin() - trA.getOrigin(); - } - else - { - ofs = trA.getOrigin() - trB.getOrigin(); - } - k = info->fps * info->erp * slider->getSoftnessOrthoLin(); - info->m_constraintError[2] = k * p.dot(ofs); - info->m_constraintError[3] = k * q.dot(ofs); - int nrow = 3; // last filled row - int srow; - // check linear limits linear - btScalar limit_err = btScalar(0.0); - int limit = 0; - if(slider->getSolveLinLimit()) - { - limit_err = slider->getLinDepth(); - if(m_body1) - { - limit = (limit_err > btScalar(0.0)) ? 1 : 2; - } - else - { - limit = (limit_err > btScalar(0.0)) ? 2 : 1; - } - } - int powered = 0; - if(slider->getPoweredLinMotor()) - { - powered = 1; - } - // if the slider has joint limits, add in the extra row - if (limit || powered) - { - nrow++; - srow = nrow * info->rowskip; - info->m_J1linearAxis[srow+0] = ax1[0]; - info->m_J1linearAxis[srow+1] = ax1[1]; - info->m_J1linearAxis[srow+2] = ax1[2]; - if(m_body1) - { - info->m_J2linearAxis[srow+0] = -ax1[0]; - info->m_J2linearAxis[srow+1] = -ax1[1]; - info->m_J2linearAxis[srow+2] = -ax1[2]; - } - // linear torque decoupling step: - // - // we have to be careful that the linear constraint forces (+/- ax1) applied to the two bodies - // do not create a torque couple. in other words, the points that the - // constraint force is applied at must lie along the same ax1 axis. - // a torque couple will result in limited slider-jointed free - // bodies from gaining angular momentum. - // the solution used here is to apply the constraint forces at the point - // halfway between the body centers. there is no penalty (other than an - // extra tiny bit of computation) in doing this adjustment. note that we - // only need to do this if the constraint connects two bodies. - if (m_body1) - { - dVector3 ltd; // Linear Torque Decoupling vector (a torque) - c = btScalar(0.5) * c; - dCROSS (ltd,=,c,ax1); - info->m_J1angularAxis[srow+0] = ltd[0]; - info->m_J1angularAxis[srow+1] = ltd[1]; - info->m_J1angularAxis[srow+2] = ltd[2]; - info->m_J2angularAxis[srow+0] = ltd[0]; - info->m_J2angularAxis[srow+1] = ltd[1]; - info->m_J2angularAxis[srow+2] = ltd[2]; - } - // right-hand part - btScalar lostop = slider->getLowerLinLimit(); - btScalar histop = slider->getUpperLinLimit(); - if(limit && (lostop == histop)) - { // the joint motor is ineffective - powered = 0; - } - if(powered) - { - info->cfm[nrow] = btScalar(0.0); - if(!limit) - { - info->m_constraintError[nrow] = slider->getTargetLinMotorVelocity(); - info->m_lowerLimit[nrow] = -slider->getMaxLinMotorForce() * info->fps; - info->m_higherLimit[nrow] = slider->getMaxLinMotorForce() * info->fps; - } - } - if(limit) - { - k = info->fps * info->erp; - if(m_body1) - { - info->m_constraintError[nrow] = k * limit_err; - } - else - { - info->m_constraintError[nrow] = - k * limit_err; - } - info->cfm[nrow] = btScalar(0.0); // stop_cfm; - if(lostop == histop) - { - // limited low and high simultaneously - info->m_lowerLimit[nrow] = -SIMD_INFINITY; - info->m_higherLimit[nrow] = SIMD_INFINITY; - } - else - { - if(limit == 1) - { - // low limit - info->m_lowerLimit[nrow] = 0; - info->m_higherLimit[nrow] = SIMD_INFINITY; - } - else - { - // high limit - info->m_lowerLimit[nrow] = -SIMD_INFINITY; - info->m_higherLimit[nrow] = 0; - } - } - // bounce (we'll use slider parameter abs(1.0 - m_dampingLimLin) for that) - btScalar bounce = btFabs(btScalar(1.0) - slider->getDampingLimLin()); - if(bounce > btScalar(0.0)) - { - btScalar vel = m_body0->m_originalBody->getLinearVelocity().dot(ax1); - if(m_body1) - { - vel -= m_body1->m_originalBody->getLinearVelocity().dot(ax1); - } - // only apply bounce if the velocity is incoming, and if the - // resulting c[] exceeds what we already have. - if(limit == 1) - { - // low limit - if(vel < 0) - { - btScalar newc = -bounce * vel; - if (newc > info->m_constraintError[nrow]) - info->m_constraintError[nrow] = newc; - } - } - else - { - // high limit - all those computations are reversed - if(vel > 0) - { - btScalar newc = -bounce * vel; - if(newc < info->m_constraintError[nrow]) - info->m_constraintError[nrow] = newc; - } - } - } - info->m_constraintError[nrow] *= slider->getSoftnessLimLin(); - } // if(limit) - } // if linear limit - // check angular limits - limit_err = btScalar(0.0); - limit = 0; - if(slider->getSolveAngLimit()) - { - limit_err = slider->getAngDepth(); - if(m_body1) - { - limit = (limit_err > btScalar(0.0)) ? 1 : 2; - } - else - { - limit = (limit_err > btScalar(0.0)) ? 2 : 1; - } - } - // if the slider has joint limits, add in the extra row - powered = 0; - if(slider->getPoweredAngMotor()) - { - powered = 1; - } - if(limit || powered) - { - nrow++; - srow = nrow * info->rowskip; - info->m_J1angularAxis[srow+0] = ax1[0]; - info->m_J1angularAxis[srow+1] = ax1[1]; - info->m_J1angularAxis[srow+2] = ax1[2]; - if(m_body1) - { - info->m_J2angularAxis[srow+0] = -ax1[0]; - info->m_J2angularAxis[srow+1] = -ax1[1]; - info->m_J2angularAxis[srow+2] = -ax1[2]; - } - btScalar lostop = slider->getLowerAngLimit(); - btScalar histop = slider->getUpperAngLimit(); - if(limit && (lostop == histop)) - { // the joint motor is ineffective - powered = 0; - } - if(powered) - { - info->cfm[nrow] = btScalar(0.0); - if(!limit) - { - info->m_constraintError[nrow] = slider->getTargetAngMotorVelocity(); - info->m_lowerLimit[nrow] = -slider->getMaxAngMotorForce() * info->fps; - info->m_higherLimit[nrow] = slider->getMaxAngMotorForce() * info->fps; - } - } - if(limit) - { - k = info->fps * info->erp; - if (m_body1) - { - info->m_constraintError[nrow] = k * limit_err; - } - else - { - info->m_constraintError[nrow] = -k * limit_err; - } - info->cfm[nrow] = btScalar(0.0); // stop_cfm; - if(lostop == histop) - { - // limited low and high simultaneously - info->m_lowerLimit[nrow] = -SIMD_INFINITY; - info->m_higherLimit[nrow] = SIMD_INFINITY; - } - else - { - if (limit == 1) - { - // low limit - info->m_lowerLimit[nrow] = 0; - info->m_higherLimit[nrow] = SIMD_INFINITY; - } - else - { - // high limit - info->m_lowerLimit[nrow] = -SIMD_INFINITY; - info->m_higherLimit[nrow] = 0; - } - } - // bounce (we'll use slider parameter abs(1.0 - m_dampingLimAng) for that) - btScalar bounce = btFabs(btScalar(1.0) - slider->getDampingLimAng()); - if(bounce > btScalar(0.0)) - { - btScalar vel = m_body0->m_originalBody->getAngularVelocity().dot(ax1); - if(m_body1) - { - vel -= m_body1->m_originalBody->getAngularVelocity().dot(ax1); - } - // only apply bounce if the velocity is incoming, and if the - // resulting c[] exceeds what we already have. - if(limit == 1) - { - // low limit - if(vel < 0) - { - btScalar newc = -bounce * vel; - if (newc > info->m_constraintError[nrow]) info->m_constraintError[nrow] = newc; - } - } - else - { - // high limit - all those computations are reversed - if(vel > 0) - { - btScalar newc = -bounce * vel; - if(newc < info->m_constraintError[nrow]) info->m_constraintError[nrow] = newc; - } - } - } - info->m_constraintError[nrow] *= slider->getSoftnessLimAng(); - } // if(limit) - } // if angular limit or powered -} // OdeSliderJoint::GetInfo2() - -//---------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------- - - - - diff --git a/Extras/quickstep/btOdeTypedJoint.h b/Extras/quickstep/btOdeTypedJoint.h deleted file mode 100644 index ae3e078b6..000000000 --- a/Extras/quickstep/btOdeTypedJoint.h +++ /dev/null @@ -1,142 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ -/* -2007-09-09 -Added support for typed joints by Francisco Le?n -email: projectileman@yahoo.com -http://gimpact.sf.net -*/ - -#ifndef TYPED_JOINT_H -#define TYPED_JOINT_H - -#include "btOdeJoint.h" -#include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h" -#include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h" -#include "BulletDynamics/ConstraintSolver/btSliderConstraint.h" - -struct btOdeSolverBody; - -class btOdeTypedJoint : public btOdeJoint -{ -public: - btTypedConstraint * m_constraint; - int m_index; - bool m_swapBodies; - btOdeSolverBody* m_body0; - btOdeSolverBody* m_body1; - - btOdeTypedJoint(){} - btOdeTypedJoint( - btTypedConstraint * constraint, - int index,bool swap,btOdeSolverBody* body0,btOdeSolverBody* body1): - m_constraint(constraint), - m_index(index), - m_swapBodies(swap), - m_body0(body0), - m_body1(body1) - { - } - - virtual void GetInfo1(Info1 *info); - virtual void GetInfo2(Info2 *info); -}; - - - -class OdeP2PJoint : public btOdeTypedJoint -{ -protected: - inline btPoint2PointConstraint * getP2PConstraint() - { - return static_cast(m_constraint); - } -public: - - OdeP2PJoint() {}; - - OdeP2PJoint(btTypedConstraint* constraint,int index,bool swap,btOdeSolverBody* body0,btOdeSolverBody* body1); - - //btOdeJoint interface for solver - - virtual void GetInfo1(Info1 *info); - - virtual void GetInfo2(Info2 *info); -}; - - -class OdeD6Joint : public btOdeTypedJoint -{ -protected: - inline btGeneric6DofConstraint * getD6Constraint() - { - return static_cast(m_constraint); - } - - int setLinearLimits(Info2 *info); - int setAngularLimits(Info2 *info, int row_offset); - -public: - - OdeD6Joint() {}; - - OdeD6Joint(btTypedConstraint* constraint,int index,bool swap,btOdeSolverBody* body0,btOdeSolverBody* body1); - - //btOdeJoint interface for solver - - virtual void GetInfo1(Info1 *info); - - virtual void GetInfo2(Info2 *info); -}; - -//! retrieves the constraint info from a btRotationalLimitMotor object -/*! \pre testLimitValue must be called on limot*/ -int bt_get_limit_motor_info2( - btRotationalLimitMotor * limot, - btRigidBody * body0, btRigidBody * body1, - btOdeJoint::Info2 *info, int row, btVector3& ax1, int rotational); - -/* -OdeSliderJoint -Ported from ODE by Roman Ponomarev (rponom@gmail.com) -April 24, 2008 -*/ -class OdeSliderJoint : public btOdeTypedJoint -{ -protected: - inline btSliderConstraint * getSliderConstraint() - { - return static_cast(m_constraint); - } -public: - - OdeSliderJoint() {}; - - OdeSliderJoint(btTypedConstraint* constraint,int index,bool swap, btOdeSolverBody* body0, btOdeSolverBody* body1); - - //BU_Joint interface for solver - - virtual void GetInfo1(Info1 *info); - - virtual void GetInfo2(Info2 *info); -}; - - - - -#endif //CONTACT_JOINT_H - - - diff --git a/Extras/quickstep/btSorLcp.cpp b/Extras/quickstep/btSorLcp.cpp deleted file mode 100644 index 5304bf0e5..000000000 --- a/Extras/quickstep/btSorLcp.cpp +++ /dev/null @@ -1,690 +0,0 @@ -/* - * Quickstep constraint solver re-distributed under the ZLib license with permission from Russell L. Smith - * Original version is from Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. - * All rights reserved. Email: russ@q12.org Web: www.q12.org - Bullet Continuous Collision Detection and Physics Library - Bullet is Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#include "btSorLcp.h" -#include "btOdeSolverBody.h" -#include "LinearMath/btQuickProf.h" - -#ifdef USE_SOR_SOLVER - -// SOR LCP taken from ode quickstep, for comparisons to Bullet sequential impulse solver. -#include "LinearMath/btScalar.h" - -#include "BulletDynamics/Dynamics/btRigidBody.h" -#include -#include //FLT_MAX -#ifdef WIN32 -#include -#endif -#include -#include - -#if defined (WIN32) -#include -#else -#if defined (__FreeBSD__) -#include -#else -#include -#endif -#endif - -#include "btOdeJoint.h" -#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h" -//////////////////////////////////////////////////////////////////// -//math stuff -#include "btOdeMacros.h" - -//*************************************************************************** -// configuration - -// for the SOR and CG methods: -// uncomment the following line to use warm starting. this definitely -// help for motor-driven joints. unfortunately it appears to hurt -// with high-friction contacts using the SOR method. use with care - -//#define WARM_STARTING 1 - -// for the SOR method: -// uncomment the following line to randomly reorder constraint rows -// during the solution. depending on the situation, this can help a lot -// or hardly at all, but it doesn't seem to hurt. - -//#define RANDOMLY_REORDER_CONSTRAINTS 1 - -//*************************************************************************** -// various common computations involving the matrix JconstraintAxis -// compute iMJ = inv(M)*JconstraintAxis' -inline void compute_invM_JT (int numConstraintRows, dRealMutablePtr JconstraintAxis, dRealMutablePtr iMJ, int *jb, - //OdeSolverBody* const *body, - const btAlignedObjectArray &body, - dRealPtr inverseInertiaWorld) -{ - int i,j; - dRealMutablePtr iMJ_ptr = iMJ; - dRealMutablePtr J_ptr = JconstraintAxis; - for (i=0; im_invMass*J_ptr[j]; - dMULTIPLY0_331 (iMJ_ptr + 3, inverseInertiaWorld + 12*b1, J_ptr + 3); - - if (b2 >= 0) { - for (j=0; j<3; j++) - iMJ_ptr[j+6] = body[b2]->m_invMass*J_ptr[j+6];//inv mass * constraint (normal) axis - dMULTIPLY0_331 (iMJ_ptr + 9, inverseInertiaWorld + 12*b2, J_ptr + 9);//inverse inertia world * constraint (normal) axis - } - J_ptr += 12; - iMJ_ptr += 12; - } -} - -#if 0 -static void multiply_invM_JTSpecial (int numConstraintRows, int nb, dRealMutablePtr iMJ, int *jb, - dRealMutablePtr in, dRealMutablePtr out,int onlyBody1,int onlyBody2) -{ - int i,j; - - - - dRealMutablePtr out_ptr1 = out + onlyBody1*6; - - for (j=0; j<6; j++) - out_ptr1[j] = 0; - - if (onlyBody2 >= 0) - { - out_ptr1 = out + onlyBody2*6; - - for (j=0; j<6; j++) - out_ptr1[j] = 0; - } - - dRealPtr iMJ_ptr = iMJ; - for (i=0; i= 0) - { - out_ptr = out + b2*6; - for (j=0; j<6; j++) - out_ptr[j] += iMJ_ptr[j] * in[i]; - } - } - - iMJ_ptr += 6; - - } -} -#endif - - -// compute out = inv(M)*JconstraintAxis'*in. - -#if 0 -static void multiply_invM_JT (int numConstraintRows, int nb, dRealMutablePtr iMJ, int *jb, - dRealMutablePtr in, dRealMutablePtr out) -{ - int i,j; - dSetZero1 (out,6*nb); - dRealPtr iMJ_ptr = iMJ; - for (i=0; i= 0) { - out_ptr = out + b2*6; - for (j=0; j<6; j++) out_ptr[j] += iMJ_ptr[j] * in[i]; - } - iMJ_ptr += 6; - } -} -#endif - - -// compute out = JconstraintAxis*in. -inline void multiply_J (int numConstraintRows, dRealMutablePtr JconstraintAxis, int *jb, - dRealMutablePtr in, dRealMutablePtr out) -{ - int i,j; - dRealPtr J_ptr = JconstraintAxis; - for (i=0; i= 0) { - in_ptr = in + b2*6; - for (j=0; j<6; j++) sum += J_ptr[j] * in_ptr[j]; - } - J_ptr += 6; - out[i] = sum; - } -} - -//*************************************************************************** -// SOR-LCP method - -// nb is the number of bodies in the body array. -// JconstraintAxis is an numConstraintRows*12 matrix of constraint rows -// jb is an array of first and second body numbers for each constraint row -// inverseInertiaWorld is the global frame inverse inertia for each body (stacked 3x3 matrices) -// -// this returns lambdaAccumulatedImpulse and fc (the constraint force). -// note: fc is returned as inv(M)*JconstraintAxis'*lambdaAccumulatedImpulse, the constraint force is actually JconstraintAxis'*lambdaAccumulatedImpulse -// -// b, lowerLimit and higherLimit are modified on exit - -//------------------------------------------------------------------------------ -ATTRIBUTE_ALIGNED16(struct) IndexError { - btScalar error; // error to sort on - int findex; - int index; // row index -}; - -//------------------------------------------------------------------------------ -void btSorLcpSolver::SOR_LCP(int numConstraintRows, int nb, dRealMutablePtr JconstraintAxis, int *jb, - const btAlignedObjectArray &body, - dRealPtr inverseInertiaWorld, dRealMutablePtr lambdaAccumulatedImpulse, dRealMutablePtr invMforce, dRealMutablePtr rhs, - dRealMutablePtr lowerLimit, dRealMutablePtr higherLimit, dRealPtr cfm, int *findex, - int numiter,float overRelax, - btStackAlloc* stackAlloc - ) -{ - BT_PROFILE("btSorLcpSolver::SOR_LCP"); - - //btBlock* saBlock = stackAlloc->beginBlock();//Remo: 10.10.2007 - AutoBlockSa asaBlock(stackAlloc); - - const int num_iterations = numiter; - const float sor_w = overRelax; // SOR over-relaxation parameter - - int i,j; - -#ifdef WARM_STARTING - // for warm starting, this seems to be necessary to prevent - // jerkiness in motor-driven joints. i have no idea why this works. - for (i=0; i= 0) { - for (j=6; j<12; j++) - sum += iMJ_ptr[j] * J_ptr[j]; - } - iMJ_ptr += 12; - J_ptr += 12; - Ad[i] = sor_w / sum;//(sum + cfm[i]); - } - - // scale JconstraintAxis and b by Ad - J_ptr = JconstraintAxis; - for (i=0; i= 0) - order[j++].index = i; - dIASSERT (j==numConstraintRows); -#endif - - for (int iteration=0; iteration < num_iterations; iteration++) { - -#ifdef REORDER_CONSTRAINTS - // constraints with findex < 0 always come first. - if (iteration < 2) { - // for the first two iterations, solve the constraints in - // the given order - for (i=0; i v2) ? v1 : v2; - if (max > 0) { - //@@@ relative error: order[i].error = dFabs(lambdaAccumulatedImpulse[i]-last_lambda[i])/max; - order[i].error = dFabs(lambdaAccumulatedImpulse[i]-last_lambda[i]); - } - else { - order[i].error = dInfinity; - } - order[i].findex = findex[i]; - order[i].index = i; - } - } - qsort (order,numConstraintRows,sizeof(IndexError),&compare_index_error); -#endif -#ifdef RANDOMLY_REORDER_CONSTRAINTS - if ((iteration & 7) == 0) { - for (i=1; i= 0) { - higherLimit[index] = btFabs (hicopy[index] * lambdaAccumulatedImpulse[findex[index]]); - lowerLimit[index] = -higherLimit[index]; - } - - int b1 = jb[index*2]; - int b2 = jb[index*2+1]; - - dRealMutablePtr deltaVelocity = invMforce + 6*b1; - - float deltaAppliedImpulse = rhs[index] - lambdaAccumulatedImpulse[index]*Ad[index]; - - // @@@ potential optimization: SIMD-ize this and the b2 >= 0 case - deltaAppliedImpulse -=deltaVelocity[0] * J_ptr[0] + deltaVelocity[1] * J_ptr[1] + - deltaVelocity[2] * J_ptr[2] + deltaVelocity[3] * J_ptr[3] + - deltaVelocity[4] * J_ptr[4] + deltaVelocity[5] * J_ptr[5]; - // @@@ potential optimization: handle 1-body constraints in a separate - // loop to avoid the cost of test & jump? - if (b2 >= 0) { - deltaVelocity = invMforce + 6*b2; - deltaAppliedImpulse -=deltaVelocity[0] * J_ptr[6] + deltaVelocity[1] * J_ptr[7] + - deltaVelocity[2] * J_ptr[8] + deltaVelocity[3] * J_ptr[9] + - deltaVelocity[4] * J_ptr[10] + deltaVelocity[5] * J_ptr[11]; - } - - // compute lambdaAccumulatedImpulse and clamp it to [lowerLimit,higherLimit]. - // @@@ potential optimization: does SSE have clamping instructions - // to save test+jump penalties here? - float sum = lambdaAccumulatedImpulse[index] + deltaAppliedImpulse; - if (sum < lowerLimit[index]) { - deltaAppliedImpulse = lowerLimit[index]-lambdaAccumulatedImpulse[index]; - lambdaAccumulatedImpulse[index] = lowerLimit[index]; - } - else if (sum > higherLimit[index]) { - deltaAppliedImpulse = higherLimit[index]-lambdaAccumulatedImpulse[index]; - lambdaAccumulatedImpulse[index] = higherLimit[index]; - } - else { - lambdaAccumulatedImpulse[index] = sum; - } - - //@@@ a trick that may or may not help - //float ramp = (1-((float)(iteration+1)/(float)num_iterations)); - //deltaAppliedImpulse *= ramp; - - // update invMforce. - // @@@ potential optimization: SIMD for this and the b2 >= 0 case - deltaVelocity = invMforce + 6*b1; - deltaVelocity[0] += deltaAppliedImpulse * iMJ_ptr[0]; - deltaVelocity[1] += deltaAppliedImpulse * iMJ_ptr[1]; - deltaVelocity[2] += deltaAppliedImpulse * iMJ_ptr[2]; - deltaVelocity[3] += deltaAppliedImpulse * iMJ_ptr[3]; - deltaVelocity[4] += deltaAppliedImpulse * iMJ_ptr[4]; - deltaVelocity[5] += deltaAppliedImpulse * iMJ_ptr[5]; - // @@@ potential optimization: handle 1-body constraints in a separate - // loop to avoid the cost of test & jump? - if (b2 >= 0) { - deltaVelocity = invMforce + 6*b2; - deltaVelocity[0] += deltaAppliedImpulse * iMJ_ptr[6]; - deltaVelocity[1] += deltaAppliedImpulse * iMJ_ptr[7]; - deltaVelocity[2] += deltaAppliedImpulse * iMJ_ptr[8]; - deltaVelocity[3] += deltaAppliedImpulse * iMJ_ptr[9]; - deltaVelocity[4] += deltaAppliedImpulse * iMJ_ptr[10]; - deltaVelocity[5] += deltaAppliedImpulse * iMJ_ptr[11]; - } - } - } - //stackAlloc->endBlock(saBlock);//Remo: 10.10.2007 -} - -//------------------------------------------------------------------------------ -void btSorLcpSolver::SolveInternal1 (const btAlignedObjectArray &body, int nb, - btAlignedObjectArray &joint, - int nj, const btContactSolverInfo& solverInfo, - btStackAlloc* stackAlloc) -{ - BT_PROFILE("btSorLcpSolver::SolveInternal1"); - //btBlock* saBlock = stackAlloc->beginBlock();//Remo: 10.10.2007 - AutoBlockSa asaBlock(stackAlloc); - - int numIter = solverInfo.m_numIterations; - float sOr = solverInfo.m_sor; - - int i,j; - - btScalar stepsize1 = dRecip(solverInfo.m_timeStep); - - // number all bodies in the body list - set their tag values - for (i=0; im_odeTag = i; - - // make a local copy of the joint array, because we might want to modify it. - // (the "btOdeJoint *const*" declaration says we're allowed to modify the joints - // but not the joint array, because the caller might need it unchanged). - //@@@ do we really need to do this? we'll be sorting constraint rows individually, not joints - //btOdeJoint **joint = (btOdeJoint**) alloca (nj * sizeof(btOdeJoint*)); - //memcpy (joint,_joint,nj * sizeof(btOdeJoint*)); - - // for all bodies, compute the inertia tensor and its inverse in the global - // frame, and compute the rotational force and add it to the torque - // accumulator. I and inverseInertiaWorld are a vertical stack of 3x4 matrices, one per body. - dRealAllocaArray (I,3*4*nb); - dRealAllocaArray (inverseInertiaWorld,3*4*nb); -/* for (i=0; im_I,body[i]->m_R); - // compute inverse inertia tensor in global frame - dMULTIPLY2_333 (tmp,body[i]->m_invI,body[i]->m_R); - dMULTIPLY0_333 (inverseInertiaWorld+i*12,body[i]->m_R,tmp); - // compute rotational force - dCROSS (body[i]->m_tacc,-=,body[i]->getAngularVelocity(),tmp); - } -*/ - for (i=0; im_I,body[i]->m_R); - dMULTIPLY0_333 (I+i*12,body[i]->m_R,tmp); - - // compute inverse inertia tensor in global frame - dMULTIPLY2_333 (tmp,body[i]->m_invI,body[i]->m_R); - dMULTIPLY0_333 (inverseInertiaWorld+i*12,body[i]->m_R,tmp); - // compute rotational force -// dMULTIPLY0_331 (tmp,I+i*12,body[i]->m_angularVelocity); -// dCROSS (body[i]->m_tacc,-=,body[i]->m_angularVelocity,tmp); - } - - - - - // get joint information (numConstraintRows = total constraint dimension, nub = number of unbounded variables). - // joints with numConstraintRows=0 are inactive and are removed from the joints array - // entirely, so that the code that follows does not consider them. - //@@@ do we really need to save all the info1's - btOdeJoint::Info1 *info = (btOdeJoint::Info1*) ALLOCA (nj*sizeof(btOdeJoint::Info1)); - - for (i=0, j=0; jGetInfo1 (info+i); - dIASSERT (info[i].m_numConstraintRows >= 0 && info[i].m_numConstraintRows <= 6 && info[i].nub >= 0 && info[i].nub <= info[i].m_numConstraintRows); - if (info[i].m_numConstraintRows > 0) { - joint[i] = joint[j]; - i++; - } - } - nj = i; - - // create the row offset array - int numConstraintRows = 0; - int *constraintRowOffsets = (int*) ALLOCA (nj*sizeof(int)); - for (i=0; i 0) { - // create a constraint equation right hand side vector `c', a constraint - // force mixing vector `cfm', and LCP low and high bound vectors, and an - // 'findex' vector. - dRealAllocaArray (c_rhs,numConstraintRows); - dRealAllocaArray (cfm,numConstraintRows); - dRealAllocaArray (lowerLimit,numConstraintRows); - dRealAllocaArray (higherLimit,numConstraintRows); - - int *findex = (int*) ALLOCA (numConstraintRows*sizeof(int)); - - dSetZero1 (c_rhs,numConstraintRows); - dSetValue1 (cfm,numConstraintRows,solverInfo.m_globalCfm); - dSetValue1 (lowerLimit,numConstraintRows,-dInfinity); - dSetValue1 (higherLimit,numConstraintRows, dInfinity); - for (i=0; iGetInfo2 (&Jinfo); - - if (Jinfo.m_constraintError[0] > solverInfo.m_maxErrorReduction) - Jinfo.m_constraintError[0] = solverInfo.m_maxErrorReduction; - - // adjust returned findex values for global index numbering - for (j=0; j= 0) - findex[constraintRowOffsets[i] + j] += constraintRowOffsets[i]; - } - } - - // create an array of body numbers for each joint row - int *jb_ptr = jb; - for (i=0; inode[0].body) ? (joint[i]->node[0].body->m_odeTag) : -1; - int b2 = (joint[i]->node[1].body) ? (joint[i]->node[1].body->m_odeTag) : -1; - for (j=0; jm_invMass; - for (j=0; j<3; j++) - tmp1[i*6+j] = body[i]->m_facc[j] * body_invMass + body[i]->m_linearVelocity[j] * stepsize1; - dMULTIPLY0_331NEW (tmp1 + i*6 + 3,=,inverseInertiaWorld + i*12,body[i]->m_tacc); - for (j=0; j<3; j++) - tmp1[i*6+3+j] += body[i]->m_angularVelocity[j] * stepsize1; - } - - // put JconstraintAxis*tmp1 into rhs - dRealAllocaArray (rhs,numConstraintRows); - multiply_J (numConstraintRows,JconstraintAxis,jb,tmp1,rhs); - - // complete rhs - for (i=0; ilambdaAccumulatedImpulse,info[i].numConstraintRows * sizeof(btScalar)); - } -#endif - - // solve the LCP problem and get lambdaAccumulatedImpulse and invM*constraint_force - dRealAllocaArray (cforce,nb*6); - - /// SOR_LCP - SOR_LCP (numConstraintRows,nb,JconstraintAxis,jb,body,inverseInertiaWorld,lambdaAccumulatedImpulse,cforce,rhs,lowerLimit,higherLimit,cfm,findex,numIter,sOr,stackAlloc); - -#ifdef WARM_STARTING - // save lambdaAccumulatedImpulse for the next iteration - //@@@ note that this doesn't work for contact joints yet, as they are - // recreated every iteration - for (i=0; ilambdaAccumulatedImpulse,lambdaAccumulatedImpulse+constraintRowOffsets[i],info[i].numConstraintRows * sizeof(btScalar)); - } -#endif - - // note that the SOR method overwrites rhs and JconstraintAxis at this point, so - // they should not be used again. - // add stepsize * cforce to the body velocity - for (i=0; im_linearVelocity[j] += solverInfo.m_timeStep* cforce[i*6+j]; - for (j=0; j<3; j++) - body[i]->m_angularVelocity[j] += solverInfo.m_timeStep* cforce[i*6+3+j]; - - } - } - - // compute the velocity update: - // add stepsize * invM * fe to the body velocity - for (i=0; im_invMass; - btVector3 linvel = body[i]->m_linearVelocity; - btVector3 angvel = body[i]->m_angularVelocity; - - for (j=0; j<3; j++) - { - linvel[j] += solverInfo.m_timeStep * body_invMass * body[i]->m_facc[j]; - } - for (j=0; j<3; j++) - { - body[i]->m_tacc[j] *= solverInfo.m_timeStep; - } - dMULTIPLY0_331NEW(angvel,+=,inverseInertiaWorld + i*12,body[i]->m_tacc); - body[i]->m_angularVelocity = angvel; - } - //stackAlloc->endBlock(saBlock);//Remo: 10.10.2007 -} - - -#endif //USE_SOR_SOLVER diff --git a/Extras/quickstep/btSorLcp.h b/Extras/quickstep/btSorLcp.h deleted file mode 100644 index 46d1a190b..000000000 --- a/Extras/quickstep/btSorLcp.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Quickstep constraint solver re-distributed under the ZLib license with permission from Russell L. Smith - * Original version is from Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. - * All rights reserved. Email: russ@q12.org Web: www.q12.org - Bullet Continuous Collision Detection and Physics Library - Bullet is Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#define USE_SOR_SOLVER -#ifdef USE_SOR_SOLVER - -#ifndef SOR_LCP_H -#define SOR_LCP_H -struct btOdeSolverBody; -class btOdeJoint; -#include "LinearMath/btScalar.h" -#include "LinearMath/btAlignedObjectArray.h" -#include "LinearMath/btStackAlloc.h" - -struct btContactSolverInfo; - - -//============================================================================= -class btSorLcpSolver //Remotion: 11.10.2007 -{ -public: - btSorLcpSolver() - { - dRand2_seed = 0; - } - - void SolveInternal1 (const btAlignedObjectArray &body, int nb, - btAlignedObjectArray &joint, - int nj, const btContactSolverInfo& solverInfo, - btStackAlloc* stackAlloc - ); - -public: //data - unsigned long dRand2_seed; - -protected: //typedef - typedef const btScalar *dRealPtr; - typedef btScalar *dRealMutablePtr; - -protected: //members - //------------------------------------------------------------------------------ - SIMD_FORCE_INLINE unsigned long dRand2() - { - dRand2_seed = (1664525L*dRand2_seed + 1013904223L) & 0xffffffff; - return dRand2_seed; - } - //------------------------------------------------------------------------------ - SIMD_FORCE_INLINE int dRandInt2 (int n) - { - float a = float(n) / 4294967296.0f; - return (int) (float(dRand2()) * a); - } - //------------------------------------------------------------------------------ - void SOR_LCP(int m, int nb, dRealMutablePtr J, int *jb, - const btAlignedObjectArray &body, - dRealPtr invI, dRealMutablePtr lambda, dRealMutablePtr invMforce, dRealMutablePtr rhs, - dRealMutablePtr lo, dRealMutablePtr hi, dRealPtr cfm, int *findex, - int numiter,float overRelax, - btStackAlloc* stackAlloc - ); -}; - - -//============================================================================= -class AutoBlockSa //Remotion: 10.10.2007 -{ - btStackAlloc* stackAlloc; - btBlock* saBlock; -public: - AutoBlockSa(btStackAlloc* stackAlloc_) - { - stackAlloc = stackAlloc_; - saBlock = stackAlloc->beginBlock(); - } - ~AutoBlockSa() - { - stackAlloc->endBlock(saBlock); - } - //operator btBlock* () { return saBlock; } -}; -// //Usage -//void function(btStackAlloc* stackAlloc) -//{ -// AutoBlockSa(stackAlloc); -// ... -// if(...) return; -// return; -//} -//------------------------------------------------------------------------------ - - -#endif //SOR_LCP_H - -#endif //USE_SOR_SOLVER - diff --git a/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp b/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp index 2191ddcbe..1e7119955 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp @@ -104,4 +104,10 @@ const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* seriali } - +void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const +{ + int len = calculateSerializeBufferSize(); + btChunk* chunk = serializer->allocate(len,1); + const char* structType = serialize(chunk->m_oldPtr, serializer); + serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,(void*)this); +} diff --git a/src/BulletCollision/CollisionDispatch/btCollisionObject.h b/src/BulletCollision/CollisionDispatch/btCollisionObject.h index be3d5a710..549b404dc 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionObject.h +++ b/src/BulletCollision/CollisionDispatch/btCollisionObject.h @@ -430,6 +430,7 @@ public: ///fills the dataBuffer and returns the struct name (and 0 on failure) virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const; + virtual void serializeSingleObject(class btSerializer* serializer) const; }; diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index e20317e50..e478d1bb1 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -1382,9 +1382,7 @@ void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer) btCollisionObject* colObj = m_collisionObjects[i]; if (colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT) { - btChunk* chunk = serializer->allocate(colObj->calculateSerializeBufferSize(),1); - const char* structType = colObj->serialize(chunk->m_oldPtr, serializer); - serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,colObj); + colObj->serializeSingleObject(serializer); } } @@ -1399,11 +1397,7 @@ void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer) if (!serializedShapes.find(shape)) { serializedShapes.insert(shape,shape); - //serialize all collision shapes - int len = shape->calculateSerializeBufferSize(); - btChunk* chunk = serializer->allocate(len,1); - const char* structType = shape->serialize(chunk->m_oldPtr, serializer); - serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,shape); + shape->serializeSingleShape(serializer); } } @@ -1412,6 +1406,8 @@ void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer) void btCollisionWorld::serialize(btSerializer* serializer) { + + serializer->startSerialization(); serializeCollisionObjects(serializer); diff --git a/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp b/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp index f5b569727..d1c771fb4 100644 --- a/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp +++ b/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp @@ -439,5 +439,28 @@ const char* btBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* se return "btTriangleMeshShapeData"; } +void btBvhTriangleMeshShape::serializeSingleBvh(btSerializer* serializer) const +{ + if (m_bvh) + { + int len = m_bvh->calculateSerializeBufferSizeNew(); //make sure not to use calculateSerializeBufferSize because it is used for in-place + btChunk* chunk = serializer->allocate(len,1); + const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer); + serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,(void*)m_bvh); + } +} + +void btBvhTriangleMeshShape::serializeSingleTriangleInfoMap(btSerializer* serializer) const +{ + if (m_triangleInfoMap) + { + int len = m_triangleInfoMap->calculateSerializeBufferSize(); + btChunk* chunk = serializer->allocate(len,1); + const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer); + serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,(void*)m_triangleInfoMap); + } +} + + diff --git a/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h b/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h index c172c4f01..e4d4386ae 100644 --- a/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h +++ b/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h @@ -104,6 +104,10 @@ public: ///fills the dataBuffer and returns the struct name (and 0 on failure) virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; + virtual void serializeSingleBvh(btSerializer* serializer) const; + + virtual void serializeSingleTriangleInfoMap(btSerializer* serializer) const; + }; ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 diff --git a/src/BulletCollision/CollisionShapes/btCollisionShape.cpp b/src/BulletCollision/CollisionShapes/btCollisionShape.cpp index 9372a67b0..3a31ab7a5 100644 --- a/src/BulletCollision/CollisionShapes/btCollisionShape.cpp +++ b/src/BulletCollision/CollisionShapes/btCollisionShape.cpp @@ -109,3 +109,10 @@ const char* btCollisionShape::serialize(void* dataBuffer, btSerializer* serializ return "btCollisionShapeData"; } +void btCollisionShape::serializeSingleShape(btSerializer* serializer) const +{ + int len = calculateSerializeBufferSize(); + btChunk* chunk = serializer->allocate(len,1); + const char* structType = serialize(chunk->m_oldPtr, serializer); + serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,(void*)this); +} \ No newline at end of file diff --git a/src/BulletCollision/CollisionShapes/btCollisionShape.h b/src/BulletCollision/CollisionShapes/btCollisionShape.h index a3278aa3a..693c77820 100644 --- a/src/BulletCollision/CollisionShapes/btCollisionShape.h +++ b/src/BulletCollision/CollisionShapes/btCollisionShape.h @@ -123,6 +123,8 @@ public: ///fills the dataBuffer and returns the struct name (and 0 on failure) virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; + virtual void serializeSingleShape(btSerializer* serializer) const; + }; ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 diff --git a/src/BulletDynamics/Dynamics/btRigidBody.cpp b/src/BulletDynamics/Dynamics/btRigidBody.cpp index d9eb33b94..35de8e475 100644 --- a/src/BulletDynamics/Dynamics/btRigidBody.cpp +++ b/src/BulletDynamics/Dynamics/btRigidBody.cpp @@ -19,6 +19,7 @@ subject to the following restrictions: #include "LinearMath/btTransformUtil.h" #include "LinearMath/btMotionState.h" #include "BulletDynamics/ConstraintSolver/btTypedConstraint.h" +#include "LinearMath/btSerializer.h" //'temporarily' global variables btScalar gDeactivationTime = btScalar(2.); @@ -388,3 +389,12 @@ const char* btRigidBody::serialize(void* dataBuffer, class btSerializer* seriali } + +void btRigidBody::serializeSingleObject(class btSerializer* serializer) const +{ + btChunk* chunk = serializer->allocate(calculateSerializeBufferSize(),1); + const char* structType = serialize(chunk->m_oldPtr, serializer); + serializer->finalizeChunk(chunk,structType,BT_RIGIDBODY_CODE,(void*)this); +} + + diff --git a/src/BulletDynamics/Dynamics/btRigidBody.h b/src/BulletDynamics/Dynamics/btRigidBody.h index 236e04e08..571a30ce6 100644 --- a/src/BulletDynamics/Dynamics/btRigidBody.h +++ b/src/BulletDynamics/Dynamics/btRigidBody.h @@ -606,6 +606,8 @@ public: ///fills the dataBuffer and returns the struct name (and 0 on failure) virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const; + virtual void serializeSingleObject(class btSerializer* serializer) const; + }; //@todo add m_optionalMotionState and m_constraintRefs to btRigidBodyData diff --git a/src/LinearMath/btSerializer.cpp b/src/LinearMath/btSerializer.cpp index dc28b6c14..e8af3b5bd 100644 --- a/src/LinearMath/btSerializer.cpp +++ b/src/LinearMath/btSerializer.cpp @@ -1,289 +1,3 @@ -unsigned char sBulletDNAstr64[]= { -83,68,78,65,78,65,77,69,-81,0,0,0,109,95,115,105,122,101,0,109, -95,99,97,112,97,99,105,116,121,0,42,109,95,100,97,116,97,0,109,95, -99,111,108,108,105,115,105,111,110,83,104,97,112,101,115,0,109,95,99,111, -108,108,105,115,105,111,110,79,98,106,101,99,116,115,0,109,95,99,111,110, -115,116,114,97,105,110,116,115,0,42,102,105,114,115,116,0,42,108,97,115, -116,0,109,95,102,108,111,97,116,115,91,52,93,0,109,95,101,108,91,51, -93,0,109,95,98,97,115,105,115,0,109,95,111,114,105,103,105,110,0,109, -95,114,111,111,116,78,111,100,101,73,110,100,101,120,0,109,95,115,117,98, -116,114,101,101,83,105,122,101,0,105,110,116,0,109,95,113,117,97,110,116, -105,122,101,100,65,97,98,98,77,105,110,91,51,93,0,109,95,113,117,97, -110,116,105,122,101,100,65,97,98,98,77,97,120,91,51,93,0,109,95,97, -97,98,98,77,105,110,79,114,103,0,109,95,97,97,98,98,77,97,120,79, -114,103,0,109,95,101,115,99,97,112,101,73,110,100,101,120,0,109,95,115, -117,98,80,97,114,116,0,109,95,116,114,105,97,110,103,108,101,73,110,100, -101,120,0,109,95,101,115,99,97,112,101,73,110,100,101,120,79,114,84,114, -105,97,110,103,108,101,73,110,100,101,120,0,109,95,98,118,104,65,97,98, -98,77,105,110,0,109,95,98,118,104,65,97,98,98,77,97,120,0,109,95, -98,118,104,81,117,97,110,116,105,122,97,116,105,111,110,0,109,95,99,117, -114,78,111,100,101,73,110,100,101,120,0,109,95,117,115,101,81,117,97,110, -116,105,122,97,116,105,111,110,0,109,95,110,117,109,67,111,110,116,105,103, -117,111,117,115,76,101,97,102,78,111,100,101,115,0,109,95,110,117,109,81, -117,97,110,116,105,122,101,100,67,111,110,116,105,103,117,111,117,115,78,111, -100,101,115,0,42,109,95,99,111,110,116,105,103,117,111,117,115,78,111,100, -101,115,80,116,114,0,42,109,95,113,117,97,110,116,105,122,101,100,67,111, -110,116,105,103,117,111,117,115,78,111,100,101,115,80,116,114,0,109,95,116, -114,97,118,101,114,115,97,108,77,111,100,101,0,109,95,110,117,109,83,117, -98,116,114,101,101,72,101,97,100,101,114,115,0,42,109,95,115,117,98,84, -114,101,101,73,110,102,111,80,116,114,0,42,109,95,110,97,109,101,0,109, -95,115,104,97,112,101,84,121,112,101,0,109,95,112,97,100,100,105,110,103, -91,52,93,0,109,95,99,111,108,108,105,115,105,111,110,83,104,97,112,101, -68,97,116,97,0,109,95,108,111,99,97,108,83,99,97,108,105,110,103,0, -109,95,112,108,97,110,101,78,111,114,109,97,108,0,109,95,112,108,97,110, -101,67,111,110,115,116,97,110,116,0,109,95,112,97,100,91,52,93,0,109, -95,105,109,112,108,105,99,105,116,83,104,97,112,101,68,105,109,101,110,115, -105,111,110,115,0,109,95,99,111,108,108,105,115,105,111,110,77,97,114,103, -105,110,0,109,95,112,97,100,100,105,110,103,0,109,95,112,111,115,0,109, -95,114,97,100,105,117,115,0,109,95,99,111,110,118,101,120,73,110,116,101, -114,110,97,108,83,104,97,112,101,68,97,116,97,0,42,109,95,108,111,99, -97,108,80,111,115,105,116,105,111,110,65,114,114,97,121,80,116,114,0,109, -95,108,111,99,97,108,80,111,115,105,116,105,111,110,65,114,114,97,121,83, -105,122,101,0,109,95,118,97,108,117,101,0,42,109,95,118,101,114,116,105, -99,101,115,51,102,0,42,109,95,118,101,114,116,105,99,101,115,51,100,0, -42,109,95,105,110,100,105,99,101,115,51,50,0,42,109,95,105,110,100,105, -99,101,115,49,54,0,109,95,110,117,109,84,114,105,97,110,103,108,101,115, -0,109,95,110,117,109,86,101,114,116,105,99,101,115,0,42,109,95,109,101, -115,104,80,97,114,116,115,80,116,114,0,109,95,115,99,97,108,105,110,103, -0,109,95,110,117,109,77,101,115,104,80,97,114,116,115,0,109,95,109,101, -115,104,73,110,116,101,114,102,97,99,101,0,42,109,95,113,117,97,110,116, -105,122,101,100,70,108,111,97,116,66,118,104,0,42,109,95,113,117,97,110, -116,105,122,101,100,68,111,117,98,108,101,66,118,104,0,42,109,95,116,114, -105,97,110,103,108,101,73,110,102,111,77,97,112,0,109,95,112,97,100,51, -91,52,93,0,109,95,116,114,97,110,115,102,111,114,109,0,42,109,95,99, -104,105,108,100,83,104,97,112,101,0,109,95,99,104,105,108,100,83,104,97, -112,101,84,121,112,101,0,109,95,99,104,105,108,100,77,97,114,103,105,110, -0,42,109,95,99,104,105,108,100,83,104,97,112,101,80,116,114,0,109,95, -110,117,109,67,104,105,108,100,83,104,97,112,101,115,0,109,95,117,112,65, -120,105,115,0,109,95,102,108,97,103,115,0,109,95,101,100,103,101,86,48, -86,49,65,110,103,108,101,0,109,95,101,100,103,101,86,49,86,50,65,110, -103,108,101,0,109,95,101,100,103,101,86,50,86,48,65,110,103,108,101,0, -42,109,95,104,97,115,104,84,97,98,108,101,80,116,114,0,42,109,95,110, -101,120,116,80,116,114,0,42,109,95,118,97,108,117,101,65,114,114,97,121, -80,116,114,0,42,109,95,107,101,121,65,114,114,97,121,80,116,114,0,109, -95,99,111,110,118,101,120,69,112,115,105,108,111,110,0,109,95,112,108,97, -110,97,114,69,112,115,105,108,111,110,0,109,95,101,113,117,97,108,86,101, -114,116,101,120,84,104,114,101,115,104,111,108,100,0,109,95,101,100,103,101, -68,105,115,116,97,110,99,101,84,104,114,101,115,104,111,108,100,0,109,95, -122,101,114,111,65,114,101,97,84,104,114,101,115,104,111,108,100,0,109,95, -110,101,120,116,83,105,122,101,0,109,95,104,97,115,104,84,97,98,108,101, -83,105,122,101,0,109,95,110,117,109,86,97,108,117,101,115,0,109,95,110, -117,109,75,101,121,115,0,109,95,103,105,109,112,97,99,116,83,117,98,84, -121,112,101,0,42,109,95,117,110,115,99,97,108,101,100,80,111,105,110,116, -115,70,108,111,97,116,80,116,114,0,42,109,95,117,110,115,99,97,108,101, -100,80,111,105,110,116,115,68,111,117,98,108,101,80,116,114,0,109,95,110, -117,109,85,110,115,99,97,108,101,100,80,111,105,110,116,115,0,109,95,112, -97,100,100,105,110,103,51,91,52,93,0,42,109,95,98,114,111,97,100,112, -104,97,115,101,72,97,110,100,108,101,0,42,109,95,99,111,108,108,105,115, -105,111,110,83,104,97,112,101,0,42,109,95,114,111,111,116,67,111,108,108, -105,115,105,111,110,83,104,97,112,101,0,109,95,119,111,114,108,100,84,114, -97,110,115,102,111,114,109,0,109,95,105,110,116,101,114,112,111,108,97,116, -105,111,110,87,111,114,108,100,84,114,97,110,115,102,111,114,109,0,109,95, -105,110,116,101,114,112,111,108,97,116,105,111,110,76,105,110,101,97,114,86, -101,108,111,99,105,116,121,0,109,95,105,110,116,101,114,112,111,108,97,116, -105,111,110,65,110,103,117,108,97,114,86,101,108,111,99,105,116,121,0,109, -95,97,110,105,115,111,116,114,111,112,105,99,70,114,105,99,116,105,111,110, -0,109,95,99,111,110,116,97,99,116,80,114,111,99,101,115,115,105,110,103, -84,104,114,101,115,104,111,108,100,0,109,95,100,101,97,99,116,105,118,97, -116,105,111,110,84,105,109,101,0,109,95,102,114,105,99,116,105,111,110,0, -109,95,114,101,115,116,105,116,117,116,105,111,110,0,109,95,104,105,116,70, -114,97,99,116,105,111,110,0,109,95,99,99,100,83,119,101,112,116,83,112, -104,101,114,101,82,97,100,105,117,115,0,109,95,99,99,100,77,111,116,105, -111,110,84,104,114,101,115,104,111,108,100,0,109,95,104,97,115,65,110,105, -115,111,116,114,111,112,105,99,70,114,105,99,116,105,111,110,0,109,95,99, -111,108,108,105,115,105,111,110,70,108,97,103,115,0,109,95,105,115,108,97, -110,100,84,97,103,49,0,109,95,99,111,109,112,97,110,105,111,110,73,100, -0,109,95,97,99,116,105,118,97,116,105,111,110,83,116,97,116,101,49,0, -109,95,105,110,116,101,114,110,97,108,84,121,112,101,0,109,95,99,104,101, -99,107,67,111,108,108,105,100,101,87,105,116,104,0,109,95,99,111,108,108, -105,115,105,111,110,79,98,106,101,99,116,68,97,116,97,0,109,95,105,110, -118,73,110,101,114,116,105,97,84,101,110,115,111,114,87,111,114,108,100,0, -109,95,108,105,110,101,97,114,86,101,108,111,99,105,116,121,0,109,95,97, -110,103,117,108,97,114,86,101,108,111,99,105,116,121,0,109,95,97,110,103, -117,108,97,114,70,97,99,116,111,114,0,109,95,108,105,110,101,97,114,70, -97,99,116,111,114,0,109,95,103,114,97,118,105,116,121,0,109,95,103,114, -97,118,105,116,121,95,97,99,99,101,108,101,114,97,116,105,111,110,0,109, -95,105,110,118,73,110,101,114,116,105,97,76,111,99,97,108,0,109,95,116, -111,116,97,108,70,111,114,99,101,0,109,95,116,111,116,97,108,84,111,114, -113,117,101,0,109,95,105,110,118,101,114,115,101,77,97,115,115,0,109,95, -108,105,110,101,97,114,68,97,109,112,105,110,103,0,109,95,97,110,103,117, -108,97,114,68,97,109,112,105,110,103,0,109,95,97,100,100,105,116,105,111, -110,97,108,68,97,109,112,105,110,103,70,97,99,116,111,114,0,109,95,97, -100,100,105,116,105,111,110,97,108,76,105,110,101,97,114,68,97,109,112,105, -110,103,84,104,114,101,115,104,111,108,100,83,113,114,0,109,95,97,100,100, -105,116,105,111,110,97,108,65,110,103,117,108,97,114,68,97,109,112,105,110, -103,84,104,114,101,115,104,111,108,100,83,113,114,0,109,95,97,100,100,105, -116,105,111,110,97,108,65,110,103,117,108,97,114,68,97,109,112,105,110,103, -70,97,99,116,111,114,0,109,95,108,105,110,101,97,114,83,108,101,101,112, -105,110,103,84,104,114,101,115,104,111,108,100,0,109,95,97,110,103,117,108, -97,114,83,108,101,101,112,105,110,103,84,104,114,101,115,104,111,108,100,0, -109,95,97,100,100,105,116,105,111,110,97,108,68,97,109,112,105,110,103,0, -109,95,110,117,109,67,111,110,115,116,114,97,105,110,116,82,111,119,115,0, -110,117,98,0,42,109,95,114,98,65,0,42,109,95,114,98,66,0,109,95, -111,98,106,101,99,116,84,121,112,101,0,109,95,117,115,101,114,67,111,110, -115,116,114,97,105,110,116,84,121,112,101,0,109,95,117,115,101,114,67,111, -110,115,116,114,97,105,110,116,73,100,0,109,95,110,101,101,100,115,70,101, -101,100,98,97,99,107,0,109,95,97,112,112,108,105,101,100,73,109,112,117, -108,115,101,0,109,95,100,98,103,68,114,97,119,83,105,122,101,0,109,95, -100,105,115,97,98,108,101,67,111,108,108,105,115,105,111,110,115,66,101,116, -119,101,101,110,76,105,110,107,101,100,66,111,100,105,101,115,0,109,95,112, -97,100,52,91,52,93,0,109,95,116,121,112,101,67,111,110,115,116,114,97, -105,110,116,68,97,116,97,0,109,95,112,105,118,111,116,73,110,65,0,109, -95,112,105,118,111,116,73,110,66,0,109,95,114,98,65,70,114,97,109,101, -0,109,95,114,98,66,70,114,97,109,101,0,109,95,117,115,101,82,101,102, -101,114,101,110,99,101,70,114,97,109,101,65,0,109,95,97,110,103,117,108, -97,114,79,110,108,121,0,109,95,101,110,97,98,108,101,65,110,103,117,108, -97,114,77,111,116,111,114,0,109,95,109,111,116,111,114,84,97,114,103,101, -116,86,101,108,111,99,105,116,121,0,109,95,109,97,120,77,111,116,111,114, -73,109,112,117,108,115,101,0,109,95,108,111,119,101,114,76,105,109,105,116, -0,109,95,117,112,112,101,114,76,105,109,105,116,0,109,95,108,105,109,105, -116,83,111,102,116,110,101,115,115,0,109,95,98,105,97,115,70,97,99,116, -111,114,0,109,95,114,101,108,97,120,97,116,105,111,110,70,97,99,116,111, -114,0,109,95,115,119,105,110,103,83,112,97,110,49,0,109,95,115,119,105, -110,103,83,112,97,110,50,0,109,95,116,119,105,115,116,83,112,97,110,0, -109,95,100,97,109,112,105,110,103,0,109,95,108,105,110,101,97,114,85,112, -112,101,114,76,105,109,105,116,0,109,95,108,105,110,101,97,114,76,111,119, -101,114,76,105,109,105,116,0,109,95,97,110,103,117,108,97,114,85,112,112, -101,114,76,105,109,105,116,0,109,95,97,110,103,117,108,97,114,76,111,119, -101,114,76,105,109,105,116,0,109,95,117,115,101,76,105,110,101,97,114,82, -101,102,101,114,101,110,99,101,70,114,97,109,101,65,0,109,95,117,115,101, -79,102,102,115,101,116,70,111,114,67,111,110,115,116,114,97,105,110,116,70, -114,97,109,101,0,0,0,0,84,89,80,69,57,0,0,0,99,104,97,114, -0,117,99,104,97,114,0,115,104,111,114,116,0,117,115,104,111,114,116,0, -105,110,116,0,108,111,110,103,0,117,108,111,110,103,0,102,108,111,97,116, -0,100,111,117,98,108,101,0,118,111,105,100,0,80,111,105,110,116,101,114, -65,114,114,97,121,0,98,116,80,104,121,115,105,99,115,83,121,115,116,101, -109,0,76,105,115,116,66,97,115,101,0,98,116,86,101,99,116,111,114,51, -70,108,111,97,116,68,97,116,97,0,98,116,86,101,99,116,111,114,51,68, -111,117,98,108,101,68,97,116,97,0,98,116,77,97,116,114,105,120,51,120, -51,70,108,111,97,116,68,97,116,97,0,98,116,77,97,116,114,105,120,51, -120,51,68,111,117,98,108,101,68,97,116,97,0,98,116,84,114,97,110,115, -102,111,114,109,70,108,111,97,116,68,97,116,97,0,98,116,84,114,97,110, -115,102,111,114,109,68,111,117,98,108,101,68,97,116,97,0,98,116,66,118, -104,83,117,98,116,114,101,101,73,110,102,111,68,97,116,97,0,98,116,79, -112,116,105,109,105,122,101,100,66,118,104,78,111,100,101,70,108,111,97,116, -68,97,116,97,0,98,116,79,112,116,105,109,105,122,101,100,66,118,104,78, -111,100,101,68,111,117,98,108,101,68,97,116,97,0,98,116,81,117,97,110, -116,105,122,101,100,66,118,104,78,111,100,101,68,97,116,97,0,98,116,81, -117,97,110,116,105,122,101,100,66,118,104,70,108,111,97,116,68,97,116,97, -0,98,116,81,117,97,110,116,105,122,101,100,66,118,104,68,111,117,98,108, -101,68,97,116,97,0,98,116,67,111,108,108,105,115,105,111,110,83,104,97, -112,101,68,97,116,97,0,98,116,83,116,97,116,105,99,80,108,97,110,101, -83,104,97,112,101,68,97,116,97,0,98,116,67,111,110,118,101,120,73,110, -116,101,114,110,97,108,83,104,97,112,101,68,97,116,97,0,98,116,80,111, -115,105,116,105,111,110,65,110,100,82,97,100,105,117,115,0,98,116,77,117, -108,116,105,83,112,104,101,114,101,83,104,97,112,101,68,97,116,97,0,98, -116,73,110,116,73,110,100,101,120,68,97,116,97,0,98,116,83,104,111,114, -116,73,110,116,73,110,100,101,120,68,97,116,97,0,98,116,77,101,115,104, -80,97,114,116,68,97,116,97,0,98,116,83,116,114,105,100,105,110,103,77, -101,115,104,73,110,116,101,114,102,97,99,101,68,97,116,97,0,98,116,84, -114,105,97,110,103,108,101,77,101,115,104,83,104,97,112,101,68,97,116,97, -0,98,116,84,114,105,97,110,103,108,101,73,110,102,111,77,97,112,68,97, -116,97,0,98,116,67,111,109,112,111,117,110,100,83,104,97,112,101,67,104, -105,108,100,68,97,116,97,0,98,116,67,111,109,112,111,117,110,100,83,104, -97,112,101,68,97,116,97,0,98,116,67,121,108,105,110,100,101,114,83,104, -97,112,101,68,97,116,97,0,98,116,67,97,112,115,117,108,101,83,104,97, -112,101,68,97,116,97,0,98,116,84,114,105,97,110,103,108,101,73,110,102, -111,68,97,116,97,0,98,116,71,73,109,112,97,99,116,77,101,115,104,83, -104,97,112,101,68,97,116,97,0,98,116,67,111,110,118,101,120,72,117,108, -108,83,104,97,112,101,68,97,116,97,0,98,116,67,111,108,108,105,115,105, -111,110,79,98,106,101,99,116,68,111,117,98,108,101,68,97,116,97,0,98, -116,67,111,108,108,105,115,105,111,110,79,98,106,101,99,116,70,108,111,97, -116,68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121,70,108,111, -97,116,68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121,68,111, -117,98,108,101,68,97,116,97,0,98,116,67,111,110,115,116,114,97,105,110, -116,73,110,102,111,49,0,98,116,84,121,112,101,100,67,111,110,115,116,114, -97,105,110,116,68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121, -68,97,116,97,0,98,116,80,111,105,110,116,50,80,111,105,110,116,67,111, -110,115,116,114,97,105,110,116,70,108,111,97,116,68,97,116,97,0,98,116, -80,111,105,110,116,50,80,111,105,110,116,67,111,110,115,116,114,97,105,110, -116,68,111,117,98,108,101,68,97,116,97,0,98,116,72,105,110,103,101,67, -111,110,115,116,114,97,105,110,116,68,111,117,98,108,101,68,97,116,97,0, -98,116,72,105,110,103,101,67,111,110,115,116,114,97,105,110,116,70,108,111, -97,116,68,97,116,97,0,98,116,67,111,110,101,84,119,105,115,116,67,111, -110,115,116,114,97,105,110,116,68,97,116,97,0,98,116,71,101,110,101,114, -105,99,54,68,111,102,67,111,110,115,116,114,97,105,110,116,68,97,116,97, -0,98,116,83,108,105,100,101,114,67,111,110,115,116,114,97,105,110,116,68, -97,116,97,0,84,76,69,78,1,0,1,0,2,0,2,0,4,0,4,0, -4,0,4,0,8,0,0,0,16,0,48,0,16,0,16,0,32,0,48,0, -96,0,64,0,-128,0,24,0,44,0,76,0,20,0,96,0,-112,0,16,0, -56,0,56,0,20,0,72,0,4,0,4,0,40,0,32,0,80,0,72,0, -80,0,32,0,64,0,64,0,16,0,72,0,80,0,-40,1,8,1,-16,1, --88,3,8,0,56,0,0,0,88,0,120,0,96,1,-32,0,-40,0,0,1, --48,0,0,0,83,84,82,67,46,0,0,0,10,0,3,0,4,0,0,0, -4,0,1,0,9,0,2,0,11,0,3,0,10,0,3,0,10,0,4,0, -10,0,5,0,12,0,2,0,9,0,6,0,9,0,7,0,13,0,1,0, -7,0,8,0,14,0,1,0,8,0,8,0,15,0,1,0,13,0,9,0, -16,0,1,0,14,0,9,0,17,0,2,0,15,0,10,0,13,0,11,0, -18,0,2,0,16,0,10,0,14,0,11,0,19,0,6,0,4,0,12,0, -4,0,13,0,2,0,14,0,2,0,15,0,2,0,14,0,2,0,16,0, -20,0,5,0,13,0,17,0,13,0,18,0,4,0,19,0,4,0,20,0, -4,0,21,0,21,0,5,0,14,0,17,0,14,0,18,0,4,0,19,0, -4,0,20,0,4,0,21,0,22,0,5,0,4,0,22,0,2,0,14,0, -2,0,15,0,2,0,14,0,2,0,16,0,23,0,12,0,13,0,23,0, -13,0,24,0,13,0,25,0,4,0,26,0,4,0,27,0,4,0,28,0, -4,0,29,0,20,0,30,0,22,0,31,0,4,0,32,0,4,0,33,0, -19,0,34,0,24,0,12,0,14,0,23,0,14,0,24,0,14,0,25,0, -4,0,26,0,4,0,27,0,4,0,28,0,4,0,29,0,21,0,30,0, -22,0,31,0,4,0,32,0,4,0,33,0,19,0,34,0,25,0,3,0, -0,0,35,0,4,0,36,0,0,0,37,0,26,0,5,0,25,0,38,0, -13,0,39,0,13,0,40,0,7,0,41,0,0,0,42,0,27,0,5,0, -25,0,38,0,13,0,39,0,13,0,43,0,7,0,44,0,4,0,45,0, -28,0,2,0,13,0,46,0,7,0,47,0,29,0,4,0,27,0,48,0, -28,0,49,0,4,0,50,0,0,0,37,0,30,0,1,0,4,0,51,0, -31,0,2,0,2,0,14,0,2,0,51,0,32,0,6,0,13,0,52,0, -14,0,53,0,30,0,54,0,31,0,55,0,4,0,56,0,4,0,57,0, -33,0,4,0,32,0,58,0,13,0,59,0,4,0,60,0,0,0,37,0, -34,0,7,0,25,0,38,0,33,0,61,0,23,0,62,0,24,0,63,0, -35,0,64,0,7,0,44,0,0,0,65,0,36,0,4,0,17,0,66,0, -25,0,67,0,4,0,68,0,7,0,69,0,37,0,4,0,25,0,38,0, -36,0,70,0,4,0,71,0,7,0,44,0,38,0,3,0,27,0,48,0, -4,0,72,0,0,0,37,0,39,0,3,0,27,0,48,0,4,0,72,0, -0,0,37,0,40,0,4,0,4,0,73,0,7,0,74,0,7,0,75,0, -7,0,76,0,35,0,14,0,4,0,77,0,4,0,78,0,40,0,79,0, -4,0,80,0,7,0,81,0,7,0,82,0,7,0,83,0,7,0,84,0, -7,0,85,0,4,0,86,0,4,0,87,0,4,0,88,0,4,0,89,0, -0,0,37,0,41,0,5,0,25,0,38,0,33,0,61,0,13,0,39,0, -7,0,44,0,4,0,90,0,42,0,5,0,27,0,48,0,13,0,91,0, -14,0,92,0,4,0,93,0,0,0,94,0,43,0,24,0,9,0,95,0, -9,0,96,0,25,0,97,0,0,0,35,0,18,0,98,0,18,0,99,0, -14,0,100,0,14,0,101,0,14,0,102,0,8,0,103,0,8,0,104,0, -8,0,105,0,8,0,106,0,8,0,107,0,8,0,108,0,8,0,109,0, -4,0,110,0,4,0,111,0,4,0,112,0,4,0,113,0,4,0,114,0, -4,0,115,0,4,0,116,0,0,0,37,0,44,0,23,0,9,0,95,0, -9,0,96,0,25,0,97,0,0,0,35,0,17,0,98,0,17,0,99,0, -13,0,100,0,13,0,101,0,13,0,102,0,7,0,103,0,7,0,104,0, -7,0,105,0,7,0,106,0,7,0,107,0,7,0,108,0,7,0,109,0, -4,0,110,0,4,0,111,0,4,0,112,0,4,0,113,0,4,0,114,0, -4,0,115,0,4,0,116,0,45,0,21,0,44,0,117,0,15,0,118,0, -13,0,119,0,13,0,120,0,13,0,121,0,13,0,122,0,13,0,123,0, -13,0,124,0,13,0,125,0,13,0,126,0,13,0,127,0,7,0,-128,0, -7,0,-127,0,7,0,-126,0,7,0,-125,0,7,0,-124,0,7,0,-123,0, -7,0,-122,0,7,0,-121,0,7,0,-120,0,4,0,-119,0,46,0,22,0, -43,0,117,0,16,0,118,0,14,0,119,0,14,0,120,0,14,0,121,0, -14,0,122,0,14,0,123,0,14,0,124,0,14,0,125,0,14,0,126,0, -14,0,127,0,8,0,-128,0,8,0,-127,0,8,0,-126,0,8,0,-125,0, -8,0,-124,0,8,0,-123,0,8,0,-122,0,8,0,-121,0,8,0,-120,0, -4,0,-119,0,0,0,37,0,47,0,2,0,4,0,-118,0,4,0,-117,0, -48,0,11,0,49,0,-116,0,49,0,-115,0,0,0,35,0,4,0,-114,0, -4,0,-113,0,4,0,-112,0,4,0,-111,0,7,0,-110,0,7,0,-109,0, -4,0,-108,0,0,0,-107,0,50,0,3,0,48,0,-106,0,13,0,-105,0, -13,0,-104,0,51,0,3,0,48,0,-106,0,14,0,-105,0,14,0,-104,0, -52,0,13,0,48,0,-106,0,18,0,-103,0,18,0,-102,0,4,0,-101,0, -4,0,-100,0,4,0,-99,0,7,0,-98,0,7,0,-97,0,7,0,-96,0, -7,0,-95,0,7,0,-94,0,7,0,-93,0,7,0,-92,0,53,0,13,0, -48,0,-106,0,17,0,-103,0,17,0,-102,0,4,0,-101,0,4,0,-100,0, -4,0,-99,0,7,0,-98,0,7,0,-97,0,7,0,-96,0,7,0,-95,0, -7,0,-94,0,7,0,-93,0,7,0,-92,0,54,0,11,0,48,0,-106,0, -17,0,-103,0,17,0,-102,0,7,0,-91,0,7,0,-90,0,7,0,-89,0, -7,0,-94,0,7,0,-93,0,7,0,-92,0,7,0,-88,0,0,0,42,0, -55,0,9,0,48,0,-106,0,17,0,-103,0,17,0,-102,0,13,0,-87,0, -13,0,-86,0,13,0,-85,0,13,0,-84,0,4,0,-83,0,4,0,-82,0, -56,0,9,0,48,0,-106,0,17,0,-103,0,17,0,-102,0,7,0,-87,0, -7,0,-86,0,7,0,-85,0,7,0,-84,0,4,0,-83,0,4,0,-82,0, -}; -int sBulletDNAlen64= sizeof(sBulletDNAstr64); - unsigned char sBulletDNAstr[]= { 83,68,78,65,78,65,77,69,-81,0,0,0,109,95,115,105,122,101,0,109, 95,99,97,112,97,99,105,116,121,0,42,109,95,100,97,116,97,0,109,95, diff --git a/src/LinearMath/btSerializer.h b/src/LinearMath/btSerializer.h index c395e49ba..9ee3bd8af 100644 --- a/src/LinearMath/btSerializer.h +++ b/src/LinearMath/btSerializer.h @@ -62,7 +62,8 @@ public: enum btSerializationFlags { BT_SERIALIZE_NO_BVH = 1, - BT_SERIALIZE_NO_TRIANGLEINFOMAP = 2 + BT_SERIALIZE_NO_TRIANGLEINFOMAP = 2, + BT_SERIALIZE_NO_DUPLICATE_ASSERT = 4 }; class btSerializer @@ -464,7 +465,10 @@ public: virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr) { - btAssert(!findPointer(oldPtr)); + if (!(m_serializationFlags&BT_SERIALIZE_NO_DUPLICATE_ASSERT)) + { + btAssert(!findPointer(oldPtr)); + } chunk->m_dna_nr = getReverseType(structType);