I need to know what math I need to check if the mouse is moving clockwise or counterclockwise. I am not sure where to start with this…
EDIT: A little more detail, though, I have figured out this tends to scare away answers, so I try to avoid having a big block of info…
This all may be a very bad way of doing this, so if you know a better way, don’t be afraid to change it all.
What I am trying to do is create a rotation manipulator much like Maya’s. The camera can view it from any angle, so it is quite confusing. But here is what I have done so far
//"this" is the rotation maninpulator
Vector3 manipPos = ManipulatorCamera.WorldToScreenPoint(this.transform.position);
float o = Vector3.Distance(Input.mousePosition, mousePositionLastFrame);
float a = Vector3.Distance(mousePositionLastFrame, manipPos);
float angle = Mathf.Rad2Deg*Mathf.Atan(o/a)*GetDirection(manipPos,Input.mousePosition,mousePositionLastFrame);
Managers.SelectionManager.SelectedSmartPart.transform.localEulerAngles = new Vector3(
Managers.SelectionManager.SelectedSmartPart.transform.localEulerAngles.x,
Managers.SelectionManager.SelectedSmartPart.transform.localEulerAngles.y,
Managers.SelectionManager.SelectedSmartPart.transform.localEulerAngles.z + angle
);
mousePositionLastFrame = Input.mousePosition;
Since direction is always positive, I have to figure out the direction. GetDirection is defined as
private int GetDirection(Vector3 manipPos, Vector3 newMousePos, Vector3 oldMousePos)
{
//Where in the coordinate system compared to the manipPos
//is the mouse
Vector3 coord = newMousePos - manipPos;
//Gets the direction
Vector3 dir = newMousePos - oldMousePos;
if(coord.x >= 0 && coord.y >= 0)
{
if(dir.x >= 0 && dir.y <= 0)
return -1;
else if(dir.x <= 0 && dir.y >= 0)
return 1;
}
else if(coord.x >= 0 && coord.y <= 0)
{
if(dir.x <= 0 && dir.y <= 0)
return -1;
else if(dir.x >= 0 && dir.y >= 0)
return 1;
}
else if(coord.x <= 0 && coord.y <= 0)
{
if(dir.x <= 0 && dir.y >= 0)
return -1;
else if(dir.x >= 0 && dir.y <= 0)
return 1;
}
else
{
if(dir.x >= 0 && dir.y >= 0)
return -1;
else if(dir.x <= 0 && dir.y <= 0)
return 1;
}
return 0;
}
But this gets really messed up at each 90 degree angle because this assumes you are moving in a perfect circle. There has to be a better way. Any ideas?