Currently, I can draw two line segments and have them intersect.
What I want to do:
I would like to be able to rotate either of the two intersecting line segments about the intersection point by clicking on the endpoint of the line or the line itself and dragging it left or right.
Here's what I have so far:
//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);
}
I think the formula I have is correct, the problem is the mouse position doesn't get updated when dragging/rotating/scaling my line. The line is stuck in the same place.
That is, I need to track where the mouse was at the "click" event, and then subtract the angle of that point from the angle I'm computing for the new mouse position. How do I do that?
EDIT:
I have my mouse position in Update.
Update() {
Vector3 mousePos = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -transform.position.z));
}