조아혜

0614: add cameraMoving.cs and step comparing function

Showing 864 changed files with 272 additions and 8 deletions
1 +using System.Collections;
2 +using System.Collections.Generic;
3 +using UnityEngine;
4 +using UnityEngine.UI;
5 +using UnityEngine.EventSystems;
6 +using Windows.Kinect;
7 +using System;
8 +using System.IO;
9 +
10 +public class cameraMoving : MonoBehaviour
11 +{
12 + private KinectSensor _Sensor;
13 + private BodyFrameReader _Reader;
14 + private Body[] _Data = null;
15 +
16 + public Text stepText;
17 +
18 + public Body[] GetData()
19 + {
20 + return _Data;
21 + }
22 +
23 + int step = 0;
24 + float speed = 2f;
25 +
26 + KinectManager manager;
27 +
28 + /*
29 + Windows.Kinect.KinectSensor sensor;
30 + KinectManager manager;
31 + Windows.Kinect.Body body;
32 + Windows.Kinect.BodyIndexFrameArrivedEventArgs e;
33 + Windows.Kinect.BodyFrameReader bodyFrameReader;
34 +
35 + Vector3 moveToPosition;
36 + float speed = 2f;
37 + bool started = false;
38 +
39 +
40 + BodyIndexFrameReader bodyIndexFrameReader = null;
41 + FrameDescription bodyIndexFrameDescription = null;
42 + //byte[] bodyIndexBuffer = null;
43 + */
44 + // Start is called before the first frame update
45 + void Start()
46 + {
47 + _Sensor = KinectSensor.GetDefault();
48 +
49 + if (_Sensor != null)
50 + {
51 + _Reader = _Sensor.BodyFrameSource.OpenReader();
52 +
53 + if (!_Sensor.IsOpen)
54 + {
55 + _Sensor.Open();
56 + Debug.Log(_Sensor.IsOpen);
57 +
58 + }
59 + }
60 +
61 +
62 + //Debug.Log(_Sensor.IsAvailable);
63 +
64 + /*
65 + sensor = Windows.Kinect.KinectSensor.GetDefault();
66 + sensor.Open();
67 + //bodyIndexFrameDescription = sensor.BodyIndexFrameSource.FrameDescription;
68 + bodyIndexFrameReader = sensor.BodyIndexFrameSource.OpenReader();
69 + bodyFrameReader = sensor.BodyFrameSource.OpenReader();
70 +
71 + Debug.Log(sensor.IsOpen);
72 + Debug.Log(sensor.IsAvailable);
73 + Debug.Log(e);
74 + Debug.Log(bodyIndexFrameReader);
75 + var bodyIndexFrame = e.FrameReference.AcquireFrame();
76 + bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer);
77 + for (int i = 0; i < bodyIndexBuffer.Length; i++)
78 + {
79 + var index = bodyIndexBuffer[i];
80 + if (index != 255) {}
81 + }
82 + //bodyIndexFrameReader.FrameArrived += bodyIndexBuffer;
83 + //bodyIndexFrameReader.FrameArrived += KinectManager.BodyIndexFrameReader_FrameArrived(sensor, e);
84 + //var bodyIndexFrame =
85 + //bodyFrameReader = sensor.BodyFrameSource.OpenReader();
86 + //sensor.Open();
87 + //bodyFrameReader.FrameArrived += Reader_FrameArrived;
88 + //body = Windows.Kinect.BodyFrameSource;
89 + moveToPosition = new Vector3(0, 2, 0);
90 + Debug.Log("started");
91 + //Debug.Log(body);
92 + started = true;
93 + */
94 + }
95 +
96 + // Update is called once per frame
97 + void Update()
98 + {
99 + if (_Reader != null)
100 + {
101 + var frame = _Reader.AcquireLatestFrame();
102 + if (frame != null)
103 + {
104 + //Debug.Log("frame");
105 +
106 + if (_Data == null)
107 + {
108 + //Debug.Log("data");
109 +
110 + _Data = new Body[_Sensor.BodyFrameSource.BodyCount];
111 + Debug.Log("2");
112 +
113 + transform.Translate(Vector3.forward * Time.deltaTime * speed);
114 + //Debug.Log("3");
115 +
116 + //Camera.main.transform.position = Vector3.Lerp(transform.position, moveToPosition, speed);
117 + //transform.position = Vector3.Lerp(transform.position, moveToPosition, speed);
118 + step = manager.UpdateKinect(_Data);
119 + Debug.Log(step);
120 +
121 + stepText.text = "Step: " + step;
122 +
123 + }
124 +
125 + frame.GetAndRefreshBodyData(_Data);
126 +
127 +
128 + frame.Dispose();
129 + frame = null;
130 + }
131 + }
132 +
133 + }
134 +}
135 +
136 +public class KinectManager
137 +{
138 + int step_num = 0;
139 +
140 + //var bodyIndexFrame =
141 +
142 + public int UpdateKinect(Windows.Kinect.Body[] bodies)
143 + {
144 + //Debug.Log("1");
145 + var body = bodies[0];
146 + var joints = body.Joints;
147 + //Debug.Log("2");
148 +
149 + //if (body == null || !body.IsTracked) return 0;
150 +
151 + JointType left_knee = (Windows.Kinect.JointType)13;
152 + JointType right_knee = (Windows.Kinect.JointType)17;
153 + //Debug.Log("3");
154 +
155 + var left_knee_position = joints[left_knee].Position;
156 + var right_knee_position = joints[right_knee].Position;
157 + //Debug.Log("4");
158 + //Walking
159 + if (right_knee_position.X < left_knee_position.X && right_knee_position.Y < left_knee_position.Y)
160 + {
161 + Debug.Log(string.Format("{0} STEP", step_num.ToString()));
162 + //Console.WriteLine(string.Format("{0} STEP", step_num.ToString()));
163 + step_num++;
164 + }
165 + else if (right_knee_position.X > left_knee_position.X && right_knee_position.Y > left_knee_position.Y)
166 + {
167 + Debug.Log(string.Format("{0} STEP", step_num.ToString()));
168 + //Console.WriteLine(string.Format("{0} STEP", step_num.ToString()));
169 + step_num++;
170 + }
171 + else
172 + {
173 + Debug.Log("not walking");
174 + //Console.WriteLine("not walking");
175 + }
176 + return step_num;
177 + }
178 +
179 +}
...@@ -13,12 +13,13 @@ public class GaugeIncreasing : MonoBehaviour ...@@ -13,12 +13,13 @@ public class GaugeIncreasing : MonoBehaviour
13 GameObject clue; 13 GameObject clue;
14 GameObject panel; 14 GameObject panel;
15 GameObject apple; 15 GameObject apple;
16 + GameObject step;
17 + Text stepText;
18 + int beforeStep;
19 + int afterStep;
16 20
17 Color color; 21 Color color;
18 - //Text textBlink;
19 22
20 - float timeSpan;
21 - float checkTime;
22 23
23 // Start is called before the first frame update 24 // Start is called before the first frame update
24 void Start() 25 void Start()
...@@ -30,9 +31,11 @@ public class GaugeIncreasing : MonoBehaviour ...@@ -30,9 +31,11 @@ public class GaugeIncreasing : MonoBehaviour
30 panel = GameObject.Find("Panel"); 31 panel = GameObject.Find("Panel");
31 apple = GameObject.Find("SweetPepper"); 32 apple = GameObject.Find("SweetPepper");
32 cheerUp = GameObject.Find("CheerUp"); 33 cheerUp = GameObject.Find("CheerUp");
34 + step = GameObject.Find("Step");
35 + stepText = step.GetComponent<Text>();
36 + beforeStep = int.Parse(stepText.text);
37 +
33 color = new Color(255f, 0, 0); 38 color = new Color(255f, 0, 0);
34 - timeSpan = 0.0f;
35 - checkTime = 0.1667f;
36 39
37 afterText.SetActive(false); 40 afterText.SetActive(false);
38 panel.SetActive(false); 41 panel.SetActive(false);
...@@ -44,6 +47,7 @@ public class GaugeIncreasing : MonoBehaviour ...@@ -44,6 +47,7 @@ public class GaugeIncreasing : MonoBehaviour
44 // Update is called once per frame 47 // Update is called once per frame
45 void Update() 48 void Update()
46 { 49 {
50 +
47 if (gauge.value >= 0.5f && gauge.value < 1) 51 if (gauge.value >= 0.5f && gauge.value < 1)
48 cheerUp.SetActive(true); 52 cheerUp.SetActive(true);
49 else if (gauge.value >= 1) 53 else if (gauge.value >= 1)
...@@ -64,13 +68,14 @@ public class GaugeIncreasing : MonoBehaviour ...@@ -64,13 +68,14 @@ public class GaugeIncreasing : MonoBehaviour
64 } 68 }
65 } 69 }
66 70
67 - timeSpan += Time.deltaTime; 71 + afterStep = int.Parse(stepText.text);
68 - if (timeSpan > checkTime) 72 +
73 + if (beforeStep != afterStep)
69 { 74 {
70 gauge.value += 0.01f; 75 gauge.value += 0.01f;
71 apple.transform.localScale += new Vector3(0.05f, 0.05f, 0.05f); 76 apple.transform.localScale += new Vector3(0.05f, 0.05f, 0.05f);
72 77
73 - timeSpan = 0; 78 + beforeStep = afterStep;
74 } 79 }
75 80
76 } 81 }
......
...@@ -11115,6 +11115,7 @@ RectTransform: ...@@ -11115,6 +11115,7 @@ RectTransform:
11115 - {fileID: 266829199} 11115 - {fileID: 266829199}
11116 - {fileID: 1925813590} 11116 - {fileID: 1925813590}
11117 - {fileID: 258223669} 11117 - {fileID: 258223669}
11118 + - {fileID: 1350118847}
11118 m_Father: {fileID: 0} 11119 m_Father: {fileID: 0}
11119 m_RootOrder: 33 11120 m_RootOrder: 33
11120 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 11121 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
...@@ -12067,6 +12068,85 @@ Transform: ...@@ -12067,6 +12068,85 @@ Transform:
12067 m_CorrespondingSourceObject: {fileID: 4208458315195486, guid: c96016c34e7be62488e588470988ef5b, type: 3} 12068 m_CorrespondingSourceObject: {fileID: 4208458315195486, guid: c96016c34e7be62488e588470988ef5b, type: 3}
12068 m_PrefabInstance: {fileID: 1345181705} 12069 m_PrefabInstance: {fileID: 1345181705}
12069 m_PrefabAsset: {fileID: 0} 12070 m_PrefabAsset: {fileID: 0}
12071 +--- !u!1 &1350118846
12072 +GameObject:
12073 + m_ObjectHideFlags: 0
12074 + m_CorrespondingSourceObject: {fileID: 0}
12075 + m_PrefabInstance: {fileID: 0}
12076 + m_PrefabAsset: {fileID: 0}
12077 + serializedVersion: 6
12078 + m_Component:
12079 + - component: {fileID: 1350118847}
12080 + - component: {fileID: 1350118849}
12081 + - component: {fileID: 1350118848}
12082 + m_Layer: 5
12083 + m_Name: Step
12084 + m_TagString: Untagged
12085 + m_Icon: {fileID: 0}
12086 + m_NavMeshLayer: 0
12087 + m_StaticEditorFlags: 0
12088 + m_IsActive: 1
12089 +--- !u!224 &1350118847
12090 +RectTransform:
12091 + m_ObjectHideFlags: 0
12092 + m_CorrespondingSourceObject: {fileID: 0}
12093 + m_PrefabInstance: {fileID: 0}
12094 + m_PrefabAsset: {fileID: 0}
12095 + m_GameObject: {fileID: 1350118846}
12096 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
12097 + m_LocalPosition: {x: 0, y: 0, z: 0}
12098 + m_LocalScale: {x: 1, y: 1, z: 1}
12099 + m_Children: []
12100 + m_Father: {fileID: 1213300144}
12101 + m_RootOrder: 5
12102 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
12103 + m_AnchorMin: {x: 0.5, y: 0.5}
12104 + m_AnchorMax: {x: 0.5, y: 0.5}
12105 + m_AnchoredPosition: {x: 49.8, y: -92.9}
12106 + m_SizeDelta: {x: 160, y: 30}
12107 + m_Pivot: {x: 0.5, y: 0.5}
12108 +--- !u!114 &1350118848
12109 +MonoBehaviour:
12110 + m_ObjectHideFlags: 0
12111 + m_CorrespondingSourceObject: {fileID: 0}
12112 + m_PrefabInstance: {fileID: 0}
12113 + m_PrefabAsset: {fileID: 0}
12114 + m_GameObject: {fileID: 1350118846}
12115 + m_Enabled: 1
12116 + m_EditorHideFlags: 0
12117 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
12118 + m_Name:
12119 + m_EditorClassIdentifier:
12120 + m_Material: {fileID: 0}
12121 + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
12122 + m_RaycastTarget: 1
12123 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
12124 + m_Maskable: 1
12125 + m_OnCullStateChanged:
12126 + m_PersistentCalls:
12127 + m_Calls: []
12128 + m_FontData:
12129 + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
12130 + m_FontSize: 14
12131 + m_FontStyle: 0
12132 + m_BestFit: 0
12133 + m_MinSize: 10
12134 + m_MaxSize: 40
12135 + m_Alignment: 0
12136 + m_AlignByGeometry: 0
12137 + m_RichText: 1
12138 + m_HorizontalOverflow: 0
12139 + m_VerticalOverflow: 0
12140 + m_LineSpacing: 1
12141 + m_Text: 'Step: 0'
12142 +--- !u!222 &1350118849
12143 +CanvasRenderer:
12144 + m_ObjectHideFlags: 0
12145 + m_CorrespondingSourceObject: {fileID: 0}
12146 + m_PrefabInstance: {fileID: 0}
12147 + m_PrefabAsset: {fileID: 0}
12148 + m_GameObject: {fileID: 1350118846}
12149 + m_CullTransparentMesh: 1
12070 --- !u!1001 &1350335654 12150 --- !u!1001 &1350335654
12071 PrefabInstance: 12151 PrefabInstance:
12072 m_ObjectHideFlags: 0 12152 m_ObjectHideFlags: 0
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.