Created
January 23, 2014 22:19
-
-
Save richstoner/8587990 to your computer and use it in GitHub Desktop.
EyeTribe Beta SDK & Unity3d (win7 only)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CursorImage : MonoBehaviour { | |
public Texture currentEyePosition; | |
// Use this for initialization | |
void Start () { | |
Screen.showCursor = true; | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
void OnGUI(){ | |
EyeTribeClient trackerScript = (EyeTribeClient )FindObjectOfType(typeof(EyeTribeClient )); | |
Vector3 currentPosition= trackerScript.gazePosNormalY; | |
Rect curpos = new Rect(currentPosition.x, currentPosition.y, currentEyePosition.width, currentEyePosition.height); | |
if(currentPosition.z > 0){ | |
GUI.Label (curpos, currentEyePosition); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System; | |
using TETCSharpClient; | |
using TETCSharpClient.Data; | |
public class ETListener : IGazeUpdateListener | |
{ | |
public GazeData lastGazeData; | |
// z value for lastgaze point indicates a valid gaze location is present (0 no, 1 yes); | |
public Vector3 lastGazePoint = new Vector3(0,0,0); | |
public ETListener () | |
{ | |
Debug.Log("Launch ET listener"); | |
var connectedOk = true; | |
GazeManager.Instance.Activate(1, GazeManager.ClientMode.Push); | |
GazeManager.Instance.AddGazeListener(this); | |
if (!GazeManager.Instance.IsConnected) | |
{ | |
Debug.Log("Eyetracking Server not started"); | |
//Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("EyeTracking Server not started"))); | |
connectedOk = false; | |
} | |
else if (!GazeManager.Instance.IsCalibrated) | |
{ | |
Debug.Log("User is not calibrated"); | |
//Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("User is not calibrated"))); | |
connectedOk = false; | |
} | |
if (!connectedOk) | |
{ | |
Debug.Log("Connection not ready"); | |
return; | |
} | |
} | |
#region Undefined methods | |
public void startCalibration() | |
{ | |
//GazeManager.Instance.CalibrationStart(); | |
} | |
#endregion | |
#region Listener methods | |
public void OnScreenIndexChanged(int number) | |
{ | |
} | |
public void OnCalibrationStateChanged(bool val) | |
{ | |
} | |
public void OnGazeUpdate(GazeData gazeData) | |
{ | |
var x = (int) Math.Round(gazeData.SmoothedCoordinates.X, 0); | |
var y = (int) Math.Round(gazeData.SmoothedCoordinates.Y, 0); | |
if (x == 0 & y == 0) | |
{ | |
lastGazePoint = new Vector3(x,y,0); | |
return; | |
} | |
lastGazeData = gazeData; | |
lastGazePoint = new Vector3(x,y,1); | |
//Debug.Log(String.Format("{0} - {1}", x, y)); | |
} | |
#endregion | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Net; | |
using System.Net.Sockets; | |
using System.Threading; | |
using System.Text; | |
using System.Xml; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class EyeTribeClient : MonoBehaviour { | |
public Vector3 gazePosNormalY = new Vector3(Screen.width/2, Screen.height/2, 0); | |
public Vector3 gazePosInvertY = new Vector3(Screen.width/2, Screen.height/2, 0); | |
private ETListener listener; | |
// Use this for initialization | |
void Start () { | |
try | |
{ | |
listener = new ETListener(); | |
} | |
catch( SocketException e ) | |
{ | |
print(e); | |
} | |
} | |
public void startCalibration() { | |
Debug.Log("Sending Start calibration"); | |
try | |
{ | |
listener.startCalibration(); | |
} | |
catch | |
{ | |
} | |
} | |
// Update is called once per frame | |
void Update () { | |
Vector3 lastGazePoint = listener.lastGazePoint; | |
gazePosNormalY = lastGazePoint; | |
gazePosInvertY = new Vector3(lastGazePoint.x, Screen.height - lastGazePoint.y, lastGazePoint.z); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class PlayerInput : MonoBehaviour { | |
public AudioClip canHitSound; | |
void Update () { | |
if(true){ | |
EyeTribeClient trackerScript = (EyeTribeClient )FindObjectOfType(typeof(EyeTribeClient )); | |
Vector3 currentPosition= trackerScript.gazePosInvertY; | |
Ray ray = Camera.main.ScreenPointToRay (currentPosition); | |
RaycastHit hit; | |
if (Physics.Raycast (ray, out hit, 100)) { | |
Debug.DrawLine (ray.origin, hit.point); | |
if (hit.transform.tag == "ShootingObject") | |
{ | |
audio.pitch = Random.Range(0.9f, 1.3f); | |
audio.Play(); | |
GameManager.SP.RemoveObject(hit.transform); | |
}else if(hit.transform.tag == "Can"){ | |
audio.PlayOneShot(canHitSound); | |
Vector3 explosionPos = transform.position; | |
hit.rigidbody.AddExplosionForce(5000, explosionPos, 25.0f, 1.0f); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment