Commit f64bc143 authored by Alexander Krause's avatar Alexander Krause

again: overhaul of grip and selection.

parent 5eed1bba
......@@ -26,7 +26,7 @@ namespace ExplorVizGestureControl.General
#region Initialization
public GestureTimer(double timeSpan)
{
timer = new Timer(timeSpan);
timer = new Timer(timeSpan);
timer.AutoReset = false;
// Add the event handler for timer.Elapsed, to set the busy attribute on false. See OnElapsedTime()
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
......@@ -46,6 +46,12 @@ namespace ExplorVizGestureControl.General
timer.Stop();
timer.Start();
}
public void stopTimer()
{
busy = false;
timer.Stop();
}
/*
* OnElapsedTime defines the event, triggered, if the timer has ran out. In this case, busy is set back to false.
......
......@@ -27,17 +27,17 @@ namespace ExplorVizGestureControl.Gestures
private const int MOUSEEVENTF_RIGHTUP = 0x10;
private const int MOUSEEVENTF_WHEEL = 0x0800;
private GestureTimer scrollTimer;
private GestureTimer openObjectTimer;
private GestureTimer selectionObjectTimer;
private GestureTimer scrollTimer;
private GestureTimer selectionTimer;
internal static GestureTimer delayTimer;
private Boolean rotationActive = false;
private Boolean gripActive = false;
private Boolean selectionActive = false;
private Dictionary<string, double> dynamicValues = new Dictionary<string, double>();
private float rightHandAnchorLength;
#endregion
#region Constructor
......@@ -51,10 +51,9 @@ namespace ExplorVizGestureControl.Gestures
dynamicValues.Add("scrollBackwardFactor", 0.05);
dynamicValues.Add("zoomVelocity", 250);
scrollTimer = new GestureTimer(dynamicValues["zoomVelocity"]);
openObjectTimer = new GestureTimer(450);
scrollTimer = new GestureTimer(dynamicValues["zoomVelocity"]);
delayTimer = new GestureTimer(2000);
selectionObjectTimer = new GestureTimer(500);
selectionTimer = new GestureTimer(500);
}
#endregion
......@@ -88,7 +87,7 @@ namespace ExplorVizGestureControl.Gestures
if (key.Equals("zoomVelocity")) scrollTimer.changeTimerCycle(value);
}
private void HandleRotation()
{
......@@ -103,8 +102,8 @@ namespace ExplorVizGestureControl.Gestures
}
else { return; }
}
if (!GestureDatabase.LeftHandClosed() &&
if (!GestureDatabase.LeftHandClosed() &&
!GestureDatabase.HandsCrossed())
{
......@@ -132,7 +131,7 @@ namespace ExplorVizGestureControl.Gestures
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);
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y) + new Size(moveX, moveY);
}
......@@ -148,7 +147,7 @@ namespace ExplorVizGestureControl.Gestures
private void HandleZoom()
{
int scrollValue = 0;
double distance = GestureDatabase.Joints[(int)JointType.SpineBase].Z -
double distance = GestureDatabase.Joints[(int)JointType.SpineBase].Z -
GestureDatabase.PreviousFrameJoints[(int)JointType.SpineBase].Z;
if (Math.Abs(distance) != dynamicValues["scrollForwardFactor"])
......@@ -163,47 +162,61 @@ namespace ExplorVizGestureControl.Gestures
}
}
private int selectionStatus = 0;
private void HandleGripAndSelection()
{
if (rotationActive) return;
if (selectionObjectTimer.busy && !GestureDatabase.DragObject() && selectionActive)
if (!GestureDatabase.DragObject() && selectionStatus == 1)
{
selectionStatus = 2;
selectionTimer.startTimer();
}
if (!GestureDatabase.DragObject() && selectionStatus == 2 && !selectionTimer.busy)
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
selectionActive = false;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
selectionStatus = 0;
}
if (!GestureDatabase.DragObject() && selectionStatus == 3 && selectionTimer.busy)
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Thread.Sleep(150);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
selectionStatus = 0;
}
if (GestureDatabase.DragObject())
{
if (!selectionActive)
if (selectionStatus == 0)
{
selectionObjectTimer.startTimer();
selectionActive = true;
selectionStatus = 1;
rightHandAnchorLength = GestureDatabase.CalculateVectorLength(GestureDatabase.Joints[(int)JointType.HandRight]);
return;
}
float vLength = GestureDatabase.CalculateVectorLength(GestureDatabase.Joints[(int)JointType.HandRight]);
if (selectionStatus == 2 && selectionTimer.busy) selectionStatus = 3;
// If hand position didn't change 1 cm, do no more processing for this frame
if (Math.Abs(rightHandAnchorLength - vLength) < 0.01f) return;
// Else handle grip processing
if (!gripActive)
{
if (selectionObjectTimer.busy) return;
gripActive = true;
if (openObjectTimer.busy)
{
// mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
// Thread.Sleep(150);
// mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
else
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
}
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
gripActive = true;
selectionTimer.stopTimer();
}
double distanceX = GestureDatabase.Joints[(int)JointType.HandRight].X -
double distanceX = GestureDatabase.Joints[(int)JointType.HandRight].X -
GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].X;
double distanceY = GestureDatabase.Joints[(int)JointType.HandRight].Y -
double distanceY = GestureDatabase.Joints[(int)JointType.HandRight].Y -
GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].Y;
int moveX = (int)(distanceX * 1000);
......@@ -214,9 +227,8 @@ namespace ExplorVizGestureControl.Gestures
else if (gripActive)
{
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
selectionStatus = 0;
gripActive = false;
selectionActive = false;
openObjectTimer.startTimer();
}
}
......
......@@ -34,7 +34,7 @@ namespace ExplorVizGestureControl.Gestures
private static HandState handLeftState;
private static int maxCapacity;
private static int newestOldHead = 0;
private static int headIndex = 0;
private static CameraSpacePoint[] headsStack;
private static int[] flags;
......@@ -48,6 +48,7 @@ namespace ExplorVizGestureControl.Gestures
tempGestureDictionary.Add("Start_Reset", StartOrReset);
gestureDictionary = tempGestureDictionary;
// + 1 for head stack
flags = new int[gestureDictionary.Count + 1];
foreach (int i in flags)
{
......@@ -95,10 +96,10 @@ namespace ExplorVizGestureControl.Gestures
handLeftState = left;
handRightState = right;
headsStack[newestOldHead] = joints[(int)JointType.Head];
newestOldHead = ++newestOldHead % maxCapacity;
headsStack[headIndex] = joints[(int)JointType.Head];
headIndex = ++headIndex % maxCapacity;
// newestOldHead == 0 <=> one circle <=> full array
if (newestOldHead == 0) flags[1] = 1;
if (headIndex == 0) flags[1] = 1;
}
#endregion
......@@ -114,6 +115,11 @@ namespace ExplorVizGestureControl.Gestures
}
}
public static float CalculateVectorLength(CameraSpacePoint point)
{
return (float)Math.Sqrt(Math.Pow(point.X, 2) + Math.Pow(point.Y, 2) + Math.Pow(point.Z, 2));
}
#region HandStates
public static bool RightHandClosed()
......@@ -137,7 +143,7 @@ namespace ExplorVizGestureControl.Gestures
}
#endregion
#region Joint comparison
#region Joint comparison
public static Boolean RightElbowBelowRightHand()
{
......
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