Exemple #1
0
_Use_decl_annotations_
void KdTreeCompiler2::BuildVisibleIndexList(const XMMATRIX& cameraWorld, const XMMATRIX& projection, uint32_t* indices, uint32_t maxIndices, uint32_t* numIndices, uint32_t* materials, uint32_t maxMaterials, uint32_t* numMaterials)
{
    *numIndices = 0;
    *numMaterials = 0;

    // TODO: Remove dependency on BoundingFrustum. Since all we
    // need is the 4 corners, we can derive those directly from view & projection
    BoundingFrustum frustum;
    BoundingFrustum::CreateFromMatrix(frustum, projection);
    frustum.Transform(frustum, cameraWorld);

    XMFLOAT3 corners[8];
    frustum.GetCorners(corners);

    XMFLOAT3 min = corners[0];
    XMFLOAT3 max = corners[0];

    for (uint32_t i = 1; i < 8; ++i)
    {
        min = VecMin(min, corners[i]);
        max = VecMax(max, corners[i]);
    }

    XMFLOAT3 position;
    XMStoreFloat3(&position, cameraWorld.r[3]);
    AppendVisibleIndices(&position.x, &min.x, &max.x, _root, indices, maxIndices, numIndices, materials, maxMaterials, numMaterials);
}
Exemple #2
0
void QuadTree::Render(ID3D11DeviceContext* DeviceContext, const XMMATRIX &projection, const XMMATRIX &view)
{
	//Frust på Projection sen multiplicera med inverse proj inverse view iverse world.


	BoundingFrustum frust;//göra om frustumet till worldspace för boxarna...

	frust.CreateFromMatrix(frust, projection);
	frust.Transform(frust, XMMatrixInverse(nullptr, view));//FUNKAR TESTAT!

	//if (frust.Intersects(box))
	//{
	//		if (!leaf)
	//		{
	//			for (int i = 0; i < 4; i++)
	//			{
	//				Children[i].Render(DeviceContext, projection,view,World);
	//			}
	//		}
	//		else
	//		{
	//			UINT32 vertexSize = sizeof(Vertex);
	//			UINT32 offset = 0;

	//			DeviceContext->IASetIndexBuffer(IndexB, DXGI_FORMAT_R32_UINT, 0);

	//			DeviceContext->IASetVertexBuffers(0, 1, &VertexB, &vertexSize, &offset);
	//			DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	//			DeviceContext->DrawIndexed(nrIndices, 0, 0);
	//		}

	int testValue = frust.Contains(box);
	switch (testValue)
	{
	case 0:
		break;
	case 1:
		if (!leaf)
		{
			for (int i = 0; i < 4; i++)
			{
				Children[i].Render(DeviceContext, projection,view);
			}
		}
		else
		{
			UINT32 vertexSize = sizeof(Vertex);
			UINT32 offset = 0;

			DeviceContext->IASetIndexBuffer(IndexB, DXGI_FORMAT_R32_UINT, 0);

			DeviceContext->IASetVertexBuffers(0, 1, &VertexB, &vertexSize, &offset);
			DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
			DeviceContext->DrawIndexed(nrIndices, 0, 0);
		}
		break;
	default:
		if (!leaf)
		{
			for (int i = 0; i < 4; i++)
			{
				Children[i].Render(DeviceContext, projection, view);
			}
		}
		else
		{
			UINT32 vertexSize = sizeof(Vertex);
			UINT32 offset = 0;

			DeviceContext->IASetIndexBuffer(IndexB, DXGI_FORMAT_R32_UINT, 0);

			DeviceContext->IASetVertexBuffers(0, 1, &VertexB, &vertexSize, &offset);
			DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
			DeviceContext->DrawIndexed(nrIndices, 0, 0);
		}
		break;
	}
}