Merge remote-tracking branch 'origin/Physics' into GameLogic

This commit is contained in:
Erik Persson 2014-01-22 10:51:13 +01:00
commit db593f65a2
12 changed files with 164 additions and 12 deletions

View File

@ -108,7 +108,7 @@ std::vector<ICustomBody*>& Octree::Sample(const Oyster::Collision3D::ICollideabl
return updateList; return updateList;
} }
void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) void Octree::Visit(ICustomBody* customBodyRef, VisitorAction hitAction )
{ {
auto object = this->mapReferences.find(customBodyRef); 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; i<this->leafData.size(); i++) for(unsigned int i = 0; i<this->leafData.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);
} }
} }
} }

View File

@ -17,7 +17,8 @@ namespace Oyster
public: public:
static const unsigned int invalid_ref; 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 struct Data
{ {
@ -51,8 +52,8 @@ namespace Oyster
std::vector<ICustomBody*>& Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList); std::vector<ICustomBody*>& Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList);
std::vector<ICustomBody*>& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector<ICustomBody*>& updateList); std::vector<ICustomBody*>& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector<ICustomBody*>& updateList);
void Visit(ICustomBody* customBodyRef, VistorAction hitAction ); void Visit(ICustomBody* customBodyRef, VisitorAction hitAction );
void Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction ); void Visit(const Oyster::Collision3D::ICollideable& collideable, VisitorActionCollideable hitAction );
ICustomBody* GetCustomBody(const unsigned int tempRef); ICustomBody* GetCustomBody(const unsigned int tempRef);

View File

@ -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 ) //void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF )
//{ //{
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); // unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );

View File

@ -35,6 +35,8 @@ namespace Oyster
void AddGravity( const API::Gravity &g ); void AddGravity( const API::Gravity &g );
void RemoveGravity( 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 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 ); //void SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI );

View File

