/// <summary>
            /// Override the ToString to return all the velocity data as a string.
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                StringBuilder builder = new StringBuilder();

                builder.Append("X : " + VelocityX.ToString() + "\n");
                builder.Append("Y : " + VelocityY.ToString() + "\n");
                builder.Append("Z : " + VelocityZ.ToString() + "\n");
                builder.Append("Q : " + VelocityQ.ToString() + "\n");
                builder.Append("Depth Layer : " + WaterMassDepthLayer.ToString());


                return(builder.ToString());
            }
 private void CalculateDivergence()
 {
     for (var i = 0; i < VelocityX.GetLength(0); i++)
     {
         for (var j = 0; j < VelocityX.GetLength(1); j++)
         {
             if (!IsInSimulatedSpace(i, j) || DefineBoundaryType(i, j) != BoundaryCondition.None)
             {
                 continue;
             }
             _divergence[i, j] = (_gradientX[i, j] - _gradientX[i - 1, j]) / GridStep +
                                 (_gradientY[i, j] - _gradientY[i - 1, j]) / GridStep;
         }
     }
 }
Example #3
0
 public static VelocityX LerpUnclamped(VelocityX a, VelocityX b, float t)
 {
     return(new VelocityX(Mathf.LerpUnclamped(a.Float, b.Float, t)));
 }
Example #4
0
 public static VelocityX Clamp(VelocityX value, VelocityX min, VelocityX max)
 {
     return(new VelocityX(Mathf.Clamp(value.Float, min.Float, max.Float)));
 }
Example #5
0
 public static VelocityX Max(VelocityX a, VelocityX b)
 {
     return(new VelocityX(Mathf.Max(a.Float, b.Float)));
 }
