コード例 #1
0
        static void Main(string[] args)
        {
/*
 *          WriteLine(MyMath.Abs(52));
 *          WriteLine(MyMath.Abs(-273));
 */
            MyMath myMath = new MyMath();

            WriteLine(myMath.Abs(52));
            WriteLine(myMath.Abs(-273));
        }
コード例 #2
0
 public void Update()
 {
     if (Value != ValueToGo)
     {
         Value = MyMath.AdjustValue(Value, MyMath.Abs(ValueToGo - Value) * Friction + BasicSpeed, ValueToGo);
     }
 }
コード例 #3
0
        public override bool IsIn(IEventArgs args, UnitPosition entity)
        {
            bool isIn = false;

            foreach (MapConfigPoints.ID_Point p in MapConfigPoints.current.IDPints)
            {
                if (p.ID == FreeUtil.ReplaceInt(type, args))
                {
                    foreach (MapConfigPoints.SavedPointData spd in p.points)
                    {
                        float dx = MyMath.Abs(entity.GetX() - spd.pos.x);
                        float dz = MyMath.Abs(entity.GetZ() - spd.pos.z);
                        float dy = MyMath.Abs(entity.GetY() - spd.pos.y);
                        if (dx * dx + dz * dz <= spd.cylinderVolR * spd.cylinderVolR && dy <= spd.cylinderVolH)
                        {
                            isIn = true;
                            break;
                        }
                    }

                    if (isIn)
                    {
                        break;
                    }
                }
            }

            if (useOut)
            {
                return(!isIn);
            }

            return(isIn);
        }
