Skip to content

Commit

Permalink
[#18] Added a nod up but its very sensitive. I commented it out but w…
Browse files Browse the repository at this point in the history
…e can adjust the settings
  • Loading branch information
Songtone committed Oct 16, 2019
1 parent 01d2d1c commit f1c78d1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class YesNoMessageGenerator : MonoBehaviour

void Start()
{
VRGestureRecognizer.Current.NodHandler += OnNod;
//VRGestureRecognizer.Current.NodHandler += OnNod;
//VRGestureRecognizer.Current.HeadshakeHandler += OnHeadshake;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class VRGestureRecognizer : MonoBehaviour
[SerializeField]
float recognitionInterval = 0.5f;

public event Action NodHandler;
public event Action NodDownHandler;
//public event Action NodUpHandler;
public event Action HeadshakeRightHandler;
public event Action HeadshakeLeftHandler;

Expand All @@ -55,7 +56,8 @@ void Update()
}

// Recognize gestures
RecognizeNod();
RecognizeNodDown();
//RecognizeNodUp();
RecognizeHeadshakeRight();
RecognizeHeadshakeLeft();
}
Expand All @@ -67,7 +69,7 @@ IEnumerable<PoseSample> PoseSamplesWithin(float startTime, float endTime)
sample.timestamp >= Time.time - endTime);
}

void RecognizeNod()
void RecognizeNodDown()
{
try
{
Expand All @@ -81,7 +83,7 @@ void RecognizeNod()
if (prevGestureTime < Time.time - recognitionInterval)
{
prevGestureTime = Time.time;
NodHandler?.Invoke();
NodDownHandler?.Invoke();
}
}
}
Expand All @@ -91,6 +93,30 @@ void RecognizeNod()
}
}

/* void RecognizeNodUp()
{
try
{
var averagePitch = PoseSamplesWithin(0.2f, 0.4f).Average(sample => sample.eulerAngles.x);
var maxPitch = PoseSamplesWithin(0.01f, 0.2f).Max(sample => sample.eulerAngles.x);
var pitch = PoseSamples.First().eulerAngles.x;
if (maxPitch - averagePitch < 10f &&
Mathf.Abs(pitch - averagePitch) < 5f)
{
if (prevGestureTime < Time.time - recognitionInterval)
{
prevGestureTime = Time.time;
NodUpHandler?.Invoke();
}
}
}
catch (InvalidOperationException)
{
// PoseSamplesWithin contains no entry
}
}*/

void RecognizeHeadshakeLeft()
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Main : MonoBehaviour

void Start()
{
VRGestureRecognizer.Current.NodHandler += OnNod;
//VRGestureRecognizer.Current.NodHandler += OnNod;
//VRGestureRecognizer.Current.HeadshakeHandler += OnHeadshake;
}

Expand Down
12 changes: 9 additions & 3 deletions Social_AI_XR/Assets/cubefly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ public class cubefly : MonoBehaviour
void Start()
{

VRGestureRecognizer.Current.NodHandler += OnNod;
VRGestureRecognizer.Current.NodDownHandler += OnNodDown;
//VRGestureRecognizer.Current.NodUpHandler += OnNodUp;
VRGestureRecognizer.Current.HeadshakeLeftHandler += OnHeadshakeLeft;
VRGestureRecognizer.Current.HeadshakeRightHandler += OnHeadshakeRight;
textDebugger.text = "START";
}

void OnNod()
void OnNodDown()
{
gameObject.GetComponent<Rigidbody>().AddForce(0, 5, 0, ForceMode.Impulse);
textDebugger.text = "Nodding";
textDebugger.text = "Nod Down";
}
/*void OnNodUp()
{
gameObject.GetComponent<Rigidbody>().AddForce(0, 0, -5, ForceMode.Impulse);
textDebugger.text = "Nod Up";
}*/

void OnHeadshakeLeft()
{
Expand Down

0 comments on commit f1c78d1

Please sign in to comment.