Back to index

supertuxkart  0.5+dfsg1
btStaticPlaneShape.cpp
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
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 :m_planeNormal(planeNormal),
00023 m_planeConstant(planeConstant),
00024 m_localScaling(btScalar(0.),btScalar(0.),btScalar(0.))
00025 {
00026 }
00027 
00028 
00029 btStaticPlaneShape::~btStaticPlaneShape()
00030 {
00031 }
00032 
00033 
00034 
00035 void btStaticPlaneShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
00036 {
00037        (void)t;
00038        /*
00039        btVector3 infvec (btScalar(1e30),btScalar(1e30),btScalar(1e30));
00040 
00041        btVector3 center = m_planeNormal*m_planeConstant;
00042        aabbMin = center + infvec*m_planeNormal;
00043        aabbMax = aabbMin;
00044        aabbMin.setMin(center - infvec*m_planeNormal);
00045        aabbMax.setMax(center - infvec*m_planeNormal); 
00046        */
00047 
00048        aabbMin.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
00049        aabbMax.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
00050 
00051 }
00052 
00053 
00054 
00055 
00056 void   btStaticPlaneShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
00057 {
00058 
00059        btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
00060        btScalar radius = halfExtents.length();
00061        btVector3 center = (aabbMax + aabbMin) * btScalar(0.5);
00062        
00063        //this is where the triangles are generated, given AABB and plane equation (normal/constant)
00064 
00065        btVector3 tangentDir0,tangentDir1;
00066 
00067        //tangentDir0/tangentDir1 can be precalculated
00068        btPlaneSpace1(m_planeNormal,tangentDir0,tangentDir1);
00069 
00070        btVector3 supVertex0,supVertex1;
00071 
00072        btVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant)*m_planeNormal;
00073        
00074        btVector3 triangle[3];
00075        triangle[0] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
00076        triangle[1] = projectedCenter + tangentDir0*radius - tangentDir1*radius;
00077        triangle[2] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
00078 
00079        callback->processTriangle(triangle,0,0);
00080 
00081        triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
00082        triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius;
00083        triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
00084 
00085        callback->processTriangle(triangle,0,1);
00086 
00087 }
00088 
00089 void   btStaticPlaneShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
00090 {
00091        (void)mass;
00092 
00093        //moving concave objects not supported
00094        
00095        inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
00096 }
00097 
00098 void   btStaticPlaneShape::setLocalScaling(const btVector3& scaling)
00099 {
00100        m_localScaling = scaling;
00101 }
00102 const btVector3& btStaticPlaneShape::getLocalScaling() const
00103 {
00104        return m_localScaling;
00105 }