コード例 #4
0
        /// <summary>
        /// 计算候选点6
        /// </summary>
        /// <param name="c">两个碰撞点</param>
        /// <param name="h"></param>
        /// <param name="pos"></param>
        /// <param name="Rot"></param>
        /// <param name="normal">此法向量为参考面的法向量</param>
        public static void ComputeIncidentEdge(ref ClipVertex[] c, Vector2f h, Vector2f pos, Mat22 Rot, Vector2f normal)
        {
            Mat22    RotT = Rot.Transpose();
            Vector2f n    = -(RotT * normal);
            Vector2f nAbs = MyMath.Abs(n);

            if (nAbs.x > nAbs.y)
            {
                if (MyMath.Sign(n.x) > 0.0f)
                {
                    c[0].v.Set(h.x, -h.y);
                    c[0].fp.e.inEdge2  = (char)EdgeNumbers.EDGE3;
                    c[0].fp.e.outEdge2 = (char)EdgeNumbers.EDGE4;

                    c[1].v.Set(h.x, h.y);
                    c[1].fp.e.inEdge2  = (char)EdgeNumbers.EDGE4;
                    c[1].fp.e.outEdge2 = (char)EdgeNumbers.EDGE1;
                }
                else
                {
                    c[0].v.Set(-h.x, h.y);
                    c[0].fp.e.inEdge2  = (char)EdgeNumbers.EDGE1;
                    c[0].fp.e.outEdge2 = (char)EdgeNumbers.EDGE2;

                    c[1].v.Set(-h.x, -h.y);
                    c[1].fp.e.inEdge2  = (char)EdgeNumbers.EDGE2;
                    c[1].fp.e.outEdge2 = (char)EdgeNumbers.EDGE3;
                }
            }
            else
            {
                if (MyMath.Sign(n.y) > 0.0f)
                {
                    c[0].v.Set(h.x, h.y);
                    c[0].fp.e.inEdge2  = (char)EdgeNumbers.EDGE4;
                    c[0].fp.e.outEdge2 = (char)EdgeNumbers.EDGE1;

                    c[1].v.Set(-h.x, h.y);
                    c[1].fp.e.inEdge2  = (char)EdgeNumbers.EDGE1;
                    c[1].fp.e.outEdge2 = (char)EdgeNumbers.EDGE2;
                }
                else
                {
                    c[0].v.Set(-h.x, -h.y);
                    c[0].fp.e.inEdge2  = (char)EdgeNumbers.EDGE2;
                    c[0].fp.e.outEdge2 = (char)EdgeNumbers.EDGE3;

                    c[1].v.Set(h.x, -h.y);
                    c[1].fp.e.inEdge2  = (char)EdgeNumbers.EDGE3;
                    c[1].fp.e.outEdge2 = (char)EdgeNumbers.EDGE4;
                }
            }

            c[0].v = pos + Rot * c[0].v;
            c[1].v = pos + Rot * c[1].v;
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: jhy0409/jhy0409
        private void button_abs_Click(object sender, EventArgs e)
        {
            int result;

            int.TryParse(textBox_input.Text, out result);
            MessageBox.Show(MyMath.Abs(result).ToString());
            double value;

            double.TryParse(textBox_input.Text, out value);
            MessageBox.Show(MyMath.Abs(value).ToString());
        }
コード例 #6
0
        public override bool IsIn(IEventArgs args, UnitPosition entity)
        {
            if (pos == null || change)
            {
                pos = selector.Select(args);
            }
            float r = 0f;

            try
            {
                r = float.Parse(radius);
            }
            catch (Exception)
            {
                r = FreeUtil.ReplaceFloat(radius, args);
            }

            double dx = MyMath.Abs(entity.GetX() - pos.GetX());

            if (dx > r)
            {
                if (useOut)
                {
                    return(true);
                }
                return(false);
            }
            double dz = MyMath.Abs(entity.GetZ() - pos.GetZ());

            if (dz > r)
            {
                if (useOut)
                {
                    return(true);
                }
                return(false);
            }
            double dy     = MyMath.Abs(entity.GetY() - pos.GetY());
            float  zrange = FreeUtil.ReplaceFloat(zRange, args);

            if (zrange <= 0)
            {
                zrange = 170;
            }

            bool isIn = (dx * dx + dz * dz) <= r * r && (dy < zrange);

            if (useOut)
            {
                return(!isIn);
            }
            return(isIn);
        }
コード例 #7
0
        static void Main(string[] args)
        {
            //int
            WriteLine(MyMath.Abs(52));
            WriteLine(MyMath.Abs(-273));

            //double
            WriteLine(MyMath.Abs(52.273));
            WriteLine(MyMath.Abs(-30.103));

            //long
            WriteLine(MyMath.Abs(21474836470));
            WriteLine(MyMath.Abs(-21474836470));
        }
コード例 #8
0
        static void Main(string[] args)
        {
            //int
            Console.WriteLine(MyMath.Abs(52));
            Console.WriteLine(MyMath.Abs(273));

            //double
            Console.WriteLine(MyMath.Abs(52.273));
            Console.WriteLine(MyMath.Abs(-3.236236));

            //long
            Console.WriteLine(MyMath.Abs(21474836470));
            Console.WriteLine(MyMath.Abs(-21474836470));
        }
コード例 #9
0
        public static void Main24(string[] args)
        {
            //int
            Console.WriteLine(MyMath.Abs(-589));
            Console.WriteLine(MyMath.Abs(589));

            //double
            Console.WriteLine(MyMath.Abs(53.323));
            Console.WriteLine(MyMath.Abs(-53.323));

            //long
            Console.WriteLine(MyMath.Abs(5212414534515134515));
            Console.WriteLine(MyMath.Abs(-5212414534515134515));
        }
コード例 #10
0
        public static void MovePosition(ItemInventory fromIn, ItemInventory toIn, SimpleInventoryUI fromUI, SimpleInventoryUI toUI, ItemPosition ip, int x, int y, ISkillArgs args)
        {
            FreeRuleEventArgs fr = (FreeRuleEventArgs)args;
            int oneX             = toUI.GetWidth(args) / toIn.GetColumn();
            int countX           = x / (oneX);
            int remain           = x % (oneX);

            if (fromIn == toIn)
            {
                if (MyMath.Abs(remain) > oneX / 2)
                {
                    if (remain > 0)
                    {
                        countX++;
                    }
                    else
                    {
                        countX--;
                    }
                }
                countX = countX + ip.GetX();
            }
            else
            {
                if (countX < 0)
                {
                    countX = 0;
                }
            }
            int oneY   = toUI.GetHeight(args) / toIn.GetRow();
            int countY = y / (oneY);

            remain = y % (oneY);
            if (fromIn == toIn)
            {
                if (MyMath.Abs(remain) > oneY / 2)
                {
                    if (remain > 0)
                    {
                        countY++;
                    }
                    else
                    {
                        countY--;
                    }
                }
                countY = countY + ip.GetY();
            }
            else
            {
                if (countY < 0)
                {
                    countY = 0;
                }
                //countY = toIn.row - countY - 1;
            }
            if (MoveOut(fromIn, toIn, ip, countX, countY, args, fr, fromUI, toUI))
            {
                return;
            }
            Move(fromIn, toIn, ip, countX, countY, args, fr, fromUI, toUI);
        }
コード例 #11
0
 static void Main23(string[] args)
 {
     Console.WriteLine(MyMath.Abs(500));
     //Console.WriteLine(MyMath.myValue); //인스턴스변수는 클래스메소드안에서는 실행 X
     Console.WriteLine(MyMath.myValue2);
 }
コード例 #12
0
        public void Abs_CorrectValues_ShouldBeOk(double number, double expected)
        {
            var actual = MyMath.Abs(number);

            Assert.AreEqual(expected, actual);
        }
コード例 #13
0
        public void Sqrt_CorrectValues_ShouldBeOk(double number, double root)
        {
            var actual = MyMath.Sqrt(number);

            Assert.IsTrue(MyMath.Abs(root - actual) < MyMath.Epsilon);
        }
コード例 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="contacts"> A 和 B 的接触点</param>
        /// <param name="bodyA"></param>
        /// <param name="bodyB"></param>
        /// <returns></returns>
        public static int Collide(ref Contact[] contacts, Body bodyA, Body bodyB)
        {
            // 初始化
            Vector2f hA = 0.5f * bodyA.width_height;
            Vector2f hB = 0.5f * bodyB.width_height;

            Vector2f posA = bodyA.position;
            Vector2f posB = bodyB.position;

            Mat22 RotA  = new Mat22(bodyA.rotation);
            Mat22 RotB  = new Mat22(bodyB.rotation);
            Mat22 RotAT = RotA.Transpose();
            Mat22 RotBT = RotB.Transpose();

            Vector2f dp = posB - posA;
            Vector2f dA = RotAT * dp;
            Vector2f dB = RotBT * dp;

            Mat22 C     = RotAT * RotB;
            Mat22 absC  = MyMath.Abs(C);
            Mat22 absCT = absC.Transpose();

            //dA是两个矩形终点连线的向量,做了Abs运算后,dA表示的只是数值意义。
            //实际上,下面的代码是Abs(dA) - (hA + absC * hB)
            //hA就是矩形A右上角的点,absC * hB就是求出B点在A矩形的局部坐标系下的四个顶点中
            //x,y方向上的最大值,因为dA,hA,hB都是从(0,0)点出发的向量,所以向量中的数值仅仅
            //表示数值意义
            //Abs(dA) - (hA + absC * hB)对于这个式子,如果只看x轴
            //实际上就是dA的x坐标表示两个矩形的中心连线在x轴投影长度为s,
            //hA是矩形A的x方向在中心连线的最大投影长度a,absC*hB就是矩形B的x方向在中心连线的最大投影长度b
            //如果s-a-b大于0,这说明投影不相交。
            // Box A faces
            Vector2f faceA = MyMath.Abs(dA) - hA - absC * hB;

            if (faceA.x > 0.0f || faceA.y > 0.0f)
            {
                return(0);
            }
            // Box B facesa
            Vector2f faceB = MyMath.Abs(dB) - absCT * hA - hB;

            if (faceB.x > 0.0f || faceB.y > 0.0f)
            {
                return(0);
            }
            // 找到最佳碰撞轴
            Axis  axis;
            float separation;


            // Box A faces
            axis       = Axis.FACE_A_X;
            separation = faceA.x;
            Vector2f normal = dA.x > 0.0f ? RotA.ex : -RotA.ex;

            const float relativeTol = 0.95f;
            const float absoluteTol = 0.05f;

            if (faceA.y > relativeTol * separation + absoluteTol * hA.y)
            {
                axis       = Axis.FACE_A_Y;
                separation = faceA.y;
                normal     = dA.y > 0.0f ? RotA.ey : -RotA.ey;
            }
            // Box B faces
            if (faceB.x > relativeTol * separation + absoluteTol * hB.x)
            {
                axis       = Axis.FACE_B_X;
                separation = faceB.x;
                normal     = dB.x > 0.0f ? RotB.ex : -RotB.ex;
            }

            if (faceB.y > relativeTol * separation + absoluteTol * hB.y)
            {
                axis       = Axis.FACE_B_Y;
                separation = faceB.y;
                normal     = dB.y > 0.0f ? RotB.ey : -RotB.ey;
            }
            // 根据分离轴初始化分离平面
            Vector2f frontNormal = new Vector2f();
            Vector2f sideNormal  = new Vector2f();

            ClipVertex[] incidentEdge = new ClipVertex[2];
            incidentEdge[0] = new ClipVertex();
            incidentEdge[1] = new ClipVertex();

            float front = 0.0f, negSide = 0.0f, posSide = 0.0f;
            char  negEdge = (char)EdgeNumbers.NO_EDGE, posEdge = (char)EdgeNumbers.NO_EDGE;

            // 计算分离线和要分离的线段
            switch (axis)
            {
            case Axis.FACE_A_X:
            {
                frontNormal = normal;
                front       = MyMath.Dot(posA, frontNormal) + hA.x;
                sideNormal  = RotA.ey;
                float side = MyMath.Dot(posA, sideNormal);
                negSide = -side + hA.y;
                posSide = side + hA.y;
                negEdge = (char)EdgeNumbers.EDGE3;
                posEdge = (char)EdgeNumbers.EDGE1;
                ComputeIncidentEdge(ref incidentEdge, hB, posB, RotB, frontNormal);
            }
            break;

            case Axis.FACE_A_Y:
            {
                frontNormal = normal;
                front       = MyMath.Dot(posA, frontNormal) + hA.y;
                sideNormal  = RotA.ex;
                float side = MyMath.Dot(posA, sideNormal);
                negSide = -side + hA.x;
                posSide = side + hA.x;
                negEdge = (char)EdgeNumbers.EDGE2;
                posEdge = (char)EdgeNumbers.EDGE4;
                ComputeIncidentEdge(ref incidentEdge, hB, posB, RotB, frontNormal);
            }
            break;

            case Axis.FACE_B_X:
            {
                frontNormal = -normal;
                front       = MyMath.Dot(posB, frontNormal) + hB.x;
                sideNormal  = RotB.ey;
                float side = MyMath.Dot(posB, sideNormal);
                negSide = -side + hB.y;
                posSide = side + hB.y;
                negEdge = (char)EdgeNumbers.EDGE3;
                posEdge = (char)EdgeNumbers.EDGE1;
                ComputeIncidentEdge(ref incidentEdge, hA, posA, RotA, frontNormal);
            }
            break;

            case Axis.FACE_B_Y:
            {
                frontNormal = -normal;
                front       = MyMath.Dot(posB, frontNormal) + hB.y;
                sideNormal  = RotB.ex;
                float side = MyMath.Dot(posB, sideNormal);
                negSide = -side + hB.x;
                posSide = side + hB.x;
                negEdge = (char)EdgeNumbers.EDGE2;
                posEdge = (char)EdgeNumbers.EDGE4;
                ComputeIncidentEdge(ref incidentEdge, hA, posA, RotA, frontNormal);
            }
            break;
            }
            // 分离其他面
            ClipVertex[] clipPoints1 = new ClipVertex[2];
            clipPoints1[0] = new ClipVertex();
            clipPoints1[1] = new ClipVertex();
            ClipVertex[] clipPoints2 = new ClipVertex[2];
            clipPoints2[0] = new ClipVertex();
            clipPoints2[1] = new ClipVertex();
            int np;

            // Clip to box side 1
            np = ClipSegmentToLine(ref clipPoints1, ref incidentEdge, -sideNormal, negSide, negEdge);

            if (np < 2)
            {
                return(0);
            }

            // Clip to negative box side 1
            np = ClipSegmentToLine(ref clipPoints2, ref clipPoints1, sideNormal, posSide, posEdge);

            if (np < 2)
            {
                return(0);
            }

            // Now clipPoints2 contains the clipping points.
            // 由于舍入,分离可能删去所有点

            int numContacts = 0;

            for (int i = 0; i < 2; ++i)
            {
                separation = MyMath.Dot(frontNormal, clipPoints2[i].v) - front;

                if (separation <= 0)
                {
                    contacts[numContacts].separation = separation;
                    contacts[numContacts].normal     = normal;
                    // slide contact point onto reference face (easy to cull)
                    contacts[numContacts].position = clipPoints2[i].v - separation * frontNormal;
                    contacts[numContacts].feature  = clipPoints2[i].fp;
                    if (axis == Axis.FACE_B_X || axis == Axis.FACE_B_Y)
                    {
                        Flip(contacts[numContacts].feature);
                    }
                    ++numContacts;
                }
            }
            return(numContacts);
        }
コード例 #15
0
 /// <summary>Returns the positive value of the value stored at index location 0.</summary>
 public virtual double Of(double[] d, int numParam)
 {
     return(MyMath.Abs(d[0]));
 }
コード例 #16
0
 static void Main(string[] args)
 {
     Console.WriteLine(MyMath.Abs(52));
     Console.WriteLine(MyMath.Abs(-273));
 }
コード例 #17
0
 public static double GetTimeBySecond(DateTime date1, DateTime date2)
 {
     return(MyMath.Abs((date1.Millisecond - date2.Millisecond)) / 1000);
 }