Esempio n. 1
0
        public void LimitToWalls(int minx, int miny, int minz, int maxx, int maxy, int maxz)
        {
            origin.X = GameMath.Clamp(origin.X, minx, maxx);
            origin.Y = GameMath.Clamp(origin.Y, miny, maxy);
            origin.Z = GameMath.Clamp(origin.Z, minz, maxz);

            dir.X = GameMath.Clamp(origin.X + dir.X, minx, maxx) - origin.X;
            dir.Y = GameMath.Clamp(origin.Y + dir.Y, miny, maxy) - origin.Y;
            dir.Z = GameMath.Clamp(origin.Z + dir.Z, minz, maxz) - origin.Z;
        }
Esempio n. 2
0
        public virtual double Noise(double x, double y, double offset = 0)
        {
            double value = 1;

            for (int i = 0; i < amplitudes.Length; i++)
            {
                value += octaves[i].Evaluate(x * frequencies[i], y * frequencies[i]) * amplitudes[i];
            }

            return(GameMath.Clamp(value / 2 + offset, 0, 1));
        }
Esempio n. 3
0
        /// <summary>
        /// Returns the shortest horizontal distance to any point between this and given cuboid
        /// </summary>
        public double ShortestHorizontalDistanceFrom(Cuboidf cuboid, BlockPos offset)
        {
            double cx = offset.X + cuboid.X1 - GameMath.Clamp(offset.X + cuboid.X1, X1, X2);
            double cz = offset.Z + cuboid.Z1 - GameMath.Clamp(offset.Z + cuboid.Z1, Z1, Z2);

            double dx = offset.X + cuboid.X2 - GameMath.Clamp(offset.X + cuboid.X2, X1, X2);
            double dz = offset.Z + cuboid.Z2 - GameMath.Clamp(offset.Z + cuboid.Z2, Z1, Z2);

            return(Math.Sqrt(
                       Math.Min(cx * cx, dx * dx) + Math.Min(cz * cz, dz * dz)
                       ));
        }
Esempio n. 4
0
        /// <summary>
        /// Returns the shortest distance to any point between this and given cuboid
        /// </summary>
        public double ShortestDistanceFrom(Cuboidd cuboid)
        {
            double cx = cuboid.X1 - GameMath.Clamp(cuboid.X1, X1, X2);
            double cy = cuboid.Y1 - GameMath.Clamp(cuboid.Y1, Y1, Y2);
            double cz = cuboid.Z1 - GameMath.Clamp(cuboid.Z1, Z1, Z2);

            double dx = cuboid.X2 - GameMath.Clamp(cuboid.X2, X1, X2);
            double dy = cuboid.Y2 - GameMath.Clamp(cuboid.Y2, Y1, Y2);
            double dz = cuboid.Z2 - GameMath.Clamp(cuboid.Z2, Z1, Z2);

            return(Math.Sqrt(
                       Math.Min(cx * cx, dx * dx) + Math.Min(cy * cy, dy * dy) + Math.Min(cz * cz, dz * dz)
                       ));
        }
Esempio n. 5
0
        /// <summary>
        /// Clamps supplied value to avg-var and avg+var
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public float ClampToRange(float value)
        {
            switch (dist)
            {
            case EnumDistribution.INVEXP:
            case EnumDistribution.STRONGINVEXP:
            case EnumDistribution.STRONGERINVEXP:
                return(Math.Min(value, value + var));

            default:
                float min = avg - var;
                float max = avg + var;
                return(GameMath.Clamp(value, Math.Min(min, max), Math.Max(min, max)));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Returns the shortest distance to any point between this and given cuboid
        /// </summary>
        public double ShortestVerticalDistanceFrom(Cuboidf cuboid, EntityPos offset)
        {
            double oY1 = offset.Y + cuboid.Y1;
            double oY2 = offset.Y + cuboid.Y2;

            double cy = oY1 - GameMath.Clamp(oY1, Y1, Y2);

            // Test if inside
            if (oY1 <= Y1 && oY2 >= Y2)
            {
                cy = 0;
            }

            double dy = oY2 - GameMath.Clamp(oY2, Y1, Y2);

            return(Math.Min(cy, dy));
        }
Esempio n. 7
0
        /// <summary>
        /// Returns the shortest distance to any point between this and given cuboid
        /// </summary>
        public double ShortestDistanceFrom(Cuboidf cuboid, BlockPos offset)
        {
            double oX1 = offset.X + cuboid.X1;
            double oY1 = offset.Y + cuboid.Y1;
            double oZ1 = offset.Z + cuboid.Z1;

            double oX2 = offset.X + cuboid.X2;
            double oY2 = offset.Y + cuboid.Y2;
            double oZ2 = offset.Z + cuboid.Z2;


            double cx = oX1 - GameMath.Clamp(oX1, X1, X2);
            double cy = oY1 - GameMath.Clamp(oY1, Y1, Y2);
            double cz = oZ1 - GameMath.Clamp(oZ1, Z1, Z2);

            // Test if inside
            if (oX1 <= X1 && oX2 >= X2)
            {
                cx = 0;
            }
            if (oY1 <= Y1 && oY2 >= Y2)
            {
                cy = 0;
            }
            if (oZ1 <= Z1 && oZ2 >= Z2)
            {
                cz = 0;
            }

            double dx = oX2 - GameMath.Clamp(oX2, X1, X2);
            double dy = oY2 - GameMath.Clamp(oY2, Y1, Y2);
            double dz = oZ2 - GameMath.Clamp(oZ2, Z1, Z2);

            return(Math.Sqrt(
                       Math.Min(cx * cx, dx * dx) + Math.Min(cy * cy, dy * dy) + Math.Min(cz * cz, dz * dz)
                       ));
        }
Esempio n. 8
0
 /// <summary>
 /// Returns the shortest distance between given point and any point inside the cuboid
 /// </summary>
 public double ShortestVerticalDistanceFrom(double y)
 {
     return(y - GameMath.Clamp(y, Y1, Y2));
 }