public void Forward(float value) { var vec = _root.Vector + _mid.Vector; var target = vec.magnitude + value; if (target > _root.Vector.magnitude + _mid.Vector.magnitude) { return; } if (Fix()) { return; } // 利用三角函数计算出要移动的角度,相对法线进行移动 { var old = Kit.Angle(_root.Vector.magnitude, vec.magnitude, _mid.Vector.magnitude); var now = Kit.Angle(_root.Vector.magnitude, target, _mid.Vector.magnitude); var angle = old - now; var axis = Vector3.Cross(_root.Vector, _mid.Vector).normalized; _root.RotateAround(_root.Transform.position, axis, angle); } { var old = Kit.Angle(_root.Vector.magnitude, _mid.Vector.magnitude, vec.magnitude); var now = Kit.Angle(_root.Vector.magnitude, _mid.Vector.magnitude, target); var angle = old - now; var axis = Vector3.Cross(_root.Vector, _mid.Vector).normalized; _mid.RotateAround(_mid.Transform.position, axis, angle); } }
public static void Forward(IFkJoint root, IFkJoint end, float value) { var vec = root.Vector + end.Vector; var target = vec.magnitude + value; if (target > root.Vector.magnitude + end.Vector.magnitude) { return; } { var old = Kit.Angle(root.Vector.magnitude, vec.magnitude, end.Vector.magnitude); var now = Kit.Angle(root.Vector.magnitude, target, end.Vector.magnitude); var angle = old - now; var axis = Vector3.Cross(root.Vector, end.Vector).normalized; root.RotateAround(root.Transform.position, axis, angle); } { var old = Kit.Angle(root.Vector.magnitude, end.Vector.magnitude, vec.magnitude); var now = Kit.Angle(root.Vector.magnitude, end.Vector.magnitude, target); var angle = old - now; var axis = Vector3.Cross(root.Vector, end.Vector).normalized; end.RotateAround(end.Transform.position, axis, angle); } }