From 28fbcebf98b627b4cfb46e317ca89f983c07778c Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 20 Jan 2014 18:45:34 +0100 Subject: [PATCH 01/13] general lerp & vector nlerp --- Code/OysterMath/LinearMath.h | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index b5eab471..791999db 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -146,6 +146,85 @@ namespace LinearAlgebra targetMem = out * (in.GetAdjoint() /= d); return true; } + + /******************************************************************** + * Linear Interpolation + * @return start * (1-t) + end * t + ********************************************************************/ + template + inline PointType Lerp( const PointType &start, const PointType &end, const ScalarType &t ) + { + return end * t + start * ( 1 - t ); + } + + /******************************************************************** + * Normalized Linear Interpolation + * @return nullvector if impossible to solve. + ********************************************************************/ + template + inline Vector2 Nlerp( const Vector2 &start, const Vector2 &end, const ScalarType &t ) + { + Vector2 output = Lerp( start, end, t ); + ScalarType magnitudeSquared = output.Dot( output ); + if( magnitudeSquared == 0 ) + { + ScalarType half = t * 0.5f; + output = Lerp( start, end, half ); + magnitudeSquared = output.Dot( output ); + + if( magnitudeSquared == 0 ) + return output; // error: returning nullvector + + return Nlerp( output /= magnitudeSquared, end, half / (1.0f - half) ); + } + return output /= magnitudeSquared; + } + + /******************************************************************** + * Normalized Linear Interpolation + * @return nullvector if impossible to solve. + ********************************************************************/ + template + inline Vector3 Nlerp( const Vector3 &start, const Vector3 &end, const ScalarType &t ) + { + Vector3 output = Lerp( start, end, t ); + ScalarType magnitudeSquared = output.Dot( output ); + if( magnitudeSquared == 0 ) + { + ScalarType half = t * 0.5f; + output = Lerp( start, end, half ); + magnitudeSquared = output.Dot( output ); + + if( magnitudeSquared == 0 ) + return output; // error: returning nullvector + + return Nlerp( output /= magnitudeSquared, end, half / (1.0f - half) ); + } + return output /= magnitudeSquared; + } + + /******************************************************************** + * Normalized Linear Interpolation + * @return nullvector if impossible to solve. + ********************************************************************/ + template + inline Vector4 Nlerp( const Vector4 &start, const Vector4 &end, const ScalarType &t ) + { + Vector4 output = Lerp( start, end, t ); + ScalarType magnitudeSquared = output.Dot( output ); + if( magnitudeSquared == 0 ) + { + ScalarType half = t * 0.5f; + output = Lerp( start, end, half ); + magnitudeSquared = output.Dot( output ); + + if( magnitudeSquared == 0 ) + return output; // error: returning nullvector + + return Nlerp( output /= magnitudeSquared, end, half / (1.0f - half) ); + } + return output /= magnitudeSquared; + } } namespace LinearAlgebra2D From 2ec8662a8348b1c44faf95007dbb10dc9f71ec0c Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 20 Jan 2014 18:46:08 +0100 Subject: [PATCH 02/13] Utility::Value::Clamp --- Code/Misc/Utilities.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h index 7e76dbba..9c71a515 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -327,6 +327,10 @@ namespace Utility inline ValueType Min( const ValueType &valueA, const ValueType &valueB ) { return valueA < valueB ? valueA : valueB; } + template + inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max ) + { return value < min ? Max( value, max ) : min; } + template inline ValueType Average( const ValueType &valueA, const ValueType &valueB ) { return (valueA + valueB) * 0.5f; } From 748023bf9e4b08f523ce50dc8c19dcca350423cf Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 21 Jan 2014 08:57:18 +0100 Subject: [PATCH 03/13] Vector Nlerp fix --- Code/OysterMath/LinearMath.h | 51 +++++++++++------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index 791999db..b8dfe481 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -159,71 +159,50 @@ namespace LinearAlgebra /******************************************************************** * Normalized Linear Interpolation - * @return nullvector if impossible to solve. + * @return nullvector if Lerp( start, end, t ) is nullvector. ********************************************************************/ template inline Vector2 Nlerp( const Vector2 &start, const Vector2 &end, const ScalarType &t ) { Vector2 output = Lerp( start, end, t ); ScalarType magnitudeSquared = output.Dot( output ); - if( magnitudeSquared == 0 ) + if( magnitudeSquared != 0 ) { - ScalarType half = t * 0.5f; - output = Lerp( start, end, half ); - magnitudeSquared = output.Dot( output ); - - if( magnitudeSquared == 0 ) - return output; // error: returning nullvector - - return Nlerp( output /= magnitudeSquared, end, half / (1.0f - half) ); - } - return output /= magnitudeSquared; + return output /= (ScalarType)::std::sqrt( magnitudeSquared ); + } + return output; // error: returning nullvector } /******************************************************************** * Normalized Linear Interpolation - * @return nullvector if impossible to solve. + * @return nullvector if Lerp( start, end, t ) is nullvector. ********************************************************************/ template inline Vector3 Nlerp( const Vector3 &start, const Vector3 &end, const ScalarType &t ) { Vector3 output = Lerp( start, end, t ); ScalarType magnitudeSquared = output.Dot( output ); - if( magnitudeSquared == 0 ) + if( magnitudeSquared != 0 ) { - ScalarType half = t * 0.5f; - output = Lerp( start, end, half ); - magnitudeSquared = output.Dot( output ); - - if( magnitudeSquared == 0 ) - return output; // error: returning nullvector - - return Nlerp( output /= magnitudeSquared, end, half / (1.0f - half) ); - } - return output /= magnitudeSquared; + return output /= (ScalarType)::std::sqrt( magnitudeSquared ); + } + return output; // error: returning nullvector } /******************************************************************** * Normalized Linear Interpolation - * @return nullvector if impossible to solve. + * @return nullvector if Lerp( start, end, t ) is nullvector. ********************************************************************/ template inline Vector4 Nlerp( const Vector4 &start, const Vector4 &end, const ScalarType &t ) { Vector4 output = Lerp( start, end, t ); ScalarType magnitudeSquared = output.Dot( output ); - if( magnitudeSquared == 0 ) + if( magnitudeSquared != 0 ) { - ScalarType half = t * 0.5f; - output = Lerp( start, end, half ); - magnitudeSquared = output.Dot( output ); - - if( magnitudeSquared == 0 ) - return output; // error: returning nullvector - - return Nlerp( output /= magnitudeSquared, end, half / (1.0f - half) ); - } - return output /= magnitudeSquared; + return output /= (ScalarType)::std::sqrt( magnitudeSquared ); + } + return output; // error: returning nullvector } } From 7087421bb9f94e044838ebdbd6ef0bc2e88d97f2 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 21 Jan 2014 10:32:44 +0100 Subject: [PATCH 04/13] InterpolateAxisYToAxis_Nlerp implemented --- Code/OysterMath/LinearMath.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index b8dfe481..0fac61e6 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -726,6 +726,21 @@ namespace LinearAlgebra3D template inline ::LinearAlgebra::Vector4 NormalProjection( const ::LinearAlgebra::Vector4 &vector, const ::LinearAlgebra::Vector4 &normalizedAxis ) { return normalizedAxis * ( vector.Dot(normalizedAxis) ); } + + template + ::LinearAlgebra::Matrix4x4 & SnapAxisYToAxis_Nlerp( ::LinearAlgebra::Matrix4x4 &rotation, const ::LinearAlgebra::Vector4 &normalizedAxis ) + { + + } + + template + ::LinearAlgebra::Matrix4x4 & InterpolateAxisYToAxis_Nlerp( ::LinearAlgebra::Matrix4x4 &rotation, const ::LinearAlgebra::Vector4 &normalizedAxis, ScalarType t ) + { + ::LinearAlgebra::Vector4 interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, t ); + if( interpolated.Dot(interpolated) == 0 ) + return rotation; // return no change + return SnapAxisYToAxis_Nlerp( rotation, interpolated ); + } } #include "Utilities.h" From 408d51e46bc0cab1f357b67cf456b4d8ed58c3c0 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 21 Jan 2014 11:15:33 +0100 Subject: [PATCH 05/13] SnapAxisYToNormal_UsingNlerp implemented --- Code/OysterMath/LinearMath.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index 0fac61e6..e7e99c91 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -728,13 +728,27 @@ namespace LinearAlgebra3D { return normalizedAxis * ( vector.Dot(normalizedAxis) ); } template - ::LinearAlgebra::Matrix4x4 & SnapAxisYToAxis_Nlerp( ::LinearAlgebra::Matrix4x4 &rotation, const ::LinearAlgebra::Vector4 &normalizedAxis ) + ::LinearAlgebra::Matrix4x4 & SnapAxisYToNormal_UsingNlerp( ::LinearAlgebra::Matrix4x4 &rotation, const ::LinearAlgebra::Vector4 &normalizedAxis ) { - + ScalarType projectedMagnitude = rotation.v[0].Dot( normalizedAxis ); + if( projectedMagnitude == 1 ) + { // infinite possible solutions -> roadtrip! + ::LinearAlgebra::Vector4 interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, t ); + + // interpolated.Dot( interpolated ) == 0 should be impossible at this point + projectedMagnitude = rotation.v[0].Dot( interpolated ); + rotation.v[0] -= projectedMagnitude * interpolated; + rotation.v[0].Normalize(); + projectedMagnitude = rotation.v[0].Dot( normalizedAxis ); + } + rotation.v[0] -= projectedMagnitude * normalizedAxis; + rotation.v[0].Normalize(); + rotation.v[1] = normalizedAxis; + rotation.v[2] = rotation.v[0].Cross( rotation.v[1] ); } template - ::LinearAlgebra::Matrix4x4 & InterpolateAxisYToAxis_Nlerp( ::LinearAlgebra::Matrix4x4 &rotation, const ::LinearAlgebra::Vector4 &normalizedAxis, ScalarType t ) + ::LinearAlgebra::Matrix4x4 & InterpolateAxisYToNormal_UsingNlerp( ::LinearAlgebra::Matrix4x4 &rotation, const ::LinearAlgebra::Vector4 &normalizedAxis, ScalarType t ) { ::LinearAlgebra::Vector4 interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, t ); if( interpolated.Dot(interpolated) == 0 ) From 9a2d2b94907e0624113f77f9bfd5f2e42b556cea Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 21 Jan 2014 11:23:03 +0100 Subject: [PATCH 06/13] Interpolation methods referred in ::Oyster::Math & Math3D --- Code/OysterMath/OysterMath.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h index 2fe57718..9ce38deb 100644 --- a/Code/OysterMath/OysterMath.h +++ b/Code/OysterMath/OysterMath.h @@ -45,6 +45,9 @@ namespace Oyster { namespace Math //! Oyster's native math library //! Creates a solution matrix for 'outī= 'targetMem' * 'in'. //! Returns false if there is no explicit solution. bool SuperpositionMatrix( const Float4x4 &in, const Float4x4 &out, Float4x4 &targetMem ); + + using ::LinearAlgebra::Lerp; + using ::LinearAlgebra::Nlerp; } } inline ::Oyster::Math::Float2 & operator *= ( ::Oyster::Math::Float2 &left, const ::Oyster::Math::Float2 &right ) @@ -328,6 +331,9 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized //! Helper inline function that sets and then returns targetMem = transformer * transformee inline Float4 & TransformVector( const Float4x4 &transformer, const Float4 &transformee, Float4 &targetMem = Float4() ) { return targetMem = transformer * transformee; } + + using ::LinearAlgebra3D::SnapAxisYToNormal_UsingNlerp; + using ::LinearAlgebra3D::InterpolateAxisYToNormal_UsingNlerp; } } #endif \ No newline at end of file From 94f1c208176adad301505ddef96ec282801123d8 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Tue, 21 Jan 2014 11:48:04 +0100 Subject: [PATCH 07/13] Added more data to rigid body description. Friction and restitution coeffs --- Code/GamePhysics/PhysicsStructs-Impl.h | 6 ++++++ Code/GamePhysics/PhysicsStructs.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index 2f218095..512c8e7a 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -16,6 +16,9 @@ namespace Oyster this->centerPosition = ::Oyster::Math::Float4::standard_unit_w; this->size = ::Oyster::Math::Float4( 1.0f ); this->mass = 12.0f; + this->restitutionCoeff = 1.0f; + this->frictionCoeff_Dynamic = 0.5f; + this->frictionCoeff_Static = 0.5f; this->inertiaTensor = ::Oyster::Math::Float4x4::identity; this->subscription_onCollision = NULL; this->subscription_onMovement = NULL; @@ -28,6 +31,9 @@ namespace Oyster this->centerPosition = ::Oyster::Math::Float4::standard_unit_w; this->radius = 0.5f; this->mass = 10.0f; + this->restitutionCoeff = 1.0f; + this->frictionCoeff_Dynamic = 0.5f; + this->frictionCoeff_Static = 0.5f; this->subscription_onCollision = NULL; this->subscription_onMovement = NULL; this->ignoreGravity = false; diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index 1d3d58dd..eafe2b20 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -14,6 +14,9 @@ namespace Oyster { namespace Physics ::Oyster::Math::Float4 centerPosition; ::Oyster::Math::Float4 size; ::Oyster::Math::Float mass; + ::Oyster::Math::Float restitutionCoeff; + ::Oyster::Math::Float frictionCoeff_Static; + ::Oyster::Math::Float frictionCoeff_Dynamic; ::Oyster::Math::Float4x4 inertiaTensor; ::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision; ::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement; @@ -28,6 +31,9 @@ namespace Oyster { namespace Physics ::Oyster::Math::Float4 centerPosition; ::Oyster::Math::Float radius; ::Oyster::Math::Float mass; + ::Oyster::Math::Float restitutionCoeff; + ::Oyster::Math::Float frictionCoeff_Static; + ::Oyster::Math::Float frictionCoeff_Dynamic; ::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision; ::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement; bool ignoreGravity; From b422d2d5092efd0e90744cd1f6502bcf5be7d001 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 21 Jan 2014 12:00:54 +0100 Subject: [PATCH 08/13] lerp fix --- Code/OysterMath/LinearMath.h | 2 +- Code/OysterMath/OysterMath.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index e7e99c91..5926a635 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -753,7 +753,7 @@ namespace LinearAlgebra3D ::LinearAlgebra::Vector4 interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, t ); if( interpolated.Dot(interpolated) == 0 ) return rotation; // return no change - return SnapAxisYToAxis_Nlerp( rotation, interpolated ); + return SnapAxisYToNormal_UsingNlerp( rotation, interpolated ); } } diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h index 9ce38deb..3770bf02 100644 --- a/Code/OysterMath/OysterMath.h +++ b/Code/OysterMath/OysterMath.h @@ -46,7 +46,16 @@ namespace Oyster { namespace Math //! Oyster's native math library //! Returns false if there is no explicit solution. bool SuperpositionMatrix( const Float4x4 &in, const Float4x4 &out, Float4x4 &targetMem ); + /******************************************************************** + * Linear Interpolation + * @return start * (1-t) + end * t + ********************************************************************/ using ::LinearAlgebra::Lerp; + + /******************************************************************** + * Normalized Linear Interpolation + * @return nullvector if Lerp( start, end, t ) is nullvector. + ********************************************************************/ using ::LinearAlgebra::Nlerp; } } From 0d39240fc23c4a16ae93a5215567bfddadd853b4 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 21 Jan 2014 12:08:31 +0100 Subject: [PATCH 09/13] lerp fix 2 --- Code/OysterMath/LinearMath.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index 5926a635..d8ef06da 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -733,7 +733,7 @@ namespace LinearAlgebra3D ScalarType projectedMagnitude = rotation.v[0].Dot( normalizedAxis ); if( projectedMagnitude == 1 ) { // infinite possible solutions -> roadtrip! - ::LinearAlgebra::Vector4 interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, t ); + ::LinearAlgebra::Vector4 interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, (ScalarType)0.5f ); // interpolated.Dot( interpolated ) == 0 should be impossible at this point projectedMagnitude = rotation.v[0].Dot( interpolated ); @@ -744,7 +744,7 @@ namespace LinearAlgebra3D rotation.v[0] -= projectedMagnitude * normalizedAxis; rotation.v[0].Normalize(); rotation.v[1] = normalizedAxis; - rotation.v[2] = rotation.v[0].Cross( rotation.v[1] ); + rotation.v[2].xyz = rotation.v[0].xyz.Cross( rotation.v[1].xyz ); } template From 65db1bf90d5a784a7f3f7795edd9f2398efeafde Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 21 Jan 2014 12:11:30 +0100 Subject: [PATCH 10/13] lerp fix 3 --- Code/OysterMath/LinearMath.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index d8ef06da..d32ea04f 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -745,6 +745,7 @@ namespace LinearAlgebra3D rotation.v[0].Normalize(); rotation.v[1] = normalizedAxis; rotation.v[2].xyz = rotation.v[0].xyz.Cross( rotation.v[1].xyz ); + return rotation; } template From 090d44b518aca8580f2081094889a09f305fa109 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Tue, 21 Jan 2014 14:10:31 +0100 Subject: [PATCH 11/13] Added visit function to API Called with collideable and hit action --- Code/GamePhysics/Implementation/Octree.cpp | 8 ++++---- Code/GamePhysics/Implementation/Octree.h | 7 ++++--- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 5 +++++ Code/GamePhysics/Implementation/PhysicsAPI_Impl.h | 2 ++ Code/GamePhysics/PhysicsAPI.h | 3 +++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index a1ccdbd8..60f05298 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -108,7 +108,7 @@ std::vector& Octree::Sample(const Oyster::Collision3D::ICollideabl return updateList; } -void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) +void Octree::Visit(ICustomBody* customBodyRef, VisitorAction hitAction ) { auto object = this->mapReferences.find(customBodyRef); @@ -128,13 +128,13 @@ void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) } } -void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction) +void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, VisitorActionCollideable hitAction) { for(unsigned int i = 0; ileafData.size(); i++) { - if(this->leafData[i].container.Intersects(collideable)) + if(collideable.Intersects(this->leafData[i].container)) { - //hitAction(*this, tempRef, i); // @todo TODO: Add typedef to handle function calls with ICollideable + hitAction(*this, i); } } } diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 96631605..6c6606a9 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -17,7 +17,8 @@ namespace Oyster public: static const unsigned int invalid_ref; - typedef void(*VistorAction)(Octree&, unsigned int, unsigned int); + typedef void(*VisitorAction)(Octree&, unsigned int, unsigned int); + typedef void(*VisitorActionCollideable)(Octree&, unsigned int); struct Data { @@ -51,8 +52,8 @@ namespace Oyster std::vector& Sample(ICustomBody* customBodyRef, std::vector& updateList); std::vector& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector& updateList); - void Visit(ICustomBody* customBodyRef, VistorAction hitAction ); - void Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction ); + void Visit(ICustomBody* customBodyRef, VisitorAction hitAction ); + void Visit(const Oyster::Collision3D::ICollideable& collideable, VisitorActionCollideable hitAction ); ICustomBody* GetCustomBody(const unsigned int tempRef); diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 7bec7852..2899eae6 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -268,6 +268,11 @@ void API_Impl::RemoveGravity( const API::Gravity &g ) } } +void API_Impl::ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(Octree&, unsigned int) ) +{ + this->worldScene.Visit(collideable, hitAction); +} + //void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF ) //{ // unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h index 8b38004c..ad2c91a4 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -35,6 +35,8 @@ namespace Oyster void AddGravity( const API::Gravity &g ); void RemoveGravity( const API::Gravity &g ); + void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(Octree&, unsigned int) ); + //void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ); //void SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI ); diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 4fcd2940..3e213dc4 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -16,6 +16,7 @@ namespace Oyster { class API; class ICustomBody; + class Octree; namespace Struct { @@ -136,6 +137,8 @@ namespace Oyster ********************************************************/ virtual void RemoveGravity( const API::Gravity &g ) = 0; + virtual void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(Octree&, unsigned int) ) = 0; + ///******************************************************** // * Apply force on an object. // * @param objRef: A pointer to the ICustomBody representing a physical object. From 39e4f7881be77cf9a2a5e35a12e6b1019035cc11 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Tue, 21 Jan 2014 14:24:45 +0100 Subject: [PATCH 12/13] Added typedef for collision response --- Code/GamePhysics/PhysicsAPI.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 3e213dc4..4e1844f5 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -238,6 +238,7 @@ namespace Oyster }; typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); + typedef void (*EventAction_CollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ); typedef void (*EventAction_Move)( const ICustomBody *object ); typedef Struct::SimpleBodyDescription SimpleBodyDescription; typedef Struct::SphericalBodyDescription SphericalBodyDescription; From 5c85580ffd006aa65ca4e758190f2c124137c2ad Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Tue, 21 Jan 2014 14:56:34 +0100 Subject: [PATCH 13/13] Added gravity normal to state struct --- .../GamePhysics/Implementation/SimpleRigidBody.cpp | 8 ++++++-- Code/GamePhysics/PhysicsStructs-Impl.h | 14 +++++++++++++- Code/GamePhysics/PhysicsStructs.h | 6 +++++- Code/OysterPhysics3D/RigidBody.h | 3 ++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index df191059..1f2837b2 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -101,7 +101,8 @@ SimpleRigidBody::State SimpleRigidBody::GetState() const this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic, this->rigid.GetMomentOfInertia(), this->rigid.boundingReach, this->rigid.centerPos, this->rigid.axis, - this->rigid.momentum_Linear, this->rigid.momentum_Angular ); + this->rigid.momentum_Linear, this->rigid.momentum_Angular, + this->rigid.gravityNormal ); } SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targetMem ) const @@ -110,7 +111,8 @@ SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targ this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic, this->rigid.GetMomentOfInertia(), this->rigid.boundingReach, this->rigid.centerPos, this->rigid.axis, - this->rigid.momentum_Linear, this->rigid.momentum_Angular ); + this->rigid.momentum_Linear, this->rigid.momentum_Angular, + this->rigid.gravityNormal ); } void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) @@ -127,6 +129,7 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) this->rigid.frictionCoeff_Kinetic = state.GetFrictionCoeff_Kinetic(); this->rigid.SetMass_KeepMomentum( state.GetMass() ); this->rigid.SetMomentOfInertia_KeepMomentum( state.GetMomentOfInertia() ); + this->rigid.gravityNormal = state.GetGravityNormal(); if( state.IsForwarded() ) { @@ -333,6 +336,7 @@ void SimpleRigidBody::SetGravity( bool ignore) void SimpleRigidBody::SetGravityNormal( const Float3 &normalizedVector ) { this->gravityNormal = normalizedVector; + this->rigid.gravityNormal = Float4( this->gravityNormal, 0 ); } void SimpleRigidBody::SetCustomTag( void *ref ) diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index 512c8e7a..eac9bef3 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -39,7 +39,7 @@ namespace Oyster this->ignoreGravity = false; } - inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float kineticFrictionCoeff, const ::Oyster::Math::Float4x4 &inertiaTensor, const ::Oyster::Math::Float4 &reach, const ::Oyster::Math::Float4 ¢erPos, const ::Oyster::Math::Float4 &rotation, const ::Oyster::Math::Float4 &linearMomentum, const ::Oyster::Math::Float4 &angularMomentum ) + inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float kineticFrictionCoeff, const ::Oyster::Math::Float4x4 &inertiaTensor, const ::Oyster::Math::Float4 &reach, const ::Oyster::Math::Float4 ¢erPos, const ::Oyster::Math::Float4 &rotation, const ::Oyster::Math::Float4 &linearMomentum, const ::Oyster::Math::Float4 &angularMomentum, const ::Oyster::Math::Float4 &gravityNormal ) { this->mass = mass; this->restitutionCoeff = restitutionCoeff; @@ -54,6 +54,7 @@ namespace Oyster this->linearImpulse = this->angularImpulse = ::Oyster::Math::Float4::null; this->deltaPos = this->deltaAxis = ::Oyster::Math::Float4::null; this->isSpatiallyAltered = this->isDisturbed = this->isForwarded = false; + this->gravityNormal = gravityNormal; } inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state ) @@ -75,6 +76,7 @@ namespace Oyster this->isSpatiallyAltered = state.isSpatiallyAltered; this->isDisturbed = state.isDisturbed; this->isForwarded = state.isForwarded; + this->gravityNormal = state.gravityNormal; return *this; } @@ -183,6 +185,11 @@ namespace Oyster return this->deltaAxis; } + inline const ::Oyster::Math::Float4 & CustomBodyState::GetGravityNormal() const + { + return this->gravityNormal; + } + inline void CustomBodyState::SetMass_KeepMomentum( ::Oyster::Math::Float m ) { this->mass = m; @@ -285,6 +292,11 @@ namespace Oyster this->isDisturbed = true; } + inline void CustomBodyState::SetGravityNormal( const ::Oyster::Math::Float4 &gravityNormal ) + { + this->gravityNormal = gravityNormal; + } + inline void CustomBodyState::AddRotation( const ::Oyster::Math::Float4 &angularAxis ) { this->angularAxis += angularAxis; diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index eafe2b20..059e9f98 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -53,7 +53,8 @@ namespace Oyster { namespace Physics const ::Oyster::Math::Float4 ¢erPos = ::Oyster::Math::Float4::standard_unit_w, const ::Oyster::Math::Float4 &rotation = ::Oyster::Math::Float4::null, const ::Oyster::Math::Float4 &linearMomentum = ::Oyster::Math::Float4::null, - const ::Oyster::Math::Float4 &angularMomentum = ::Oyster::Math::Float4::null ); + const ::Oyster::Math::Float4 &angularMomentum = ::Oyster::Math::Float4::null, + const ::Oyster::Math::Float4 &gravityNormal = ::Oyster::Math::Float4::null); CustomBodyState & operator = ( const CustomBodyState &state ); @@ -78,6 +79,7 @@ namespace Oyster { namespace Physics const ::Oyster::Math::Float4 & GetAngularImpulse() const; const ::Oyster::Math::Float4 & GetForward_DeltaPos() const; const ::Oyster::Math::Float4 & GetForward_DeltaAxis() const; + const ::Oyster::Math::Float4 & GetGravityNormal() const; void SetMass_KeepMomentum( ::Oyster::Math::Float m ); void SetMass_KeepVelocity( ::Oyster::Math::Float m ); @@ -95,6 +97,7 @@ namespace Oyster { namespace Physics void SetAngularMomentum( const ::Oyster::Math::Float4 &h ); void SetLinearImpulse( const ::Oyster::Math::Float4 &j ); void SetAngularImpulse( const ::Oyster::Math::Float4 &j ); + void SetGravityNormal( const ::Oyster::Math::Float4 &gravityNormal ); void AddRotation( const ::Oyster::Math::Float4 &angularAxis ); void AddTranslation( const ::Oyster::Math::Float4 &deltaPos ); @@ -115,6 +118,7 @@ namespace Oyster { namespace Physics ::Oyster::Math::Float4 linearMomentum, angularMomentum; ::Oyster::Math::Float4 linearImpulse, angularImpulse; ::Oyster::Math::Float4 deltaPos, deltaAxis; // Forwarding data sum + ::Oyster::Math::Float4 gravityNormal; bool isSpatiallyAltered, isDisturbed, isForwarded; }; diff --git a/Code/OysterPhysics3D/RigidBody.h b/Code/OysterPhysics3D/RigidBody.h index a2f44480..51c5d2d8 100644 --- a/Code/OysterPhysics3D/RigidBody.h +++ b/Code/OysterPhysics3D/RigidBody.h @@ -20,7 +20,8 @@ namespace Oyster { namespace Physics3D momentum_Linear, //!< The linear momentum G (kg*m/s). momentum_Angular, //!< The angular momentum H (Nm*s) around an parallell axis. impulse_Linear, //!< The linear impulse sum Jl (kg*m/s) that will be consumed each update. - impulse_Angular; //!< The angular impulse sum Ja (kg*m^2/s) that will be consumed each update. + impulse_Angular, //!< The angular impulse sum Ja (kg*m^2/s) that will be consumed each update. + gravityNormal; ::Oyster::Math::Float restitutionCoeff, //!< frictionCoeff_Static, //!< frictionCoeff_Kinetic; //!<