|
@@ -4,7 +4,6 @@ using UnityEngine;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using UnityEngine.UI;
|
|
using UnityEngine.UI;
|
|
|
-using o0Project;
|
|
|
|
|
|
|
|
|
|
public class BluetoothAim : MonoBehaviour
|
|
public class BluetoothAim : MonoBehaviour
|
|
|
{
|
|
{
|
|
@@ -92,7 +91,6 @@ public class BluetoothAim : MonoBehaviour
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
Invoke("OpenReceiveData", 1);
|
|
Invoke("OpenReceiveData", 1);
|
|
|
- Invoke("SetReceiveDataInterval20", 2);
|
|
|
|
|
};
|
|
};
|
|
|
bluetoothHelper.OnConnectionFailed += (BluetoothHelper helper) =>
|
|
bluetoothHelper.OnConnectionFailed += (BluetoothHelper helper) =>
|
|
|
{
|
|
{
|
|
@@ -102,7 +100,7 @@ public class BluetoothAim : MonoBehaviour
|
|
|
bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) =>
|
|
bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) =>
|
|
|
{
|
|
{
|
|
|
byte[] bytes = value;
|
|
byte[] bytes = value;
|
|
|
- aimHandler.onDataReceived(bytes);
|
|
|
|
|
|
|
+ aimHandler.OnDataReceived(bytes);
|
|
|
};
|
|
};
|
|
|
bluetoothHelper.OnScanEnded += (BluetoothHelper helper, LinkedList<BluetoothDevice> nearbyDevices) =>
|
|
bluetoothHelper.OnScanEnded += (BluetoothHelper helper, LinkedList<BluetoothDevice> nearbyDevices) =>
|
|
|
{
|
|
{
|
|
@@ -138,13 +136,7 @@ public class BluetoothAim : MonoBehaviour
|
|
|
BluetoothHelperCharacteristic ch = new BluetoothHelperCharacteristic(characteristicWrite.getName());
|
|
BluetoothHelperCharacteristic ch = new BluetoothHelperCharacteristic(characteristicWrite.getName());
|
|
|
ch.setService(bluetoothService.getName());
|
|
ch.setService(bluetoothService.getName());
|
|
|
bluetoothHelper.WriteCharacteristic(ch, "3");
|
|
bluetoothHelper.WriteCharacteristic(ch, "3");
|
|
|
- Log("开始接收信息\n" + deviceName);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- void SetReceiveDataInterval20()
|
|
|
|
|
- {
|
|
|
|
|
- bluetoothHelper.WriteCharacteristic(characteristicWrite, "b");
|
|
|
|
|
- Log("修改接收频率\n" + deviceName);
|
|
|
|
|
|
|
+ Log("瞄准模块准备完成\n" + deviceName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Log(string text)
|
|
void Log(string text)
|
|
@@ -166,6 +158,7 @@ class AimHandler
|
|
|
Vector3 Acc = default;
|
|
Vector3 Acc = default;
|
|
|
Vector3 Gyr = default;
|
|
Vector3 Gyr = default;
|
|
|
Vector3 Mag = default;
|
|
Vector3 Mag = default;
|
|
|
|
|
+ long TimeGap = default;
|
|
|
|
|
|
|
|
static Vector3 AccIdentity = new Vector3(0, -1, 0);
|
|
static Vector3 AccIdentity = new Vector3(0, -1, 0);
|
|
|
static Vector3 MagIdentity = new Vector3(-1, 2, 0).normalized;
|
|
static Vector3 MagIdentity = new Vector3(-1, 2, 0).normalized;
|
|
@@ -286,7 +279,7 @@ class AimHandler
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void onDataReceived(byte[] bytes)
|
|
|
|
|
|
|
+ public void OnDataReceived(byte[] bytes)
|
|
|
{
|
|
{
|
|
|
if (bytes.Length != 26)
|
|
if (bytes.Length != 26)
|
|
|
{
|
|
{
|
|
@@ -335,7 +328,7 @@ class AimHandler
|
|
|
msOld = ms;
|
|
msOld = ms;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- var TimeGap = ms - msOld;
|
|
|
|
|
|
|
+ TimeGap = ms - msOld;
|
|
|
msOld = ms;
|
|
msOld = ms;
|
|
|
|
|
|
|
|
newRotation = o06DOFUpdate(Acc * 10, Gyr, Mag, TimeGap);
|
|
newRotation = o06DOFUpdate(Acc * 10, Gyr, Mag, TimeGap);
|
|
@@ -360,15 +353,6 @@ class AimHandler
|
|
|
if (hasAutoIdentity)
|
|
if (hasAutoIdentity)
|
|
|
{
|
|
{
|
|
|
controlObj.transform.localRotation = Quaternion.Lerp(controlObj.transform.localRotation, newRotation, Time.deltaTime * 6);
|
|
controlObj.transform.localRotation = Quaternion.Lerp(controlObj.transform.localRotation, newRotation, Time.deltaTime * 6);
|
|
|
- // newEularAngles.x = baseEularAngles.x + newRotation.eulerAngles.x;
|
|
|
|
|
- // newEularAngles.y = baseEularAngles.y + newRotation.eulerAngles.y;
|
|
|
|
|
- // newEularAngles.z = baseEularAngles.z + newRotation.eulerAngles.z;
|
|
|
|
|
- // controlObj.transform.localRotation = Quaternion.Lerp(
|
|
|
|
|
- // controlObj.transform.localRotation,
|
|
|
|
|
- // Quaternion.Euler(newEularAngles.x, newEularAngles.y, newEularAngles.z),
|
|
|
|
|
- // Time.deltaTime * 8
|
|
|
|
|
- // );
|
|
|
|
|
- // controlObj.localEulerAngles = Vector3.Lerp(controlObj.localEulerAngles, newEularAngles, Time.deltaTime * 6);
|
|
|
|
|
}
|
|
}
|
|
|
if (doIdentity)
|
|
if (doIdentity)
|
|
|
{
|
|
{
|
|
@@ -384,15 +368,6 @@ class AimHandler
|
|
|
AccIdentity = AccOld;
|
|
AccIdentity = AccOld;
|
|
|
MagIdentity = MagOld;
|
|
MagIdentity = MagOld;
|
|
|
}
|
|
}
|
|
|
- // baseEularAngles.x = 0 - newRotation.eulerAngles.x;
|
|
|
|
|
- // baseEularAngles.y = 0 - newRotation.eulerAngles.y;
|
|
|
|
|
- // baseEularAngles.z = 0 - newRotation.eulerAngles.z;
|
|
|
|
|
- // newEularAngles.x = baseEularAngles.x + newRotation.eulerAngles.x;
|
|
|
|
|
- // newEularAngles.y = baseEularAngles.y + newRotation.eulerAngles.y;
|
|
|
|
|
- // newEularAngles.z = baseEularAngles.z + newRotation.eulerAngles.z;
|
|
|
|
|
- // controlObj.localEulerAngles = newEularAngles;
|
|
|
|
|
- // doIdentity = false;
|
|
|
|
|
- // hasAutoIdentity = true;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -401,6 +376,4 @@ class AimHandler
|
|
|
bool hasAutoIdentity = false;
|
|
bool hasAutoIdentity = false;
|
|
|
Quaternion newRotation;
|
|
Quaternion newRotation;
|
|
|
Quaternion baseRotation = new Quaternion(0, 0, 0, 1);
|
|
Quaternion baseRotation = new Quaternion(0, 0, 0, 1);
|
|
|
- Vector3 baseEularAngles = new Vector3();
|
|
|
|
|
- Vector3 newEularAngles = new Vector3();
|
|
|
|
|
}
|
|
}
|