handInfo.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using UnityEngine;
  6. namespace SC.XR.Unity.Module_InputSystem.InputDeviceHand {
  7. public class handInfo {
  8. public handInfo(string configPath) {
  9. if(Application.platform == RuntimePlatform.Android) {
  10. try {
  11. CommonConfig config;
  12. config = new CommonConfig(configPath);
  13. float x = 0, y = 0, z = 0;
  14. string xx = config.GetLineValue(1);
  15. x = float.Parse(xx != null ? xx : "0");
  16. xx = config.GetLineValue(2);
  17. y = float.Parse(xx != null ? xx : "0");
  18. xx = config.GetLineValue(3);
  19. z = float.Parse(xx != null ? xx : "0");
  20. if(x > -10 && x < 10 && y > -10 && y < 10 && z > -10 && z < 10) {
  21. positionOffest = new Vector3(x, y, z);
  22. Debug.Log("Read "+ configPath + "" + x + " " + y + " " + z);
  23. }
  24. config = null;
  25. } catch(Exception e) {
  26. Debug.Log(e);
  27. }
  28. }
  29. }
  30. public Quaternion rotation =Quaternion.identity;
  31. public Vector3 position = Vector3.zero;
  32. public Vector3 normal = Vector3.zero;//只能自算,手掌中法向量
  33. public Vector3 right = Vector3.zero;//只能自算,手掌right向量
  34. public Vector3 centerLocalPosition = Vector3.zero;//手掌中心点局部坐标
  35. public Vector3 centerPosition = Vector3.zero;//手掌中心点全局坐标
  36. public float zdeep = 0;
  37. public int findFrameCount = 0;//识别开始后共多少帧,丢失即复位
  38. public int frameCountValid = 10;//丢失后重新识别到frameCountValid帧连续有效才算识别
  39. protected Vector3 deltaOffset=Vector3.zero;
  40. public virtual Vector3 positionOffest {
  41. get {
  42. return deltaOffset;//new Vector3(0.05f, 0.00f, 0.14f) + new Vector3(-0.025f, 0.00f, -0.14f) + Vector3.forward * zdeep + deltaOffset;//摄像头向下15度 //new Vector3(0, 0, 0.25f);z正常机器// new Vector3(0.280f,-0.10f,0f);
  43. }
  44. set {
  45. deltaOffset = value;
  46. }
  47. }
  48. private Vector3 _eulerAnglesOffset = new Vector3(-11,0,0);
  49. public Vector3 eulerAnglesOffset {
  50. get {
  51. //if(ShadowSystem.Instant && ShadowSystem.Instant.Device) {
  52. // return ShadowSystem.Instant.Device.CurrentDevice.RGBRotationOffset;
  53. //}
  54. if(Application.platform == RuntimePlatform.Android) {
  55. return _eulerAnglesOffset;
  56. }
  57. return Vector3.zero;
  58. }
  59. }
  60. public Vector3 localPosition = Vector3.zero;
  61. public bool isLost = false;//是否丢失手
  62. public float lostPercent = 0;//丢失的比例 0 - 1 范围
  63. public float lostTimer = 0.8f;//多久没识别到算丢失
  64. public Vector3 trend = Vector3.zero;//手势的趋势 食指指尖
  65. //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 21, ArraySubType = UnmanagedType.Struct)]
  66. //public Vector3[] fingerPos = new Vector3[21];
  67. public fingerInfo[] finger = new fingerInfo[5] {
  68. new fingerInfo(){
  69. joint = new jointInfo[4]{
  70. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  71. }
  72. },
  73. new fingerInfo(){
  74. joint = new jointInfo[4]{
  75. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  76. }
  77. },
  78. new fingerInfo(){
  79. joint = new jointInfo[4]{
  80. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  81. }
  82. },
  83. new fingerInfo(){
  84. joint = new jointInfo[4]{
  85. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  86. }
  87. },
  88. new fingerInfo(){
  89. joint = new jointInfo[5]{
  90. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  91. }
  92. },
  93. };
  94. }
  95. }