Exemplo n.º 1
0
    public void InitVectorFields()
    {
        this.vfVecX = new float[this.gridSize, this.gridSize];
        this.vfVecY = new float[this.gridSize, this.gridSize];

        for (int i = 1; i < this.gridSize + 1; i++)
        {
            for (int j = 1; j < this.gridSize + 1; j++)
            {
                float rAngle = RandomFuncts.GetRandomFloat((float)-Math.PI, (float)Math.PI);
                float rVel   = RandomFuncts.GetRandomFloat(0, 20);

                this.vfVecX[i - 1, j - 1] = (float)Math.Sin(rAngle) * rVel;
                this.vfVecY[i - 1, j - 1] = (float)-Math.Cos(rAngle) * rVel;

                //this.vfVecX[i-1, j-1] = (float) Math.Sin((this.Length(Math.Min(i, j),i)));
                //this.vfVecY[i-1, j-1] = (float) Math.Sin(this.Length(i,Math.Min(i, j)));

                // this.vfVecX[i - 1, j - 1] = (i - gridSize / 2) * (20f / gridSize);
                // this.vfVecY[i - 1, j - 1] = (i - gridSize / 2) * (20f / gridSize);

                //this.vfVecX[i - 1, j - 1] = (float) -(Math.Sin((j - gridSize / 2)) * (20f / gridSize));
                //this.vfVecY[i - 1, j - 1] = (i - gridSize / 2) * (20f / gridSize);

                // this.vfVecX[i-1, j-1] = VectorFuncts.Length(i, j) - gridSize / 2;
                // this.vfVecY[i-1, j-1] = (float) (Math.Sin(VectorFuncts.Length(i,j)) - gridSize / 2);

                // this.vfVecX[i-1, j-1] = (j - gridSize / 2) * (20f / gridSize);
                // this.vfVecY[i-1, j-1] = (i - gridSize / 2) * (20f / gridSize);

                //this.vfVecX[i - 1, j - 1] = (float) Math.Sin(Math.Cos(i + Math.Min(i, j)));
                //this.vfVecY[i - 1, j - 1] = (float) Math.Cos(Math.Sin(j));
            }
        }
    }
Exemplo n.º 2
0
 public void ResetPoint(int index)
 {
     this.posX[index] = RandomFuncts.GetRandomFloat(0, this.width);
     this.posY[index] = RandomFuncts.GetRandomFloat(0, this.height);
     this.vecX[index] = 0f;
     this.vecY[index] = 0f;
 }
Exemplo n.º 3
0
 public void AddPointsAtPosition(int count, float xPos, float yPos, float xVec, float yVec)
 {
     for (int i = 0; i < count; i++)
     {
         int index = RandomFuncts.GetRandomInt(0, this.pointSize);
         this.posX[index] = xPos + RandomFuncts.GetRandomFloat(1, 50);
         this.posY[index] = yPos + RandomFuncts.GetRandomFloat(1, 50);
         this.vecX[index] = xVec;
         this.vecY[index] = yVec;
     }
 }
Exemplo n.º 4
0
    public void ResetVectorField(int gridWidthIndex, int gridHeightIndex)
    {
        float rAngle = RandomFuncts.GetRandomFloat((float)-Math.PI, (float)Math.PI);
        float rVel   = RandomFuncts.GetRandomFloat(0, 20);

        float x = (float)Math.Sin(rAngle) * rVel;
        float y = (float)-Math.Cos(rAngle) * rVel;

        for (int j = -1; j < 2; j++)
        {
            for (int k = -1; k < 2; k++)
            {
                this.vfVecX[MathFuncts.Mod(gridWidthIndex - j, this.gridSize), MathFuncts.Mod(gridHeightIndex - j, this.gridSize)] = x;
                this.vfVecY[MathFuncts.Mod(gridWidthIndex - k, this.gridSize), MathFuncts.Mod(gridHeightIndex - k, this.gridSize)] = y;
            }
        }
    }
