Skip to content
Snippets Groups Projects
Commit 4f1b7ace authored by florian.hassler's avatar florian.hassler
Browse files

better full circle detection and real time tracking

parent c95e3237
Branches
No related tags found
No related merge requests found
......@@ -88,11 +88,8 @@ public class HandController : MonoBehaviour
LastPosition = currentPosition;
displayPoint(false, rightHandPosition);
if (checkFullRotation(currentPosition))
{
trackHand = !trackHand;
EndTracking();
}
}
// display position for debug purpose
......@@ -118,7 +115,9 @@ public class HandController : MonoBehaviour
if (left)
{
o.GetComponent<Renderer>().material.color = Color.green;
} else {
}
else
{
o.GetComponent<Renderer>().material.color = Color.blue;
}
o.transform.position = pos;
......@@ -189,9 +188,30 @@ public class HandController : MonoBehaviour
SpeedText.text = "Speed" + (average / Speed.Count).ToString();
}
bool fullRotation = false;
// Update is called once per frame
void Update()
{
if (fullRotation)
{
if (CheckCircle(rightHandGesture))
{
Msg.text = "Circle OK!";
DetermineCircleDirection();
} else
{
Msg.text = "Circle KO!";
}
RemovePoints();
trackHand = !trackHand;
beginTracking();
fullRotation = false;
}
//left hand actions
OnButtonAPushed();
OnButtonBPushed();
......@@ -200,23 +220,21 @@ public class HandController : MonoBehaviour
HandTracking();
if (CheckCircle(rightHandGesture))
if (trackHand && checkFullRotation(LastPosition))
{
Msg.text = "Circle OK!";
DetermineCircleDirection();
trackHand = !trackHand;
EndTracking();
fullRotation = true;
}
}
else
{
Msg.text = "Circle KO!";
}
}
void OnButtonBPushed()
{
if (OVRInput.GetDown(OVRInput.Button.Two)){
if (OVRInput.GetDown(OVRInput.Button.Two))
{
OVRManager.display.RecenterPose();
Debug.Log("Recenter head pose");
}
......@@ -252,7 +270,7 @@ public class HandController : MonoBehaviour
else
{
EndTracking();
SpeedText.text = GetAngle(rightHandGesture[rightHandGesture.Count - 1], rightHandGesture[0]).ToString();
SpeedText.text = GetAngle(rightHandGesture[0], rightHandGesture[rightHandGesture.Count - 1]).ToString();
//checkFullRotation(rightHandGesture[rightHandGesture.Count - 1]);
}
......@@ -260,10 +278,11 @@ public class HandController : MonoBehaviour
}
public float GetAngle(Vector2 point, Vector2 center)
public float GetAngle(Vector2 a, Vector2 b)
{
Vector2 relPoint = point - center;
return (Mathf.Atan2(relPoint.y, relPoint.x)*Mathf.Rad2Deg + 450f) % 360f;
return Vector2.Distance(a, b);
// return Mathf.Acos(Vector2.Dot(a.normalized, b.normalized)) * Mathf.Rad2Deg;
}
......@@ -290,10 +309,7 @@ public class HandController : MonoBehaviour
Vector2 firstPoint = rightHandGesture[0];
float dist = Vector2.Distance(currentPosition, firstPoint);
float angle = Vector2.Angle(firstPoint.normalized, currentPosition.normalized);
angle = Quaternion.FromToRotation(Vector2.up, currentPosition - firstPoint).eulerAngles.z;
float FullAngle= Mathf.Sign(Vector3.Cross(firstPoint.normalized, currentPosition.normalized).z) < 0 ? (360 - angle) % 360 : angle;
if (FullAngle >=358)
if (dist < 0.05)
return true;
}
......@@ -318,7 +334,8 @@ public class HandController : MonoBehaviour
if (res)
{
cntClockwise++;
}else
}
else
{
cntAntiClockwise++;
}
......@@ -329,7 +346,8 @@ public class HandController : MonoBehaviour
if (cntClockwise > cntAntiClockwise)
{
Msg.text += " clockwise rotation";
}else if(cntAntiClockwise > cntClockwise)
}
else if (cntAntiClockwise > cntClockwise)
{
Msg.text += " anti Clockwise rotation";
}
......@@ -342,17 +360,19 @@ public class HandController : MonoBehaviour
void OnButtonXPushed()
{
if (OVRInput.GetDown(OVRInput.Button.Three))
{
RemovePoints();
}
}
private void RemovePoints()
{
Debug.Log("Remove points");
foreach (GameObject point in points)
Destroy(point);
points.Clear();
}
}
void HandTracking2()
{
debugLeftHand.text =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment