예제 #1
0
        public override Texture2D DidRequestTextureUpdate(int size, float spread)
        {
            Texture2D      tex  = new Texture2D(size, size);
            ConstraintNode cons = ConstraintValue;

            //Fill texture with black
            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    tex.SetPixel(x, y, Color.black);
                }
            }

            AbsGeneratorNode maskNode = null;
            Generator        gen      = null;

            if (cons != null)
            {
                maskNode = cons.GetMaskValue();
            }
            if (maskNode != null)
            {
                gen = maskNode.GetGenerator();
            }

            Vector2[] samples = SamplePositions(new System.Random());
            for (var i = 0; i < samples.Length; i++)
            {
                Vector2 sample = samples[i];

                if (gen != null)
                {
                    Vector2 world = MathUtil.NormalToWorld(GridPosition.Zero, sample);

                    if (gen.GetValue(world.x, world.y, 0) < cons.Tolerance)
                    {
                        continue;
                    }
                }

                int x = Mathf.Clamp((int)(sample.x * size), 0, size);
                int y = Mathf.Clamp((int)(sample.y * size), 0, size);

                tex.SetPixel(x, y, Color.white);

                if (i >= MaxObjects)
                {
                    break;
                }
            }

            tex.Apply();
            return(tex);
        }
예제 #2
0
        /// <summary>
        /// Decides whether or not this object should be placed at
        /// the specified height and angle. Does not check for intersections.
        /// </summary>
        /// <param name="height">Height to evaluate at</param>
        /// <param name="angle">Angle to evaluate at (0 to 90 degrees)</param>
        public bool ShouldPlaceAt(float x, float y, float height, float angle)
        {
            if (_cachedCv == null)
            {
                _cachedCv = ConstraintValue;

                if (_cachedCv == null)
                {
                    return(true);
                }
            }

            return(_cachedCv.ShouldPlaceAt(x, y, height, angle));
        }