public static void sincos(out IntFactor s, out IntFactor c, IntFactor angle) { int index = IntSinCosTable.getIndex(angle.numerator, angle.denominator); s = new IntFactor((long)IntSinCosTable.sin_table[index], (long)IntSinCosTable.FACTOR); c = new IntFactor((long)IntSinCosTable.cos_table[index], (long)IntSinCosTable.FACTOR); }
public static void sincos(out IntFactor s, out IntFactor c, long nom, long den) { int index = IntSinCosTable.getIndex(nom, den); s = new IntFactor((long)IntSinCosTable.sin_table[index], (long)IntSinCosTable.FACTOR); c = new IntFactor((long)IntSinCosTable.cos_table[index], (long)IntSinCosTable.FACTOR); }
public IntFactor GetCosineAngle(Int3 dest, out int edgeIndex) { Int3 vInt = this.v1 - this.v0; Int3 vInt2 = this.v2 - this.v0; Int3 vInt3 = dest - this.v0; vInt3.NormalizeTo(1000); vInt.NormalizeTo(1000); vInt2.NormalizeTo(1000); long num = Int3.DotXZLong(ref vInt3, ref vInt); long num2 = Int3.DotXZLong(ref vInt3, ref vInt2); IntFactor result = default(IntFactor); result.denominator = 1000000L; if (num > num2) { edgeIndex = this.vi; result.numerator = num; } else { edgeIndex = (this.vi + 2) % 3; result.numerator = num2; } return(result); }
public Int3 RotateY(ref IntFactor radians) { IntFactor IntVectorFactor; IntFactor IntVectorFactor2; IntMath.sincos(out IntVectorFactor, out IntVectorFactor2, radians.numerator, radians.denominator); long num = IntVectorFactor2.numerator * IntVectorFactor.denominator; long num2 = IntVectorFactor2.denominator * IntVectorFactor.numerator; long b = IntVectorFactor2.denominator * IntVectorFactor.denominator; Int3 vInt; vInt.x = (int)IntMath.Divide((long)this.x * num + (long)this.z * num2, b); vInt.z = (int)IntMath.Divide((long)(-(long)this.x) * num2 + (long)this.z * num, b); vInt.y = 0; return(vInt.NormalizeTo(1000)); }
private static void getMinMax(out int min, out int max, long axis, ref IntFactor factor) { long num = axis * factor.numerator; int num2 = (int)(num / factor.denominator); if (num < 0L) { min = num2 - 1; max = num2; } else { min = num2; max = num2 + 1; } }
public static Int3 Lerp(Int3 a, Int3 b, IntFactor f) { return(new Int3((int)IntMath.Divide((long)(b.x - a.x) * f.numerator, f.denominator) + a.x, (int)IntMath.Divide((long)(b.y - a.y) * f.numerator, f.denominator) + a.y, (int)IntMath.Divide((long)(b.z - a.z) * f.numerator, f.denominator) + a.z)); }
private static void MoveFromNode(TriangleMeshNode node, int startEdge, Int3 srcLoc, Int3 destLoc, out Int3 result) { result = srcLoc; while (node != null) { int count = 2; int i; if (node.IsVertex(srcLoc, out i)) { int vertexIndex = node.GetVertexIndex(i); List <PathfindingUtility.TMNodeInfo> list = null; PathfindingUtility.GetAllNodesByVert(ref list, node, vertexIndex); TriangleMeshNode triangleMeshNode = null; int num = -1; for (int j = 0; j < list.Count; j++) { PathfindingUtility.TMNodeInfo tMNodeInfo = list[j]; if (!PathfindingUtility.checkedNodes.Contains(tMNodeInfo.node) && !Polygon.LeftNotColinear(tMNodeInfo.v0, tMNodeInfo.v2, destLoc) && Polygon.Left(tMNodeInfo.v0, tMNodeInfo.v1, destLoc)) { triangleMeshNode = tMNodeInfo.node; num = tMNodeInfo.vi; break; } } if (triangleMeshNode != null) { node = triangleMeshNode; startEdge = (num + 1) % 3; count = 1; } else { int edge = -1; IntFactor b = new IntFactor { numerator = -2L, denominator = 1L }; for (int k = 0; k < list.Count; k++) { PathfindingUtility.TMNodeInfo tMNodeInfo2 = list[k]; if (!PathfindingUtility.checkedNodes.Contains(tMNodeInfo2.node)) { int num2; IntFactor cosineAngle = tMNodeInfo2.GetCosineAngle(destLoc, out num2); if (cosineAngle > b) { b = cosineAngle; edge = num2; triangleMeshNode = tMNodeInfo2.node; } } } if (triangleMeshNode != null) { PathfindingUtility.MoveAlongEdge(triangleMeshNode, edge, srcLoc, destLoc, out result, true); break; } } } int num3; if (startEdge == -1) { num3 = node.EdgeIntersect(srcLoc, destLoc); } else { num3 = node.EdgeIntersect(srcLoc, destLoc, startEdge, count); } if (num3 == -1) { if (node.ContainsPoint(destLoc)) { result = destLoc; if (PathfindingUtility.MoveAxisY) { PathfindingUtility.CalculateY(ref result, node); } } else { num3 = node.GetColinearEdge(srcLoc, destLoc); if (num3 != -1) { PathfindingUtility.MoveAlongEdge(node, num3, srcLoc, destLoc, out result, true); } } break; } int num4; TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(num3, out num4); if (neighborByEdge == null) { PathfindingUtility.MoveAlongEdge(node, num3, srcLoc, destLoc, out result, true); break; } node = neighborByEdge; startEdge = num4 + 1; } }
private static void MoveAlongEdge(TriangleMeshNode node, int edge, Int3 srcLoc, Int3 destLoc, out Int3 result, bool checkAnotherEdge = true) { Int3 vertex = node.GetVertex(edge); Int3 vertex2 = node.GetVertex((edge + 1) % 3); Int3 vInt = destLoc - srcLoc; vInt.y = 0; Int3 vInt2 = vertex2 - vertex; vInt2.y = 0; vInt2.NormalizeTo(1000); int num; num = vInt2.x * vInt.x + vInt2.z * vInt.z; bool flag; Int3 rhs = Polygon.IntersectionPoint(ref vertex, ref vertex2, ref srcLoc, ref destLoc, out flag); if (!flag) { if (!Polygon.IsColinear(vertex, vertex2, srcLoc) || !Polygon.IsColinear(vertex, vertex2, destLoc)) { result = srcLoc; return; } if (num >= 0) { int num2 = vInt2.x * (vertex2.x - vertex.x) + vInt2.z * (vertex2.z - vertex.z); int num3 = vInt2.x * (destLoc.x - vertex.x) + vInt2.z * (destLoc.z - vertex.z); rhs = ((num2 <= num3) ? vertex2 : destLoc); } else { int num4 = -vInt2.x * (vertex.x - vertex2.x) - vInt2.z * (vertex.z - vertex2.z); int num5 = -vInt2.x * (destLoc.x - vertex2.x) - vInt2.z * (destLoc.z - vertex2.z); rhs = ((Mathf.Abs(num4) <= Mathf.Abs(num5)) ? vertex : destLoc); } } int num6 = -IntMath.Sqrt(vertex.XZSqrMagnitude(rhs) * 1000000L); int num7 = IntMath.Sqrt(vertex2.XZSqrMagnitude(rhs) * 1000000L); if (num >= num6 && num <= num7) { result = IntMath.Divide(vInt2, (long)num, 1000000L) + rhs; if (!node.ContainsPoint(result)) { Vector3 vector = (Vector3)(vertex2 - vertex); vector.y = 0f; vector.Normalize(); Int3 lhs = vertex2 - vertex; lhs.y = 0; lhs *= 10000; long num8 = (long)lhs.magnitude; IntFactor vFactor = default(IntFactor); vFactor.numerator = (long)num; vFactor.denominator = num8 * 1000L; int num9; int num10; PathfindingUtility.getMinMax(out num9, out num10, (long)lhs.x, ref vFactor); int num11; int num12; PathfindingUtility.getMinMax(out num11, out num12, (long)lhs.z, ref vFactor); if (!PathfindingUtility.MakePointInTriangle(ref result, node, num9, num10, num11, num12, srcLoc) && !PathfindingUtility.MakePointInTriangle(ref result, node, num9 - 4, num10 + 4, num11 - 4, num12 + 4, srcLoc)) { result = srcLoc; } } if (PathfindingUtility.MoveAxisY) { PathfindingUtility.CalculateY(ref result, node); } } else { int rhs2; int edge2; Int3 vInt4; if (num < num6) { rhs2 = num - num6; edge2 = (edge + 2) % 3; vInt4 = vertex; } else { rhs2 = num - num7; edge2 = (edge + 1) % 3; vInt4 = vertex2; } Int3 vInt5 = vInt2 * rhs2 / 1000000f; int startEdge; TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(edge2, out startEdge); if (neighborByEdge != null) { PathfindingUtility.checkedNodes.Add(node); PathfindingUtility.MoveFromNode(neighborByEdge, startEdge, vInt4, vInt5 + vInt4, out result); } else { if (checkAnotherEdge) { Int3 vertex3 = node.GetVertex((edge + 2) % 3); Int3 lhs2 = (vertex3 - vInt4).NormalizeTo(1000); if (Int3.Dot(lhs2, vInt5) > 0) { PathfindingUtility.checkedNodes.Add(node); PathfindingUtility.MoveAlongEdge(node, edge2, vInt4, vInt5 + vInt4, out result, false); return; } } result = vInt4; } } }