1

目前,我可以绘制两条线段并让它们相交。

我想做的事:

我希望能够通过单击线的端点或线本身并向左或向右拖动来围绕交叉点旋转两个相交的线段中的任何一个。

这是我到目前为止所拥有的:

   //Shift coordinate system so that origin is at the point of rotation, do the rotation and then shift the coordinate system
   //back to original intersection poiint
   public Vector2 RotateLineAboutIntersectionPoint(Vector2 intersectionPoint, Line line, Vector2 mousePosition)
   {
       double angle = Math.Atan2(mousePosition.y - intersectionPoint.y, mousePosition.x - intersectionPoint.x);
       double newPointOne = (line.point1.x - intersectionPoint.x) * Math.Cos(angle) - (line.point1.y - intersectionPoint.y) * Math.Sin(angle) + intersectionPoint.x;
       double newPointTwo = (line.point1.x - intersectionPoint.x) * Math.Sin(angle) + (line.point1.y - intersectionPoint.y) * Math.Cos(angle) + intersectionPoint.y;

       return new Vector2((float)newPointOne,(float)newPointTwo);
   }

我认为我的公式是正确的,问题是拖动/旋转/缩放我的线时鼠标位置没有更新。线路卡在同一个地方。

也就是说,我需要跟踪鼠标在“点击”事件中的位置,然后从我为新鼠标位置计算的角度中减去该点的角度。我怎么做?

编辑:

我在更新中有我的鼠标位置。

Update() {

   Vector3 mousePos = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -transform.position.z));
}
4

0 回答 0