Beispiel #1
0
        private static void RunSquaredDistance(Gpu aleaGpu, CudaAccelerator ilGpu)
        {
            const int c = 20;
            const int x = 2 * 10000;

            var matrixM     = new Real[x * x];
            var matrixC     = new Real[x * x];
            var coordinates = new Real[c * x];

            Benchmark.Run(Loops,
                          () => SquaredDistance.Initialise(matrixM, coordinates, c, x),
                          () => SquaredDistance.Initialise(matrixC, coordinates, c, x),
                          () => AssertAreEqual(matrixM, matrixC, x, x),
                          () => SquaredDistance.Managed(matrixM, coordinates, c, x),
#if USE_ALEA
                          () => SquaredDistance.Alea(aleaGpu, matrixC, coordinates, c, x),
#endif
                          () => SquaredDistance.IlGpu(ilGpu, matrixC, coordinates, c, x),
#if USE_ALEA
                          () => SquaredDistance.AleaSharedMemory(aleaGpu, matrixC, coordinates, c, x),
#endif
                          () => SquaredDistance.IlGpuSharedMemory(ilGpu, matrixC, coordinates, c, x),
#if USE_ALEA
                          () => SquaredDistance.AleaFloat2(aleaGpu, matrixC, coordinates, c, x),
#endif
                          () => SquaredDistance.IlGpuFloat2(ilGpu, matrixC, coordinates, c, x),
#if USE_ALEA
                          () => SquaredDistance.AleaConstants(aleaGpu, matrixC, coordinates, c, x),
#endif
                          () => SquaredDistance.IlGpuConstants(ilGpu, matrixC, coordinates, c, x),
#if USE_ALEA
                          () => SquaredDistance.AleaLocalMemory(aleaGpu, matrixC, coordinates, c, x),
#endif
                          () => SquaredDistance.IlGpuLocalMemory(ilGpu, matrixC, coordinates, c, x));
        }
Beispiel #2
0
        private static void RunSquaredDistance()
        {
            const int c = 20;
            const int x = 10000;

            var matrixM     = new Real[x * x];
            var matrixC     = new Real[x * x];
            var coordinates = new Real[c * x];

            Benchmark.Run(Loops,
                          () => SquaredDistance.Initialise(coordinates, c, x),
                          () => SquaredDistance.Initialise(coordinates, c, x),
                          () => AssertAreEqual(matrixM, matrixC, x, x),
                          () => SquaredDistance.Managed(matrixM, coordinates, c, x),
                          () => SquaredDistance.Cuda(matrixC, coordinates, c, x),
                          () => SquaredDistance.CudaSharedMemory(matrixC, coordinates, c, x),
                          () => SquaredDistance.CudaFloat2(matrixC, coordinates, c, x),
                          () => SquaredDistance.CudaConstants(matrixC, coordinates, c, x),
                          () => SquaredDistance.CudaLocalMemory(matrixC, coordinates, c, x));
        }
Beispiel #3
0
        private static void Test(
            Entity entity1, AlignedBox3TreeNode node1, Vector3[] positions1, ref Matrix worldTransform1, ref Vector3 translation1, ref Quaternion rotation1, ref Vector3 scale1,
            Entity entity2, ref Sphere3 sphere2, ref Matrix worldTransform2, ref Vector3 translation2, ref Quaternion rotation2, ref Vector3 scale2,
            bool needAllContacts, ref Contact contact
            )
        {
            /*Sphere3 sphere1;
             * node1.BoundingBox.CreateSphere3(ref worldTransform1, out sphere1);
             * Vector3 diff = sphere1.Center - sphere2.Center;
             * if (diff.LengthSquared() > (sphere1.Radius + sphere2.Radius) * (sphere1.Radius + sphere2.Radius))
             * {
             *  return;
             * }
             */
            Box3   box1, box2;
            Matrix identityMatrix = Matrix.Identity;

            node1.BoundingBox.CreateBox3(ref worldTransform1, out box1);
            sphere2.CreateBox3(ref identityMatrix, out box2);
            if (!Intersection.IntersectBox3Box3(ref box1, ref box2))
            {
                return;
            }

            // see if this node has some primitives => has no children
            if (!node1.HasChildren)
            {
                // test here for all triangles...
                int tricount = node1.NumTriangles;
                for (int i = 0; i < tricount; ++i)
                {
                    //size_t contacts_size = contacts.size();
                    Triangle3 tri = node1.GetTriangle(positions1, i);
                    tri.Vertex0 = Vector3.Transform(tri.Vertex0, worldTransform1);
                    tri.Vertex1 = Vector3.Transform(tri.Vertex1, worldTransform1);
                    tri.Vertex2 = Vector3.Transform(tri.Vertex2, worldTransform1);

                    Vector3 sphereCenter    = sphere2.Center;
                    Vector3 closestPoint    = Vector3.Zero;
                    float   squaredDistance = SquaredDistance.Vector3Triangle3(ref sphereCenter, ref tri, out closestPoint);
                    if (squaredDistance < sphere2.Radius * sphere2.Radius)
                    {
                        if (!contact.ContainsPoint(ref closestPoint))
                        {
                            Vector3 normal = tri.Normal;
                            contact.AddContactPoint(ref closestPoint, ref normal);
                        }

                        if (!needAllContacts)
                        {
                            return;
                        }
                    }
                }
            }
            else
            {
                Test(
                    entity1, node1.Left, positions1, ref worldTransform1, ref translation1, ref rotation1, ref scale1,
                    entity2, ref sphere2, ref worldTransform2, ref translation2, ref rotation2, ref scale2,
                    needAllContacts, ref contact
                    );

                if (!needAllContacts && contact.Count > 0)
                {
                    return;
                }

                Test(
                    entity1, node1.Right, positions1, ref worldTransform1, ref translation1, ref rotation1, ref scale1,
                    entity2, ref sphere2, ref worldTransform2, ref translation2, ref rotation2, ref scale2,
                    needAllContacts, ref contact
                    );
            }
        }