@ -101,7 +101,8 @@ SimpleRigidBody::State SimpleRigidBody::GetState() const
this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic, this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic,
this->rigid.GetMomentOfInertia(), this->rigid.boundingReach, this->rigid.GetMomentOfInertia(), this->rigid.boundingReach,
this->rigid.centerPos, this->rigid.axis, 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 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.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic,
this->rigid.GetMomentOfInertia(), this->rigid.boundingReach, this->rigid.GetMomentOfInertia(), this->rigid.boundingReach,
this->rigid.centerPos, this->rigid.axis, 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 ) 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.frictionCoeff_Kinetic = state.GetFrictionCoeff_Kinetic();
this->rigid.SetMass_KeepMomentum( state.GetMass() ); this->rigid.SetMass_KeepMomentum( state.GetMass() );
this->rigid.SetMomentOfInertia_KeepMomentum( state.GetMomentOfInertia() ); this->rigid.SetMomentOfInertia_KeepMomentum( state.GetMomentOfInertia() );
this->rigid.gravityNormal = state.GetGravityNormal();
if( state.IsForwarded() ) if( state.IsForwarded() )
{ {
@ -333,6 +336,7 @@ void SimpleRigidBody::SetGravity( bool ignore)
void SimpleRigidBody::SetGravityNormal( const Float3 &normalizedVector ) void SimpleRigidBody::SetGravityNormal( const Float3 &normalizedVector )
{ {
this->gravityNormal = normalizedVector; this->gravityNormal = normalizedVector;
this->rigid.gravityNormal = Float4( this->gravityNormal, 0 );
} }
void SimpleRigidBody::SetCustomTag( void *ref ) void SimpleRigidBody::SetCustomTag( void *ref )

View File

@ -16,6 +16,7 @@ namespace Oyster
{ {
class API; class API;
class ICustomBody; class ICustomBody;
class Octree;
namespace Struct namespace Struct
{ {
@ -136,6 +137,8 @@ namespace Oyster
********************************************************/ ********************************************************/
virtual void RemoveGravity( const API::Gravity &g ) = 0; 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. // * Apply force on an object.
// * @param objRef: A pointer to the ICustomBody representing a physical object. // * @param objRef: A pointer to the ICustomBody representing a physical object.
@ -235,6 +238,7 @@ namespace Oyster
}; };
typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); 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 void (*EventAction_Move)( const ICustomBody *object );
typedef Struct::SimpleBodyDescription SimpleBodyDescription; typedef Struct::SimpleBodyDescription SimpleBodyDescription;
typedef Struct::SphericalBodyDescription SphericalBodyDescription; typedef Struct::SphericalBodyDescription SphericalBodyDescription;

View File

@ -16,6 +16,9 @@ namespace Oyster
this->centerPosition = ::Oyster::Math::Float4::standard_unit_w; this->centerPosition = ::Oyster::Math::Float4::standard_unit_w;
this->size = ::Oyster::Math::Float4( 1.0f ); this->size = ::Oyster::Math::Float4( 1.0f );
this->mass = 12.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->inertiaTensor = ::Oyster::Math::Float4x4::identity;
this->subscription_onCollision = NULL; this->subscription_onCollision = NULL;
this->subscription_onMovement = NULL; this->subscription_onMovement = NULL;
@ -28,12 +31,15 @@ namespace Oyster
this->centerPosition = ::Oyster::Math::Float4::standard_unit_w; this->centerPosition = ::Oyster::Math::Float4::standard_unit_w;
this->radius = 0.5f; this->radius = 0.5f;
this->mass = 10.0f; this->mass = 10.0f;
this->restitutionCoeff = 1.0f;
this->frictionCoeff_Dynamic = 0.5f;
this->frictionCoeff_Static = 0.5f;
this->subscription_onCollision = NULL; this->subscription_onCollision = NULL;
this->subscription_onMovement = NULL; this->subscription_onMovement = NULL;
this->ignoreGravity = false; 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 &centerPos, 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 &centerPos, const ::Oyster::Math::Float4 &rotation, const ::Oyster::Math::Float4 &linearMomentum, const ::Oyster::Math::Float4 &angularMomentum, const ::Oyster::Math::Float4 &gravityNormal )
{ {
this->mass = mass; this->mass = mass;
this->restitutionCoeff = restitutionCoeff; this->restitutionCoeff = restitutionCoeff;
@ -48,6 +54,7 @@ namespace Oyster
this->linearImpulse = this->angularImpulse = ::Oyster::Math::Float4::null; this->linearImpulse = this->angularImpulse = ::Oyster::Math::Float4::null;
this->deltaPos = this->deltaAxis = ::Oyster::Math::Float4::null; this->deltaPos = this->deltaAxis = ::Oyster::Math::Float4::null;
this->isSpatiallyAltered = this->isDisturbed = this->isForwarded = false; this->isSpatiallyAltered = this->isDisturbed = this->isForwarded = false;
this->gravityNormal = gravityNormal;
} }
inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state ) inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state )
@ -69,6 +76,7 @@ namespace Oyster
this->isSpatiallyAltered = state.isSpatiallyAltered; this->isSpatiallyAltered = state.isSpatiallyAltered;
this->isDisturbed = state.isDisturbed; this->isDisturbed = state.isDisturbed;
this->isForwarded = state.isForwarded; this->isForwarded = state.isForwarded;
this->gravityNormal = state.gravityNormal;
return *this; return *this;
} }
@ -177,6 +185,11 @@ namespace Oyster
return this->deltaAxis; return this->deltaAxis;
} }
inline const ::Oyster::Math::Float4 & CustomBodyState::GetGravityNormal() const
{
return this->gravityNormal;
}
inline void CustomBodyState::SetMass_KeepMomentum( ::Oyster::Math::Float m ) inline void CustomBodyState::SetMass_KeepMomentum( ::Oyster::Math::Float m )
{ {
this->mass = m; this->mass = m;
@ -279,6 +292,11 @@ namespace Oyster
this->isDisturbed = true; this->isDisturbed = true;
} }
inline void CustomBodyState::SetGravityNormal( const ::Oyster::Math::Float4 &gravityNormal )
{
this->gravityNormal = gravityNormal;
}
inline void CustomBodyState::AddRotation( const ::Oyster::Math::Float4 &angularAxis ) inline void CustomBodyState::AddRotation( const ::Oyster::Math::Float4 &angularAxis )
{ {
this->angularAxis += angularAxis; this->angularAxis += angularAxis;

View File

@ -14,6 +14,9 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float4 centerPosition; ::Oyster::Math::Float4 centerPosition;
::Oyster::Math::Float4 size; ::Oyster::Math::Float4 size;
::Oyster::Math::Float mass; ::Oyster::Math::Float mass;
::Oyster::Math::Float restitutionCoeff;
::Oyster::Math::Float frictionCoeff_Static;
::Oyster::Math::Float frictionCoeff_Dynamic;
::Oyster::Math::Float4x4 inertiaTensor; ::Oyster::Math::Float4x4 inertiaTensor;
::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision; ::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement; ::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
@ -28,6 +31,9 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float4 centerPosition; ::Oyster::Math::Float4 centerPosition;
::Oyster::Math::Float radius; ::Oyster::Math::Float radius;
::Oyster::Math::Float mass; ::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_Collision subscription_onCollision;
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement; ::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
bool ignoreGravity; bool ignoreGravity;
@ -47,7 +53,8 @@ namespace Oyster { namespace Physics
const ::Oyster::Math::Float4 &centerPos = ::Oyster::Math::Float4::standard_unit_w, const ::Oyster::Math::Float4 &centerPos = ::Oyster::Math::Float4::standard_unit_w,
const ::Oyster::Math::Float4 &rotation = ::Oyster::Math::Float4::null, const ::Oyster::Math::Float4 &rotation = ::Oyster::Math::Float4::null,
const ::Oyster::Math::Float4 &linearMomentum = ::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 ); CustomBodyState & operator = ( const CustomBodyState &state );
@ -72,6 +79,7 @@ namespace Oyster { namespace Physics
const ::Oyster::Math::Float4 & GetAngularImpulse() const; const ::Oyster::Math::Float4 & GetAngularImpulse() const;
const ::Oyster::Math::Float4 & GetForward_DeltaPos() const; const ::Oyster::Math::Float4 & GetForward_DeltaPos() const;
const ::Oyster::Math::Float4 & GetForward_DeltaAxis() const; const ::Oyster::Math::Float4 & GetForward_DeltaAxis() const;
const ::Oyster::Math::Float4 & GetGravityNormal() const;
void SetMass_KeepMomentum( ::Oyster::Math::Float m ); void SetMass_KeepMomentum( ::Oyster::Math::Float m );
void SetMass_KeepVelocity( ::Oyster::Math::Float m ); void SetMass_KeepVelocity( ::Oyster::Math::Float m );
@ -89,6 +97,7 @@ namespace Oyster { namespace Physics
void SetAngularMomentum( const ::Oyster::Math::Float4 &h ); void SetAngularMomentum( const ::Oyster::Math::Float4 &h );
void SetLinearImpulse( const ::Oyster::Math::Float4 &j ); void SetLinearImpulse( const ::Oyster::Math::Float4 &j );
void SetAngularImpulse( 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 AddRotation( const ::Oyster::Math::Float4 &angularAxis );
void AddTranslation( const ::Oyster::Math::Float4 &deltaPos ); void AddTranslation( const ::Oyster::Math::Float4 &deltaPos );
@ -109,6 +118,7 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float4 linearMomentum, angularMomentum; ::Oyster::Math::Float4 linearMomentum, angularMomentum;
::Oyster::Math::Float4 linearImpulse, angularImpulse; ::Oyster::Math::Float4 linearImpulse, angularImpulse;
::Oyster::Math::Float4 deltaPos, deltaAxis; // Forwarding data sum ::Oyster::Math::Float4 deltaPos, deltaAxis; // Forwarding data sum
::Oyster::Math::Float4 gravityNormal;
bool isSpatiallyAltered, isDisturbed, isForwarded; bool isSpatiallyAltered, isDisturbed, isForwarded;
}; };

View File

@ -327,6 +327,10 @@ namespace Utility
inline ValueType Min( const ValueType &valueA, const ValueType &valueB ) inline ValueType Min( const ValueType &valueA, const ValueType &valueB )
{ return valueA < valueB ? valueA : valueB; } { return valueA < valueB ? valueA : valueB; }
template<typename ValueType>
inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max )
{ return value < min ? Max( value, max ) : min; }
template<typename ValueType> template<typename ValueType>
inline ValueType Average( const ValueType &valueA, const ValueType &valueB ) inline ValueType Average( const ValueType &valueA, const ValueType &valueB )
{ return (valueA + valueB) * 0.5f; } { return (valueA + valueB) * 0.5f; }

View File

@ -146,6 +146,64 @@ namespace LinearAlgebra
targetMem = out * (in.GetAdjoint() /= d); targetMem = out * (in.GetAdjoint() /= d);
return true; return true;
} }
/********************************************************************
* Linear Interpolation
* @return start * (1-t) + end * t
********************************************************************/
template<typename PointType, typename ScalarType>
inline PointType Lerp( const PointType &start, const PointType &end, const ScalarType &t )
{
return end * t + start * ( 1 - t );
}
/********************************************************************
* Normalized Linear Interpolation
* @return nullvector if Lerp( start, end, t ) is nullvector.
********************************************************************/
template<typename ScalarType>
inline Vector2<ScalarType> Nlerp( const Vector2<ScalarType> &start, const Vector2<ScalarType> &end, const ScalarType &t )
{
Vector2<ScalarType> output = Lerp( start, end, t );
ScalarType magnitudeSquared = output.Dot( output );
if( magnitudeSquared != 0 )
{
return output /= (ScalarType)::std::sqrt( magnitudeSquared );
}
return output; // error: returning nullvector
}
/********************************************************************
* Normalized Linear Interpolation
* @return nullvector if Lerp( start, end, t ) is nullvector.
********************************************************************/
template<typename ScalarType>
inline Vector3<ScalarType> Nlerp( const Vector3<ScalarType> &start, const Vector3<ScalarType> &end, const ScalarType &t )
{
Vector3<ScalarType> output = Lerp( start, end, t );
ScalarType magnitudeSquared = output.Dot( output );
if( magnitudeSquared != 0 )
{
return output /= (ScalarType)::std::sqrt( magnitudeSquared );
}
return output; // error: returning nullvector
}
/********************************************************************
* Normalized Linear Interpolation
* @return nullvector if Lerp( start, end, t ) is nullvector.
********************************************************************/
template<typename ScalarType>
inline Vector4<ScalarType> Nlerp( const Vector4<ScalarType> &start, const Vector4<ScalarType> &end, const ScalarType &t )
{
Vector4<ScalarType> output = Lerp( start, end, t );
ScalarType magnitudeSquared = output.Dot( output );
if( magnitudeSquared != 0 )
{
return output /= (ScalarType)::std::sqrt( magnitudeSquared );
}
return output; // error: returning nullvector
}
} }
namespace LinearAlgebra2D namespace LinearAlgebra2D
@ -668,6 +726,36 @@ namespace LinearAlgebra3D
template<typename ScalarType> template<typename ScalarType>
inline ::LinearAlgebra::Vector4<ScalarType> NormalProjection( const ::LinearAlgebra::Vector4<ScalarType> &vector, const ::LinearAlgebra::Vector4<ScalarType> &normalizedAxis ) inline ::LinearAlgebra::Vector4<ScalarType> NormalProjection( const ::LinearAlgebra::Vector4<ScalarType> &vector, const ::LinearAlgebra::Vector4<ScalarType> &normalizedAxis )
{ return normalizedAxis * ( vector.Dot(normalizedAxis) ); } { return normalizedAxis * ( vector.Dot(normalizedAxis) ); }
template<typename ScalarType>
::LinearAlgebra::Matrix4x4<ScalarType> & SnapAxisYToNormal_UsingNlerp( ::LinearAlgebra::Matrix4x4<ScalarType> &rotation, const ::LinearAlgebra::Vector4<ScalarType> &normalizedAxis )
{
ScalarType projectedMagnitude = rotation.v[0].Dot( normalizedAxis );
if( projectedMagnitude == 1 )
{ // infinite possible solutions -> roadtrip!
::LinearAlgebra::Vector4<ScalarType> 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 );
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].xyz = rotation.v[0].xyz.Cross( rotation.v[1].xyz );
return rotation;
}
template<typename ScalarType>
::LinearAlgebra::Matrix4x4<ScalarType> & InterpolateAxisYToNormal_UsingNlerp( ::LinearAlgebra::Matrix4x4<ScalarType> &rotation, const ::LinearAlgebra::Vector4<ScalarType> &normalizedAxis, ScalarType t )
{
::LinearAlgebra::Vector4<ScalarType> interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, t );
if( interpolated.Dot(interpolated) == 0 )
return rotation; // return no change
return SnapAxisYToNormal_UsingNlerp( rotation, interpolated );
}
} }
#include "Utilities.h" #include "Utilities.h"

