Merge branch 'Physics' of https://github.com/dean11/Danbias into GameLogic
This commit is contained in:
commit
6e0dd63d64
|
@ -15,7 +15,7 @@ API_Impl API_instance;
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
void OnPossibleCollision( Octree& worldScene, unsigned int protoTempRef, unsigned int deuterTempRef )
|
void OnPossibleCollision( Octree& worldScene, unsigned int protoTempRef, unsigned int deuterTempRef )
|
||||||
{ /** @todo TODO: OnPossibleCollision is a temporary solution .*/
|
{
|
||||||
auto proto = worldScene.GetCustomBody( protoTempRef );
|
auto proto = worldScene.GetCustomBody( protoTempRef );
|
||||||
auto deuter = worldScene.GetCustomBody( deuterTempRef );
|
auto deuter = worldScene.GetCustomBody( deuterTempRef );
|
||||||
|
|
||||||
|
@ -26,11 +26,31 @@ namespace
|
||||||
ICustomBody::State protoState; proto->GetState( protoState );
|
ICustomBody::State protoState; proto->GetState( protoState );
|
||||||
ICustomBody::State deuterState; deuter->GetState( deuterState );
|
ICustomBody::State deuterState; deuter->GetState( deuterState );
|
||||||
|
|
||||||
|
// calc from perspective of deuter.
|
||||||
|
Float4 normal = worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f ); // Init value is only borrowed
|
||||||
|
if( normal.Dot(normal) > 0.0f )
|
||||||
|
{
|
||||||
|
deuter->GetNormalAt( worldPointOfContact, normal );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // special case: deuter is completly contained within proto or they have overlapping centers.
|
||||||
|
|
||||||
|
normal = Float4( protoState.GetCenterPosition() - deuterState.GetCenterPosition(), 0.0f );
|
||||||
|
if( normal.Dot(normal) == 0.0f )
|
||||||
|
{ // they have overlapping centers. Rebound at least
|
||||||
|
// calculate and store time interpolation value, for later rebound.
|
||||||
|
proto->SetTimeOfContact( worldPointOfContact );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// borrowing the negated normal of proto.
|
||||||
|
proto->GetNormalAt( worldPointOfContact, normal );
|
||||||
|
normal = -normal;
|
||||||
|
}
|
||||||
|
|
||||||
Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ),
|
Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ),
|
||||||
deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz );
|
deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz );
|
||||||
|
|
||||||
// calc from perspective of deuter
|
|
||||||
Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal );
|
|
||||||
Float protoG_Magnitude = protoG.Dot( normal ),
|
Float protoG_Magnitude = protoG.Dot( normal ),
|
||||||
deuterG_Magnitude = deuterG.Dot( normal );
|
deuterG_Magnitude = deuterG.Dot( normal );
|
||||||
|
|
||||||
|
@ -70,9 +90,22 @@ namespace
|
||||||
|
|
||||||
|
|
||||||
// calc from perspective of proto
|
// calc from perspective of proto
|
||||||
|
|
||||||
|
normal = worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f );
|
||||||
|
if( normal.Dot(normal) > 0.0f )
|
||||||
|
{
|
||||||
proto->GetNormalAt( worldPointOfContact, normal );
|
proto->GetNormalAt( worldPointOfContact, normal );
|
||||||
protoG_Magnitude = protoG.Dot( normal ),
|
protoG_Magnitude = protoG.Dot( normal );
|
||||||
deuterG_Magnitude = deuterG.Dot( normal );
|
deuterG_Magnitude = deuterG.Dot( normal );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // special case: proto is completly contained within deuter.
|
||||||
|
// borrowing the negated normal of deuter.
|
||||||
|
deuter->GetNormalAt( worldPointOfContact, normal );
|
||||||
|
normal = -normal;
|
||||||
|
protoG_Magnitude = -protoG_Magnitude;
|
||||||
|
deuterG_Magnitude = -deuterG_Magnitude;
|
||||||
|
}
|
||||||
|
|
||||||
// bounce
|
// bounce
|
||||||
Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(),
|
Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(),
|
||||||
|
|
|
@ -159,7 +159,12 @@ namespace Oyster
|
||||||
|
|
||||||
inline ::Oyster::Math::Float3 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const
|
inline ::Oyster::Math::Float3 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const
|
||||||
{
|
{
|
||||||
return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos );
|
::Oyster::Math::Float3 offset = at - this->centerPos;
|
||||||
|
if( offset.Dot(offset) > 0.0f )
|
||||||
|
{
|
||||||
|
return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, offset );
|
||||||
|
}
|
||||||
|
return this->linearMomentum;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularMomentum() const
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularMomentum() const
|
||||||
|
|
Loading…
Reference in New Issue