/*! \file btGImpactShape.h
\author Francisco Len N�jera
*/
/*
This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.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.
*/
#ifndef GIMPACT_SHAPE_H
#define GIMPACT_SHAPE_H
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
#include "BulletCollision/CollisionShapes/btTriangleShape.h"
#include "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
#include "BulletCollision/CollisionShapes/btConcaveShape.h"
#include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
#include "LinearMath/btVector3.h"
#include "LinearMath/btTransform.h"
#include "LinearMath/btMatrix3x3.h"
#include "LinearMath/btAlignedObjectArray.h"
#include "btGImpactQuantizedBvh.h" // box tree class
//! declare Quantized trees, (you can change to float based trees)
typedef btGImpactQuantizedBvh btGImpactBoxSet;
enum eGIMPACT_SHAPE_TYPE
{
CONST_GIMPACT_COMPOUND_SHAPE = 0,
CONST_GIMPACT_TRIMESH_SHAPE_PART,
CONST_GIMPACT_TRIMESH_SHAPE
};
//! Helper class for tetrahedrons
class btTetrahedronShapeEx:public btBU_Simplex1to4
{
public:
btTetrahedronShapeEx()
{
m_numVertices = 4;
}
SIMD_FORCE_INLINE void setVertices(
const btVector3 & v0,const btVector3 & v1,
const btVector3 & v2,const btVector3 & v3)
{
m_vertices[0] = v0;
m_vertices[1] = v1;
m_vertices[2] = v2;
m_vertices[3] = v3;
recalcLocalAabb();
}
};
//! Base class for gimpact shapes
class btGImpactShapeInterface : public btConcaveShape
{
protected:
btAABB m_localAABB;
bool m_needs_update;
btVector3 localScaling;
btGImpactBoxSet m_box_set;// optionally boxset
//! use this function for perfofm refit in bounding boxes
//! use this function for perfofm refit in bounding boxes
virtual void calcLocalAABB()
{
lockChildShapes();
if(m_box_set.getNodeCount() == 0)
{
m_box_set.buildSet();
}
else
{
m_box_set.update();
}
unlockChildShapes();
m_localAABB = m_box_set.getGlobalBox();
}
public:
btGImpactShapeInterface()
{
m_shapeType=GIMPACT_SHAPE_PROXYTYPE;
m_localAABB.invalidate();
m_needs_update = true;
localScaling.setValue(1.f,1.f,1.f);
}
//! performs refit operation
/*!
Updates the entire Box set of this shape.
\pre postUpdate() must be called for attemps to calculating the box set, else this function
will does nothing.
\post if m_needs_update == true, then it calls calcLocalAABB();
*/
SIMD_FORCE_INLINE void updateBound()
{
if(!m_needs_update) return;
calcLocalAABB();
m_needs_update = false;
}
//! If the Bounding box is not updated, then this class attemps to calculate it.
/*!
\post Calls updateBound() for update the box set.
*/
void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
{
btAABB transformedbox = m_localAABB;
transformedbox.appy_transform(t);
aabbMin = transformedbox.m_min;
aabbMax = transformedbox.m_max;
}
//! Tells to this object that is needed to refit the box set
virtual void postUpdate()
{
m_needs_update = true;
}
//! Obtains the local box, which is the global calculated box of the total of subshapes
SIMD_FORCE_INLINE const btAABB & getLocalBox()
{
return m_localAABB;
}
virtual int getShapeType() const
{
return GIMPACT_SHAPE_PROXYTYPE;