static TestCollidable[] GetRandomLeaves(int leafCount, BoundingBox bounds, Vector3 minimumSize, Vector3 maximumSize, float sizePower, VelocityDescription velocityDescription) { var leaves = new TestCollidable[leafCount]; Random random = new Random(5); var range = bounds.Max - bounds.Min; var sizeRange = maximumSize - minimumSize; for (int i = 0; i < leafCount; ++i) { leaves[i] = new TestCollidable(); leaves[i].HalfSize = 0.5f * (minimumSize + new Vector3((float)Math.Pow(random.NextDouble(), sizePower), (float)Math.Pow(random.NextDouble(), sizePower), (float)Math.Pow(random.NextDouble(), sizePower)) * sizeRange); leaves[i].Position = bounds.Min + new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()) * range; } for (int i = 0; i < leaves.Length * velocityDescription.PortionOfMovingLeaves; ++i) { var speed = (float)(velocityDescription.MinVelocity + (velocityDescription.MaxVelocity - velocityDescription.MinVelocity) * Math.Pow(random.NextDouble(), velocityDescription.VelocityDistributionPower)); var direction = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()) * 2 - Vector3.One; var lengthSquared = direction.LengthSquared(); if (lengthSquared < 1e-9f) { direction = new Vector3(0, 1, 0); } else { direction /= (float)Math.Sqrt(lengthSquared); } leaves[i].Velocity = speed * direction; } return leaves; }
static TestCollidable[] GetRandomLeaves(int leafCount, BoundingBox bounds, Vector3 minimumSize, Vector3 maximumSize, float sizePower, VelocityDescription velocityDescription) { var leaves = new TestCollidable[leafCount]; Random random = new Random(5); var range = bounds.Max - bounds.Min; var sizeRange = maximumSize - minimumSize; for (int i = 0; i < leafCount; ++i) { leaves[i] = new TestCollidable(); leaves[i].HalfSize = 0.5f * (minimumSize + new Vector3((float)Math.Pow(random.NextDouble(), sizePower), (float)Math.Pow(random.NextDouble(), sizePower), (float)Math.Pow(random.NextDouble(), sizePower)) * sizeRange); leaves[i].Position = bounds.Min + new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()) * range; } for (int i = 0; i < leaves.Length * velocityDescription.PortionOfMovingLeaves; ++i) { var speed = (float)(velocityDescription.MinVelocity + (velocityDescription.MaxVelocity - velocityDescription.MinVelocity) * Math.Pow(random.NextDouble(), velocityDescription.VelocityDistributionPower)); var direction = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()) * 2 - Vector3.One; var lengthSquared = direction.LengthSquared(); if (lengthSquared < 1e-9f) { direction = new Vector3(0, 1, 0); } else { direction /= (float)Math.Sqrt(lengthSquared); } leaves[i].Velocity = speed * direction; } return(leaves); }
public static void Test() { float leafMinSize = 1; float leafMaxSize = 100; float leafSizePower = 10; int queryCount = 1000000; int selfTestCount = 1; int refitCount = 1; int frameCount = 2048; float dt = 1 / 60f; VelocityDescription velocityDescription = new VelocityDescription { MinVelocity = 0, MaxVelocity = 10, VelocityDistributionPower = 10, PortionOfMovingLeaves = 1 }; Vector3 querySize = new Vector3(20); int queryLocationCount = 16384; //<-- POWER OF TWO!!! REMEMBER! ParallelLooper looper = new ParallelLooper(); for (int i = 0; i < Environment.ProcessorCount; ++i) { looper.AddThread(); } #if RANDOMLEAVES BoundingBox randomLeafBounds = new BoundingBox { Min = new Vector3(0, 0, 0), Max = new Vector3(629.96f) }; BoundingBox queryBounds = randomLeafBounds; int randomLeafCount = 65536; #else int leafCountX = 64; int leafCountY = 64; int leafCountZ = 64; float leafGap = 10; BoundingBox queryBounds = new BoundingBox { Min = new Vector3(0), Max = new Vector3(leafCountX, leafCountY, leafCountZ) * (new Vector3(leafSize) + new Vector3(leafGap)) }; #endif { var queries = GetQueryLocations(queryLocationCount, queryBounds, querySize); #if RANDOMLEAVES var leaves = GetRandomLeaves(randomLeafCount, randomLeafBounds, new Vector3(leafMinSize), new Vector3(leafMaxSize), leafSizePower, velocityDescription); #else var leaves = GetLeaves(leafCountX, leafCountY, leafCountZ, leafSize, leafGap); #endif GC.Collect(); //TestVectorized(leaves, queries, queryCount, selfTestCount, refitCount); #if RANDOMLEAVES leaves = GetRandomLeaves(randomLeafCount, randomLeafBounds, new Vector3(leafMinSize), new Vector3(leafMaxSize), leafSizePower, velocityDescription); #else leaves = GetLeaves(leafCountX, leafCountY, leafCountZ, leafSize, leafGap); #endif GC.Collect(); //TestBaseline(leaves, queries, queryCount, selfTestCount, refitCount); #if RANDOMLEAVES leaves = GetRandomLeaves(randomLeafCount, randomLeafBounds, new Vector3(leafMinSize), new Vector3(leafMaxSize), leafSizePower, velocityDescription); #else leaves = GetLeaves(leafCountX, leafCountY, leafCountZ, leafSize, leafGap); #endif GC.Collect(); var results = TestSingleArray(leaves, queries, randomLeafBounds, queryCount, selfTestCount, refitCount, frameCount, dt, looper); using (var stream = File.Open("newTreeResults.txt", FileMode.Create)) { using (var textWriter = new StreamWriter(stream)) { results.Save(textWriter); } } } { #if RANDOMLEAVES var leaves = GetRandomLeavesBEPU(randomLeafCount, randomLeafBounds, new Vector3(leafMinSize), new Vector3(leafMaxSize), leafSizePower, velocityDescription); #else var leaves = GetLeavesBEPU(leafCountX, leafCountY, leafCountZ, leafSize, leafGap); #endif var queries = GetBEPUQueryLocations(queryLocationCount, queryBounds, querySize); GC.Collect(); //TestBEPU(leaves, queries, queryCount, selfTestCount, refitCount); var results = TestDH(leaves, queries, ref randomLeafBounds, queryCount, selfTestCount, refitCount, frameCount, dt, looper); using (var stream = File.Open("oldDHResults.txt", FileMode.Create)) { using (var textWriter = new StreamWriter(stream)) { results.Save(textWriter); } } } }