Пример #1
0
// NOTE Dez 15, 2006: <pvl> not called ATM. Should be moved to BaseGrabHandler.
Vec3 CAnimatedGrabHandler::GetGrabIKPos(IEntity *pGrab,int limbIdx)
{
	AABB bbox;
	pGrab->GetLocalBounds(bbox);

	Vec3 grabCenter((bbox.max + bbox.min) * 0.5f);

	if(m_grabStats.limbNum<2)
	{
	}
	else
	{
		IEntity *pEnt = m_pActor->GetEntity();
		SIKLimb *pLimb = m_pActor->GetIKLimb(m_grabStats.limbId[limbIdx]);
		ICharacterInstance *pCharacter = pEnt->GetCharacter(pLimb->characterSlot);

		if(pCharacter)
		{
			Vec3 posPool[2]= {grabCenter,grabCenter};
			posPool[0].x = bbox.min.x;
			posPool[1].x = bbox.max.x;

			Vec3 limbPosInLocal(pGrab->GetWorldTM().GetInverted()*(pEnt->GetSlotWorldTM(pLimb->characterSlot) * pCharacter->GetISkeletonPose()->GetAbsJointByID(pLimb->rootBoneID).t));

			float minDist(9999.9f);

			for(int i=0; i<2; ++i)
			{
				//gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(pGrab->GetWorldTM() * posPool[i], ColorB(0,255,0,100), pGrab->GetWorldTM() * limbPosInLocal, ColorB(0,255,0,100));
				float len2((posPool[i] - limbPosInLocal).len2());

				if(len2<minDist)
				{
					minDist = len2;
					grabCenter = posPool[i];
				}
			}
		}
	}

	return (pGrab->GetWorldTM() * grabCenter);
}
Пример #2
0
void CBaseGrabHandler::UpdatePosVelRot(float frameTime)
{
	IEntity *pGrab = gEnv->pEntitySystem->GetEntity(m_grabStats.grabId);
	
	if ( !pGrab) return;

	IEntity *pEnt = m_pActor->GetEntity();

	// NOTE Dez 14, 2006: <pvl> fade away the initial difference between
	// orientations of grabber and grabbed entities, so that they're
	// the same finally.
	m_grabStats.additionalRotation = Quat::CreateSlerp( m_grabStats.additionalRotation, IDENTITY, frameTime * 3.3f );
	pGrab->SetRotation(pEnt->GetRotation() * m_grabStats.additionalRotation,ENTITY_XFORM_USER);

	AABB bbox;
	pGrab->GetLocalBounds(bbox);
	Vec3 grabCenter(pGrab->GetWorldTM() * ((bbox.max + bbox.min) * 0.5f));

	Vec3 grabWPos(GetGrabWPos());
	Vec3 setGrabVel(0,0,0);

	// TODO Dez 14, 2006: <pvl> if you finally delete this make sure that
	// BasicActor:DropObject() (in BasicActor.lua) doesn't support its
	// 'throwDelay' parameter anymore.
























	// NOTE Dez 14, 2006: <pvl> grabCenter is where the grabbed object's
	// AABB's center is, grabWPos is where it should be.  Use physics
	// to set the grabbed object's speed towards grabWPos.
	if (pEnt->GetPhysics() && pGrab->GetPhysics())
	{
		pe_status_dynamics dyn;
		pEnt->GetPhysics()->GetStatus(&dyn);

		pe_action_set_velocity asv;
		if (setGrabVel.len2()>0.01f)
			asv.v = dyn.v + setGrabVel;
		else
			asv.v = dyn.v + (grabWPos - grabCenter)*m_grabStats.followSpeed;
		asv.w.Set(0,0,0);
		
		pGrab->GetPhysics()->Action(&asv);
	}

}