コード例 #1
0
        private float GenInterpolatedNoise(float x, float y)
        {
            int floorX = (x > 0) ? (int)x : (int)x - 1;
            int floorY = (y > 0) ? (int)y : (int)y - 1;

            float fractionalX = x - floorX;
            float fractionalY = y - floorY;

            float centerInter, bottomInter;

            FastPerlinInterpolatedNoise2D noise;

            Vector2 key = new Vector2(floorX, floorY);

            calcLookup.TryGetValue(key, out noise);

            if (noise == null)
            {
                noise             = new FastPerlinInterpolatedNoise2D();
                noise.center      = GenSmoothNoise(floorX, floorY);
                noise.bottom      = GenSmoothNoise(floorX, floorY + 1);
                noise.centerRight = GenSmoothNoise(floorX + 1, floorY);
                noise.bottomRight = GenSmoothNoise(floorX + 1, floorY + 1);

                calcLookup.Add(key, noise);
            }

            centerInter = GraphMath.LinearInterpolateFloat(noise.center, noise.centerRight, fractionalX);
            bottomInter = GraphMath.LinearInterpolateFloat(noise.bottom, noise.bottomRight, fractionalX);

            return(GraphMath.LinearInterpolateFloat(centerInter, bottomInter, fractionalY));
        }
コード例 #2
0
        static public double GenInterpolatedNoise(double x, double y, double z, int seed)
        {
            int floorX = (x > 0) ? (int)x : (int)Math.Floor(x);
            int floorY = (y > 0) ? (int)y : (int)Math.Floor(y);
            int floorZ = (z > 0) ? (int)z : (int)Math.Floor(z);

            double fractionalX = x - floorX;
            double fractionalY = y - floorY;
            double fractionalZ = z - floorZ;

            double center, centerRight, bottom, bottomRight;
            double centerAbove, centerRightAbove, bottomAbove, bottomRightAbove;
            double centerInter, bottomInter, belowInter, aboveInter;

            center      = GenSmoothNoise(floorX, floorY, floorZ, seed);
            bottom      = GenSmoothNoise(floorX, floorY + 1, floorZ, seed);
            centerRight = GenSmoothNoise(floorX + 1, floorY, floorZ, seed);
            bottomRight = GenSmoothNoise(floorX + 1, floorY + 1, floorZ, seed);

            centerAbove      = GenSmoothNoise(floorX, floorY, floorZ + 1, seed);
            bottomAbove      = GenSmoothNoise(floorX, floorY + 1, floorZ + 1, seed);
            centerRightAbove = GenSmoothNoise(floorX + 1, floorY, floorZ + 1, seed);
            bottomRightAbove = GenSmoothNoise(floorX + 1, floorY + 1, floorZ + 1, seed);

            centerInter = GraphMath.CosineInterpolate(center, centerRight, fractionalX);
            bottomInter = GraphMath.CosineInterpolate(bottom, bottomRight, fractionalX);
            belowInter  = GraphMath.CosineInterpolate(centerInter, bottomInter, fractionalY);

            centerInter = GraphMath.CosineInterpolate(centerAbove, centerRightAbove, fractionalX);
            bottomInter = GraphMath.CosineInterpolate(bottomAbove, bottomRightAbove, fractionalX);
            aboveInter  = GraphMath.CosineInterpolate(centerInter, bottomInter, fractionalY);

            return(GraphMath.CosineInterpolate(belowInter, aboveInter, fractionalZ));
        }
コード例 #3
0
        public Camera3D(Rectangle clientBounds, Vector3 position, Vector3 lookAt, Vector3 up)
        {
            this.position = position;
            this.up       = up;

            Vector3 origionalForward = lookAt - position;

            origionalForward.Normalize( );

            rotation = GraphMath.AngleBetweenNorms(Vector3.Forward, origionalForward);

            aspectRatio  = (float)clientBounds.Width / (float)clientBounds.Height;
            fov          = 45;
            drawDistance = new Vector2(1, 300);

            BuildProjection();
        }
