コード例 #1
0
        private void Initialize()
        {
            noiseFactors = new NoiseFactors
                           (
                size: 800,
                octave: 10,
                interval: 10,
                randomSeed: new Random().Next(255),
                softness: 2.35f
                           );
            noise = Noise(noiseFactors);
            Renderer.Clear();

            boxes = new Box[(int)boxCount.X, (int)boxCount.Y, (int)boxCount.Z];
            for (int x = 0; x < (int)boxCount.X; x++)
            {
                for (int y = 0; y < (int)boxCount.Y; y++)
                {
                    for (int z = 0; z < (int)boxCount.Z; z++)
                    {
                        SetBoxState(x, y, z);
                    }
                }
            }

            boxList = new List <Box>();

            foreach (var box in boxes)
            {
                boxList.Add(box);
            }
        }
コード例 #2
0
ファイル: Utility.cs プロジェクト: Kwanhong/InverseKinematics
        public static float[] Noise(NoiseFactors noiseFactors)
        {
            float[] output = new float[noiseFactors.Size];
            float[] seed   = new float[noiseFactors.Size];

            Random rand = new Random(noiseFactors.RandomSeed);

            for (int i = 0; i < noiseFactors.Size; i++)
            {
                seed[i] = (float)rand.NextDouble();
            }

            for (int x = 0; x < noiseFactors.Size; x++)
            {
                float noise    = 0f;
                float scale    = 1f;
                float scaleAcc = 0f;

                for (int o = 0; o < noiseFactors.Octave; o++)
                {
                    int   pitch   = noiseFactors.Size >> o;
                    int   sample1 = (x / pitch) * pitch;
                    int   sample2 = (sample1 + pitch) % noiseFactors.Size;
                    float blend   = (float)(x - sample1) / (float)pitch;
                    float sample  = (1f - blend) * seed[sample1] + blend * seed[sample2];

                    noise    += sample * scale;
                    scaleAcc += scale;
                    scale     = scale / noiseFactors.Softness;
                }
                output[x] = noise / scaleAcc;
            }
            return(output);
        }
コード例 #3
0
ファイル: Segment.cs プロジェクト: Kwanhong/InverseKinematics
        // Root Segment
        public Segment(float X, float Y, float length, float angle, NoiseFactors noiseFactors)
        {
            this.Angle      = angle;
            this.rootAngle  = this.Angle;
            this.localAngle = this.Angle;

            this.Length       = length;
            this.StartPos     = new Vector2f(X, Y);
            this.noiseFactors = noiseFactors;
            this.noise        = Noise(noiseFactors);
            CalculateEndPos();
        }
コード例 #4
0
ファイル: Segment.cs プロジェクト: Kwanhong/InverseKinematics
        // Child Segment
        public Segment(Segment parent, float length, float angle, float offset)
        {
            this.Parent       = parent;
            this.StartPos     = this.Parent.EndPos;
            this.noiseFactors = this.Parent.noiseFactors;

            this.Angle      = angle;
            this.rootAngle  = this.Angle;
            this.localAngle = this.Angle;

            this.Length = length;
            this.offset = offset;
            this.noise  = Noise(noiseFactors);
            CalculateEndPos();
        }
コード例 #5
0
        public Tentacle(NoiseFactors noiseFactors, float posX = winSizeX / 2, float posY = winSizeY, float angle = -90, float rootLength = 30f, float reductionRatio = 0.95f, int size = 50)
        {
            this.noiseFactors = noiseFactors;

            tentacleRoot = new Segment(posX, posY, rootLength, ToRadian(angle), noiseFactors);
            Segment current = tentacleRoot;

            for (int i = 0; i < size; i++)
            {
                rootLength *= reductionRatio;
                var     noiseOffset = (int)Map(i, 0, size, 0, noiseFactors.Size);
                Segment next        = new Segment(current, rootLength, 0, noiseOffset);
                current.Child = next;
                current       = next;
            }
        }
コード例 #6
0
ファイル: Game.cs プロジェクト: Kwanhong/InverseKinematics
        private void Initialize()
        {
            window.SetFramerateLimit(60);
            window.Closed     += OnClose;
            window.KeyPressed += OnKeyPressed;

            tentacles = new Tentacle[tentacleCount];
            Random rnd = new Random();

            for (int i = 0; i < tentacleCount; i++)
            {
                NoiseFactors noiseFactors = new NoiseFactors(randomSeed: i + rnd.Next(100), interval: 5, softness: 2.25f);
                float        xPosition    = Map(i, 0, tentacleCount, winSizeX * 0.45f, winSizeX * 0.55f);
                tentacles[i] = new Tentacle(noiseFactors, posX: xPosition);
            }
        }