Floor() public static method

public static Floor ( float f ) : float
f float
return float
Ejemplo n.º 1
0
    /// <summary>
    /// Works like GridNoise(), but allows for interpolation instead of hard jumps between values.
    /// </summary>
    public static float InterpolateNoise(Vector3 seed, Func <Vector3, Vector3> tModifier)
    {
        //Get the integer values behind and in front of the seed values.
        float minX = Mathf.Floor(seed.x),
              maxX = Mathf.Ceil(seed.x),
              minY = Mathf.Floor(seed.y),
              maxY = Mathf.Ceil(seed.y),
              minZ = Mathf.Floor(seed.z),
              maxZ = Mathf.Ceil(seed.z);

        //Get the interpolant (will be linear if nothing is done to modify it).
        Vector3 lerp = tModifier(seed - new Vector3(minX, minY, minZ));

        return(Mathf.Lerp(Mathf.Lerp(Mathf.Lerp(WhiteNoise(new Vector3(minX, minY, minZ)),
                                                WhiteNoise(new Vector3(maxX, minY, minZ)),
                                                lerp.x),
                                     Mathf.Lerp(WhiteNoise(new Vector3(minX, maxY, minZ)),
                                                WhiteNoise(new Vector3(maxX, maxY, minZ)),
                                                lerp.x),
                                     lerp.y),
                          Mathf.Lerp(Mathf.Lerp(WhiteNoise(new Vector3(minX, minY, maxZ)),
                                                WhiteNoise(new Vector3(maxX, minY, maxZ)),
                                                lerp.x),
                                     Mathf.Lerp(WhiteNoise(new Vector3(minX, maxY, maxZ)),
                                                WhiteNoise(new Vector3(maxX, maxY, maxZ)),
                                                lerp.x),
                                     lerp.y),
                          lerp.z));
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (!this.getSelf())
        {
            return;
        }

        Rect r = this.img.uvRect;

        if (this.lastProgress != this.progress)
        {
            if (this.progress < 0.0f)
            {
                this.progress = 0.0f;
            }
            else if (this.progress > 1.0f)
            {
                this.progress = 1.0f;
            }

            int size = (int)Math.Floor(this.progress * this.width);
            this.uit.SetSizeWithCurrentAnchors(Axis.Horizontal, size);
            r.width           = this.progress * (this.width / texWidth);
            this.lastProgress = this.progress;
        }

        this.offx += UnityEngine.Time.deltaTime * ProgressBar.speed;
        if (this.offx > 1.0f)
        {
            this.offx -= 1.0f;
        }
        r.x             = this.offx;
        this.img.uvRect = r;
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Computes Worley/Voroni noise for the given seed.
    /// </summary>
    /// <param name="distFunc">
    /// The function to get the distance between two positions.
    /// </param>
    /// <param name="distsToValue">
    /// Takes in the closest and second-closest distances and outputs a noise value from them.
    /// </param>
    /// <example>
    /// //A standard effect is straight-line distance and using the closest distance value.
    /// float noiseVal = WorleyNoise(seed, Vector2.Distance, (f1, f2) => f1);
    /// //Another nice effect is distance squared and using the average of both distance values.
    /// float noiseVal2 = WorleyNoise(seed,
    ///								  (v1, v2) => (v1 - v2).sqrMagnitude,
    ///								  (f1, f2) => (f1 + f2) * 0.5f);
    /// </example>
    public static float WorleyNoise(Vector2 seed, Func <Vector2, Vector2, float> distFunc,
                                    Func <float, float, float> distsToValue)
    {
        //Get the min corner of each of the 9 grid cells near the seed value.
        Vector2 posCenter    = new Vector2(Mathf.Floor(seed.x), Mathf.Floor(seed.y)),
                posMinCorner = posCenter - Vector2.one,
                posMaxCorner = posCenter + Vector2.one,
                pos4         = new Vector2(posCenter.x, posMinCorner.y),
                pos5         = new Vector2(posMaxCorner.x, posMinCorner.y),
                pos6         = new Vector2(posMinCorner.x, posCenter.y),
                pos7         = new Vector2(posMaxCorner.x, posCenter.y),
                pos8         = new Vector2(posMinCorner.x, posMaxCorner.y),
                pos9         = new Vector2(posCenter.x, posMaxCorner.y);

        //Get a random point inside each of these cells
        //    and get the distance from the seed pos to the two closest points.
        float min1 = float.PositiveInfinity,
              min2 = float.PositiveInfinity;

        Utils.GetWorleyMins(ref min1, ref min2, distFunc(Utils.GetWorleyPos(posCenter) + posCenter, seed));
        Utils.GetWorleyMins(ref min1, ref min2, distFunc(Utils.GetWorleyPos(posMinCorner) + posMinCorner, seed));
        Utils.GetWorleyMins(ref min1, ref min2, distFunc(Utils.GetWorleyPos(posMaxCorner) + posMaxCorner, seed));
        Utils.GetWorleyMins(ref min1, ref min2, distFunc(Utils.GetWorleyPos(pos4) + pos4, seed));
        Utils.GetWorleyMins(ref min1, ref min2, distFunc(Utils.GetWorleyPos(pos5) + pos5, seed));
        Utils.GetWorleyMins(ref min1, ref min2, distFunc(Utils.GetWorleyPos(pos6) + pos6, seed));
        Utils.GetWorleyMins(ref min1, ref min2, distFunc(Utils.GetWorleyPos(pos7) + pos7, seed));
        Utils.GetWorleyMins(ref min1, ref min2, distFunc(Utils.GetWorleyPos(pos8) + pos8, seed));
        Utils.GetWorleyMins(ref min1, ref min2, distFunc(Utils.GetWorleyPos(pos9) + pos9, seed));

        //Filter these distance values into some noise value.
        return(distsToValue(min1, min2));
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Works like GridNoise(), but allows for interpolation instead of hard jumps between values.
    /// </summary>
    public static float InterpolateNoise(float seed, Func <float, float> tModifier)
    {
        //Get the integer values behind and in front of the seed values.
        float min = Mathf.Floor(seed),
              max = Mathf.Ceil(seed);

        //Get the interpolant (will be linear if nothing is done to modify it).
        float lerp = tModifier(seed - min);

        return(Mathf.Lerp(min, max, lerp));
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Computes Worley/Voroni noise for the given seed.
    /// </summary>
    /// <param name="distsToValue">
    /// Takes in the closest and second-closest distances and outputs a noise value from them.
    /// </param>
    public static float WorleyNoise(float seed, Func <float, float, float> distsToValue)
    {
        //Get the min corner of each of the 9 grid cells near the seed value.
        float posMid  = Mathf.Floor(seed),
              posLess = posMid - 1.0f,
              posMore = posMid + 1.0f;

        //Get a random point inside each of these cells
        //    and get the distance from the seed pos to the two closest points.
        float min1 = float.PositiveInfinity,
              min2 = float.PositiveInfinity;

        Utils.GetWorleyMins(ref min1, ref min2, Mathf.Abs(seed - (posMid + WhiteNoise(posMid))));
        Utils.GetWorleyMins(ref min1, ref min2, Mathf.Abs(seed - (posLess + WhiteNoise(posLess))));
        Utils.GetWorleyMins(ref min1, ref min2, Mathf.Abs(seed - (posMore + WhiteNoise(posMore))));

        //Filter these distance values into some noise value.
        return(distsToValue(min1, min2));
    }
Ejemplo n.º 6
0
        public static Texture2D Extrude(this Texture2D source, Vector2 tileSize, Vector2 borderSize, TextureExtrude extrudeColor = TextureExtrude.Default)
        {
            if (source == null)
            {
                return(null);
            }
            int   cols   = (int)Mathf.Floor(source.width / tileSize.x);
            int   rows   = (int)Mathf.Floor(source.height / tileSize.y);
            Color border = Color.black;

            switch (extrudeColor)
            {
            case TextureExtrude.White:
                border = Color.white;
                break;

            case TextureExtrude.Red:
                border = Color.red;
                break;

            case TextureExtrude.Green:
                border = Color.green;
                break;

            case TextureExtrude.Blue:
                border = Color.blue;
                break;

            case TextureExtrude.Yellow:
                border = Color.yellow;
                break;

            case TextureExtrude.Gray:
                border = Color.gray;
                break;

            default:
                border = Color.black;
                break;
            }
            Texture2D texture = new Texture2D((int)(cols * (tileSize.x + borderSize.x * 2f)), source.height, source.format, false);

            texture.filterMode = source.filterMode;
            for (int i = 0; i < cols; i++)
            {
                Color[] c1 = source.GetPixels((int)(i * tileSize.x), 0, 1, source.height);
                Color[] c2 = source.GetPixels((int)((i + 1) * tileSize.x - 1), 0, 1, source.height);
                // Format border pixels
                if (extrudeColor != TextureExtrude.Default && extrudeColor != TextureExtrude.Mirror)
                {
                    for (int index = 0; index < c1.Length; index++)
                    {
                        c1[index] = border;
                    }
                    for (int index = 0; index < c2.Length; index++)
                    {
                        c2[index] = border;
                    }
                }
                else if (extrudeColor == TextureExtrude.Mirror)
                {
                    // TODO: Mirror Edge Pixels
                }
                for (int j = 0; j < borderSize.x; j++)
                {
                    texture.SetPixels((int)(i * (tileSize.x + borderSize.x * 2) + j), 0, 1, source.height, c1);
                    texture.SetPixels((int)(i * (tileSize.x + borderSize.x * 2) + j + tileSize.x + borderSize.x), 0, 1, source.height, c2);
                }
                texture.SetPixels((int)(i * (tileSize.x + borderSize.x * 2) + borderSize.x), 0, (int)tileSize.x, source.height, source.GetPixels((int)(i * tileSize.x), 0, (int)tileSize.x, source.height));
            }

            Texture2D temp = texture;

            texture            = new Texture2D(temp.width, (int)(rows * (tileSize.y + borderSize.y * 2f)), source.format, false);
            texture.filterMode = source.filterMode;
            for (int i = 0; i < rows; i++)
            {
                Color [] c1 = temp.GetPixels(0, (int)(i * tileSize.y), temp.width, 1);
                Color [] c2 = temp.GetPixels(0, (int)((i + 1) * tileSize.y - 1), temp.width, 1);
                // Format border pixels
                if (extrudeColor != TextureExtrude.Default && extrudeColor != TextureExtrude.Mirror)
                {
                    for (int index = 0; index < c1.Length; index++)
                    {
                        c1[index] = border;
                    }
                    for (int index = 0; index < c2.Length; index++)
                    {
                        c2[index] = border;
                    }
                }
                else if (extrudeColor == TextureExtrude.Mirror)
                {
                    // TODO: Mirror Edge Pixels
                }
                for (int j = 0; j < borderSize.y; j++)
                {
                    texture.SetPixels(0, (int)(i * (tileSize.y + borderSize.y * 2) + j), temp.width, 1, c1);
                    texture.SetPixels(0, (int)(i * (tileSize.y + borderSize.y * 2) + j + tileSize.y + borderSize.y), temp.width, 1, c2);
                }
                texture.SetPixels(0, (int)(i * (tileSize.y + borderSize.y * 2) + borderSize.y), temp.width, (int)tileSize.y, temp.GetPixels(0, (int)(i * tileSize.y), temp.width, (int)tileSize.y));
            }
            texture.Apply();
            return(texture);
        }
Ejemplo n.º 7
0
 public static int FloorToInt(float d)
 {
     return((int)Mathf.Floor(d));
 }
Ejemplo n.º 8
0
 public static float Floor(float d)
 {
     return(Mathf.Floor(d));
 }
Ejemplo n.º 9
0
 // Loops the value t, so that it is never larger than length and never smaller than 0.
 public static float Repeat(float t, float length)
 {
     return(Clamp(t - Mathf.Floor(t / length) * length, 0.0f, length));
 }
Ejemplo n.º 10
0
        public static Color HSVToRGB(float H, float S, float V, bool hdr)
        {
            Color white = Color.white;

            if (S == 0f)
            {
                white.r = V;
                white.g = V;
                white.b = V;
            }
            else if (V == 0f)
            {
                white.r = 0f;
                white.g = 0f;
                white.b = 0f;
            }
            else
            {
                white.r = 0f;
                white.g = 0f;
                white.b = 0f;
                float num  = H * 6f;
                int   num2 = (int)Mathf.Floor(num);
                float num3 = num - (float)num2;
                float num4 = V * (1f - S);
                float num5 = V * (1f - S * num3);
                float num6 = V * (1f - S * (1f - num3));
                switch (num2 + 1)
                {
                case 0:
                    white.r = V;
                    white.g = num4;
                    white.b = num5;
                    break;

                case 1:
                    white.r = V;
                    white.g = num6;
                    white.b = num4;
                    break;

                case 2:
                    white.r = num5;
                    white.g = V;
                    white.b = num4;
                    break;

                case 3:
                    white.r = num4;
                    white.g = V;
                    white.b = num6;
                    break;

                case 4:
                    white.r = num4;
                    white.g = num5;
                    white.b = V;
                    break;

                case 5:
                    white.r = num6;
                    white.g = num4;
                    white.b = V;
                    break;

                case 6:
                    white.r = V;
                    white.g = num4;
                    white.b = num5;
                    break;

                case 7:
                    white.r = V;
                    white.g = num6;
                    white.b = num4;
                    break;
                }
                if (!hdr)
                {
                    white.r = Mathf.Clamp(white.r, 0f, 1f);
                    white.g = Mathf.Clamp(white.g, 0f, 1f);
                    white.b = Mathf.Clamp(white.b, 0f, 1f);
                }
            }
            return(white);
        }
Ejemplo n.º 11
0
        // Convert a set of HSV values to an RGB Color.
        public static Color HSVToRGB(float H, float S, float V, bool hdr)
        {
            Color retval = Color.white;

            if (S == 0)
            {
                retval.r = V;
                retval.g = V;
                retval.b = V;
            }
            else if (V == 0)
            {
                retval.r = 0;
                retval.g = 0;
                retval.b = 0;
            }
            else
            {
                retval.r = 0;
                retval.g = 0;
                retval.b = 0;

                //crazy hsv conversion
                float t_S, t_V, h_to_floor;

                t_S        = S;
                t_V        = V;
                h_to_floor = H * 6.0f;

                int   temp  = (int)Mathf.Floor(h_to_floor);
                float t     = h_to_floor - ((float)temp);
                float var_1 = (t_V) * (1 - t_S);
                float var_2 = t_V * (1 - t_S * t);
                float var_3 = t_V * (1 - t_S * (1 - t));

                switch (temp)
                {
                case 0:
                    retval.r = t_V;
                    retval.g = var_3;
                    retval.b = var_1;
                    break;

                case 1:
                    retval.r = var_2;
                    retval.g = t_V;
                    retval.b = var_1;
                    break;

                case 2:
                    retval.r = var_1;
                    retval.g = t_V;
                    retval.b = var_3;
                    break;

                case 3:
                    retval.r = var_1;
                    retval.g = var_2;
                    retval.b = t_V;
                    break;

                case 4:
                    retval.r = var_3;
                    retval.g = var_1;
                    retval.b = t_V;
                    break;

                case 5:
                    retval.r = t_V;
                    retval.g = var_1;
                    retval.b = var_2;
                    break;

                case 6:
                    retval.r = t_V;
                    retval.g = var_3;
                    retval.b = var_1;
                    break;

                case -1:
                    retval.r = t_V;
                    retval.g = var_1;
                    retval.b = var_2;
                    break;
                }

                if (!hdr)
                {
                    retval.r = Mathf.Clamp(retval.r, 0.0f, 1.0f);
                    retval.g = Mathf.Clamp(retval.g, 0.0f, 1.0f);
                    retval.b = Mathf.Clamp(retval.b, 0.0f, 1.0f);
                }
            }
            return(retval);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Returns a pseudo-random value between 0 and 1 based on the given seed's floored value.
 /// </summary>
 public static float GridNoise(Vector2 seed)
 {
     return(WhiteNoise(new Vector2(Mathf.Floor(seed.x), Mathf.Floor(seed.y))));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Returns a pseudo-random value between 0 and 1 based on the given seed's floored value.
 /// </summary>
 public static float GridNoise(float seed)
 {
     return(WhiteNoise(Mathf.Floor(seed)));
 }