コード例 #4
0
        private float GenInterpolatedNoise(float x, float y, float z)
        {
            int floorX = (x > 0) ? (int)x : (int)x - 1;
            int floorY = (y > 0) ? (int)y : (int)y - 1;
            int floorZ = (z > 0) ? (int)z : (int)z - 1;

            float fractionalX = x - floorX;
            float fractionalY = y - floorY;
            float fractionalZ = z - floorZ;

            float centerInter, bottomInter, belowInter, aboveInter;

            FastPerlinInterpolatedNoise3D noise;

            Vector3 key = new Vector3(floorX, floorY, floorZ);

            calcLookup.TryGetValue(key, out noise);

            if (noise == null)
            {
                noise             = new FastPerlinInterpolatedNoise3D();
                noise.center      = GenSmoothNoise(floorX, floorY, floorZ);
                noise.bottom      = GenSmoothNoise(floorX, floorY + 1, floorZ);
                noise.centerRight = GenSmoothNoise(floorX + 1, floorY, floorZ);
                noise.bottomRight = GenSmoothNoise(floorX + 1, floorY + 1, floorZ);

                noise.centerAbove      = GenSmoothNoise(floorX, floorY, floorZ + 1);
                noise.bottomAbove      = GenSmoothNoise(floorX, floorY + 1, floorZ + 1);
                noise.centerRightAbove = GenSmoothNoise(floorX + 1, floorY, floorZ + 1);
                noise.bottomRightAbove = GenSmoothNoise(floorX + 1, floorY + 1, floorZ + 1);

                calcLookup.Add(key, noise);
            }

            centerInter = GraphMath.LinearInterpolateFloat(noise.center, noise.centerRight, fractionalX);
            bottomInter = GraphMath.LinearInterpolateFloat(noise.bottom, noise.bottomRight, fractionalX);
            belowInter  = GraphMath.LinearInterpolateFloat(centerInter, bottomInter, fractionalY);

            centerInter = GraphMath.LinearInterpolateFloat(noise.centerAbove, noise.centerRightAbove, fractionalX);
            bottomInter = GraphMath.LinearInterpolateFloat(noise.bottomAbove, noise.bottomRightAbove, fractionalX);
            aboveInter  = GraphMath.LinearInterpolateFloat(centerInter, bottomInter, fractionalY);

            return(GraphMath.LinearInterpolateFloat(belowInter, aboveInter, fractionalZ));
        }
コード例 #5
0
        static public double GenInterpolatedNoise(double x, double y, int seed)
        {
            int floorX = (int)x;
            int floorY = (int)y;

            double center, centerRight, bottom, bottomRight;
            double centerInter, bottomInter;

            center      = GenSmoothNoise(floorX, floorY, seed);
            centerRight = GenSmoothNoise(floorX + 1, floorY, seed);
            bottom      = GenSmoothNoise(floorX, floorY + 1, seed);
            bottomRight = GenSmoothNoise(floorX + 1, floorY + 1, seed);

            centerInter = GraphMath.CosineInterpolate(center, centerRight, floorX - x); //Interpolates the two
            bottomInter = GraphMath.CosineInterpolate(bottom, bottomRight, floorX - x); // Horizontal parts.

            return(GraphMath.CosineInterpolate(centerInter, bottomInter, y - floorY));  //Interpolatse the interpolated
                                                                                        //Horizontal parts vertically
        }
コード例 #6
0
        private void SetSpawn(GameMap newMap)
        {
            const int TIMEOUT = 500;
            int       trys    = 0;

            Point spawn;

            do
            {
                spawn = new Point(rng.Next(0, newMap.Size.X - 1), rng.Next(0, newMap.Size.Y - 1));
                trys++;
            }while(newMap.GetTile(spawn) == Tile.Water &&
                   GraphMath.DistanceBetweenVector2s(spawn, newMap.BossPoint) > mapParams.minDistBossSpawn &&
                   trys < TIMEOUT);

            while (newMap.GetTile(spawn) == Tile.Water)
            {
                spawn = new Point(rng.Next(0, newMap.Size.X - 1), rng.Next(0, newMap.Size.Y - 1));
            }

            newMap.SpawnPoint = spawn;
        }