Add PhysicsEffects to Extras. The build is only tested on Windows and Android.
The Android/NEON optimized version of Physics Effects is thanks to Graham Rhodes and Anthony Hamilton, See Issue 587
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_AABB_H
|
||||
#define _SCE_PFX_AABB_H
|
||||
|
||||
#include "../sort/pfx_sort_data.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
typedef PfxSortData16 PfxAabb16;
|
||||
typedef PfxSortData32 PfxAabb32;
|
||||
|
||||
SCE_PFX_FORCE_INLINE void pfxSetXMin(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(0,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetXMax(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(1,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetYMin(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(2,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetYMax(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(3,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetZMin(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(4,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetZMax(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(5,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetXYZMin(PfxAabb16 &aabb,PfxUInt16 i,int axis) {aabb.set16(axis<<1,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetXYZMax(PfxAabb16 &aabb,PfxUInt16 i,int axis) {aabb.set16((axis<<1)+1,i);}
|
||||
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXMin(const PfxAabb16& aabb) {return aabb.get16(0);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXMax(const PfxAabb16& aabb) {return aabb.get16(1);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetYMin(const PfxAabb16& aabb) {return aabb.get16(2);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetYMax(const PfxAabb16& aabb) {return aabb.get16(3);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetZMin(const PfxAabb16& aabb) {return aabb.get16(4);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetZMax(const PfxAabb16& aabb) {return aabb.get16(5);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXYZMin(const PfxAabb16 &aabb,int axis) {return aabb.get16(axis<<1);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXYZMax(const PfxAabb16 &aabb,int axis) {return aabb.get16((axis<<1)+1);}
|
||||
|
||||
SCE_PFX_FORCE_INLINE void pfxSetXMin(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(0,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetXMax(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(1,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetYMin(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(2,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetYMax(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(3,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetZMin(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(4,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetZMax(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(5,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetXYZMin(PfxAabb32 &aabb,PfxUInt16 i,int axis) {aabb.set16(axis<<1,i);}
|
||||
SCE_PFX_FORCE_INLINE void pfxSetXYZMax(PfxAabb32 &aabb,PfxUInt16 i,int axis) {aabb.set16((axis<<1)+1,i);}
|
||||
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXMin(const PfxAabb32& aabb) {return aabb.get16(0);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXMax(const PfxAabb32& aabb) {return aabb.get16(1);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetYMin(const PfxAabb32& aabb) {return aabb.get16(2);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetYMax(const PfxAabb32& aabb) {return aabb.get16(3);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetZMin(const PfxAabb32& aabb) {return aabb.get16(4);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetZMax(const PfxAabb32& aabb) {return aabb.get16(5);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXYZMin(const PfxAabb32 &aabb,int axis) {return aabb.get16(axis<<1);}
|
||||
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXYZMax(const PfxAabb32 &aabb,int axis) {return aabb.get16((axis<<1)+1);}
|
||||
|
||||
|
||||
#define SCE_PFX_TEST_AABB(aabbA,aabbB) \
|
||||
if(pfxGetXMax(aabbA) < pfxGetXMin(aabbB) || pfxGetXMin(aabbA) > pfxGetXMax(aabbB)) return false;\
|
||||
if(pfxGetYMax(aabbA) < pfxGetYMin(aabbB) || pfxGetYMin(aabbA) > pfxGetYMax(aabbB)) return false;\
|
||||
if(pfxGetZMax(aabbA) < pfxGetZMin(aabbB) || pfxGetZMin(aabbA) > pfxGetZMax(aabbB)) return false;\
|
||||
return true;
|
||||
|
||||
SCE_PFX_FORCE_INLINE
|
||||
bool pfxTestAabb(const PfxAabb16 &aabbA,const PfxAabb16 &aabbB)
|
||||
{
|
||||
SCE_PFX_TEST_AABB(aabbA,aabbB)
|
||||
}
|
||||
|
||||
SCE_PFX_FORCE_INLINE
|
||||
bool pfxTestAabb(const PfxAabb32 &aabbA,const PfxAabb32 &aabbB)
|
||||
{
|
||||
SCE_PFX_TEST_AABB(aabbA,aabbB)
|
||||
}
|
||||
|
||||
SCE_PFX_FORCE_INLINE
|
||||
bool pfxTestAabb(const PfxAabb32 &aabbA,const PfxAabb16 &aabbB)
|
||||
{
|
||||
SCE_PFX_TEST_AABB(aabbA,aabbB)
|
||||
}
|
||||
|
||||
SCE_PFX_FORCE_INLINE
|
||||
bool pfxTestAabb(const PfxAabb16 &aabbA,const PfxAabb32 &aabbB)
|
||||
{
|
||||
SCE_PFX_TEST_AABB(aabbA,aabbB)
|
||||
}
|
||||
|
||||
|
||||
SCE_PFX_FORCE_INLINE
|
||||
PfxAabb16 pfxMergeAabb(const PfxAabb16 &aabbA,const PfxAabb16 &aabbB)
|
||||
{
|
||||
PfxAabb16 aabb = aabbA;
|
||||
pfxSetXMin(aabb,SCE_PFX_MIN(pfxGetXMin(aabbA),pfxGetXMin(aabbB)));
|
||||
pfxSetXMax(aabb,SCE_PFX_MAX(pfxGetXMax(aabbA),pfxGetXMax(aabbB)));
|
||||
pfxSetYMin(aabb,SCE_PFX_MIN(pfxGetYMin(aabbA),pfxGetYMin(aabbB)));
|
||||
pfxSetYMax(aabb,SCE_PFX_MAX(pfxGetYMax(aabbA),pfxGetYMax(aabbB)));
|
||||
pfxSetZMin(aabb,SCE_PFX_MIN(pfxGetZMin(aabbA),pfxGetZMin(aabbB)));
|
||||
pfxSetZMax(aabb,SCE_PFX_MAX(pfxGetZMax(aabbA),pfxGetZMax(aabbB)));
|
||||
return aabb;
|
||||
}
|
||||
|
||||
SCE_PFX_FORCE_INLINE
|
||||
PfxAabb32 pfxMergeAabb(const PfxAabb32 &aabbA,const PfxAabb32 &aabbB)
|
||||
{
|
||||
PfxAabb32 aabb = aabbA;
|
||||
pfxSetXMin(aabb,SCE_PFX_MIN(pfxGetXMin(aabbA),pfxGetXMin(aabbB)));
|
||||
pfxSetXMax(aabb,SCE_PFX_MAX(pfxGetXMax(aabbA),pfxGetXMax(aabbB)));
|
||||
pfxSetYMin(aabb,SCE_PFX_MIN(pfxGetYMin(aabbA),pfxGetYMin(aabbB)));
|
||||
pfxSetYMax(aabb,SCE_PFX_MAX(pfxGetYMax(aabbA),pfxGetYMax(aabbB)));
|
||||
pfxSetZMin(aabb,SCE_PFX_MIN(pfxGetZMin(aabbA),pfxGetZMin(aabbB)));
|
||||
pfxSetZMax(aabb,SCE_PFX_MAX(pfxGetZMax(aabbA),pfxGetZMax(aabbB)));
|
||||
return aabb;
|
||||
}
|
||||
} //namespace PhysicsEffects
|
||||
} //namespace sce
|
||||
|
||||
#endif // _SCE_PFX_AABB_H
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_BOX_H
|
||||
#define _SCE_PFX_BOX_H
|
||||
|
||||
#include "../base/pfx_common.h"
|
||||
|
||||
namespace sce{
|
||||
namespace PhysicsEffects{
|
||||
struct PfxBox {
|
||||
PfxVector3 m_half;
|
||||
|
||||
inline PfxBox() {}
|
||||
inline PfxBox(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG half);
|
||||
inline PfxBox(PfxFloat hx, PfxFloat hy, PfxFloat hz);
|
||||
|
||||
inline void set(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG half);
|
||||
inline void set(PfxFloat hx, PfxFloat hy, PfxFloat hz);
|
||||
};
|
||||
|
||||
inline
|
||||
PfxBox::PfxBox(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG half)
|
||||
{
|
||||
set(half);
|
||||
}
|
||||
|
||||
inline
|
||||
PfxBox::PfxBox(PfxFloat hx, PfxFloat hy, PfxFloat hz)
|
||||
{
|
||||
set(hx, hy, hz);
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxBox::set(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG half)
|
||||
{
|
||||
m_half = half;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxBox::set(PfxFloat hx, PfxFloat hy, PfxFloat hz)
|
||||
{
|
||||
m_half = PfxVector3(hx, hy, hz);
|
||||
}
|
||||
} // namespace PhysicsEffects
|
||||
} // namespace sce
|
||||
|
||||
#endif // _SCE_PFX_BOX_H
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_CAPSULE_H
|
||||
#define _SCE_PFX_CAPSULE_H
|
||||
|
||||
#include "../base/pfx_common.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
struct PfxCapsule
|
||||
{
|
||||
PfxFloat m_halfLen;
|
||||
PfxFloat m_radius;
|
||||
|
||||
PfxCapsule() {}
|
||||
PfxCapsule(PfxFloat halfLength, PfxFloat radius);
|
||||
|
||||
void set(PfxFloat halfLength, PfxFloat radius);
|
||||
};
|
||||
|
||||
inline
|
||||
PfxCapsule::PfxCapsule(PfxFloat halfLength, PfxFloat radius)
|
||||
{
|
||||
m_halfLen = halfLength;
|
||||
m_radius = radius;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxCapsule::set(PfxFloat halfLength, PfxFloat radius)
|
||||
{
|
||||
m_halfLen = halfLength;
|
||||
m_radius = radius;
|
||||
}
|
||||
|
||||
} // namespace PhysicsEffects
|
||||
} // namespace sce
|
||||
|
||||
#endif // _SCE_PFX_CAPSULE_H
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_COLLIDABLE_H
|
||||
#define _SCE_PFX_COLLIDABLE_H
|
||||
|
||||
#include "pfx_shape.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
#define SCE_PFX_NUMPRIMS 64
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Collidable Object
|
||||
|
||||
class SCE_PFX_ALIGNED(128) PfxCollidable
|
||||
{
|
||||
friend class PfxShapeIterator;
|
||||
|
||||
private:
|
||||
PfxShape *m_shapeBase;
|
||||
PfxUInt16 m_shapeIds[SCE_PFX_NUMPRIMS];
|
||||
PfxUInt8 m_numShapes;
|
||||
PfxUInt8 m_maxShapes;
|
||||
SCE_PFX_PADDING(1,2)
|
||||
PfxFloat m_center[3]; // AABB center (Local)
|
||||
PfxFloat m_half[3]; // AABB half (Local)
|
||||
PfxShape m_defShape;
|
||||
SCE_PFX_PADDING(2,32)
|
||||
|
||||
inline PfxShape &getNewShape();
|
||||
|
||||
public:
|
||||
inline void reset();
|
||||
inline void reset(PfxShape *base,PfxUInt16 *ids,int n=1);
|
||||
|
||||
void finish();
|
||||
|
||||
void addShape(const PfxShape &shape);
|
||||
|
||||
inline PfxUInt32 getNumShapes() const;
|
||||
const PfxShape& getDefShape() const {return m_defShape;}
|
||||
PfxShape& getDefShape() {return m_defShape;}
|
||||
|
||||
inline PfxUInt16 getShapeId(int i) const;
|
||||
|
||||
inline const PfxShape& getShape(int i) const;
|
||||
inline PfxShape& getShape(int i);
|
||||
|
||||
inline PfxVector3 getHalf() const;
|
||||
inline PfxVector3 getCenter() const;
|
||||
};
|
||||
|
||||
#include "pfx_collidable_implementation.h"
|
||||
|
||||
} // namespace PhysicsEffects
|
||||
} // namespace sce
|
||||
|
||||
#endif // _SCE_PFX_COLLIDABLE_H
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_COLLIDABLE_IMPLEMENTATION_H
|
||||
#define _SCE_PFX_COLLIDABLE_IMPLEMENTATION_H
|
||||
|
||||
inline
|
||||
void PfxCollidable::reset()
|
||||
{
|
||||
m_shapeBase = NULL;
|
||||
m_numShapes = 0;
|
||||
m_maxShapes = 1;
|
||||
m_center[0] = 0.0f;
|
||||
m_center[1] = 0.0f;
|
||||
m_center[2] = 0.0f;
|
||||
m_half[0] = 0.0f;
|
||||
m_half[1] = 0.0f;
|
||||
m_half[2] = 0.0f;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxCollidable::reset(PfxShape *base,PfxUInt16 *ids,int n)
|
||||
{
|
||||
m_shapeBase = base;
|
||||
m_numShapes = 0;
|
||||
m_maxShapes = n;
|
||||
for(int i=0;i<n;i++) {
|
||||
m_shapeIds[i] = ids[i];
|
||||
}
|
||||
m_center[0] = 0.0f;
|
||||
m_center[1] = 0.0f;
|
||||
m_center[2] = 0.0f;
|
||||
m_half[0] = 0.0f;
|
||||
m_half[1] = 0.0f;
|
||||
m_half[2] = 0.0f;
|
||||
}
|
||||
|
||||
inline
|
||||
PfxUInt32 PfxCollidable::getNumShapes() const
|
||||
{
|
||||
return m_numShapes;
|
||||
}
|
||||
|
||||
inline
|
||||
PfxUInt16 PfxCollidable::getShapeId(int i) const
|
||||
{
|
||||
SCE_PFX_ASSERT(i>0);
|
||||
return m_shapeIds[i-1];
|
||||
}
|
||||
|
||||
inline
|
||||
const PfxShape& PfxCollidable::getShape(int i) const
|
||||
{
|
||||
SCE_PFX_ASSERT(i<m_numShapes);
|
||||
if(i>0) {
|
||||
return m_shapeBase[m_shapeIds[i-1]];
|
||||
}
|
||||
else {
|
||||
return m_defShape;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
PfxShape& PfxCollidable::getShape(int i)
|
||||
{
|
||||
SCE_PFX_ASSERT(i<m_numShapes);
|
||||
if(i>0) {
|
||||
return m_shapeBase[m_shapeIds[i-1]];
|
||||
}
|
||||
else {
|
||||
return m_defShape;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
PfxShape &PfxCollidable::getNewShape()
|
||||
{
|
||||
SCE_PFX_ASSERT(m_numShapes<=m_maxShapes);
|
||||
if(m_numShapes == 0) {
|
||||
m_numShapes++;
|
||||
return m_defShape;
|
||||
}
|
||||
else {
|
||||
m_numShapes++;
|
||||
return m_shapeBase[m_shapeIds[m_numShapes-2]];
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
PfxVector3 PfxCollidable::getHalf() const
|
||||
{
|
||||
return pfxReadVector3(m_half);
|
||||
}
|
||||
|
||||
inline
|
||||
PfxVector3 PfxCollidable::getCenter() const
|
||||
{
|
||||
return pfxReadVector3(m_center);
|
||||
}
|
||||
|
||||
#endif // _SCE_PFX_COLLIDABLE_IMPLEMENTATION_H
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_CONTACT_MANIFOLD_H
|
||||
#define _SCE_PFX_CONTACT_MANIFOLD_H
|
||||
|
||||
#include "../base/pfx_common.h"
|
||||
#include "../base/pfx_vec_utils.h"
|
||||
#include "pfx_sub_data.h"
|
||||
#include "../solver/pfx_constraint_row.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
#define SCE_PFX_NUMCONTACTS_PER_BODIES 4
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Contact Point
|
||||
|
||||
struct PfxContactPoint
|
||||
{
|
||||
PfxUInt8 m_duration;
|
||||
PfxUInt8 m_shapeIdA;
|
||||
PfxUInt8 m_shapeIdB;
|
||||
SCE_PFX_PADDING(1,1)
|
||||
PfxSubData m_subData;
|
||||
PfxFloat m_distance;
|
||||
PfxFloat m_localPointA[3];
|
||||
PfxFloat m_localPointB[3];
|
||||
SCE_PFX_PADDING(2,8)
|
||||
PfxConstraintRow m_constraintRow[3];
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_duration = 0;
|
||||
m_shapeIdA = m_shapeIdB = 0;
|
||||
m_subData = PfxSubData();
|
||||
m_distance = SCE_PFX_FLT_MAX;
|
||||
m_constraintRow[0].m_accumImpulse = 0.0f;
|
||||
m_constraintRow[1].m_accumImpulse = 0.0f;
|
||||
m_constraintRow[2].m_accumImpulse = 0.0f;
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Contact Manifold
|
||||
|
||||
//J 同一ペアの衝突が続く限り保持されるコンタクト情報
|
||||
//E PfxContactManifold keeps contact information until two rigid bodies are separated.
|
||||
|
||||
class SCE_PFX_ALIGNED(128) PfxContactManifold
|
||||
{
|
||||
private:
|
||||
PfxUInt16 m_rigidBodyIdA,m_rigidBodyIdB;
|
||||
PfxUInt16 m_duration;
|
||||
PfxUInt16 m_numContacts;
|
||||
PfxFloat m_compositeFriction;
|
||||
PfxUInt32 m_internalFlag;
|
||||
PfxContactPoint m_contactPoints[SCE_PFX_NUMCONTACTS_PER_BODIES];
|
||||
void *m_userData;
|
||||
PfxUInt32 m_userParam[4];
|
||||
SCE_PFX_PADDING(1,28)
|
||||
|
||||
int findNearestContactPoint(const PfxPoint3 &newPoint,const PfxVector3 &newNormal);
|
||||
int sort4ContactPoints(const PfxPoint3 &newPoint,PfxFloat newDistance);
|
||||
|
||||
public:
|
||||
// Internal method
|
||||
PfxFloat getCompositeFriction() const {return m_compositeFriction;}
|
||||
void setCompositeFriction(PfxFloat f) {m_compositeFriction = f;}
|
||||
|
||||
PfxUInt32 getInternalFlag() const {return m_internalFlag;}
|
||||
void setInternalFlag(PfxUInt32 f) {m_internalFlag = f;}
|
||||
|
||||
public:
|
||||
void reset(PfxUInt16 rigidBodyIdA,PfxUInt16 rigidBodyIdB)
|
||||
{
|
||||
m_userData = 0;
|
||||
m_userParam[0] = m_userParam[1] = m_userParam[2] = m_userParam[3] = 0;
|
||||
m_numContacts = 0;
|
||||
m_duration = 0;
|
||||
m_rigidBodyIdA = rigidBodyIdA;
|
||||
m_rigidBodyIdB = rigidBodyIdB;
|
||||
}
|
||||
|
||||
void addContactPoint(
|
||||
PfxFloat newDistance,
|
||||
const PfxVector3 &newNormal, // world coords
|
||||
const PfxPoint3 &newPointA, // local coords to the objectA
|
||||
const PfxPoint3 &newPointB, // local coords to the objectB
|
||||
PfxSubData subData);
|
||||
|
||||
void addContactPoint(const PfxContactPoint &cp);
|
||||
|
||||
void removeContactPoint(int i)
|
||||
{
|
||||
SCE_PFX_ASSERT(i>=0&&i<m_numContacts);
|
||||
m_contactPoints[i] = m_contactPoints[m_numContacts-1];
|
||||
m_numContacts--;
|
||||
}
|
||||
|
||||
int getNumContacts() const {return (int)m_numContacts;}
|
||||
|
||||
PfxContactPoint &getContactPoint(int i) {return m_contactPoints[i];}
|
||||
|
||||
const PfxContactPoint &getContactPoint(int i) const {return m_contactPoints[i];}
|
||||
|
||||
void refresh(const PfxVector3 &pA,const PfxQuat &qA,const PfxVector3 &pB,const PfxQuat &qB);
|
||||
|
||||
void merge(const PfxContactManifold &contact);
|
||||
|
||||
PfxUInt16 getDuration() const {return m_duration;}
|
||||
|
||||
PfxUInt16 getRigidBodyIdA() const {return m_rigidBodyIdA;}
|
||||
|
||||
PfxUInt16 getRigidBodyIdB() const {return m_rigidBodyIdB;}
|
||||
};
|
||||
|
||||
} //namespace PhysicsEffects
|
||||
} //namespace sce
|
||||
|
||||
#endif // _SCE_PFX_CONTACT_MANIFOLD_H
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_CYLINDER_H
|
||||
#define _SCE_PFX_CYLINDER_H
|
||||
|
||||
#include "../base/pfx_common.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
struct PfxCylinder
|
||||
{
|
||||
PfxFloat m_halfLen;
|
||||
PfxFloat m_radius;
|
||||
|
||||
PfxCylinder() {}
|
||||
PfxCylinder(PfxFloat halfLength, PfxFloat radius);
|
||||
|
||||
void set(PfxFloat halfLength, PfxFloat radius);
|
||||
};
|
||||
|
||||
inline
|
||||
PfxCylinder::PfxCylinder(PfxFloat halfLength, PfxFloat radius)
|
||||
{
|
||||
m_halfLen = halfLength;
|
||||
m_radius = radius;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxCylinder::set(PfxFloat halfLength, PfxFloat radius)
|
||||
{
|
||||
m_halfLen = halfLength;
|
||||
m_radius = radius;
|
||||
}
|
||||
|
||||
} // namespace PhysicsEffects
|
||||
} // namespace sce
|
||||
|
||||
#endif // _SCE_PFX_CYLINDER_H
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_LARGE_TRI_MESH_H
|
||||
#define _SCE_PFX_LARGE_TRI_MESH_H
|
||||
|
||||
#include "pfx_tri_mesh.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
#define SCE_PFX_MAX_LARGETRIMESH_ISLANDS 256
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Large Mesh
|
||||
|
||||
class SCE_PFX_ALIGNED(16) PfxLargeTriMesh
|
||||
{
|
||||
public:
|
||||
//J ラージメッシュのサイズ
|
||||
//E Size of a large mesh
|
||||
PfxVector3 m_half;
|
||||
|
||||
//J 含まれるメッシュの総数
|
||||
//E Number of mesh groups
|
||||
PfxUInt16 m_numIslands;
|
||||
|
||||
//J アイランドAABB配列(ソート済み)
|
||||
//E Array of island AABB (Sorted)
|
||||
PfxUInt8 m_axis; // 0 = X , 1 = Y , 2 = Z
|
||||
SCE_PFX_PADDING(1,1)
|
||||
PfxAabb16 *m_aabbList;
|
||||
SCE_PFX_PADDING(2,4)
|
||||
|
||||
//J アイランド配列
|
||||
//E Array of island
|
||||
PfxTriMesh *m_islands;
|
||||
|
||||
PfxLargeTriMesh()
|
||||
{
|
||||
m_numIslands = 0;
|
||||
m_islands = NULL;
|
||||
m_aabbList = NULL;
|
||||
}
|
||||
|
||||
inline bool testAABB(int islandId,const PfxVector3 ¢er,const PfxVector3 &half) const;
|
||||
|
||||
//J ワールド座標値をラージメッシュローカルに変換する
|
||||
//E Convert a position in the world coordinate into a position in the local coordinate
|
||||
inline PfxVecInt3 getLocalPosition(const PfxVector3 &worldPosition) const;
|
||||
inline void getLocalPosition(
|
||||
const PfxVector3 &worldMinPosition,const PfxVector3 &worldMaxPosition,
|
||||
PfxVecInt3 &localMinPosition,PfxVecInt3 &localMaxPosition) const;
|
||||
|
||||
//J ラージメッシュローカル座標値をワールドに変換する
|
||||
//E Convert a position in the local coordinate into a position in the world coordinate
|
||||
inline PfxVector3 getWorldPosition(const PfxVecInt3 &localPosition) const;
|
||||
};
|
||||
|
||||
inline
|
||||
bool PfxLargeTriMesh::testAABB(int islandId,const PfxVector3 ¢er,const PfxVector3 &half) const
|
||||
{
|
||||
PfxVecInt3 aabbMinL = getLocalPosition(center-half);
|
||||
PfxVecInt3 aabbMaxL = getLocalPosition(center+half);
|
||||
|
||||
if(aabbMaxL.getX() < pfxGetXMin(m_aabbList[islandId]) || aabbMinL.getX() > pfxGetXMax(m_aabbList[islandId])) return false;
|
||||
if(aabbMaxL.getY() < pfxGetYMin(m_aabbList[islandId]) || aabbMinL.getY() > pfxGetYMax(m_aabbList[islandId])) return false;
|
||||
if(aabbMaxL.getZ() < pfxGetZMin(m_aabbList[islandId]) || aabbMinL.getZ() > pfxGetZMax(m_aabbList[islandId])) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline
|
||||
PfxVecInt3 PfxLargeTriMesh::getLocalPosition(const PfxVector3 &worldPosition) const
|
||||
{
|
||||
const PfxVector3 sz(65535.0f);
|
||||
PfxVector3 tmp = divPerElem(worldPosition+m_half,2.0f*m_half);
|
||||
tmp = mulPerElem(sz,minPerElem(maxPerElem(tmp,PfxVector3(0.0f)),PfxVector3(1.0f))); // clamp 0.0 - 1.0
|
||||
return PfxVecInt3(tmp);
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxLargeTriMesh::getLocalPosition(
|
||||
const PfxVector3 &worldMinPosition,const PfxVector3 &worldMaxPosition,
|
||||
PfxVecInt3 &localMinPosition,PfxVecInt3 &localMaxPosition) const
|
||||
{
|
||||
const PfxVector3 sz(65535.0f);
|
||||
PfxVector3 qmin = divPerElem(worldMinPosition+m_half,2.0f*m_half);
|
||||
qmin = mulPerElem(sz,minPerElem(maxPerElem(qmin,PfxVector3(0.0f)),PfxVector3(1.0f))); // clamp 0.0 - 1.0
|
||||
|
||||
PfxVector3 qmax = divPerElem(worldMaxPosition+m_half,2.0f*m_half);
|
||||
qmax = mulPerElem(sz,minPerElem(maxPerElem(qmax,PfxVector3(0.0f)),PfxVector3(1.0f))); // clamp 0.0 - 1.0
|
||||
|
||||
localMinPosition = PfxVecInt3(floorf(qmin[0]),floorf(qmin[1]),floorf(qmin[2]));
|
||||
localMaxPosition = PfxVecInt3(ceilf(qmax[0]),ceilf(qmax[1]),ceilf(qmax[2]));
|
||||
}
|
||||
|
||||
inline
|
||||
PfxVector3 PfxLargeTriMesh::getWorldPosition(const PfxVecInt3 &localPosition) const
|
||||
{
|
||||
PfxVector3 sz(65535.0f),lp(localPosition);
|
||||
PfxVector3 tmp = divPerElem(lp,sz);
|
||||
return mulPerElem(tmp,2.0f*m_half) - m_half;
|
||||
}
|
||||
|
||||
} // namespace PhysicsEffects
|
||||
} // namespace sce
|
||||
|
||||
#endif // _SCE_PFX_LARGE_TRI_MESH_H
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_RAY_H
|
||||
#define _SCE_PFX_RAY_H
|
||||
|
||||
#include "../base/pfx_common.h"
|
||||
#include "pfx_sub_data.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
#define SCE_PFX_RAY_FACET_MODE_FRONT_ONLY 0
|
||||
#define SCE_PFX_RAY_FACET_MODE_BACK_ONLY 1
|
||||
#define SCE_PFX_RAY_FACET_MODE_FRONT_AND_BACK 2
|
||||
|
||||
struct SCE_PFX_ALIGNED(16) PfxRayInput
|
||||
{
|
||||
PfxVector3 m_startPosition;
|
||||
PfxVector3 m_direction;
|
||||
PfxUInt32 m_contactFilterSelf;
|
||||
PfxUInt32 m_contactFilterTarget;
|
||||
PfxUInt8 m_facetMode;
|
||||
SCE_PFX_PADDING(1,7)
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_contactFilterSelf = m_contactFilterTarget = 0xffffffff;
|
||||
m_facetMode = SCE_PFX_RAY_FACET_MODE_FRONT_ONLY;
|
||||
}
|
||||
};
|
||||
|
||||
struct SCE_PFX_ALIGNED(16) PfxRayOutput
|
||||
{
|
||||
PfxVector3 m_contactPoint;
|
||||
PfxVector3 m_contactNormal;
|
||||
PfxFloat m_variable;
|
||||
PfxUInt16 m_objectId;
|
||||
PfxUInt8 m_shapeId;
|
||||
PfxBool m_contactFlag : 1;
|
||||
PfxSubData m_subData;
|
||||
};
|
||||
} //namespace PhysicsEffects
|
||||
} //namespace sce
|
||||
|
||||
#endif // _SCE_PFX_RAY_H
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_SHAPE_H
|
||||
#define _SCE_PFX_SHAPE_H
|
||||
|
||||
#include "../base/pfx_common.h"
|
||||
#include "../base/pfx_vec_utils.h"
|
||||
#include "pfx_box.h"
|
||||
#include "pfx_sphere.h"
|
||||
#include "pfx_capsule.h"
|
||||
#include "pfx_cylinder.h"
|
||||
#include "pfx_tri_mesh.h"
|
||||
#include "pfx_large_tri_mesh.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
enum ePfxShapeType
|
||||
{
|
||||
kPfxShapeSphere = 0,
|
||||
kPfxShapeBox,
|
||||
kPfxShapeCapsule,
|
||||
kPfxShapeCylinder,
|
||||
kPfxShapeConvexMesh,
|
||||
kPfxShapeLargeTriMesh,
|
||||
kPfxShapeReserved0,
|
||||
kPfxShapeReserved1,
|
||||
kPfxShapeReserved2,
|
||||
kPfxShapeUser0,
|
||||
kPfxShapeUser1,
|
||||
kPfxShapeUser2,
|
||||
kPfxShapeCount // =12
|
||||
};
|
||||
|
||||
class SCE_PFX_ALIGNED(16) PfxShape
|
||||
{
|
||||
friend class PfxCollidable;
|
||||
|
||||
private:
|
||||
union {
|
||||
PfxFloat m_vecDataF[3];
|
||||
PfxUInt32 m_vecDataI[3];
|
||||
void *m_vecDataPtr[2];
|
||||
};
|
||||
PfxUInt8 m_type;
|
||||
SCE_PFX_PADDING(1,3)
|
||||
PfxFloat m_offsetPosition[3];
|
||||
PfxFloat m_offsetOrientation[4];
|
||||
PfxUInt32 m_contactFilterSelf;
|
||||
PfxUInt32 m_contactFilterTarget;
|
||||
SCE_PFX_PADDING(2,12)
|
||||
|
||||
public:
|
||||
inline void reset();
|
||||
|
||||
// Shape
|
||||
inline void setBox(PfxBox SCE_VECTORMATH_AOS_VECTOR_ARG box);
|
||||
inline void setCapsule(PfxCapsule capsule);
|
||||
inline void setCylinder(PfxCylinder cylinder);
|
||||
inline void setSphere(PfxSphere sphere);
|
||||
inline void setConvexMesh(const PfxConvexMesh *convexMesh);
|
||||
inline void setLargeTriMesh(const PfxLargeTriMesh *largeMesh);
|
||||
|
||||
inline PfxUInt8 getType() const;
|
||||
inline PfxBox getBox()const ;
|
||||
inline PfxCapsule getCapsule() const;
|
||||
inline PfxCylinder getCylinder() const;
|
||||
inline PfxSphere getSphere() const;
|
||||
inline const PfxConvexMesh* getConvexMesh() const;
|
||||
inline const PfxLargeTriMesh* getLargeTriMesh() const;
|
||||
|
||||
// Offset
|
||||
inline void setOffsetTransform(const PfxTransform3 & xfrm);
|
||||
inline void setOffsetOrientation(const PfxQuat SCE_VECTORMATH_AOS_VECTOR_ARG rot) {return pfxStoreQuat(rot,m_offsetOrientation);}
|
||||
inline void setOffsetPosition(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG pos) {return pfxStoreVector3(pos,m_offsetPosition);}
|
||||
|
||||
inline PfxTransform3 getOffsetTransform() const;
|
||||
inline PfxVector3 getOffsetPosition() const {return pfxReadVector3(m_offsetPosition);}
|
||||
inline PfxQuat getOffsetOrientation() const {return pfxReadQuat(m_offsetOrientation);}
|
||||
|
||||
// Raw data access
|
||||
inline void setDataFloat(int i,PfxFloat v) {m_vecDataF[i]=v;}
|
||||
inline void setDataInteger(int i,PfxUInt32 v) {m_vecDataI[i]=v;}
|
||||
|
||||
inline PfxFloat getDataFloat(int i) const {return m_vecDataF[i];}
|
||||
inline PfxUInt32 getDataInteger(int i) const {return m_vecDataI[i];}
|
||||
|
||||
// Contact Filter
|
||||
PfxUInt32 getContactFilterSelf() const {return m_contactFilterSelf;}
|
||||
void setContactFilterSelf(PfxUInt32 filter) {m_contactFilterSelf = filter;}
|
||||
|
||||
PfxUInt32 getContactFilterTarget() const {return m_contactFilterTarget;}
|
||||
void setContactFilterTarget(PfxUInt32 filter) {m_contactFilterTarget = filter;}
|
||||
|
||||
// Bouding Volume
|
||||
void getAabb(PfxVector3 &aabbMin,PfxVector3 &aabbMax) const;
|
||||
};
|
||||
|
||||
#include "pfx_shape_implementation.h"
|
||||
|
||||
} // namespace PhysicsEffects
|
||||
} // namespace sce
|
||||
|
||||
#endif // _SCE_PFX_SHAPE_H
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_SHAPE_IMPLEMENTATION_H
|
||||
#define _SCE_PFX_SHAPE_IMPLEMENTATION_H
|
||||
|
||||
inline
|
||||
void PfxShape::reset()
|
||||
{
|
||||
m_type = kPfxShapeSphere;
|
||||
m_offsetPosition[0] = m_offsetPosition[1] = m_offsetPosition[2]= 0.0f;
|
||||
m_offsetOrientation[0] = m_offsetOrientation[1] = m_offsetOrientation[2]= 0.0f;
|
||||
m_offsetOrientation[3] = 1.0f;
|
||||
m_contactFilterSelf = m_contactFilterTarget = 0xffffffff;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxShape::setBox(PfxBox SCE_VECTORMATH_AOS_VECTOR_ARG box)
|
||||
{
|
||||
m_vecDataF[0] = box.m_half[0];
|
||||
m_vecDataF[1] = box.m_half[1];
|
||||
m_vecDataF[2] = box.m_half[2];
|
||||
m_type = kPfxShapeBox;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxShape::setCapsule(PfxCapsule capsule)
|
||||
{
|
||||
m_vecDataF[0] = capsule.m_halfLen;
|
||||
m_vecDataF[1] = capsule.m_radius;
|
||||
m_vecDataF[2] = 0.0f;
|
||||
m_type = kPfxShapeCapsule;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxShape::setCylinder(PfxCylinder cylinder)
|
||||
{
|
||||
m_vecDataF[0] = cylinder.m_halfLen;
|
||||
m_vecDataF[1] = cylinder.m_radius;
|
||||
m_vecDataF[2] = 0.0f;
|
||||
m_type = kPfxShapeCylinder;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxShape::setSphere(PfxSphere sphere)
|
||||
{
|
||||
m_vecDataF[0] = sphere.m_radius;
|
||||
m_vecDataF[1] = 0.0f;
|
||||
m_vecDataF[2] = 0.0f;
|
||||
m_type = kPfxShapeSphere;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxShape::setConvexMesh(const PfxConvexMesh *convexMesh)
|
||||
{
|
||||
m_vecDataPtr[0] = (void*)convexMesh;
|
||||
m_vecDataPtr[1] = NULL;
|
||||
m_type = kPfxShapeConvexMesh;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxShape::setLargeTriMesh(const PfxLargeTriMesh *largeMesh)
|
||||
{
|
||||
m_vecDataPtr[0] = (void*)largeMesh;
|
||||
m_vecDataPtr[1] = NULL;
|
||||
m_type = kPfxShapeLargeTriMesh;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxShape::setOffsetTransform(const PfxTransform3 & xfrm)
|
||||
{
|
||||
setOffsetOrientation(PfxQuat(xfrm.getUpper3x3()));
|
||||
setOffsetPosition(xfrm.getTranslation());
|
||||
}
|
||||
|
||||
inline
|
||||
PfxUInt8 PfxShape::getType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
inline
|
||||
PfxBox PfxShape::getBox() const
|
||||
{
|
||||
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeBox);
|
||||
return PfxBox(m_vecDataF[0],m_vecDataF[1],m_vecDataF[2]);
|
||||
}
|
||||
|
||||
inline
|
||||
PfxCapsule PfxShape::getCapsule() const
|
||||
{
|
||||
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeCapsule);
|
||||
return PfxCapsule(m_vecDataF[0], m_vecDataF[1]);
|
||||
}
|
||||
|
||||
inline
|
||||
PfxCylinder PfxShape::getCylinder() const
|
||||
{
|
||||
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeCylinder);
|
||||
return PfxCylinder(m_vecDataF[0], m_vecDataF[1]);
|
||||
}
|
||||
|
||||
inline
|
||||
PfxSphere PfxShape::getSphere() const
|
||||
{
|
||||
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeSphere);
|
||||
return PfxSphere(m_vecDataF[0]);
|
||||
}
|
||||
|
||||
inline
|
||||
const PfxConvexMesh *PfxShape::getConvexMesh() const
|
||||
{
|
||||
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeConvexMesh);
|
||||
SCE_PFX_ALWAYS_ASSERT(m_vecDataPtr[0]!=NULL);
|
||||
return (PfxConvexMesh*)m_vecDataPtr[0];
|
||||
}
|
||||
|
||||
inline
|
||||
const PfxLargeTriMesh *PfxShape::getLargeTriMesh() const
|
||||
{
|
||||
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeLargeTriMesh);
|
||||
SCE_PFX_ALWAYS_ASSERT(m_vecDataPtr[0]!=NULL);
|
||||
return (PfxLargeTriMesh*)m_vecDataPtr[0];
|
||||
}
|
||||
|
||||
inline
|
||||
PfxTransform3 PfxShape::getOffsetTransform() const
|
||||
{
|
||||
return PfxTransform3(getOffsetOrientation(),getOffsetPosition());
|
||||
}
|
||||
|
||||
#endif // _SCE_PFX_SHAPE_IMPLEMENTATION_H
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_SHAPE_ITERATOR_H
|
||||
#define _SCE_PFX_SHAPE_ITERATOR_H
|
||||
|
||||
#include "pfx_collidable.h"
|
||||
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
class PfxShapeIterator
|
||||
{
|
||||
private:
|
||||
PfxUInt32 m_numShapes;
|
||||
PfxShape *m_shapeBase;
|
||||
const PfxUInt16 *m_shapeIds;
|
||||
const PfxShape *m_curShape;
|
||||
PfxUInt32 m_index;
|
||||
|
||||
public:
|
||||
PfxShapeIterator(const PfxCollidable &coll) : m_shapeIds(coll.m_shapeIds)
|
||||
{
|
||||
m_numShapes = coll.m_numShapes;
|
||||
m_shapeBase = coll.m_shapeBase;
|
||||
m_index = 0;
|
||||
m_curShape = &coll.m_defShape;
|
||||
}
|
||||
|
||||
~PfxShapeIterator() {}
|
||||
|
||||
inline PfxShapeIterator& operator++()
|
||||
{
|
||||
m_curShape = &m_shapeBase[m_shapeIds[m_index++]];
|
||||
return *this;
|
||||
}
|
||||
|
||||
const PfxShape& operator*() const {return *m_curShape;}
|
||||
};
|
||||
|
||||
} //namespace PhysicsEffects
|
||||
} //namespace sce
|
||||
|
||||
#endif // _SCE_PFX_SHAPE_ITERATOR_H
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_SPHERE_H
|
||||
#define _SCE_PFX_SPHERE_H
|
||||
|
||||
#include "../base/pfx_common.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
struct PfxSphere {
|
||||
PfxFloat m_radius;
|
||||
|
||||
PfxSphere() {}
|
||||
PfxSphere( PfxFloat radius );
|
||||
|
||||
void set( PfxFloat radius );
|
||||
};
|
||||
|
||||
inline
|
||||
PfxSphere::PfxSphere( PfxFloat radius )
|
||||
{
|
||||
m_radius = radius;
|
||||
}
|
||||
|
||||
inline
|
||||
void PfxSphere::set( PfxFloat radius )
|
||||
{
|
||||
m_radius = radius;
|
||||
}
|
||||
|
||||
} // namespace PhysicsEffects
|
||||
} // namespace sce
|
||||
|
||||
#endif // _SCE_PFX_SPHERE_H
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_SUB_DATA_H
|
||||
#define _SCE_PFX_SUB_DATA_H
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
struct PfxSubData {
|
||||
enum {
|
||||
NONE = 0,
|
||||
MESH_INFO
|
||||
};
|
||||
|
||||
union {
|
||||
struct {
|
||||
PfxUInt8 m_type;
|
||||
SCE_PFX_PADDING(1,1)
|
||||
|
||||
struct {
|
||||
PfxUInt8 islandId;
|
||||
PfxUInt8 facetId;
|
||||
PfxUInt16 s;
|
||||
PfxUInt16 t;
|
||||
|
||||
} m_facetLocal;
|
||||
};
|
||||
PfxUInt32 param[2];
|
||||
};
|
||||
|
||||
PfxSubData()
|
||||
{
|
||||
param[0] = param[1] = 0;
|
||||
}
|
||||
|
||||
void setIslandId(PfxUInt8 i) {m_facetLocal.islandId = i;}
|
||||
void setFacetId(PfxUInt8 i) {m_facetLocal.facetId = i;}
|
||||
void setFacetLocalS(PfxFloat s) {m_facetLocal.s = (PfxUInt16)(s * 65535.0f);}
|
||||
void setFacetLocalT(PfxFloat t) {m_facetLocal.t = (PfxUInt16)(t * 65535.0f);}
|
||||
|
||||
PfxUInt8 getIslandId() {return m_facetLocal.islandId;}
|
||||
PfxUInt8 getFacetId() {return m_facetLocal.facetId;}
|
||||
PfxFloat getFacetLocalS() {return m_facetLocal.s / 65535.0f;}
|
||||
PfxFloat getFacetLocalT() {return m_facetLocal.t / 65535.0f;}
|
||||
};
|
||||
|
||||
} //namespace PhysicsEffects
|
||||
} //namespace sce
|
||||
#endif // _SCE_PFX_SUB_DATA_H
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
|
||||
All rights reserved.
|
||||
|
||||
Physics Effects is open software; you can redistribute it and/or
|
||||
modify it under the terms of the BSD License.
|
||||
|
||||
Physics Effects 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 BSD License for more details.
|
||||
|
||||
A copy of the BSD License is distributed with
|
||||
Physics Effects under the filename: physics_effects_license.txt
|
||||
*/
|
||||
|
||||
#ifndef _SCE_PFX_TRI_MESH_H
|
||||
#define _SCE_PFX_TRI_MESH_H
|
||||
|
||||
#include "../base/pfx_common.h"
|
||||
#include "../base/pfx_vec_utils.h"
|
||||
#include "pfx_aabb.h"
|
||||
|
||||
namespace sce {
|
||||
namespace PhysicsEffects {
|
||||
|
||||
//J メッシュのリソース制限
|
||||
//E Define some limitations of a triangle mesh
|
||||
#define SCE_PFX_NUMMESHFACETS 64
|
||||
#define SCE_PFX_NUMMESHEDGES 192
|
||||
#define SCE_PFX_NUMMESHVERTICES 128
|
||||
|
||||
//J エッジの角
|
||||
//E Edge types
|
||||
#define SCE_PFX_EDGE_FLAT 0
|
||||
#define SCE_PFX_EDGE_CONVEX 1
|
||||
#define SCE_PFX_EDGE_CONCAVE 2
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Edge
|
||||
struct PfxEdge
|
||||
{
|
||||
PfxUInt8 m_vertId[2];
|
||||
PfxUInt8 m_angleType;
|
||||
PfxUInt8 m_tilt;
|
||||
};
|
||||
|
||||
inline
|
||||
bool operator ==(const PfxEdge &e1,const PfxEdge &e2)
|
||||
{
|
||||
return (e1.m_vertId[0] == e2.m_vertId[0] && e1.m_vertId[1] == e2.m_vertId[1]) ||
|
||||
(e1.m_vertId[1] == e2.m_vertId[0] && e1.m_vertId[0] == e2.m_vertId[1]);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Facet
|
||||
|
||||
struct PfxFacet
|
||||
{
|
||||
PfxFloat m_normal[3];
|
||||
PfxFloat m_thickness;
|
||||
PfxUInt8 m_group;
|
||||
PfxUInt8 m_vertIds[3];
|
||||
PfxUInt8 m_edgeIds[3];
|
||||
PfxUInt8 m_userData;
|
||||
PfxFloat m_half[3];
|
||||
PfxFloat m_center[3];
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Mesh
|
||||
|
||||
struct SCE_PFX_ALIGNED(16) PfxTriMesh
|
||||
{
|
||||
PfxUInt8 m_numVerts;
|
||||
PfxUInt8 m_numEdges;
|
||||
PfxUInt8 m_numFacets;
|
||||
PfxUInt8 m_reserved;
|
||||
PfxFacet m_facets[SCE_PFX_NUMMESHFACETS];
|
||||
PfxEdge m_edges[SCE_PFX_NUMMESHEDGES];
|
||||
SCE_PFX_PADDING(1,12)
|
||||
PfxVector3 m_verts[SCE_PFX_NUMMESHVERTICES];
|
||||
PfxVector3 m_half;
|
||||
|
||||
PfxTriMesh()
|
||||
{
|
||||
m_numVerts = m_numEdges = m_numFacets = 0;
|
||||
}
|
||||
|
||||
inline void updateAABB();
|
||||
};
|
||||
|
||||
inline
|
||||
void PfxTriMesh::updateAABB()
|
||||
{
|
||||
PfxVector3 halfMax(0);
|
||||
|
||||
for(PfxUInt8 i=0;i<m_numFacets;i++) {
|
||||
PfxVector3 pnts[6] = {
|
||||
m_verts[m_facets[i].m_vertIds[0]],
|
||||
m_verts[m_facets[i].m_vertIds[1]],
|
||||
m_verts[m_facets[i].m_vertIds[2]],
|
||||
m_verts[m_facets[i].m_vertIds[0]] - m_facets[i].m_thickness * pfxReadVector3(m_facets[i].m_normal),
|
||||
m_verts[m_facets[i].m_vertIds[1]] - m_facets[i].m_thickness * pfxReadVector3(m_facets[i].m_normal),
|
||||
m_verts[m_facets[i].m_vertIds[2]] - m_facets[i].m_thickness * pfxReadVector3(m_facets[i].m_normal)
|
||||
};
|
||||
|
||||
PfxVector3 facetAABBmin,facetAABBmax,facetHalf,facetCenter;
|
||||
facetAABBmin = minPerElem(pnts[5],minPerElem(pnts[4],minPerElem(pnts[3],minPerElem(pnts[2],minPerElem(pnts[0],pnts[1])))));
|
||||
facetAABBmax = maxPerElem(pnts[5],maxPerElem(pnts[4],maxPerElem(pnts[3],maxPerElem(pnts[2],maxPerElem(pnts[0],pnts[1])))));
|
||||
facetHalf = 0.5f * (facetAABBmax - facetAABBmin) + PfxVector3(0.00001f); // Slightly stretch to avoid collision hole
|
||||
facetCenter = 0.5f * (facetAABBmax + facetAABBmin);
|
||||
pfxStoreVector3(facetHalf,m_facets[i].m_half);
|
||||
pfxStoreVector3(facetCenter,m_facets[i].m_center);
|
||||
halfMax = maxPerElem(absPerElem(facetAABBmax),halfMax);
|
||||
}
|
||||
m_half = halfMax;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Convex Mesh
|
||||
|
||||
struct SCE_PFX_ALIGNED(16) PfxConvexMesh
|
||||
{
|
||||
PfxUInt8 m_numVerts;
|
||||
PfxUInt8 m_numIndices;
|
||||
PfxUInt16 m_indices[SCE_PFX_NUMMESHFACETS*3];
|
||||
SCE_PFX_PADDING(1,14)
|
||||
PfxVector3 m_verts[SCE_PFX_NUMMESHVERTICES];
|
||||
PfxVector3 m_half;
|
||||
SCE_PFX_PADDING(2,16)
|
||||
|
||||
PfxConvexMesh()
|
||||
{
|
||||
m_numVerts = m_numIndices = 0;
|
||||
}
|
||||
|
||||
inline void updateAABB();
|
||||
};
|
||||
|
||||
inline
|
||||
void PfxConvexMesh::updateAABB()
|
||||
{
|
||||
PfxVector3 halfMax(0);
|
||||
for(int i=0;i<m_numVerts;i++) {
|
||||
halfMax = maxPerElem(absPerElem(m_verts[i]),halfMax);
|
||||
}
|
||||
m_half = halfMax;
|
||||
}
|
||||
|
||||
} // namespace PhysicsEffects
|
||||
} // namespace sce
|
||||
|
||||
#endif // _SCE_PFX_TRI_MESH_H
|
||||
Reference in New Issue
Block a user