2 Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
\r
5 Physics Effects is open software; you can redistribute it and/or
\r
6 modify it under the terms of the BSD License.
\r
8 Physics Effects is distributed in the hope that it will be useful,
\r
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
11 See the BSD License for more details.
\r
13 A copy of the BSD License is distributed with
\r
14 Physics Effects under the filename: physics_effects_license.txt
\r
17 #include "../../include/physics_effects/util/pfx_mass.h"
\r
20 namespace PhysicsEffects {
\r
22 ///////////////////////////////////////////////////////////////////////////////
\r
25 PfxFloat pfxCalcMassBox(PfxFloat density,const PfxVector3 &halfExtent)
\r
27 return density * halfExtent[0] * halfExtent[1] * halfExtent[2] * 8;
\r
30 PfxMatrix3 pfxCalcInertiaBox(const PfxVector3 &halfExtent,PfxFloat mass)
\r
32 PfxVector3 sqrSz = halfExtent * 2.0f;
\r
33 sqrSz = mulPerElem(sqrSz,sqrSz);
\r
34 PfxMatrix3 inertia = PfxMatrix3::identity();
\r
35 inertia[0][0] = (mass*(sqrSz[1]+sqrSz[2]))/12.0f;
\r
36 inertia[1][1] = (mass*(sqrSz[0]+sqrSz[2]))/12.0f;
\r
37 inertia[2][2] = (mass*(sqrSz[0]+sqrSz[1]))/12.0f;
\r
41 ///////////////////////////////////////////////////////////////////////////////
\r
44 PfxFloat pfxCalcMassSphere(PfxFloat density,PfxFloat radius)
\r
46 return (4.0f/3.0f) * SCE_PFX_PI * radius * radius * radius * density;
\r
49 PfxMatrix3 pfxCalcInertiaSphere(PfxFloat radius,PfxFloat mass)
\r
51 PfxMatrix3 inertia = PfxMatrix3::identity();
\r
52 inertia[0][0] = inertia[1][1] = inertia[2][2] = 0.4f * mass * radius * radius;
\r
56 ///////////////////////////////////////////////////////////////////////////////
\r
59 PfxFloat pfxCalcMassCylinder(PfxFloat density,PfxFloat halfLength,PfxFloat radius)
\r
61 return SCE_PFX_PI * radius * radius * 2.0f * halfLength * density;
\r
65 PfxMatrix3 pfxCalcInertiaCylinder(PfxFloat halfLength,PfxFloat radius,PfxFloat mass,int axis)
\r
67 PfxMatrix3 inertia = PfxMatrix3::identity();
\r
68 inertia[0][0] = inertia[1][1] = inertia[2][2] = 0.25f * mass * radius * radius + 0.33f * mass * halfLength * halfLength;
\r
69 inertia[axis][axis] = 0.5f * mass * radius * radius;
\r
73 PfxMatrix3 pfxCalcInertiaCylinderX(PfxFloat halfLength,PfxFloat radius,PfxFloat mass)
\r
75 return pfxCalcInertiaCylinder(radius,halfLength,mass,0);
\r
78 PfxMatrix3 pfxCalcInertiaCylinderY(PfxFloat halfLength,PfxFloat radius,PfxFloat mass)
\r
80 return pfxCalcInertiaCylinder(radius,halfLength,mass,1);
\r
83 PfxMatrix3 pfxCalcInertiaCylinderZ(PfxFloat halfLength,PfxFloat radius,PfxFloat mass)
\r
85 return pfxCalcInertiaCylinder(radius,halfLength,mass,2);
\r
88 ///////////////////////////////////////////////////////////////////////////////
\r
90 PfxMatrix3 pfxMassTranslate(PfxFloat mass,const PfxMatrix3 &inertia,const PfxVector3 &translation)
\r
92 PfxMatrix3 m = crossMatrix(translation);
\r
93 return inertia + mass * (-m*m);
\r
96 PfxMatrix3 pfxMassRotate(const PfxMatrix3 &inertia,const PfxMatrix3 &rotate)
\r
98 return rotate * inertia * transpose(rotate);
\r
101 } //namespace PhysicsEffects