Exemple #1
0
 /// <summary>
 /// 设置一个单弧线
 /// </summary>
 /// <param name="ani"></param>
 /// <param name="r">弧度0-180</param>
 public static AnimatBase SetArc(AnimatBase ani, float r)
 {
     ani.DataCache    = new float[3];
     ani.DataCache[0] = r;                         //弧度
     ani.DataCache[1] = 270 - r * 0.5f;            //起始弧度
     ani.DataCache[2] = MathH.Cos(270 + r * 0.5f); //弧度总长
     ani.Linear       = Arc;
     return(ani);
 }
Exemple #2
0
        public static void RotatePoint2(ref Vector2 p, ref Vector2 location, float angle, ref Vector3 o)//a=绝对角度 d=直径
        {
            int a = (int)(p.x + angle);

            if (a < 0)
            {
                a += 360;
            }
            if (a > 360)
            {
                a -= 360;
            }
            float d = p.y;

            o.x = location.x - MathH.Sin(a) * d;
            o.y = location.y + MathH.Cos(a) * d;
        }
Exemple #3
0
 public static Vector2[] RotatePoint2(ref Vector2[] P, Vector2 location, float angle)//p[].x=绝对角度 p[].y=直径
 {
     Vector2[] temp = new Vector2[P.Length];
     for (int i = 0; i < P.Length; i++)
     {
         int a = (int)(P[i].x + angle);//change angle to radin
         if (a < 0)
         {
             a += 360;
         }
         if (a >= 360)
         {
             a -= 360;
         }
         temp[i].x = location.x - MathH.Sin(a) * P[i].y;
         temp[i].y = location.y + MathH.Cos(a) * P[i].y;
     }
     return(temp);
 }
Exemple #4
0
        public static Vector3 RotateVector3(Vector2 p, ref Vector3 location, float angle)//a=绝对角度 d=直径
        {
            int a = (int)(p.x + angle);

            if (a < 0)
            {
                a += 360;
            }
            if (a > 360)
            {
                a -= 360;
            }
            float   d    = p.y;
            Vector3 temp = location;

            temp.x = location.x - MathH.Sin(a) * d;
            temp.y = location.y + MathH.Cos(a) * d;
            return(temp);
        }
Exemple #5
0
        /// <summary>
        /// 创建一个圆锥,返回顶点和三角形
        /// </summary>
        /// <param name="r">半径</param>
        /// <param name="h">高度</param>
        /// <param name="arc">三角形弧度,越小精度越高,范围0-360取整</param>
        /// <returns>顶点,三角形</returns>
        public static ConeData CreateCone(float r, float h, float arc)
        {
            int a  = (int)arc;
            int c  = 360 / a;
            int vc = c + 2;

            Vector3[] vertex = new Vector3[vc];
            int[]     tri    = new int[c * 6];
            int       o      = c;
            int       s      = 0;
            int       i      = 0;

            for (; i < c; i++)
            {
                vertex[i].x    = -MathH.Sin(s) * r;
                vertex[i].z    = MathH.Cos(s) * r;
                tri[i * 3]     = i + 1;
                tri[i * 3 + 1] = c;
                tri[i * 3 + 2] = i;
                tri[o * 3]     = i;
                tri[o * 3 + 1] = c + 1;
                tri[o * 3 + 2] = i + 1;
                o++;
                s += a;
            }
            i--;
            o--;
            vertex[c + 1].y = h;
            tri[i * 3]      = 0;
            tri[o * 3 + 2]  = 0;
            ConeData cd = new ConeData();

            cd.Vertex = vertex;
            cd.Tri    = tri;
            return(cd);
        }
Exemple #6
0
        static float Arc(AnimatBase ani, float a)
        {
            float s = ani.DataCache[1] + a * ani.DataCache[0];

            return(0.5f + 0.5f * MathH.Cos(s) / ani.DataCache[2]);//180-360 -1到1之间
        }