|
|
@@ -9,12 +9,21 @@ using o0Aien;
|
|
|
public class AimHandler : MonoBehaviour
|
|
|
{
|
|
|
[SerializeField] Transform controlObj;
|
|
|
- [SerializeField] Button SetIdentityButton = default;
|
|
|
- [SerializeField] Button MagCalibrationButton = default;
|
|
|
- [SerializeField] Button GyrCalibrationButton = default;
|
|
|
- [SerializeField] Text MagScaleText = default;
|
|
|
- [SerializeField] Text GyrScaleText = default;
|
|
|
+ [SerializeField] Button SetIdentityButton;
|
|
|
+ [SerializeField] Button MagCalibrationButton;
|
|
|
+ [SerializeField] Button GyrCalibrationButton;
|
|
|
+ [SerializeField] Text MagScaleText;
|
|
|
+ [SerializeField] Text GyrScaleText;
|
|
|
|
|
|
+ //椭圆对象
|
|
|
+ [SerializeField] Ellipse ellipseScript;
|
|
|
+ [SerializeField] Toggle ellipseToggle;
|
|
|
+ [SerializeField] GameObject AccObj;
|
|
|
+ [SerializeField] GameObject MagObj;
|
|
|
+ [SerializeField] GameObject AMesh;
|
|
|
+ [SerializeField] Transform DebugTexts;
|
|
|
+ [SerializeField] Transform DrawImage;
|
|
|
+
|
|
|
long TimeGap = default;
|
|
|
Vector3 Acc = default;
|
|
|
Vector3 Gyr = default;
|
|
|
@@ -23,33 +32,9 @@ public class AimHandler : MonoBehaviour
|
|
|
|
|
|
o0SigmoidIntegrationFilterQuaternion filter = new o0SigmoidIntegrationFilterQuaternion(0.2f);
|
|
|
|
|
|
- //椭圆对象
|
|
|
- Transform testEllipse;
|
|
|
- public Ellipse ellipseScript;
|
|
|
- public Toggle ellipseToggle;
|
|
|
- public GameObject AccObj;
|
|
|
- public GameObject MagObj;
|
|
|
- public GameObject AMesh;
|
|
|
-
|
|
|
Vector3 cMaxVector = new Vector3(0,0,0);
|
|
|
Vector3 cMinVector = new Vector3(0, 0, 0);
|
|
|
|
|
|
- // private void Awake()
|
|
|
- // {
|
|
|
- // for (var i = 0; i < 15; ++i)
|
|
|
- // {
|
|
|
- // _9Axis.TextTester.Add(GameObject.Find("Canvas").transform.Find("DebugTexts").transform.Find("Text" + i.ToString()).gameObject.GetComponent<Text>());
|
|
|
- // }
|
|
|
- // }
|
|
|
- //转换读取的数据,无符号->有符号
|
|
|
- float TwoByteToFloat(byte b1, byte b2)
|
|
|
- {
|
|
|
- ushort twoByte = (ushort) (b1 * 256 + b2);
|
|
|
- short shortNum = (short) twoByte;
|
|
|
- return (float) shortNum;
|
|
|
- }
|
|
|
-
|
|
|
- // o0MagneticCalibraterSimple MagCalibrater;
|
|
|
o0MagneticCalibraterEllipsoidFitting MagCalibrater;
|
|
|
o0GyrCalibrater GyrCalibrater;
|
|
|
long msOld = 0;
|
|
|
@@ -62,16 +47,18 @@ public class AimHandler : MonoBehaviour
|
|
|
BluetoothDispatcher.aim = OnDataReceived;
|
|
|
|
|
|
//Init
|
|
|
- ellipseToggle.onValueChanged.AddListener(OnValueChanged);
|
|
|
+ ellipseToggle.onValueChanged.AddListener(delegate(bool value) {
|
|
|
+ Debug.Log(value);
|
|
|
+ });
|
|
|
|
|
|
for (var i = 0; i < 9; ++i)
|
|
|
{
|
|
|
- _9Axis.Tester.Add(GameObject.Find("Canvas").transform.Find("DrawImage").Find(i.ToString()).gameObject.AddComponent<o0UIRawImageTester>());
|
|
|
+ _9Axis.Tester.Add(DrawImage.Find(i.ToString()).gameObject.AddComponent<o0UIRawImageTester>());
|
|
|
}
|
|
|
|
|
|
for (var i = 0; i < 15; ++i)
|
|
|
{
|
|
|
- _9Axis.TextTester.Add(GameObject.Find("Canvas").transform.Find("DebugTexts").transform.Find("Text" + i.ToString()).gameObject.GetComponent<Text>());
|
|
|
+ _9Axis.TextTester.Add(DebugTexts.transform.Find("Text" + i.ToString()).gameObject.GetComponent<Text>());
|
|
|
}
|
|
|
|
|
|
if (SetIdentityButton)
|
|
|
@@ -186,16 +173,19 @@ public class AimHandler : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void OnValueChanged(bool value)
|
|
|
+ void OnDestroy()
|
|
|
{
|
|
|
- if (value)
|
|
|
- {
|
|
|
- //选中了的逻辑
|
|
|
- }
|
|
|
- Debug.Log(value);
|
|
|
+ ins = null;
|
|
|
+ BluetoothDispatcher.aim = null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //转换读取的数据,无符号->有符号
|
|
|
+ float TwoByteToFloat(byte b1, byte b2)
|
|
|
+ {
|
|
|
+ ushort twoByte = (ushort) (b1 * 256 + b2);
|
|
|
+ short shortNum = (short) twoByte;
|
|
|
+ return (float) shortNum;
|
|
|
+ }
|
|
|
|
|
|
public void OnDataReceived(byte[] bytes)
|
|
|
{
|
|
|
@@ -321,20 +311,10 @@ public class AimHandler : MonoBehaviour
|
|
|
{
|
|
|
// 最终结果进行lerp
|
|
|
controlObj.localRotation = Quaternion.Lerp(controlObj.localRotation, newRotation, Time.deltaTime * 8);
|
|
|
- // controlObj.localRotation = newRotation;
|
|
|
- // GameObject.Find("Canvas/RPY_LOG").GetComponent<Text>().text =
|
|
|
- // "roll: " + controlObj.localEulerAngles.x +
|
|
|
- // "\npitch: " + controlObj.localEulerAngles.y +
|
|
|
- // "\nyaw: " + controlObj.localEulerAngles.z;
|
|
|
- // GameObject.Find("Canvas/RPY_LOG").GetComponent<Text>().text =
|
|
|
- // "x: " + _9Axis.x +
|
|
|
- // "\ny: " + _9Axis.y +
|
|
|
- // "\nz: " + _9Axis.States.z;
|
|
|
-
|
|
|
+ // controlObj.localRotation = newRotation;
|
|
|
}
|
|
|
if (doIdentity)
|
|
|
{
|
|
|
- // _9Axis.SetIdentityAccordingToRecords();
|
|
|
_9Axis.SetIdentity();
|
|
|
if (controlObj)
|
|
|
{
|