Esempio n. 1
0
//------------------------------------------------------------------------
void CVehiclePartEntityAttachment::PostInit()
{
	if (!m_pSharedParameters->m_helperPosName.empty())
	{
		if (IVehicleHelper* pHelper = m_pVehicle->GetHelper(m_pSharedParameters->m_helperPosName))
			SetLocalTM(pHelper->GetLocalTM());
		else
		{
			Matrix34 tm(IDENTITY);
			SetLocalTM(tm);
		}
	}
}
void CVehiclePartSuspensionPart::Update(const float frameTime)
{
	inherited::Update(frameTime);

	const Matrix34& parentTm = m_pParentPart->GetLocalTM(false);
	const Matrix34& targetTm = m_targetPart->GetLocalTM(false);

	Vec3 pos = parentTm * m_pos0;
 	Vec3 targetPos = (m_ikFlags&k_flagIgnoreTargetRotation) ? (targetTm.GetColumn3() + m_targetOffset) : (targetTm * m_targetOffset);
 	Vec3 dir = targetPos - pos;
	float length = dir.GetLength();
	if (length > 1e-2f)
	{
		Matrix33 rot = Matrix33::CreateRotationV0V1(m_direction0, dir*(1.f/length));
		Matrix33 partRot = rot*Matrix33(m_initialRot);

		if (m_mode==k_modeRotate || m_mode==k_modeSnapToEF)
		{
			if (m_mode==k_modeSnapToEF)
			{
				pos = targetPos - rot * m_direction0;
			}
			Matrix34 tm(partRot, pos);
			SetLocalTM(tm);
		}
		else if (m_mode==k_modeStretch)
		{
			const float scale = length * m_invLength0;
			const Vec3 z = m_direction0;
			const Vec3 sz = m_direction0*(scale-1.f);
			Matrix33 scaleM;
			scaleM.m00 = 1.f+sz.x*z.x; scaleM.m01 =  sz.y*z.x    ; scaleM.m02 =  sz.z*z.x;
			scaleM.m10 = sz.x*z.y    ; scaleM.m11 =  1.f+sz.y*z.y; scaleM.m12 =  sz.z*z.y;
			scaleM.m20 = sz.x*z.z    ; scaleM.m21 =  sz.y*z.z    ; scaleM.m22 =  1.f+sz.z*z.z;
			Matrix34 tm(partRot * scaleM, pos);
			SetLocalTM(tm);
		}
	}

#if !defined(_RELEASE)
	if (VehicleCVars().v_debugSuspensionIK)
	{
		IRenderAuxGeom* pAuxGeom = gEnv->pRenderer->GetIRenderAuxGeom();
		SAuxGeomRenderFlags flags = pAuxGeom->GetRenderFlags();
		SAuxGeomRenderFlags oldFlags = pAuxGeom->GetRenderFlags();
		flags.SetDepthWriteFlag(e_DepthWriteOff);
		flags.SetDepthTestFlag(e_DepthTestOff);
		pAuxGeom->SetRenderFlags(flags);
	
		ColorB colRed(255,0,0,255);
		ColorB colBlue(0,0,255,255);
		ColorB colWhite(255,255,255,255);
		ColorB colGreen(0,255,0,255);

		pos = m_pVehicle->GetEntity()->GetWorldTM() * pos;
		targetPos = m_pVehicle->GetEntity()->GetWorldTM() * targetPos;
		pAuxGeom->DrawSphere(pos, 0.02f, colGreen);
		pAuxGeom->DrawSphere(targetPos, 0.02f, colBlue);
		pAuxGeom->DrawLine(pos, colWhite, targetPos, colWhite);
	}
#endif
}