Commit a96ed0e1 authored by Alexander Krause's avatar Alexander Krause

detection for rotation

parent 9bb38d3c
......@@ -17,7 +17,7 @@ namespace ExplorVizGestureControl.Gestures
{
public class ContinuousGestureDetector
{
#region Variables
#region Variables
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
private static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
......@@ -25,16 +25,16 @@ namespace ExplorVizGestureControl.Gestures
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
private const int MOUSEEVENTF_WHEEL = 0x0800;
private const int MOUSEEVENTF_WHEEL = 0x0800;
private GestureTimer scrollTimer;
private GestureTimer openObjectTimer;
internal static GestureTimer delayTimer;
private Boolean rotationActive = false;
private Boolean gripActive = false;
private Boolean gripActive = false;
private Dictionary<string, double> dynamicValues = new Dictionary<string, double>();
private Dictionary<string, double> dynamicValues = new Dictionary<string, double>();
#endregion
......@@ -64,7 +64,7 @@ namespace ExplorVizGestureControl.Gestures
HandleRotation();
HandleZoom();
if (IntersectWithPhIZ() || gripActive) HandleGripAndSelection();
if (IntersectWithPhIZ() || gripActive) HandleGripAndSelection();
}
......@@ -92,46 +92,55 @@ namespace ExplorVizGestureControl.Gestures
{
if (gripActive) return;
if (GestureDatabase.BothHandsParallel(2) &&
GestureDatabase.BothHandsAboveSpineBase())
if (!rotationActive)
{
if (!rotationActive)
if (GestureDatabase.ActivateRotation(2.0f))
{
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
rotationActive = true;
}
else { return; }
}
if (GestureDatabase.BothHandsParallel(2.0f))
{
/*if (!rotationActive)
{
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
rotationActive = true;
}
} */
double distanceZ = 0;
double distanceY = 0;
double distanceZHands = GestureDatabase.Joints[(int)JointType.HandLeft].Z - GestureDatabase.Joints[(int)JointType.HandRight].Z;
double distanceYHands = GestureDatabase.Joints[(int)JointType.HandLeft].Y - GestureDatabase.Joints[(int)JointType.HandRight].Y;
int yDetection = 0;
double handsAbsDistanceY = Math.Abs(Math.Abs(GestureDatabase.Joints[(int)JointType.HandLeft].Y) - Math.Abs(GestureDatabase.Joints[(int)JointType.HandRight].Y));
if (handsAbsDistanceY > 0.12) yDetection = 500;
distanceZ = distanceZHands - (GestureDatabase.PreviousFrameJoints[(int)JointType.HandLeft].Z - GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].Z);
distanceY = distanceYHands - (GestureDatabase.PreviousFrameJoints[(int)JointType.HandLeft].Y - GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].Y);
int moveX = (int)(distanceZ * 1000);
int moveY = (int)(distanceY * yDetection);
int moveY = (int)(distanceY * yDetection);
//////
Console.WriteLine(distanceZ);
//Console.WriteLine(distanceZ);
/* if (!rotationActive) oldX = moveX;
/* if (!rotationActive) oldX = moveX;
if (Math.Abs(Math.Abs(moveX) - Math.Abs(oldX)) > 20)
{
Console.WriteLine("active");
oldX = moveX;
moveX = 0;
}
if (Math.Abs(Math.Abs(moveX) - Math.Abs(oldX)) > 20)
{
Console.WriteLine("active");
oldX = moveX;
moveX = 0;
}
oldX = moveX;*/
oldX = moveX;*/
//////
......@@ -140,7 +149,7 @@ namespace ExplorVizGestureControl.Gestures
else if (rotationActive)
{
rotationActive = false;
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
}
}
......@@ -151,14 +160,14 @@ namespace ExplorVizGestureControl.Gestures
if (gripActive) return;
int scrollValue = 0;
double distance = GestureDatabase.Joints[(int)JointType.SpineBase].Z - GestureDatabase.PreviousFrameJoints[(int)JointType.SpineBase].Z;
double distance = GestureDatabase.Joints[(int)JointType.SpineBase].Z - GestureDatabase.PreviousFrameJoints[(int)JointType.SpineBase].Z;
if (Math.Abs(distance) != dynamicValues["scrollForwardFactor"])
{
scrollValue = (int)(distance * dynamicValues["scrollAccelerationFactor"]);
}
if (scrollValue != 0 && !scrollTimer.busy)
if (scrollValue != 0 && !scrollTimer.busy)
{
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -scrollValue, 0);
scrollTimer.startTimer();
......@@ -190,21 +199,21 @@ namespace ExplorVizGestureControl.Gestures
double distanceX = GestureDatabase.Joints[(int)JointType.HandRight].X - GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].X;
double distanceY = GestureDatabase.Joints[(int)JointType.HandRight].Y - GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].Y;
int moveX = (int)(distanceX * 1000);
int moveY = (int)(distanceY * 1000);
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y) + new Size(moveX, -moveY);
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y) + new Size(moveX, -moveY);
}
else if (gripActive)
{
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
gripActive = false;
gripActive = false;
openObjectTimer.startTimer();
}
}
}
}
......@@ -179,24 +179,12 @@ namespace ExplorVizGestureControl.Gestures
return LeftHandClosed() && RightHandClosed();
}
public static Boolean BothHandsParallel(double maxDistanceInX)
public static Boolean BothHandsParallel(float maxDistanceInX)
{
/*return (Math.Abs(joints[(int)JointType.HandRight].X - joints[(int)JointType.HandLeft].X) < maxDistanceInX &&
return (Math.Abs(joints[(int)JointType.HandRight].X - joints[(int)JointType.HandLeft].X) < maxDistanceInX &&
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Y) - Math.Abs(joints[(int)JointType.HandLeft].Y)) < 0.3 &&
Math.Abs(joints[(int)JointType.HandRight].Z - joints[(int)JointType.HandLeft].Z) < 0.3);*/
double vectorLengthHandRight = Math.Sqrt(Math.Pow(joints[(int)JointType.HandRight].X, 2) +
Math.Pow(joints[(int)JointType.HandRight].Y, 2) +
Math.Pow(joints[(int)JointType.HandRight].Z, 2));
double vectorLengthHandLeft = Math.Sqrt(Math.Pow(joints[(int)JointType.HandLeft].X, 2) +
Math.Pow(joints[(int)JointType.HandLeft].Y, 2) +
Math.Pow(joints[(int)JointType.HandLeft].Z, 2));
Console.WriteLine(vectorLengthHandRight - vectorLengthHandLeft);
return false;
}
Math.Abs(joints[(int)JointType.HandRight].Z - joints[(int)JointType.HandLeft].Z) < 0.3);
}
public static Boolean BothHandsAboveHead()
{
......@@ -210,7 +198,6 @@ namespace ExplorVizGestureControl.Gestures
joints[(int)JointType.HandRight].Y > joints[(int)JointType.SpineBase].Y;
}
public static Boolean HandsHaveAcceptableDistance(double offset = 0.0, char axis = 'x')
{
if (axis.Equals('x')) return Math.Abs(Math.Abs(joints[(int)JointType.HandLeft].X) -
......@@ -243,6 +230,13 @@ namespace ExplorVizGestureControl.Gestures
return LeftHandBelowLeftShoulder() && LeftHandClosed() && RightHandClosed();
}
public static Boolean ActivateRotation(float maxDistanceX = 1.0f)
{
return (Math.Abs(Math.Abs(joints[(int)JointType.HandRight].X) - Math.Abs(joints[(int)JointType.HandLeft].X)) < maxDistanceX &&
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Y) - Math.Abs(joints[(int)JointType.HandLeft].Y)) < 0.05f &&
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Z) - Math.Abs(joints[(int)JointType.HandLeft].Z)) < 0.05f);
}
public static Boolean StartOrReset()
{
Boolean[] confidenceArray = new Boolean[maxCapacity];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment