|
|
@@ -176,8 +176,6 @@ class AimHandler
|
|
|
Vector3 Gyr = default;
|
|
|
Vector3 Mag = default;
|
|
|
o09Axis _9Axis = new o09Axis();
|
|
|
- //是否校正地磁计
|
|
|
- bool bAjustMagnetometer = false;
|
|
|
//转换读取的数据,无符号->有符号
|
|
|
float TwoByteToFloat(byte b1, byte b2)
|
|
|
{
|
|
|
@@ -225,24 +223,20 @@ class AimHandler
|
|
|
MagCalibrationButton.onClick.AddListener(delegate {
|
|
|
|
|
|
// if (MagCalibrater.Calibration)
|
|
|
- if (bAjustMagnetometer)
|
|
|
+ if (MagCalibrater.Calibration)
|
|
|
{
|
|
|
- // MagCalibrater.Calibration = false;
|
|
|
- bAjustMagnetometer = false;
|
|
|
+ Debug.Log(MagCalibrater.Calibration);
|
|
|
+ MagCalibrater.Calibration = false;
|
|
|
+ Debug.Log(MagCalibrater.Calibration);
|
|
|
MagCalibrationButton.GetComponentInChildren<Text>().text = "开始地磁计校准";
|
|
|
- float[] dataFloats = new float[6];
|
|
|
- dataFloats[0] = MagCalibrater.Center.x;
|
|
|
- dataFloats[1] = MagCalibrater.Center.y;
|
|
|
- dataFloats[2] = MagCalibrater.Center.z;
|
|
|
- dataFloats[3] = MagCalibrater.Radius.x;
|
|
|
- dataFloats[4] = MagCalibrater.Radius.y;
|
|
|
- dataFloats[5] = MagCalibrater.Radius.z;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // MagCalibrater.Calibration = true;
|
|
|
- bAjustMagnetometer = true;
|
|
|
- MagCalibrationButton.GetComponentInChildren<Text>().text = "停止地磁计校准";
|
|
|
+ Debug.Log(MagCalibrater.Calibration);
|
|
|
+ MagCalibrater.Calibration = true;
|
|
|
+
|
|
|
+ Debug.Log(MagCalibrater.Calibration);
|
|
|
+ MagCalibrationButton.GetComponentInChildren<Text>().text = "停止地磁计校准";
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -340,8 +334,20 @@ class AimHandler
|
|
|
TimeGap = ms - msOld;
|
|
|
msOld = ms;
|
|
|
|
|
|
- newRotation = _9Axis.Update(Acc * 10, Gyr, Mag, TimeGap);
|
|
|
-
|
|
|
+ _9Axis.Update(Acc * 10, Gyr, Mag, TimeGap);
|
|
|
+ if(_9Axis.States.Count() < 10){
|
|
|
+ newRotation = _9Axis.States.Last().Qua;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int MuliteLerpCount = 10;
|
|
|
+ for (var i = 0;i< MuliteLerpCount;++i)
|
|
|
+ {
|
|
|
+ newRotation = Quaternion.Slerp(newRotation, _9Axis.States[_9Axis.States.Count() - MuliteLerpCount + i].Qua, 1/(i+1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
receiveDataCount++;
|
|
|
if (!hasAutoIdentity && receiveDataCount == 5) {
|
|
|
doIdentity = true;
|