private float FindClosestOffset(TreeData data, Matrix4x4 objMatrix, TreeNode node, Ray mouseRay, ref float rotation) { TreeGroup group = data.GetGroup(node.groupID); if (group == null) { return 0f; } if (group.GetType() != typeof(TreeGroupBranch)) { return 0f; } data.ValidateReferences(); Matrix4x4 matrixx = objMatrix * node.matrix; float num2 = 1f / (node.spline.GetNodeCount() * 10f); float time = 0f; float num4 = 1E+07f; Vector3 zero = Vector3.zero; Vector3 closestRay = Vector3.zero; Vector3 vector3 = matrixx.MultiplyPoint(node.spline.GetPositionAtTime(0f)); for (float i = num2; i <= 1f; i += num2) { Vector3 vector4 = matrixx.MultiplyPoint(node.spline.GetPositionAtTime(i)); float squaredDist = 0f; float s = 0f; zero = MathUtils.ClosestPtSegmentRay(vector3, vector4, mouseRay, out squaredDist, out s, out closestRay); if (squaredDist < num4) { time = (i - num2) + (num2 * s); num4 = squaredDist; float radiusAtTime = node.GetRadiusAtTime(time); float t = 0f; if (MathUtils.ClosestPtRaySphere(mouseRay, zero, radiusAtTime, ref t, ref closestRay)) { Matrix4x4 matrixx3 = matrixx * node.GetLocalMatrixAtTime(time); Matrix4x4 inverse = matrixx3.inverse; Vector3 v = closestRay - zero; v = inverse.MultiplyVector(v); rotation = Mathf.Atan2(v.x, v.z) * 57.29578f; } } vector3 = vector4; } data.ClearReferences(); return time; }
private float FindClosestOffset(TreeData data, Matrix4x4 objMatrix, TreeNode node, Ray mouseRay, ref float rotation) { TreeGroup group = data.GetGroup(node.groupID); if (group == null) { return 0f; } if (group.GetType() != typeof(TreeGroupBranch)) { return 0f; } data.ValidateReferences(); Matrix4x4 lhs = objMatrix * node.matrix; float num = 1f / ((float)node.spline.GetNodeCount() * 10f); float num2 = 0f; float num3 = 1E+07f; Vector3 vector = Vector3.zero; Vector3 zero = Vector3.zero; Vector3 p = lhs.MultiplyPoint(node.spline.GetPositionAtTime(0f)); for (float num4 = num; num4 <= 1f; num4 += num) { Vector3 vector2 = lhs.MultiplyPoint(node.spline.GetPositionAtTime(num4)); float num5 = 0f; float num6 = 0f; vector = MathUtils.ClosestPtSegmentRay(p, vector2, mouseRay, out num5, out num6, out zero); if (num5 < num3) { num2 = num4 - num + num * num6; num3 = num5; float radiusAtTime = node.GetRadiusAtTime(num2); float num7 = 0f; if (MathUtils.ClosestPtRaySphere(mouseRay, vector, radiusAtTime, ref num7, ref zero)) { Matrix4x4 inverse = (lhs * node.GetLocalMatrixAtTime(num2)).inverse; Vector3 v = zero - vector; v = inverse.MultiplyVector(v); rotation = Mathf.Atan2(v.x, v.z) * 57.29578f; } } p = vector2; } data.ClearReferences(); return num2; }