Exemplo n.º 5
0
    public void InitPoints()
    {
        this.points = new VertexArray(PrimitiveType.Quads, (uint)this.pointSize * 4);
        this.posX   = new float[this.pointSize];
        this.posY   = new float[this.pointSize];
        this.vecX   = new float[this.pointSize];
        this.vecY   = new float[this.pointSize];

        for (uint i = 0; i < this.pointSize; i++)
        {
            this.posX[i] = RandomFuncts.GetRandomFloat(0, this.width);
            this.posY[i] = RandomFuncts.GetRandomFloat(0, this.height);
            this.vecX[i] = 0;
            this.vecY[i] = 0;

            Vertex vertex = new Vertex();
            vertex.Position.X = this.posX[i];
            vertex.Position.Y = this.posY[i];
            vertex.Color      = new Color((byte)RandomFuncts.GetRandomInt(0, 255), (byte)RandomFuncts.GetRandomInt(0, 255), (byte)RandomFuncts.GetRandomInt(0, 255));
            this.points[i]    = vertex;
        }
    }
Exemplo n.º 6
0
    public void Update(float deltaTime)
    {
        deltaTime *= 8;

        /*for (int i = 0; i < this.gridSize; i++) {
         *      for (int j = 0; j < this.gridSize; j++) {
         *              float avgX = this.vfVecX[MathFuncts.Mod(i - 1, this.gridSize), MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecX[i, MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecX[MathFuncts.Mod(i + 1, this.gridSize), MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecX[MathFuncts.Mod(i - 1, this.gridSize), j] + this.vfVecX[i, j] + this.vfVecX[MathFuncts.Mod(i + 1, this.gridSize), j] + this.vfVecX[MathFuncts.Mod(i - 1, this.gridSize), MathFuncts.Mod(j + 1, this.gridSize)] + this.vfVecX[i, MathFuncts.Mod(j + 1, this.gridSize)] + this.vfVecX[MathFuncts.Mod(i + 1, this.gridSize), MathFuncts.Mod(j + 1, this.gridSize)];
         *              avgX /= 9f;
         *              float avgY = this.vfVecY[MathFuncts.Mod(i - 1, this.gridSize), MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecY[i, MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecY[MathFuncts.Mod(i + 1, this.gridSize), MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecY[MathFuncts.Mod(i - 1, this.gridSize), j] + this.vfVecX[i, j] + this.vfVecY[MathFuncts.Mod(i + 1, this.gridSize), j] + this.vfVecY[MathFuncts.Mod(i - 1, this.gridSize), MathFuncts.Mod(j + 1, this.gridSize)] + this.vfVecY[i, MathFuncts.Mod(j + 1, this.gridSize)] + this.vfVecY[MathFuncts.Mod(i + 1, this.gridSize), MathFuncts.Mod(j + 1, this.gridSize)];
         *              avgY /= 9f;
         *
         *              this.vfVecX[i, j] = avgX;
         *              this.vfVecY[i, j] = avgY;
         *      }
         * }*/


        Parallel.For((long)0, this.pointSize, index => {
            int gridWidthIndex  = (int)Math.Clamp(Math.Floor((this.gridSize - 1) / (float)this.width * this.posX[index]), 0, this.gridSize - 1);
            int gridHeightIndex = (int)Math.Clamp(Math.Floor((this.gridSize - 1) / (float)this.height * this.posY[index]), 0, this.gridSize - 1);

            this.vecX[index] += this.vfVecX[gridWidthIndex, gridHeightIndex] * this.vfFriction * 1f;
            this.vecY[index] += this.vfVecY[gridWidthIndex, gridHeightIndex] * this.vfFriction * 1f;
            this.vfVecX[gridWidthIndex, gridHeightIndex] += this.vecX[index] * this.pointFriction * deltaTime;
            this.vfVecY[gridWidthIndex, gridHeightIndex] += this.vecY[index] * this.pointFriction * deltaTime;

            if (RandomFuncts.GetRandomDouble(0, 1) < this.vfRandomReset)
            {
                this.ResetVectorField(gridWidthIndex, gridHeightIndex);
            }
            else
            {
                if (VectorFuncts.Length(this.vfVecX[gridWidthIndex, gridHeightIndex], this.vfVecY[gridWidthIndex, gridHeightIndex]) > this.vfMaxSpeed)
                {
                    TweenFuncts.ExponentialSmoothing(ref this.vfVecX[gridWidthIndex, gridHeightIndex], this.vfSmoothingScalar);
                    TweenFuncts.ExponentialSmoothing(ref this.vfVecY[gridWidthIndex, gridHeightIndex], this.vfSmoothingScalar);
                }
            }

            if (RandomFuncts.GetRandomDouble(0, 1) < this.pointRandomReset)
            {
                this.ResetPoint((int)index);
            }
            else
            {
                this.posX[index] += this.vecX[index] * deltaTime;
                this.posY[index] += this.vecY[index] * deltaTime;

                if (VectorFuncts.Length(this.vecX[index], this.vecY[index]) > this.pointMaxSpeed)
                {
                    TweenFuncts.ExponentialSmoothing(ref this.vecX[index], this.pointSmoothingScalar);
                    TweenFuncts.ExponentialSmoothing(ref this.vecY[index], this.pointSmoothingScalar);
                }
            }

            this.WrapAroundWindow((int)index);
            this.SetVertex((int)index);
        });

        /*for (int i = 0; i < this.pointSize; i++) {
         *              int gridWidthIndex = (int) Math.Clamp(Math.Floor((this.gridSize - 1) / (float) this.width * this.posX[i]), 0, this.gridSize - 1);
         *              int gridHeightIndex = (int) Math.Clamp(Math.Floor((this.gridSize - 1) / (float) this.height * this.posY[i]), 0, this.gridSize - 1);
         *
         *              this.vecX[i] += this.vfVecX[gridWidthIndex, gridHeightIndex] * this.vfFriction * 1f;
         *              this.vecY[i] += this.vfVecY[gridWidthIndex, gridHeightIndex] * this.vfFriction * 1f;
         *              this.vfVecX[gridWidthIndex, gridHeightIndex] += this.vecX[i] * this.pointFriction * deltaTime;
         *              this.vfVecY[gridWidthIndex, gridHeightIndex] += this.vecY[i] * this.pointFriction * deltaTime;
         *
         *              if (RandomFuncts.GetRandomDouble(0, 1) < this.vfRandomReset) {
         *                      this.ResetVectorField(gridWidthIndex, gridHeightIndex);
         *              }
         *              else {
         *                      if (VectorFuncts.Length(this.vfVecX[gridWidthIndex, gridHeightIndex], this.vfVecY[gridWidthIndex, gridHeightIndex]) > this.vfMaxSpeed) {
         *                              TweenFuncts.ExponentialSmoothing(ref this.vfVecX[gridWidthIndex, gridHeightIndex], this.vfSmoothingScalar);
         *                              TweenFuncts.ExponentialSmoothing(ref this.vfVecY[gridWidthIndex, gridHeightIndex], this.vfSmoothingScalar);
         *                      }
         *              }
         *
         *              if (RandomFuncts.GetRandomDouble(0, 1) < this.pointRandomReset) {
         *                      this.ResetPoint(i);
         *              }
         *              else {
         *                      this.posX[i] += this.vecX[i] * deltaTime;
         *                      this.posY[i] += this.vecY[i] * deltaTime;
         *
         *                      if (VectorFuncts.Length(this.vecX[i], this.vecY[i]) > this.pointMaxSpeed) {
         *                              TweenFuncts.ExponentialSmoothing(ref this.vecX[i], this.pointSmoothingScalar);
         *                              TweenFuncts.ExponentialSmoothing(ref this.vecY[i], this.pointSmoothingScalar);
         *                      }
         *              }
         *
         *              this.WrapAroundWindow(i);
         *              this.SetVertex(i);
         *      }*/
    }