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; }
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); }
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); }
/// <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); }