Skip to content

Commit

Permalink
[#18] Added scripts from open source project for head nodding and hea…
Browse files Browse the repository at this point in the history
…d shaking
  • Loading branch information
JamalG16 committed Oct 16, 2019
1 parent 5c30c2d commit 9ca4d2e
Show file tree
Hide file tree
Showing 56 changed files with 900 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Social_AI_XR/Assets/FrameSynthesis.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Social_AI_XR/Assets/FrameSynthesis/MyMath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using UnityEngine;

namespace FrameSynthesis
{
public class MyMath
{
public static float LinearMap(float value, float s0, float s1, float d0, float d1)
{
return d0 + (value - s0) * (d1 - d0) / (s1 - s0);
}

public static float WrapDegree(float degree)
{
if (degree > 180f)
{
return degree - 360f;
}
return degree;
}
}
}
8 changes: 8 additions & 0 deletions Social_AI_XR/Assets/FrameSynthesis/MyMath.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Social_AI_XR/Assets/FrameSynthesis/VRGestureRecognizer.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using UnityEngine;

namespace FrameSynthesis.VR
{
public class DebugGraphRenderer : MonoBehaviour
{
[SerializeField]
Material material;

void OnPostRender()
{
material.SetPass(0);

GL.LoadOrtho();
GL.Begin(GL.LINES);

GL.Color(new Color(1f, 1f, 1f, 0.5f));
GL.Vertex3(0f, 0.5f, 0f);
GL.Vertex3(1f, 0.5f, 0f);
GL.Vertex3(0.5f, 0f, 0f);
GL.Vertex3(0.5f, 1f, 0f);

var poseSamples = VRGestureRecognizer.Current.PoseSamples;

GL.Color(Color.red);

var prevGraphPosition = Vector2.zero;
var i = 0;
foreach (var poseSample in poseSamples)
{
var graphPosition = GetGraphPositionFromPoseSamplePitch(poseSample);
if (i > 0)
{
GL.Vertex3(prevGraphPosition.x, prevGraphPosition.y, 0f);
GL.Vertex3(graphPosition.x, graphPosition.y, 0f);
}
prevGraphPosition = graphPosition;
i++;
}

GL.Color(Color.green);

i = 0;
foreach (var poseSample in poseSamples)
{
var graphPosition = GetGraphPositionFromPoseSampleYaw(poseSample);
if (i > 0)
{
GL.Vertex3(prevGraphPosition.x, prevGraphPosition.y, 0f);
GL.Vertex3(graphPosition.x, graphPosition.y, 0f);
}
prevGraphPosition = graphPosition;
i++;
}

GL.End();
}

Vector2 GetGraphPositionFromPoseSamplePitch(PoseSample poseSample)
{
float x = Time.time - poseSample.timestamp;
float y = ProjectDegreeTo01(poseSample.orientation.eulerAngles.x);
return new Vector2(x, y);
}

Vector2 GetGraphPositionFromPoseSampleYaw(PoseSample poseSample)
{
float x = ProjectDegreeTo01(poseSample.orientation.eulerAngles.y);
float y = Time.time - poseSample.timestamp;
return new Vector2(x, y);
}

float ProjectDegreeTo01(float degree)
{
return MyMath.LinearMap(MyMath.WrapDegree(degree), -180f, 180f, 0f, 1f);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Shader "Frame Synthesis/GL Line"
{
SubShader
{
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off Cull Off Fog { Mode Off }
BindChannels
{
Bind "vertex", vertex
Bind "color", color
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using UnityEngine;

namespace FrameSynthesis.VR.Example
{
[RequireComponent(typeof(TextMesh))]
public class YesNoMessage : MonoBehaviour
{
const string YesText = "Yes!";
const string NoText = "No!";

[SerializeField]
float lifetime = 1f;
[SerializeField]
Vector3 velocity;

void Start()
{
Destroy(gameObject, lifetime);
}

public void Initialize(bool yesNo)
{
GetComponent<TextMesh>().text = yesNo ? YesText : NoText;
}

void Update()
{
transform.Translate(velocity * Time.deltaTime);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using UnityEngine;

namespace FrameSynthesis.VR.Example
{
public class YesNoMessageGenerator : MonoBehaviour
{
[SerializeField]
GameObject yesNoMessagePrefab;

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

void OnNod()
{
InstantiateYesNoMessage(true);
}

void OnHeadshake()
{
InstantiateYesNoMessage(false);
}

void InstantiateYesNoMessage(bool yesNo)
{
var go = Instantiate(yesNoMessagePrefab);
go.GetComponent<YesNoMessage>().Initialize(yesNo);

go.transform.SetParent(Camera.main.transform);
go.transform.localPosition = new Vector3(0f, 0f, 10f);
go.transform.localRotation = Quaternion.identity;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using UnityEngine;
using UnityEngine.XR;

namespace FrameSynthesis.VR
{
public class Recenterer : MonoBehaviour
{
void Start()
{
XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary);
}

void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
InputTracking.Recenter();
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9ca4d2e

Please sign in to comment.