Ejemplo n.º 1
0
void MissionContainer::SortCopy(CU::GrowingArray<Mission*>& someOut, const CU::GrowingArray<Mission*>& someIn) const
{
	int currentIndex = 0;
	while (someOut.Size() != someIn.Size())
	{
		int prevIndex = currentIndex;
		for (int i = 0; i < someIn.Size(); ++i)
		{
			if (someIn[i]->GetIndex() == currentIndex)
			{
				++currentIndex;
				someOut.Add(someIn[i]);
				break;
			}
		}
		DL_ASSERT_EXP(prevIndex == currentIndex - 1, "Mission index " + std::to_string(currentIndex) + " not found.");
	}
}
Ejemplo n.º 2
0
	void Cube3D::CreateVertexBuffer(float aSideLength)
	{
		VertexPosNormColor temp;

		float offset = aSideLength * 0.5f;

		CU::GrowingArray<VertexPosNormColor> vertices;
		vertices.Init(16);

		temp.myPosition = { -offset, offset, -offset, 1.f };
		temp.myNormal = { 0.0f, 1.0f, 0.0f, 0.f };
		temp.myColor = myColor;
		vertices.Add(temp);

		temp.myPosition = { offset, offset, -offset, 1.f };
		temp.myNormal = { 0.0f, 1.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, offset, offset, 1.f };
		temp.myNormal = { 0.0f, 1.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, offset, offset, 1.f };
		temp.myNormal = { 0.0f, 1.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, -offset, -offset, 1.f };
		temp.myNormal = { 0.0f, -1.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, -offset, -offset, 1.f };
		temp.myNormal = { 0.0f, -1.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, -offset, offset, 1.f };
		temp.myNormal = { 0.0f, -1.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, -offset, offset, 1.f };
		temp.myNormal = { 0.0f, -1.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, -offset, offset, 1.f };
		temp.myNormal = { -1.0f, 0.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, -offset, -offset, 1.f };
		temp.myNormal = { -1.0f, 0.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, offset, -offset, 1.f };
		temp.myNormal = { -1.0f, 0.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, offset, offset, 1.f };
		temp.myNormal = { -1.0f, 0.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, -offset, offset, 1.f };
		temp.myNormal = { 1.0f, 0.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, -offset, -offset, 1.f };
		temp.myNormal = { 1.0f, 0.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, offset, -offset, 1.f };
		temp.myNormal = { 1.0f, 0.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, offset, offset, 1.f };
		temp.myNormal = { 1.0f, 0.0f, 0.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, -offset, -offset, 1.f };
		temp.myNormal = { 0.0f, 0.0f, -1.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, -offset, -offset, 1.f };
		temp.myNormal = { 0.0f, 0.0f, -1.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, offset, -offset, 1.f };
		temp.myNormal = { 0.0f, 0.0f, -1.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, offset, -offset, 1.f };
		temp.myNormal = { 0.0f, 0.0f, -1.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, -offset, offset, 1.f };
		temp.myNormal = { 0.0f, 0.0f, 1.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, -offset, offset, 1.f };
		temp.myNormal = { 0.0f, 0.0f, 1.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { offset, offset, offset, 1.f };
		temp.myNormal = { 0.0f, 0.0f, 1.0f, 0.f };
		vertices.Add(temp);

		temp.myPosition = { -offset, offset, offset, 1.f };
		temp.myNormal = { 0.0f, 0.0f, 1.0f, 0.f };
		vertices.Add(temp);
		myVertexBaseData = new VertexDataWrapper();
		myVertexBaseData->myNumberOfVertices = vertices.Size();
		myVertexBaseData->myStride = sizeof(VertexPosNormColor);
		myVertexBaseData->mySize = myVertexBaseData->myNumberOfVertices * myVertexBaseData->myStride;
		myVertexBaseData->myType = VertexType::POS_NORM_COLOR;
		myVertexBaseData->myVertexData = new char[myVertexBaseData->mySize]();
		memcpy(myVertexBaseData->myVertexData, &vertices[0], myVertexBaseData->mySize);
	}
Ejemplo n.º 3
0
	Cube3D::Cube3D()
		: myWireFrame(false)
		, mySize(1.f, 1.f, 1.f)
		, myColor(1.f, 1.f, 1.f, 1.f)
	{
		myEffect = EffectContainer::GetInstance()->GetEffect("Data/Resource/Shader/S_effect_cube3d.fx");
		CreateVertexBuffer(1.f);

		myIndexBaseData = new VertexIndexWrapper();
		myIndexBaseData->myFormat = DXGI_FORMAT_R32_UINT;
		myIndexBaseData->myNumberOfIndices = 6 * 6;
		myIndexBaseData->mySize = myIndexBaseData->myNumberOfIndices * sizeof(unsigned int);


		CU::GrowingArray<int> indices;
		indices.Init(32);

		indices.Add(3);
		indices.Add(1);
		indices.Add(0);

		indices.Add(2);
		indices.Add(1);
		indices.Add(3);

		indices.Add(6);
		indices.Add(4);
		indices.Add(5);

		indices.Add(6);
		indices.Add(7);
		indices.Add(4);

		indices.Add(11);
		indices.Add(9);
		indices.Add(8);

		indices.Add(10);
		indices.Add(9);
		indices.Add(11);

		indices.Add(14);
		indices.Add(12);
		indices.Add(13);

		indices.Add(15);
		indices.Add(12);
		indices.Add(14);

		indices.Add(19);
		indices.Add(17);
		indices.Add(16);

		indices.Add(18);
		indices.Add(17);
		indices.Add(19);

		indices.Add(22);
		indices.Add(20);
		indices.Add(21);

		indices.Add(23);
		indices.Add(20);
		indices.Add(22);

		myIndexBaseData->myIndexData = new char[myIndexBaseData->mySize]();
		memcpy(myIndexBaseData->myIndexData, &indices[0], indices.Size() * sizeof(unsigned int));

		myPrimitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;

		InitVertexBuffer();
		InitIndexBuffer();
	}
Ejemplo n.º 4
0
	void GPUData::InitCube(EffectID aEffect, GPUContext& aGPUContext, AssetContainer& aAssetContainer)
	{
#pragma region Vertices
		CU::GrowingArray<VertexPosColor> vertices;
		vertices.Init(24);

		float size = 1.f;
		float halfWidth = size / 2.f;
		float halfHeight = size / 2.f;
		float halfDepth = size / 2.f;
		CU::Vector4<float> aColour(1.f, 1.f, 1.f, 1.f);

		//0 - 3 (Top)
		vertices.Add({ { -halfWidth, halfHeight, -halfDepth }, aColour });
		vertices.Add({ { halfWidth, halfHeight, -halfDepth }, aColour });
		vertices.Add({ { halfWidth, halfHeight, halfDepth }, aColour });
		vertices.Add({ { -halfWidth, halfHeight, halfDepth }, aColour });

		//4 - 7 (Bottom)
		vertices.Add({ { -halfWidth, -halfHeight, -halfDepth }, aColour });
		vertices.Add({ { halfWidth, -halfHeight, -halfDepth }, aColour });
		vertices.Add({ { halfWidth, -halfHeight, halfDepth }, aColour });
		vertices.Add({ { -halfWidth, -halfHeight, halfDepth }, aColour });

		//8 - 11 (Left)
		vertices.Add({ { -halfWidth, -halfHeight, halfDepth }, aColour });
		vertices.Add({ { -halfWidth, -halfHeight, -halfDepth }, aColour });
		vertices.Add({ { -halfWidth, halfHeight, -halfDepth }, aColour });
		vertices.Add({ { -halfWidth, halfHeight, halfDepth }, aColour });

		//12 - 15 (Right)
		vertices.Add({ { halfWidth, -halfHeight, halfDepth }, aColour });
		vertices.Add({ { halfWidth, -halfHeight, -halfDepth }, aColour });
		vertices.Add({ { halfWidth, halfHeight, -halfDepth }, aColour });
		vertices.Add({ { halfWidth, halfHeight, halfDepth }, aColour });

		//16 - 19 (Front)
		vertices.Add({ { -halfWidth, -halfHeight, -halfDepth }, aColour });
		vertices.Add({ { halfWidth, -halfHeight, -halfDepth }, aColour });
		vertices.Add({ { halfWidth, halfHeight, -halfDepth }, aColour });
		vertices.Add({ { -halfWidth, halfHeight, -halfDepth }, aColour });

		//20 - 23 (Back)
		vertices.Add({ { -halfWidth, -halfHeight, halfDepth }, aColour });
		vertices.Add({ { halfWidth, -halfHeight, halfDepth }, aColour });
		vertices.Add({ { halfWidth, halfHeight, halfDepth }, aColour });
		vertices.Add({ { -halfWidth, halfHeight, halfDepth }, aColour });
#pragma endregion

#pragma region Indices

		CU::GrowingArray<int> indices(24);
		//Top
		indices.Add(3);
		indices.Add(1);
		indices.Add(0);

		indices.Add(2);
		indices.Add(1);
		indices.Add(3);

		//Bottom
		indices.Add(6);
		indices.Add(4);
		indices.Add(5);

		indices.Add(7);
		indices.Add(4);
		indices.Add(6);

		//Left
		indices.Add(11);
		indices.Add(9);
		indices.Add(8);

		indices.Add(10);
		indices.Add(9);
		indices.Add(11);

		//Right
		indices.Add(14);
		indices.Add(12);
		indices.Add(13);

		indices.Add(15);
		indices.Add(12);
		indices.Add(14);

		//Front
		indices.Add(19);
		indices.Add(17);
		indices.Add(16);

		indices.Add(18);
		indices.Add(17);
		indices.Add(19);

		//Back
		indices.Add(22);
		indices.Add(20);
		indices.Add(21);

		indices.Add(23);
		indices.Add(20);
		indices.Add(22);

#pragma endregion

		SetTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
		AddInputElement(new D3D11_INPUT_ELEMENT_DESC({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }));
		AddInputElement(new D3D11_INPUT_ELEMENT_DESC({ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }));

		int indexCount = indices.Size();
		int vertexCount = vertices.Size();
		int vertexStride = sizeof(VertexPosColor);
		Init(aEffect, indexCount, reinterpret_cast<char*>(&indices[0]), vertexCount
			, vertexStride, reinterpret_cast<char*>(&vertices[0]), aGPUContext, aAssetContainer);

		myIndexData = new IndexData();
		myVertexData = new VertexData();

		myIndexData->myNumberOfIndices = indexCount;
		myVertexData->myNumberOfVertices = vertexCount;
		myVertexData->myStride = vertexStride;
	}
Ejemplo n.º 5
0
bool NavGrid::FindPath(const CU::Vector2i& aStartPoint, const CU::Vector2i& aEndPoint, CU::GrowingArray<CU::Vector2f>& aOutPath)
{
	aOutPath.RemoveAll();
	ResetGrid();

	int startIndex = WorldIndexToGridIndex(aStartPoint);
	int goalIndex = WorldIndexToGridIndex(aEndPoint);

	if (!IsPositionOnGrid(aStartPoint) || !IsPositionOnGrid(aEndPoint))
		return false;

	Node& startNode = myGrid[startIndex];
	startNode.myG = 0;
	startNode.myH = CalculateHeuristic(startIndex, goalIndex);
	startNode.myF = startNode.myG + startNode.myH;
	startNode.myListState = IN_OPEN;

	Node* currentClosestNode = &myGrid[startIndex];

	CU::Heap<Node*, NavGrid_NodeComparer<Node*>> heap;
	heap.Enqueue(&startNode);

	while (!heap.IsEmpty())
	{
		Node* currNode = heap.Dequeue();
		currNode->myListState = IN_CLOSED;

		if (CalculateHeuristic(currNode->myGridIndex, goalIndex) < currentClosestNode->myH)
			currentClosestNode = currNode;

		if (currNode->myGridIndex == goalIndex)
		{
			while (currNode != nullptr)
			{
				CU::Vector2f worldPosition = ArrayIndexToWorldPosition(currNode->myGridIndex);
				aOutPath.Add(worldPosition);
				currNode = currNode->myParent;
			}

			return true;
		}

		int currIndex = currNode->myGridIndex;

		if (currIndex > myGridSize)
		{
			ExamineNeighbour(currNode, currIndex - myGridSize, goalIndex, heap);
		}

		if (currIndex < myGridSize * (myGridSize - 1))
		{
			ExamineNeighbour(currNode, currIndex + myGridSize, goalIndex, heap);
		}

		if (currIndex % myGridSize != 0)
		{
			ExamineNeighbour(currNode, currIndex - 1, goalIndex, heap);
		}

		if ((currIndex + 1) % myGridSize != 0)
		{
			ExamineNeighbour(currNode, currIndex + 1, goalIndex, heap);
		}

		currNode->myListState = IN_CLOSED;
	}

	return FindPath(aStartPoint, ArrayIndexToGridIndex(currentClosestNode->myGridIndex), aOutPath);
}