現在、2 つの線分を描画して交差させることができます。
私がしたいこと:
線の終点または線自体をクリックして左右にドラッグすることにより、交点を中心に2つの交差する線分のいずれかを回転できるようにしたいと考えています。
これが私がこれまでに持っているものです:
//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 にマウスの位置があります。
Update() {
Vector3 mousePos = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -transform.position.z));
}