Example #6
0
 public static VelocityX Clamp01(VelocityX value)
 {
     return(new VelocityX(Mathf.Clamp01(value.Float)));
 }
        private void RecalculateBoundaries()
        {
            for (var i = 0; i < Boundaries.Count / 5; i += 5)
            {
                switch ((BoundaryCondition)Boundaries[i * 5 + 4])
                {
                case BoundaryCondition.ParabaloidInput:
                    break;

                case BoundaryCondition.None:
                    break;

                case BoundaryCondition.SimpleOutput:
                {
                    if (Boundaries[i * 5] == Boundaries[i * 5 + 2]) //Если сток вертикальный
                    {
                        if (Boundaries[i * 5] == 0)                 //Если сток слева
                        {
                            for (var j = Boundaries[i * 5 + 1]; j < Boundaries[i * 5 + 3]; j++)
                            {
                                VelocityX[0, j] = VelocityX[1, j];
                                VelocityY[0, j] = VelocityY[1, j];
                            }
                        }
                        else         //Если сток справа
                        {
                            for (var j = Boundaries[i * 5 + 1]; j < Boundaries[i * 5 + 3]; j++)
                            {
                                VelocityX[VelocityX.GetLength(0), j] = VelocityX[VelocityX.GetLength(0) - 1, j];
                                VelocityY[VelocityY.GetLength(0), j] = VelocityY[VelocityY.GetLength(0) - 1, j];
                            }
                        }
                    }
                    else                                //Если сток горизонтальный
                    {
                        if (Boundaries[i * 5 + 1] == 0) //Если сток сверху
                        {
                            for (var j = Boundaries[i * 5 + 2]; j < Boundaries[i * 5 + 4]; j++)
                            {
                                VelocityX[j, 0] = VelocityX[j, 1];
                                VelocityY[j, 0] = VelocityY[j, 1];
                            }
                        }
                        else         //Если сток снизу
                        {
                            for (var j = Boundaries[i * 5 + 2]; j < Boundaries[i * 5 + 4]; j++)
                            {
                                VelocityX[j, VelocityX.GetLength(1)] = VelocityX[j, VelocityX.GetLength(1) - 1];
                                VelocityY[j, VelocityX.GetLength(1)] = VelocityY[j, VelocityX.GetLength(1) - 1];
                            }
                        }
                    }
                    break;
                }

                case BoundaryCondition.SolidWall:
                {
                    //Знак_вопроса
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
        protected int Collision(TestScreen parent)
        {
            int Result = 0;

            bool flag = false;

            foreach (GameObject o in parent.Objects)
            {
                if (o is Block)
                {
                    switch (Rectangle.OverlapTestEX(o.Rectangle))
                    {
                    case 1:
                        VelocityX = 0;
                        X         = o.X + o.Width;
                        Result    = 1;
                        break;

                    case 2:
                        VelocityX = 0;
                        X         = o.X - Rectangle.Width;
                        Result    = 2;
                        break;

                    case 3:
                        VelocityY = 0;
                        //jumpStep = 0;
                        Y      = o.Y + o.Height;
                        Result = 3;
                        break;

                    case 4:
                        if (VelocityY > 0)
                        {
                            flag   = true;
                            Y      = o.Y - Rectangle.Height;
                            Result = 4;
                        }

                        break;
                    }

                    if (flag)
                    {
                        VelocityY = 0;
                        //jumpStep = 0;
                    }


                    DebugMessage = " vx:" + VelocityX.ToString();
                }
                else if (o is Slope)
                {
                    int res = Rectangle.OverlapTestEX(o.Rectangle);
                    if (((Slope)o).Mode == 1)
                    {
                        if (res != 0 && Rectangle.Y + Rectangle.Height > o.Rectangle.Y + o.Rectangle.Height - ((Slope)o).getY(Rectangle.X + Rectangle.Width - o.Rectangle.X))
                        {
                            if (res == 1)
                            {
                                VelocityX = 0;
                                X         = o.Rectangle.X + o.Rectangle.Width;
                                Result    = 1;
                            }
                            else
                            {
                                Y = o.Rectangle.Y + o.Rectangle.Height - ((Slope)o).getY(Math.Abs(Rectangle.X + Rectangle.Width - o.Rectangle.X)) - Rectangle.Height;
                                o.DebugMessage = " X-ox:" + (Rectangle.X - o.Rectangle.X).ToString();
                                VelocityY      = 0;
                                //jumpStep = 0;
                                if (VelocityX > 0)
                                {
                                    VelocityX -= 10;
                                }
                                Result = 4;
                            }


                            DebugMessage = " " + res.ToString() + " X-ox:" + (Rectangle.X - o.Rectangle.X).ToString();

                            Result = res;
                        }
                    }
                    else if (((Slope)o).Mode == -1)
                    {
                        if (res != 0 && Rectangle.Y + Rectangle.Height > o.Rectangle.Y + o.Rectangle.Height - ((Slope)o).getY(Rectangle.X - o.Rectangle.X))
                        {
                            if (res == 2)
                            {
                                VelocityX = 0;
                                X         = o.Rectangle.X - Rectangle.Width;
                                Result    = 1;
                            }
                            else
                            {
                                Y = o.Rectangle.Y + o.Rectangle.Height - ((Slope)o).getY(Rectangle.X - o.Rectangle.X) - Rectangle.Height;
                                o.DebugMessage = " X-ox:" + (Rectangle.X - o.Rectangle.X).ToString();

                                VelocityY = 0;
                                //jumpStep = 0;
                                if (VelocityX < 0)
                                {
                                    VelocityX += 10;
                                }
                                Result = 4;
                            }


                            DebugMessage = " " + res.ToString() + " X-ox:" + (Rectangle.X - o.Rectangle.X).ToString();
                        }
                    }
                }
                else if (o is Floor)
                {
                    if (Rectangle.OverlapTestEX(o.Rectangle) == 4 && VelocityY > 0)
                    {
                        //if (VelocityY > 101) Console.WriteLine("Y:" + VelocityY.ToString());
                        VelocityY = 0;
                        Y         = o.Y - Height;
                        //jumpStep = 0;
                        Result = 4;
                    }
                }
            }

            return(Result);
        }
Example #9
0
        /********************************************************************************************
        * Public members, functions and properties
        ********************************************************************************************/

        public void Advance(
            double newTime
            )
        {
            LinearInterpolation2D interpT  = new LinearInterpolation2D(System.XAxis, System.YAxis, Temperature.GetValues());
            LinearInterpolation2D interpVX = new LinearInterpolation2D(System.XAxis, System.YAxis, VelocityX.GetValues());
            LinearInterpolation2D interpVY = new LinearInterpolation2D(System.XAxis, System.YAxis, VelocityY.GetValues());
            LinearInterpolation2D interpE  = new LinearInterpolation2D(System.XAxis, System.YAxis, ElectricField.GetValues());
            LinearInterpolation2D interpB  = new LinearInterpolation2D(System.XAxis, System.YAxis, MagneticField.GetValues());

            SetValues((xIndex, yIndex, pTIndex, stateIndex) =>
            {
                if (!IsStateAlreadyFormed(pTIndex, stateIndex, newTime))
                {
                    return(0);
                }
                else
                {
                    GetQQStateCoordinates(xIndex, yIndex, pTIndex, stateIndex, newTime,
                                          out double x, out double y);

                    if (!IsInDomainOfCalculation(x, y))
                    {
                        return(0);
                    }
                    else
                    {
                        double vQGP = Math.Sqrt(Math.Pow(interpVX.GetValue(x, y), 2)
                                                + Math.Pow(interpVY.GetValue(x, y), 2));

                        return(GetDecayWidth(
                                   (BottomiumState)stateIndex,
                                   interpT.GetValue(x, y),
                                   GetRelativeVelocityInQQFrame(BetaT[pTIndex, stateIndex], vQGP),
                                   interpE.GetValue(x, y),
                                   interpB.GetValue(x, y)) / GammaT[pTIndex, stateIndex]);
                    }
                }
            });
        }
        public override void Update(double deltaTime)
        {
            base.Update(deltaTime);
            if (dead)
            {
                goto last;
            }
            if (Input.onKeyDown(Keys.LeftShift))
            {
                Y += 50; Height = 50;
            }
            if (Input.IsKeyDown(Keys.LeftShift))
            {
                Height = 50;
            }
            else
            {
                Height = 100;
            }

            if (Input.IsKeyDown(Keys.Left) && VelocityX > -500)
            {
                VelocityX -= 40;
            }
            else if (Input.IsKeyDown(Keys.Right) && VelocityX < 500)
            {
                VelocityX += 40;
            }
            else
            {
                if (VelocityX < -1)
                {
                    VelocityX += 20;
                }
                else if (VelocityX > 1)
                {
                    VelocityX -= 20;
                }

                if (VelocityX < 0.5 && VelocityX > -0.5)
                {
                    VelocityX = 0;
                }
            }


            bool flag = false;

            foreach (GameObject o in parent.Objects)
            {
                if (o is Block)
                {
                    switch (Rectangle.OverlapTestEX(o.Rectangle))
                    {
                    case 1:
                        VelocityX = 0;
                        X         = o.X + o.Width;
                        break;

                    case 2:
                        VelocityX = 0;
                        X         = o.X - Rectangle.Width;
                        break;

                    case 3:
                        VelocityY = 0;
                        jumpStep  = 0;
                        Y         = o.Y + o.Height;
                        break;

                    case 4:
                        if (VelocityY > 0)
                        {
                            flag = true;
                            Y    = o.Y - Rectangle.Height;
                        }

                        break;
                    }

                    if (flag)
                    {
                        VelocityY = 0;
                        jumpStep  = 0;
                    }


                    DebugMessage = " vx:" + VelocityX.ToString();
                }
                else if (o is Slope)
                {
                    int res = Rectangle.OverlapTestEX(o.Rectangle);
                    if (((Slope)o).Mode == 1)
                    {
                        if (res != 0 && Y + Height > o.Y + o.Height - ((Slope)o).getY(X + Width - o.X))
                        {
                            if (res == 1)
                            {
                                VelocityX = 0;
                                X         = o.X + o.Width;
                            }
                            else
                            {
                                Y = o.Y + o.Height - ((Slope)o).getY(Math.Abs(X + Width - o.X)) - Height;
                                o.DebugMessage = " X-ox:" + (X - o.X).ToString();
                                VelocityY      = 0;
                                jumpStep       = 0;
                                if (VelocityX > 0)
                                {
                                    VelocityX -= 10;
                                }
                            }


                            DebugMessage = " " + res.ToString();
                        }
                    }
                    else if (((Slope)o).Mode == -1)
                    {
                        if (res != 0 && Rectangle.Y + Rectangle.Height > o.Rectangle.Y + o.Rectangle.Height - ((Slope)o).getY(Rectangle.X - o.Rectangle.X))
                        {
                            if (res == 2)
                            {
                                VelocityX = 0;
                                X         = o.Rectangle.X - Rectangle.Width;
                            }
                            else
                            {
                                Y = o.Rectangle.Y + o.Rectangle.Height - ((Slope)o).getY(Rectangle.X - o.Rectangle.X) - Rectangle.Height;
                                o.DebugMessage = " X-ox:" + (Rectangle.X - o.Rectangle.X).ToString();

                                VelocityY = 0;
                                jumpStep  = 0;
                                if (VelocityX < 0)
                                {
                                    VelocityX += 10;
                                }
                            }


                            DebugMessage = " " + res.ToString() + " X-ox:" + (Rectangle.X - o.Rectangle.X).ToString();
                        }
                    }
                }
                else if (o is Floor)
                {
                    if (Rectangle.OverlapTestEX(o.Rectangle) == 4 && VelocityY > 0)
                    {
                        // if (VelocityY > 101) Console.WriteLine("Y:" + VelocityY.ToString());
                        VelocityY = 0;
                        Y         = o.Y - Height;
                        jumpStep  = 0;
                    }
                }
            }

            foreach (enemy o in parent.Enemys)
            {
                switch (Rectangle.OverlapTestEX(new Rectangle((int)o.X + 20, (int)o.Y + 20, (int)o.Width - 40, (int)o.Height - 20)))
                {
                case 1:
                case 2:
                case 3:
                    if (o.dead || VelocityY > 0)
                    {
                        break;
                    }
                    dead         = true;
                    parent.pause = true;
                    a.Enable     = true;
                    break;

                case 4:
                    if (o.dead)
                    {
                        break;
                    }
                    isStepped = true;
                    o.dead    = true;
                    VelocityY = -600;
                    break;
                }
            }


            if (Input.onKeyDown(Keys.Space) && jumpStep < 2)
            {
                VelocityY = -1500;
                jumpStep++;
            }
            if (Input.IsKeyDown(Keys.Space) && isStepped)
            {
                VelocityY = -2000;
            }

            if (X > 500)
            {
                parent.X = 500 - X;
            }

            isStepped = false;

last:

            if (Y > 1200)
            {
                parent.X = 0;
                X        = 0;
                Y        = 0;
                dead     = false;
            }
            if (dead)
            {
                Alpha = 0.5f;
            }
            else
            {
                Alpha = 1;
            }

            // Console.WriteLine("XX:" + X.ToString());
            // X += VelocityX * deltaTime;
            //  Y += VelocityY * deltaTime;
        }