
///////////////////////////////////////////////////////////////////////////////
//
// File   : AVP_AnimationAttachment_Ragdoll.cpp
// Author : Will Plano
// Date   : 10/01/2008
//
// Copyright (C) 2008 Rebellion, All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////

#include "Core/Asura.h"

#include "Animation/AVP_AnimationAttachment_Ragdoll.h"
#include "Entity/Ragdoll/Asura_Ragdoll_Wrapper.h"
#include "Physics/Asura_Physics_Ragdoll.h"

void AVP_AnimationAttachment_Ragdoll::Update( float fTime, bool bIgnoreTimerFrameStamp )
{
	Asura_Ragdoll_Wrapper* pxRagdollWrapper = Asura_Ragdoll_Wrapper::GetRagdollWrapper( m_iRagdollWrapperHandle );
	if( pxRagdollWrapper )
	{
		//get world pos and orient
		Asura_Vector_3 xPos( Asura_Maths::ZeroVector3 );
		Asura_Matrix_3x3 xOri( Asura_Maths::IdentityMatrix3x3 );

		if ( GetWorldRelativePosition( &xPos, &xOri ) )
		{
			if ( m_xOldPos == Asura_Maths::ZeroVector3 )
			{
				m_xOldPos = xPos;
			}
			Asura_Physics_Ragdoll* pxRagdoll( pxRagdollWrapper->GetPhysicsRagdollPointer() );
			Asura_Assert( pxRagdoll != NULL, "No Ragdoll" );
			if ( pxRagdoll )
			{
				pxRagdoll->SetBonePosition( m_uBoneID, xPos );
			}
			m_xOldPos = xPos;
		}
	}
	else
	{
		// our ragdoll has probably been culled... time to die.
		m_bNeedsDeleting = true;
	}
}

