Пример #1
0
void CSkeletonGroup::BuildPath()
{
	// For offset spawning, will break with more then 4

	XMVECTOR vecOffsets[NUM_SKELETONS] = { { -SPAWN_OFFSET_VALUE, 0, SPAWN_OFFSET_VALUE }, { SPAWN_OFFSET_VALUE, 0, SPAWN_OFFSET_VALUE }/*
	{ -SPAWN_OFFSET_VALUE, 0, -SPAWN_OFFSET_VALUE }, { SPAWN_OFFSET_VALUE, 0, -SPAWN_OFFSET_VALUE }*/ };

	// The new Path
	vector<XMFLOAT3> newPath;

	// Find an active skeleton
	for (size_t i = 0; i < m_vSkeletons.size(); i++)
	{
		CSkeleton* curSkeleton = reinterpret_cast<CSkeleton*>(m_vSkeletons[i]);
		if (curSkeleton->GetIsActive())
		{
			// Path to offset player position
			XMVECTOR mathOffsetPos = XMLoadFloat3(m_cpPlayer->GetPosition());
			mathOffsetPos += vecOffsets[i];
			XMFLOAT3 offsetPosition; XMStoreFloat3(&offsetPosition, mathOffsetPos);

			// Find the target node
			int nPlayerNodeIndex = curSkeleton->GetPathPlanner()->FindClosestNode(&offsetPosition);

			// Get the closest nodes
			int nSkeletonNodeIndex = curSkeleton->GetPathPlanner()->FindClosestNode(curSkeleton->GetPosition());

			// Build a path to the target
			newPath = curSkeleton->GetPathPlanner()->GeneratePath(nSkeletonNodeIndex, nPlayerNodeIndex, false);

			if (newPath.empty())
			{
				newPath.push_back(*curSkeleton->GetPlayer()->GetPosition());
				newPath.push_back(*curSkeleton->GetPosition());

			}
			else if (newPath.size() == 1)
			{
				newPath.push_back(*curSkeleton->GetPlayer()->GetPosition());

			}

			// Set the new path
			curSkeleton->SetPath(newPath);

			// Set the node on path
			curSkeleton->SetNodeOnPath(newPath.size() - 1);
		}
	}

	// Went back to path finding for each
	//// Set each skeleton's new path
	//for (size_t ske = 0; ske < m_vSkeletons.size(); ske++)
	//{
	//	reinterpret_cast<CSkeleton*>(m_vSkeletons[ske])->SetPath(newPath);
	//
	//	// Set the current node
	//	reinterpret_cast<CSkeleton*>(m_vSkeletons[ske])->SetNodeOnPath(newPath.size() - 1);
	//}
}
Пример #2
0
XMVECTOR CSkeletonGroup::CalculateSeparation(CSkeleton* _current)
{
	XMVECTOR mathOutput = XMVECTOR();

	// For all skeletons
	for (size_t i = 0; i < m_vSkeletons.size(); i++)
	{
		// Cast the skeleton for future use
		CSkeleton* other = reinterpret_cast<CSkeleton*>(m_vSkeletons[i]);

		// Convert the positions for math
		XMVECTOR mathOtherPos = XMLoadFloat3(other->GetPosition());
		XMVECTOR mathCurrentPos = XMLoadFloat3(_current->GetPosition());

		// Find the distance between them
		XMVECTOR mathFromVector = mathCurrentPos - mathOtherPos;
		float fDistance = XMVector3Length(mathFromVector).m128_f32[0];

		// If within safe distance
		if (fDistance < SEPARATION_DISTANCE)
		{
			mathFromVector = XMVector3Normalize(mathFromVector);

			mathFromVector *= (SEPARATION_DISTANCE - fDistance) / SEPARATION_DISTANCE;

			mathOutput += mathFromVector;
		}
	}

	// Rescale the velocity
	if (XMVector3Length(mathOutput).m128_f32[0] > 1.0f)
		mathOutput = XMVector3Normalize(mathOutput);

	// Scale by modifier
	return mathOutput * SEPARATION_STRENGTH;



}