-
Автор темы
- #1
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Код:
Vec3 GetBonePos(IEntity*pExp, ISkeletonPose*m_pSkeleton, int vBoneId)
{
return pExp->GetWorldTM() * m_pSkeleton->GetAbsJointByID(vBoneId).t;
}
bool GetNearestBone(IEntity*pExp, ISkeletonPose*m_pSkeleton, int* Bones, int Size, Vec3* vBone, FLOAT* Dist, bool CheckVisible = false)
{
FLOAT PriorityDists = 9999.99f;
int TargerBone = Bones[0];
for (int i = 0; i < Size; i++)
{
if (Bones[i] > 0)
{
*vBone = GetBonePos(pExp, m_pSkeleton, Bones[i]);
FLOAT Dist = gRender->GetHypotenuseFromCenter(*vBone);
if (Dist < PriorityDists)
{
if (!CheckVisible || is_Visible(*vBone))
{
PriorityDists = Dist;
TargerBone = i;
}
}
}
}
*vBone = GetBonePos(pExp, m_pSkeleton, TargerBone);
*Dist = PriorityDists;
return TargerBone > 0;
}
bool IsMyTeam(IActor * mActor, IActor * pActor) { return !(mActor->TeamId != pActor->TeamId || pActor->TeamId == 0); }
void Test()
{
FLOAT MaxDist = 9999.0f;
IGameFramework*pFramework = gEnv->pGame->pGameFramework;
if (!pFramework || !pFramework->GetClientActor(&m_pActor)) return;
IItem* m_pItem = m_pActor->GetCurrentItem();
if (!m_pItem) return;
m_pItem->GetIWeapon()->SetFiringPos(ZERO);
IActorIterator*pIter = nullptr;
pFramework->GetIActorSystem()->CreateActorIterator(&pIter);
while (IActor*pActor = pIter->Next())
{
if (pActor->IsDead() || pActor == m_pActor || pActor->IsDead() || IsMyTeam(m_pActor, pActor)) continue;
IEntity* pExp = pActor->m_pEntity;
ICharacterInstance* pCharacter = pExp->GetCharacter(0);
if (!pCharacter) continue;
int Bones[3] = { 0 };
if (!strcmp(pExp->GetClass()->GetName(), "Turret"))
{
Bones[0] = pCharacter->GetISkeletonPose()->GetJointIdByName("bone_head");
}
else
{
Bones[0] = pCharacter->GetISkeletonPose()->GetJointIdByName("Bip01 Head");
Bones[1] = pCharacter->GetISkeletonPose()->GetJointIdByName("Bip01 Neck");
Bones[2] = pCharacter->GetISkeletonPose()->GetJointIdByName("Bip01 Spine");
}
Vec3 vBonePos = ZERO;
FLOAT Distance = 999.9f;
if (GetNearestBone(pExp, pCharacter->GetISkeletonPose(), Bones, 3, &vBonePos, &Distance, true))
{
if (Distance < MaxDist)
{
m_pItem->GetIWeapon()->SetFiringPos(vBonePos);
MaxDist = Distance;
}
}
}
}
Последнее редактирование: