Commit 984d2b31 authored by Alexander Krause's avatar Alexander Krause

overhaul of zooming

parent f6e6b17f
......@@ -27,7 +27,7 @@ namespace ExplorVizGestureControl.Gestures
private const int MOUSEEVENTF_RIGHTUP = 0x10;
private const int MOUSEEVENTF_WHEEL = 0x0800;
private GestureTimer scrollTimer;
private GestureTimer scrollTimer;
private GestureTimer selectionTimer;
internal static GestureTimer delayTimer;
......@@ -49,13 +49,13 @@ namespace ExplorVizGestureControl.Gestures
// dynamic values initialization, based on gui
dynamicValues.Add("scrollAccelerationFactor", 2000);
dynamicValues.Add("scrollActivation", 0.05);
dynamicValues.Add("zoomVelocity", 250);
dynamicValues.Add("scrollActivation", 0.05);
dynamicValues.Add("zoomVelocity", 1000);
dynamicValues.Add("rotationVelocityX", 2000);
dynamicValues.Add("rotationVelocityY", 1000);
dynamicValues.Add("rotationYActivation", 0.04);
scrollTimer = new GestureTimer(dynamicValues["zoomVelocity"]);
scrollTimer = new GestureTimer(dynamicValues["zoomVelocity"]);
delayTimer = new GestureTimer(2000);
selectionTimer = new GestureTimer(500);
}
......@@ -66,8 +66,8 @@ namespace ExplorVizGestureControl.Gestures
{
if (delayTimer.busy) return;
HandleRotation();
HandleZoom();
HandleRotation();
if (IntersectWithPhIZ() || gripActive) HandleGripAndSelection();
}
......@@ -94,7 +94,7 @@ namespace ExplorVizGestureControl.Gestures
private void HandleRotation()
{
if (gripActive) return;
if (gripActive || zoomingActive) return;
if (GestureDatabase.LeftHandClosed())
{
......@@ -130,29 +130,52 @@ namespace ExplorVizGestureControl.Gestures
}
}
private Boolean zoomingActive = false;
private int zoomStatus = 0;
private void HandleZoom()
{
int scrollValue = 0;
double distance = GestureDatabase.Joints[(int)JointType.SpineBase].Z -
GestureDatabase.PreviousFrameJoints[(int)JointType.SpineBase].Z;
if (rotationActive || gripActive || scrollTimer.busy) return;
double distance = GestureDatabase.Joints[(int)JointType.HandRight].Z -
GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].Z;
if (Math.Abs(distance) != dynamicValues["scrollActivation"])
if (GestureDatabase.ZoomingInitialized())
{
scrollValue = (int)(distance * dynamicValues["scrollAccelerationFactor"]);
}
zoomingActive = true;
if (distance >= 0 && GestureDatabase.BothHandsClosed())
{
zoomStatus = 1;
}
else if (distance < 0 && GestureDatabase.BothHandsClosed()) { return; }
if (scrollValue != 0 && !scrollTimer.busy)
if (distance < 0 && GestureDatabase.BothHandsOpen())
{
if (zoomStatus == 1)
{
zoomStatus = 2;
scrollTimer.startTimer();
return;
}
zoomStatus = 2;
}
else if (distance >= 0 && GestureDatabase.BothHandsOpen()) { return; }
int scrollValue = (int)(distance * dynamicValues["scrollAccelerationFactor"]);
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, scrollValue, 0);
}
else
{
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -scrollValue, 0);
scrollTimer.startTimer();
zoomingActive = false;
zoomStatus = 0;
scrollTimer.startTimer();
}
}
private void HandleGripAndSelection()
{
//if (rotationActive) return;
if (rotationActive || zoomingActive) return;
if (!GestureDatabase.DragObject() && selectionStatus == 1)
{
......@@ -172,9 +195,9 @@ namespace ExplorVizGestureControl.Gestures
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
//Thread.Sleep(150);
// mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
// mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
selectionStatus = 0;
}
}
if (GestureDatabase.DragObject())
{
......@@ -196,7 +219,7 @@ namespace ExplorVizGestureControl.Gestures
if (!gripActive)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
gripActive = true;
gripActive = true;
selectionTimer.stopTimer();
}
......
......@@ -185,10 +185,11 @@ namespace ExplorVizGestureControl.Gestures
return joints[(int)JointType.ElbowLeft].Y < joints[(int)JointType.ShoulderLeft].Y;
}
public static Boolean BothHandsParallel(float maxDistanceInX = 0.05f)
public static Boolean BothHandsParallel(float maxDistanceInX = 0.30f, float maxDistanceInY = 0.10f, float maxDistanceInZ = 0.10f)
{
return (Math.Abs(Math.Abs(joints[(int)JointType.HandRight].X) - Math.Abs(joints[(int)JointType.HandLeft].X)) < maxDistanceInX &&
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].Y) - Math.Abs(joints[(int)JointType.HandLeft].Y)) < maxDistanceInY) &&
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Z) - Math.Abs(joints[(int)JointType.HandLeft].Z)) < maxDistanceInZ;
}
public static Boolean BothHandsAboveHead()
......@@ -305,6 +306,12 @@ namespace ExplorVizGestureControl.Gestures
return confidence > 6 ? true : false;
}
public static Boolean ZoomingInitialized()
{
return BothHandsParallel(1f) && HandsAboveSpineBase("both", 0.1f) && LeftHandBelowLeftShoulder() &&
RightHandBelowRightShoulder();
}
#endregion
#region Getters & Setters
......
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