private void HandleMouseInputLocal()
{
Point mousePos;
mousePos = Control.MousePosition;
mousePos = PointToClient(mousePos);
g_mousePos.X = mousePos.X;
g_mousePos.Y = mousePos.Y;
if (g_bMousePressed)
{
int nXDiff = -(g_mousePos.X - g_LastmousePos.X);
int nYDiff = -(g_mousePos.Y - g_LastmousePos.Y);
Matrix matWorld;
if (g_eClick != EClickPos.Outside)
{
if( 0 != nYDiff && g_eClick != EClickPos.CircleHor)
{
Vector3 v = new Vector3(1.0f,0.0f,0.0f);
matWorld = Matrix.RotationAxis(v, Geometry.DegreeToRadian((float)nYDiff / 2.0f));
g_mWorldRotate = g_mWorldRotate * matWorld;
}
if( 0 != nXDiff && g_eClick != EClickPos.CircleVert)
{
Vector3 v = new Vector3(0.0f,1.0f,0.0f);
matWorld = Matrix.RotationAxis(v, Geometry.DegreeToRadian((float)nXDiff / 2.0f));
g_mWorldRotate = g_mWorldRotate * matWorld;
}
}
else
{
if(0 != nYDiff || 0 != nXDiff)
{
var sRect = new Rectangle(Point.Empty, this.Size);
// rotate around the z-axis
int xPos = g_mousePos.X - sRect.Right/2;
int yPos = g_mousePos.Y - sRect.Bottom/2;
float fXDist = (float)xPos;
float fYDist = (float)yPos / (float)Math.Sqrt(yPos * yPos + xPos * xPos);
bool bSign1;
if (fXDist < 0.0f)bSign1 = false;
else bSign1 = true;
float fAngle = (float)Math.Asin(fYDist);
xPos = g_LastmousePos.X - sRect.Right/2;
yPos = g_LastmousePos.Y - sRect.Bottom/2;
fXDist = (float)xPos;
fYDist = (float)yPos / (float)Math.Sqrt(yPos * yPos + xPos * xPos);
bool bSign2;
if (fXDist < 0.0f)bSign2 = false;
else bSign2 = true;
float fAngle2 = (float)Math.Asin(fYDist);
fAngle -= fAngle2;
if (bSign1 != bSign2)
{
g_bInvert = !g_bInvert;
}
if (g_bInvert)fAngle *= -1.0f;
Vector3 v = new Vector3(0.0f, 0.0f, 1.0f);
matWorld = Matrix.RotationAxis(v, (float)(fAngle * 1.2));
g_mWorldRotate = g_mWorldRotate * matWorld;
}
}
}
g_LastmousePos.X = g_mousePos.X;
g_LastmousePos.Y = g_mousePos.Y;
}