add GiantSnowflake and KinectOpticalFlowMath to calculate Kinect2Motion

make SceneController singleton
master
hoba 8 years ago
parent ebdaf9e2f8
commit a512105c00
  1. 76
      Unity_2018_Frozen/Assets/Frozen/Material/GiantSnowflake.mat
  2. 10
      Unity_2018_Frozen/Assets/Frozen/Material/GiantSnowflake.mat.meta
  3. 35
      Unity_2018_Frozen/Assets/Frozen/Script/GiantSnowflake.cs
  4. 13
      Unity_2018_Frozen/Assets/Frozen/Script/GiantSnowflake.cs.meta
  5. 2
      Unity_2018_Frozen/Assets/Frozen/Script/SceneController.cs
  6. 84
      Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlowMath.cs
  7. 13
      Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlowMath.cs.meta

@ -0,0 +1,76 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: GiantSnowflake
m_Shader: {fileID: 4800000, guid: a76fe72ab9c198948a9233662c9407f3, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: f59ee687c02517e45819a3f0bcf97b7f, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 3059bdeaeda202b489a491a3025d4843
timeCreated: 1525524450
licenseType: Free
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UltraCombos.Frozen
{
public class GiantSnowflake : MonoBehaviour
{
Material material;
float alpha = 0.0f;
float smooth = 0.025f;
private void Start()
{
material = GetComponent<MeshRenderer>().material;
}
private void FixedUpdate()
{
if (SceneController.Instance.rate < 0.5f)
{
alpha = Mathf.Lerp(alpha, 1.0f, smooth);
}
else
{
alpha = Mathf.Lerp(alpha, 0.0f, smooth);
}
material.color = new Color(1.0f, 1.0f, 1.0f, alpha);
}
}
}

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 9126593cba11d9145b83a6ab86efc050
timeCreated: 1525524624
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -4,7 +4,7 @@ using UnityEngine;
namespace UltraCombos.Frozen namespace UltraCombos.Frozen
{ {
public class SceneController : MonoBehaviour public class SceneController : Singleton<SceneController>
{ {
[Range(0, 1)] [Range(0, 1)]
public float rate = 0.0f; public float rate = 0.0f;

@ -0,0 +1,84 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UltraCombos
{
public class KinectOpticalFlowMath : MonoBehaviour
{
[SerializeField]
KinectOpticalFlow kinect;
[SerializeField]
int fps = 15;
float step;
float stamp = 0.0f;
int home_count;
Vector4[] samples = new Vector4[512 * 424];
public Vector3 averagePositinon = Vector3.zero;
public float triggerRadius = 1.5f;
public float standardDeviation = -1.0f;
[SerializeField]
string debug;
public string DebugString { get { return debug; } }
private void Start()
{
step = 1.0f / fps;
}
private void Update()
{
if (Time.time - stamp < step)
return;
stamp = Time.time;
var data = new int[kinect.HomeCountBuffer.count];
kinect.HomeCountBuffer.GetData(data);
home_count = data[0];
kinect.HomePositionBuffer.GetData(samples, 0, 0, home_count);
if (home_count > 0)
{
float div = 1.0f / home_count;
float avg_dist = 0.0f;
averagePositinon = Vector3.zero;
standardDeviation = 0.0f;
for (int i = 0; i < home_count; i++)
{
var smp = new Vector3(samples[i].x, samples[i].y, samples[i].z);
averagePositinon += smp;
float dist = new Vector2(smp.x - transform.position.x, smp.z - transform.position.z).magnitude;
avg_dist += dist;
standardDeviation += Mathf.Pow(dist, 2.0f);
}
averagePositinon.Scale(Vector4.one * div);
avg_dist *= div;
standardDeviation = Mathf.Sqrt(standardDeviation * div - avg_dist * avg_dist);
debug = string.Format("{0}({1}): {2}", averagePositinon, avg_dist, standardDeviation);
}
else
{
standardDeviation = -1.0f;
debug = "null";
}
}
private void OnDrawGizmosSelected()
{
Gizmos.DrawWireSphere(averagePositinon, 0.5f);
if (new Vector2(averagePositinon.x - transform.position.x, averagePositinon.z - transform.position.z).magnitude < triggerRadius)
{
Gizmos.color = Color.red;
}
Gizmos.DrawWireSphere(transform.position, triggerRadius);
Gizmos.color = Color.white;
}
}
}

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: c0e2f0c4ffce60f40a1fa79e4ec7955c
timeCreated: 1525522533
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save