Blender V2.61 - r43446
|
00001 /* 00002 Bullet Continuous Collision Detection and Physics Library 00003 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 00004 00005 This software is provided 'as-is', without any express or implied warranty. 00006 In no event will the authors be held liable for any damages arising from the use of this software. 00007 Permission is granted to anyone to use this software for any purpose, 00008 including commercial applications, and to alter it and redistribute it freely, 00009 subject to the following restrictions: 00010 00011 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. 00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00013 3. This notice may not be removed or altered from any source distribution. 00014 */ 00015 00016 #include "btStaticPlaneShape.h" 00017 00018 #include "LinearMath/btTransformUtil.h" 00019 00020 00021 btStaticPlaneShape::btStaticPlaneShape(const btVector3& planeNormal,btScalar planeConstant) 00022 : btConcaveShape (), m_planeNormal(planeNormal.normalized()), 00023 m_planeConstant(planeConstant), 00024 m_localScaling(btScalar(0.),btScalar(0.),btScalar(0.)) 00025 { 00026 m_shapeType = STATIC_PLANE_PROXYTYPE; 00027 // btAssert( btFuzzyZero(m_planeNormal.length() - btScalar(1.)) ); 00028 } 00029 00030 00031 btStaticPlaneShape::~btStaticPlaneShape() 00032 { 00033 } 00034 00035 00036 00037 void btStaticPlaneShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const 00038 { 00039 (void)t; 00040 /* 00041 btVector3 infvec (btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 00042 00043 btVector3 center = m_planeNormal*m_planeConstant; 00044 aabbMin = center + infvec*m_planeNormal; 00045 aabbMax = aabbMin; 00046 aabbMin.setMin(center - infvec*m_planeNormal); 00047 aabbMax.setMax(center - infvec*m_planeNormal); 00048 */ 00049 00050 aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 00051 aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 00052 00053 } 00054 00055 00056 00057 00058 void btStaticPlaneShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const 00059 { 00060 00061 btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5); 00062 btScalar radius = halfExtents.length(); 00063 btVector3 center = (aabbMax + aabbMin) * btScalar(0.5); 00064 00065 //this is where the triangles are generated, given AABB and plane equation (normal/constant) 00066 00067 btVector3 tangentDir0,tangentDir1; 00068 00069 //tangentDir0/tangentDir1 can be precalculated 00070 btPlaneSpace1(m_planeNormal,tangentDir0,tangentDir1); 00071 00072 btVector3 supVertex0,supVertex1; 00073 00074 btVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant)*m_planeNormal; 00075 00076 btVector3 triangle[3]; 00077 triangle[0] = projectedCenter + tangentDir0*radius + tangentDir1*radius; 00078 triangle[1] = projectedCenter + tangentDir0*radius - tangentDir1*radius; 00079 triangle[2] = projectedCenter - tangentDir0*radius - tangentDir1*radius; 00080 00081 callback->processTriangle(triangle,0,0); 00082 00083 triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius; 00084 triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius; 00085 triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius; 00086 00087 callback->processTriangle(triangle,0,1); 00088 00089 } 00090 00091 void btStaticPlaneShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const 00092 { 00093 (void)mass; 00094 00095 //moving concave objects not supported 00096 00097 inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.)); 00098 } 00099 00100 void btStaticPlaneShape::setLocalScaling(const btVector3& scaling) 00101 { 00102 m_localScaling = scaling; 00103 } 00104 const btVector3& btStaticPlaneShape::getLocalScaling() const 00105 { 00106 return m_localScaling; 00107 }