Added inertia functions.
This commit is contained in:
parent
baec4b0392
commit
3f518c72e8
Binary file not shown.
Binary file not shown.
|
@ -186,6 +186,61 @@ namespace Oyster { namespace Physics3D
|
|||
namespace MomentOfInertia
|
||||
{ /// Library of Formulas to calculate moment of inerta for simple shapes
|
||||
/** @todo TODO: add MomentOfInertia tensor formulas */
|
||||
inline ::Oyster::Math::Float CalculateSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
return (2.0f/5.0f)*mass*radius*radius;
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float4x4 Sphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity;
|
||||
inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateSphere( mass , radius );
|
||||
inertia.m[1][1] = inertia.m[0][0];
|
||||
inertia.m[2][2] = inertia.m[0][0];
|
||||
|
||||
return inertia;
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float CalculateHollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
return (2.0f/3.0f)*mass*radius*radius;
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float4x4 HollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity;
|
||||
inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateHollowSphere( mass, radius );
|
||||
inertia.m[1][1] = inertia.m[0][0];
|
||||
inertia.m[2][2] = inertia.m[0][0];
|
||||
|
||||
return inertia;
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float CalculateCuboidX( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float depth )
|
||||
{
|
||||
return (1.0f/12.0f)*mass*(height*height + depth*depth);
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float CalculateCuboidY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth )
|
||||
{
|
||||
return (1.0f/12.0f)*mass*(width*width + depth*depth);
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float CalculateCuboidZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float height )
|
||||
{
|
||||
return (1.0f/12.0f)*mass*(height*height + width*width);
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float4x4 Cuboid( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth )
|
||||
{
|
||||
::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity;
|
||||
inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidX( mass , height, depth );
|
||||
inertia.m[1][1] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidY( mass , width, depth );
|
||||
inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidZ( mass , height, width );
|
||||
|
||||
return inertia;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} }
|
||||
|
|
|
@ -31,7 +31,7 @@ bool Plane::Intersects( const ICollideable *target ) const
|
|||
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
|
||||
case Type_sphere: return Utility::Intersect( *this, *(Sphere*)target );
|
||||
case Type_plane: return Utility::Intersect( *this, *(Plane*)target );
|
||||
case Type_triangle: return false; // TODO:
|
||||
// case Type_triangle: return false; // TODO:
|
||||
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)target, *this );
|
||||
case Type_box: return Utility::Intersect( *(Box*)target, *this );
|
||||
case Type_frustrum: return false; // TODO:
|
||||
|
@ -47,7 +47,7 @@ bool Plane::Contains( const ICollideable *target ) const
|
|||
case Type_point: return Utility::Intersect( *this, *(Point*)target );
|
||||
case Type_ray: return Utility::Contains( *this, *(Ray*)target );
|
||||
case Type_plane: return Utility::Contains( *this, *(Plane*)target );
|
||||
case Type_triangle: return false; // TODO:
|
||||
// case Type_triangle: return false; // TODO:
|
||||
default: return false;
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ bool Point::Intersects( const ICollideable *target ) const
|
|||
case Type_ray: return Utility::Intersect( *(Ray*)target, *this, ((Ray*)target)->collisionDistance );
|
||||
case Type_sphere: Utility::Intersect( *(Sphere*)target, *this );
|
||||
case Type_plane: return Utility::Intersect( *(Plane*)target, *this );
|
||||
case Type_triangle: return false; // TODO:
|
||||
//case Type_triangle: return false; // TODO:
|
||||
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)target, *this );
|
||||
case Type_box: return Utility::Intersect( *(Box*)target, *this );
|
||||
case Type_frustrum: return false; // TODO:
|
||||
|
|
|
@ -33,7 +33,7 @@ bool Ray::Intersects( const ICollideable *target ) const
|
|||
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, this->collisionDistance, ((Ray*)target)->collisionDistance );
|
||||
case Type_sphere: return Utility::Intersect( *(Sphere*)target, *this, this->collisionDistance );
|
||||
case Type_plane: return Utility::Intersect( *(Plane*)target, *this, this->collisionDistance );
|
||||
case Type_triangle: return false; // TODO:
|
||||
// case Type_triangle: return false; // TODO:
|
||||
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)target, *this, this->collisionDistance );
|
||||
case Type_box: return Utility::Intersect( *(Box*)target, *this, this->collisionDistance );
|
||||
case Type_frustrum: return false; // TODO:
|
||||
|
|
|
@ -27,7 +27,7 @@ bool Sphere::Intersects( const ICollideable *target ) const
|
|||
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
|
||||
case Type_sphere: Utility::Intersect( *this, *(Sphere*)target );
|
||||
case Type_plane: return Utility::Intersect( *(Plane*)target, *this );
|
||||
case Type_triangle: return false; // TODO:
|
||||
// case Type_triangle: return false; // TODO:
|
||||
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)target, *this );
|
||||
case Type_box: return Utility::Intersect( *(Box*)target, *this );
|
||||
case Type_frustrum: return false; // TODO:
|
||||
|
@ -41,7 +41,7 @@ bool Sphere::Contains( const ICollideable *target ) const
|
|||
{
|
||||
case Type_point: return Utility::Intersect( *this, *(Point*)target );
|
||||
case Type_sphere: return Utility::Contains( *this, *(Sphere*)target );
|
||||
case Type_triangle: return false; // TODO:
|
||||
// case Type_triangle: return false; // TODO:
|
||||
case Type_box_axis_aligned: return false; // TODO:
|
||||
case Type_box: return false; // TODO:
|
||||
case Type_frustrum: return false; // TODO:
|
||||
|
|
Loading…
Reference in New Issue