View File

@ -45,6 +45,18 @@ namespace Oyster { namespace Math //! Oyster's native math library
//! Creates a solution matrix for 'out´= 'targetMem' * 'in'. //! Creates a solution matrix for 'out´= 'targetMem' * 'in'.
//! Returns false if there is no explicit solution. //! Returns false if there is no explicit solution.
bool SuperpositionMatrix( const Float4x4 &in, const Float4x4 &out, Float4x4 &targetMem ); 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;
} } } }
inline ::Oyster::Math::Float2 & operator *= ( ::Oyster::Math::Float2 &left, const ::Oyster::Math::Float2 &right ) inline ::Oyster::Math::Float2 & operator *= ( ::Oyster::Math::Float2 &left, const ::Oyster::Math::Float2 &right )
@ -328,6 +340,9 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized
//! Helper inline function that sets and then returns targetMem = transformer * transformee //! Helper inline function that sets and then returns targetMem = transformer * transformee
inline Float4 & TransformVector( const Float4x4 &transformer, const Float4 &transformee, Float4 &targetMem = Float4() ) inline Float4 & TransformVector( const Float4x4 &transformer, const Float4 &transformee, Float4 &targetMem = Float4() )
{ return targetMem = transformer * transformee; } { return targetMem = transformer * transformee; }
using ::LinearAlgebra3D::SnapAxisYToNormal_UsingNlerp;
using ::LinearAlgebra3D::InterpolateAxisYToNormal_UsingNlerp;
} } } }
#endif #endif

View File

@ -20,7 +20,8 @@ namespace Oyster { namespace Physics3D
momentum_Linear, //!< The linear momentum G (kg*m/s). momentum_Linear, //!< The linear momentum G (kg*m/s).
momentum_Angular, //!< The angular momentum H (Nm*s) around an parallell axis. 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_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, //!< ::Oyster::Math::Float restitutionCoeff, //!<
frictionCoeff_Static, //!< frictionCoeff_Static, //!<
frictionCoeff_Kinetic; //!< frictionCoeff_Kinetic; //!<