diff --git a/Code/Debug/Tester.ilk b/Code/Debug/Tester.ilk new file mode 100644 index 00000000..49c33576 Binary files /dev/null and b/Code/Debug/Tester.ilk differ diff --git a/Code/Debug/Tester.pdb b/Code/Debug/Tester.pdb new file mode 100644 index 00000000..6fcf8970 Binary files /dev/null and b/Code/Debug/Tester.pdb differ diff --git a/Code/OysterPhysics3D/OysterPhysics3D.h b/Code/OysterPhysics3D/OysterPhysics3D.h index a5d58c0b..ab2047de 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.h +++ b/Code/OysterPhysics3D/OysterPhysics3D.h @@ -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; + } + } } } } diff --git a/Code/OysterPhysics3D/Plane.cpp b/Code/OysterPhysics3D/Plane.cpp index c999324b..d495584c 100644 --- a/Code/OysterPhysics3D/Plane.cpp +++ b/Code/OysterPhysics3D/Plane.cpp @@ -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; } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Point.cpp b/Code/OysterPhysics3D/Point.cpp index 39cc93af..bf1057f3 100644 --- a/Code/OysterPhysics3D/Point.cpp +++ b/Code/OysterPhysics3D/Point.cpp @@ -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: diff --git a/Code/OysterPhysics3D/Ray.cpp b/Code/OysterPhysics3D/Ray.cpp index f7873437..1983a9ba 100644 --- a/Code/OysterPhysics3D/Ray.cpp +++ b/Code/OysterPhysics3D/Ray.cpp @@ -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: diff --git a/Code/OysterPhysics3D/Sphere.cpp b/Code/OysterPhysics3D/Sphere.cpp index f138208c..324abeeb 100644 --- a/Code/OysterPhysics3D/Sphere.cpp +++ b/Code/OysterPhysics3D/Sphere.cpp @@ -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: