コード例 #1
0
ファイル: kdtree2.cpp プロジェクト: rezanour/randomoldstuff
_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);
}
コード例 #2
0
ファイル: collision.cpp プロジェクト: YagiChanGames/CodeBox
 void action(BoundingFrustum const& f,Fn fn)const{
     for(auto const& node:nodes){
         if(f.Contains(node.bounds)!=DISJOINT)
             node.action(f,fn);
     }
     for(auto const& m:objects){
         if(f.Contains(m.bounds)!=DISJOINT)
             fn(m);
     }
 }
コード例 #3
0
 bool InView(const BoundingFrustum& frustum) {
     if (boundingBoxDirty) {
         boundingBoxDirty = false;
         const BoundingBox& box = mesh->LocalBoundingBox();
         box.CreateWorldAligned(transform->World, boundingBox);
     }
     return frustum.Intersect(boundingBox) != BoundingFrustum::OUTSIDE;
 }
コード例 #4
0
//--------------------------------------------------------------------------------------
void DrawFrustum( const BoundingFrustum& frustum, FXMVECTOR color )
{
    XMFLOAT3 corners[ BoundingFrustum::CORNER_COUNT ];
    frustum.GetCorners( corners );

    VertexPositionColor verts[24];
    verts[0].position = corners[0];
    verts[1].position = corners[1];
    verts[2].position = corners[1];
    verts[3].position = corners[2];
    verts[4].position = corners[2];
    verts[5].position = corners[3];
    verts[6].position = corners[3];
    verts[7].position = corners[0];

    verts[8].position = corners[0];
    verts[9].position = corners[4];
    verts[10].position = corners[1];
    verts[11].position = corners[5];
    verts[12].position = corners[2];
    verts[13].position = corners[6];
    verts[14].position = corners[3];
    verts[15].position = corners[7];

    verts[16].position = corners[4];
    verts[17].position = corners[5];
    verts[18].position = corners[5];
    verts[19].position = corners[6];
    verts[20].position = corners[6];
    verts[21].position = corners[7];
    verts[22].position = corners[7];
    verts[23].position = corners[4];

    for( size_t j = 0; j < _countof(verts); ++j )
    {
        XMStoreFloat4( &verts[j].color, color );
    }

    auto context = DXUTGetD3D11DeviceContext();
    g_BatchEffect->Apply( context );

    context->IASetInputLayout( g_pBatchInputLayout );

    g_Batch->Begin();

    g_Batch->Draw( D3D11_PRIMITIVE_TOPOLOGY_LINELIST, verts, _countof( verts ) );
    
    g_Batch->End();
}
コード例 #5
0
ファイル: QuadTree.cpp プロジェクト: yorkhawke/Projekt3D_Per
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;
	}
}
コード例 #6
0
ファイル: Ray.cpp プロジェクト: Swillis57/YAX
	std::unique_ptr<float> Ray::Intersects(const BoundingFrustum& bf)
	{
		return bf.Intersects(*this);
	}
