조아혜

0614: add cameraMoving.cs and step comparing function

Showing 864 changed files with 273 additions and 9 deletions
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using Windows.Kinect;
using System;
using System.IO;
public class cameraMoving : MonoBehaviour
{
private KinectSensor _Sensor;
private BodyFrameReader _Reader;
private Body[] _Data = null;
public Text stepText;
public Body[] GetData()
{
return _Data;
}
int step = 0;
float speed = 2f;
KinectManager manager;
/*
Windows.Kinect.KinectSensor sensor;
KinectManager manager;
Windows.Kinect.Body body;
Windows.Kinect.BodyIndexFrameArrivedEventArgs e;
Windows.Kinect.BodyFrameReader bodyFrameReader;
Vector3 moveToPosition;
float speed = 2f;
bool started = false;
BodyIndexFrameReader bodyIndexFrameReader = null;
FrameDescription bodyIndexFrameDescription = null;
//byte[] bodyIndexBuffer = null;
*/
// Start is called before the first frame update
void Start()
{
_Sensor = KinectSensor.GetDefault();
if (_Sensor != null)
{
_Reader = _Sensor.BodyFrameSource.OpenReader();
if (!_Sensor.IsOpen)
{
_Sensor.Open();
Debug.Log(_Sensor.IsOpen);
}
}
//Debug.Log(_Sensor.IsAvailable);
/*
sensor = Windows.Kinect.KinectSensor.GetDefault();
sensor.Open();
//bodyIndexFrameDescription = sensor.BodyIndexFrameSource.FrameDescription;
bodyIndexFrameReader = sensor.BodyIndexFrameSource.OpenReader();
bodyFrameReader = sensor.BodyFrameSource.OpenReader();
Debug.Log(sensor.IsOpen);
Debug.Log(sensor.IsAvailable);
Debug.Log(e);
Debug.Log(bodyIndexFrameReader);
var bodyIndexFrame = e.FrameReference.AcquireFrame();
bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer);
for (int i = 0; i < bodyIndexBuffer.Length; i++)
{
var index = bodyIndexBuffer[i];
if (index != 255) {}
}
//bodyIndexFrameReader.FrameArrived += bodyIndexBuffer;
//bodyIndexFrameReader.FrameArrived += KinectManager.BodyIndexFrameReader_FrameArrived(sensor, e);
//var bodyIndexFrame =
//bodyFrameReader = sensor.BodyFrameSource.OpenReader();
//sensor.Open();
//bodyFrameReader.FrameArrived += Reader_FrameArrived;
//body = Windows.Kinect.BodyFrameSource;
moveToPosition = new Vector3(0, 2, 0);
Debug.Log("started");
//Debug.Log(body);
started = true;
*/
}
// Update is called once per frame
void Update()
{
if (_Reader != null)
{
var frame = _Reader.AcquireLatestFrame();
if (frame != null)
{
//Debug.Log("frame");
if (_Data == null)
{
//Debug.Log("data");
_Data = new Body[_Sensor.BodyFrameSource.BodyCount];
Debug.Log("2");
transform.Translate(Vector3.forward * Time.deltaTime * speed);
//Debug.Log("3");
//Camera.main.transform.position = Vector3.Lerp(transform.position, moveToPosition, speed);
//transform.position = Vector3.Lerp(transform.position, moveToPosition, speed);
step = manager.UpdateKinect(_Data);
Debug.Log(step);
stepText.text = "Step: " + step;
}
frame.GetAndRefreshBodyData(_Data);
frame.Dispose();
frame = null;
}
}
}
}
public class KinectManager
{
int step_num = 0;
//var bodyIndexFrame =
public int UpdateKinect(Windows.Kinect.Body[] bodies)
{
//Debug.Log("1");
var body = bodies[0];
var joints = body.Joints;
//Debug.Log("2");
//if (body == null || !body.IsTracked) return 0;
JointType left_knee = (Windows.Kinect.JointType)13;
JointType right_knee = (Windows.Kinect.JointType)17;
//Debug.Log("3");
var left_knee_position = joints[left_knee].Position;
var right_knee_position = joints[right_knee].Position;
//Debug.Log("4");
//Walking
if (right_knee_position.X < left_knee_position.X && right_knee_position.Y < left_knee_position.Y)
{
Debug.Log(string.Format("{0} STEP", step_num.ToString()));
//Console.WriteLine(string.Format("{0} STEP", step_num.ToString()));
step_num++;
}
else if (right_knee_position.X > left_knee_position.X && right_knee_position.Y > left_knee_position.Y)
{
Debug.Log(string.Format("{0} STEP", step_num.ToString()));
//Console.WriteLine(string.Format("{0} STEP", step_num.ToString()));
step_num++;
}
else
{
Debug.Log("not walking");
//Console.WriteLine("not walking");
}
return step_num;
}
}
......@@ -13,12 +13,13 @@ public class GaugeIncreasing : MonoBehaviour
GameObject clue;
GameObject panel;
GameObject apple;
GameObject step;
Text stepText;
int beforeStep;
int afterStep;
Color color;
//Text textBlink;
float timeSpan;
float checkTime;
// Start is called before the first frame update
void Start()
......@@ -30,9 +31,11 @@ public class GaugeIncreasing : MonoBehaviour
panel = GameObject.Find("Panel");
apple = GameObject.Find("SweetPepper");
cheerUp = GameObject.Find("CheerUp");
step = GameObject.Find("Step");
stepText = step.GetComponent<Text>();
beforeStep = int.Parse(stepText.text);
color = new Color(255f, 0, 0);
timeSpan = 0.0f;
checkTime = 0.1667f;
afterText.SetActive(false);
panel.SetActive(false);
......@@ -44,6 +47,7 @@ public class GaugeIncreasing : MonoBehaviour
// Update is called once per frame
void Update()
{
if (gauge.value >= 0.5f && gauge.value < 1)
cheerUp.SetActive(true);
else if (gauge.value >= 1)
......@@ -64,13 +68,14 @@ public class GaugeIncreasing : MonoBehaviour
}
}
timeSpan += Time.deltaTime;
if (timeSpan > checkTime)
afterStep = int.Parse(stepText.text);
if (beforeStep != afterStep)
{
gauge.value += 0.01f;
apple.transform.localScale += new Vector3(0.05f, 0.05f, 0.05f);
timeSpan = 0;
beforeStep = afterStep;
}
}
......
......@@ -11115,6 +11115,7 @@ RectTransform:
- {fileID: 266829199}
- {fileID: 1925813590}
- {fileID: 258223669}
- {fileID: 1350118847}
m_Father: {fileID: 0}
m_RootOrder: 33
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
......@@ -12067,6 +12068,85 @@ Transform:
m_CorrespondingSourceObject: {fileID: 4208458315195486, guid: c96016c34e7be62488e588470988ef5b, type: 3}
m_PrefabInstance: {fileID: 1345181705}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1350118846
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1350118847}
- component: {fileID: 1350118849}
- component: {fileID: 1350118848}
m_Layer: 5
m_Name: Step
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1350118847
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1350118846}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1213300144}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 49.8, y: -92.9}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1350118848
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1350118846}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 'Step: 0'
--- !u!222 &1350118849
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1350118846}
m_CullTransparentMesh: 1
--- !u!1001 &1350335654
PrefabInstance:
m_ObjectHideFlags: 0
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.