Ejemplo n.º 1
0
 public void IntersectRect_ReturnsCorrectValues(Rect a, Rect b, Rect expected)
 {
     // Test identities
     Assert.AreEqual(a, ObjectPlacementUtilities.IntersectRect(a, a));
     Assert.AreEqual(b, ObjectPlacementUtilities.IntersectRect(b, b));
     // Test operation
     Assert.AreEqual(expected, ObjectPlacementUtilities.IntersectRect(a, b));
     // Test for symmetry
     Assert.AreEqual(expected, ObjectPlacementUtilities.IntersectRect(b, a));
 }
Ejemplo n.º 2
0
        public void Execute(int index)
        {
            var foregroundObjectBox = PlacedForegroundObjects[index];
            // See comment regarding Random in jobs in BackgroundGenerator.PlaceObjectsJob
            var rand = new Random(RandomSeed + (uint)index * ObjectPlacementUtilities.LargePrimeNumber);

            var prefabIndex = rand.NextInt(OccludingObjectBounds.Length);
            var bounds      = OccludingObjectBounds[prefabIndex];
            var foregroundObjectBoundingBox = ObjectPlacementUtilities.IntersectRect(
                foregroundObjectBox.BoundingBox, ImageCoordinates);

            //place over a foreground object such that overlap is between 10%-30%
            var numTries = 0;

            PlacedOccludingObjects[index] = new PlacedObject()
            {
                PrefabIndex = -1
            };
            while (numTries < 1000)
            {
                numTries++;
                var rotation = rand.NextQuaternionRotation();
                var position = new Vector3(rand.NextFloat(foregroundObjectBoundingBox.xMin, foregroundObjectBoundingBox.xMax),
                                           rand.NextFloat(foregroundObjectBoundingBox.yMin, foregroundObjectBoundingBox.yMax), 0f);
                var scale = ObjectPlacementUtilities.ComputeScaleToMatchArea(Transformer, position, rotation, bounds,
                                                                             rand.NextFloat(ScalingMin, ScalingMin + ScalingSize) * foregroundObjectBox.ProjectedArea);
                var placedObject = new PlacedObject()
                {
                    Scale       = scale,
                    Rotation    = rotation,
                    Position    = position,
                    PrefabIndex = prefabIndex
                };
                // NOTE: This computation is done with orthographic projection and will be slightly inaccurate
                //       when rendering with perspective projection
                var occludingObjectBox = GetBoundingBox(bounds, scale, position, rotation);
                var cropping           = ComputeOverlap(foregroundObjectBoundingBox, occludingObjectBox);
                if (cropping >= 0.10 && cropping <= 0.30)
                {
                    PlacedOccludingObjects[index] = placedObject;
                    return;
                }
            }
        }