コード例 #7
0
//--------------------------------------------------------------------------------------
// Test collisions between pairs of collision objects using XNACollision functions
//--------------------------------------------------------------------------------------
void Collide()
{
    // test collisions between objects and frustum
    g_SecondarySpheres[0].collision = g_PrimaryFrustum.Contains( g_SecondarySpheres[0].sphere );
    g_SecondaryOrientedBoxes[0].collision = g_PrimaryFrustum.Contains( g_SecondaryOrientedBoxes[0].obox );
    g_SecondaryAABoxes[0].collision = g_PrimaryFrustum.Contains( g_SecondaryAABoxes[0].aabox );
    g_SecondaryTriangles[0].collision = g_PrimaryFrustum.Contains( g_SecondaryTriangles[0].pointa,
                                                                   g_SecondaryTriangles[0].pointb,
                                                                   g_SecondaryTriangles[0].pointc );

    // test collisions between objects and aligned box
    g_SecondarySpheres[1].collision = g_PrimaryAABox.Contains( g_SecondarySpheres[1].sphere );
    g_SecondaryOrientedBoxes[1].collision = g_PrimaryAABox.Contains( g_SecondaryOrientedBoxes[1].obox );
    g_SecondaryAABoxes[1].collision = g_PrimaryAABox.Contains( g_SecondaryAABoxes[1].aabox );
    g_SecondaryTriangles[1].collision = g_PrimaryAABox.Contains( g_SecondaryTriangles[1].pointa,
                                                                 g_SecondaryTriangles[1].pointb,
                                                                 g_SecondaryTriangles[1].pointc );

    // test collisions between objects and oriented box
    g_SecondarySpheres[2].collision = g_PrimaryOrientedBox.Contains( g_SecondarySpheres[2].sphere );
    g_SecondaryOrientedBoxes[2].collision = g_PrimaryOrientedBox.Contains( g_SecondaryOrientedBoxes[2].obox );
    g_SecondaryAABoxes[2].collision = g_PrimaryOrientedBox.Contains( g_SecondaryAABoxes[2].aabox );
    g_SecondaryTriangles[2].collision = g_PrimaryOrientedBox.Contains( g_SecondaryTriangles[2].pointa,
                                                                       g_SecondaryTriangles[2].pointb,
                                                                       g_SecondaryTriangles[2].pointc );

    // test collisions between objects and ray
    float fDistance = -1.0f;

    float fDist;
    if ( g_SecondarySpheres[3].sphere.Intersects( g_PrimaryRay.origin, g_PrimaryRay.direction, fDist ) )
    {
        fDistance = fDist;
        g_SecondarySpheres[3].collision = INTERSECTS;
    }
    else
        g_SecondarySpheres[3].collision = DISJOINT;

    if ( g_SecondaryOrientedBoxes[3].obox.Intersects( g_PrimaryRay.origin, g_PrimaryRay.direction, fDist ) )
    {
        fDistance = fDist;
        g_SecondaryOrientedBoxes[3].collision = INTERSECTS;
    }
    else
        g_SecondaryOrientedBoxes[3].collision = DISJOINT;

    if ( g_SecondaryAABoxes[3].aabox.Intersects( g_PrimaryRay.origin, g_PrimaryRay.direction, fDist ) )
    {
        fDistance = fDist;
        g_SecondaryAABoxes[3].collision =  INTERSECTS;
    }
    else
        g_SecondaryAABoxes[3].collision =  DISJOINT;

    if ( TriangleTests::Intersects( g_PrimaryRay.origin, g_PrimaryRay.direction,
                                    g_SecondaryTriangles[3].pointa,
                                    g_SecondaryTriangles[3].pointb,
                                    g_SecondaryTriangles[3].pointc,
                                    fDist ) )
    {
        fDistance = fDist;
        g_SecondaryTriangles[3].collision = INTERSECTS;
    }
    else
        g_SecondaryTriangles[3].collision = DISJOINT;

    // If one of the ray intersection tests was successful, fDistance will be positive.
    // If so, compute the intersection location and store it in g_RayHitResultBox.
    if( fDistance > 0 )
    {
        // The primary ray's direction is assumed to be normalized.
        XMVECTOR HitLocation = XMVectorMultiplyAdd( g_PrimaryRay.direction, XMVectorReplicate( fDistance ),
                                                    g_PrimaryRay.origin );
        XMStoreFloat3( &g_RayHitResultBox.aabox.Center, HitLocation );
        g_RayHitResultBox.collision = INTERSECTS;
    }
    else
    {
        g_RayHitResultBox.collision = DISJOINT;
    }
}
コード例 #8
0
ファイル: Ray.cpp プロジェクト: colajam93/pomdog
Optional<float> Ray::Intersects(const BoundingFrustum& frustum) const
{
    return frustum.Intersects(*this);
}