Răsfoiți Sursa

1.修改测试工具

slambb 3 ani în urmă
părinte
comite
2f9c1bf156

Fișier diff suprimat deoarece este prea mare
+ 151 - 237
assets/boxingCount - jump.fire


+ 171 - 0
assets/js/heartBeat.ts

@@ -0,0 +1,171 @@
+const {
+    ccclass,
+    property
+} = cc._decorator;
+
+
+export class heartNode {
+    position: cc.Vec2;
+    heartBeat: heartBeat;
+
+    constructor(pos: cc.Vec2) {
+        this.position = pos;
+    }
+}
+
+@ccclass
+export default class heartBeat extends cc.Component {
+
+    @property(cc.Node)
+    rootNode: cc.Node = null;
+    @property(cc.Graphics)
+    Graphic: cc.Graphics = null;
+
+    /**
+     * 存储所有需要绘制的点
+     *
+     * @type {Array<heartNode>}
+     * @memberof heartBeat
+     */
+    heartNodeList: Array < heartNode >= null;
+
+    /**
+     * 移动速度
+     *
+     * @type {number}
+     * @memberof heartBeat
+     */
+    moveSpeed: number = 1;
+
+    /**
+     * 浮漂,最新创建的点会追逐这个浮漂
+     *
+     * @type {number}
+     * @memberof heartBeat
+     */
+    buoy: number = 0;
+
+    /**
+     * 跟随浮漂移动的当前值
+     *
+     * @type {number}
+     * @memberof heartBeat
+     */
+    nowValue: number = 0;
+
+    addPoint(y: number, qiangdu) {
+        // console.log(y);
+        if (this.heartNodeList == null) {
+            this.heartNodeList = new Array();
+        }
+
+        //控制游标到标定点
+        // this.buoy = -this.rootNode.height / 2 + (this.rootNode.height * y * 0.01);
+        this.buoy =(this.rootNode.height/2) * (y * 0.01);
+        // console.log("--> 游标位置:" + this.buoy);
+        // console.log("--> 实际数值:" + y);
+
+        // console.log("--> 强度 越强越长:" + qiangdu);
+        // let maiboqiangdu = MathUtil.reMap(qiangdu, 0, 100, 0.15, 0.25)
+        cc.tween(this)
+            .to(0.35, {
+                nowValue: this.buoy
+            }, {
+                easing: 'sineInOut'
+            })
+            .call(() => {
+                // this.buoy = -this.rootNode.height / 2;
+                this.buoy = 0;
+
+            })
+            .to(0.65, {
+                nowValue: -this.buoy
+                // nowValue: -this.rootNode.height / 2
+
+            }, {
+                easing: 'sineInOut'
+            })
+            .start();
+    }
+
+    //现在数据需要每帧更新
+    update(dt) {
+        //清空画布
+        this.Graphic.clear();
+
+        if (this.heartNodeList == null) {
+            return;
+        }
+        //没数据就不用画
+        if (this.heartNodeList.length <= 0) {
+            // this.heartNodeList.push(new heartNode(cc.v2(this.rootNode.width / 2, -this.rootNode.height / 2)));
+            this.heartNodeList.push(new heartNode(cc.v2(this.rootNode.width / 2, 0)));
+
+            return;
+        }
+        this.DrawCenterLine();
+        this.DrawWaveLine();
+    }
+
+    /**
+     * 绘制中间的横线
+     *
+     * @memberof heartBeat
+     */
+    DrawCenterLine(){
+        this.Graphic.strokeColor=new cc.Color(255,0,0,255);
+        this.Graphic.moveTo(-this.rootNode.width / 2,0);
+        this.Graphic.lineTo(this.rootNode.width / 2,0);
+        this.Graphic.stroke();
+    }
+
+
+    /**
+     * 绘制波浪线
+     *
+     * @memberof heartBeat
+     */
+    DrawWaveLine(){
+        this.Graphic.strokeColor=new cc.Color(0,255,0,255);
+        //先验证有多少个出界的,记录一下
+        let verificationCount = 0;
+
+        for (let i = 0; i < this.heartNodeList.length; i++) {
+            //计算出位置
+            if (this.heartNodeList[i].position.x < -this.rootNode.width / 2) {
+                verificationCount++;
+            } else {
+
+            }
+        }
+        if (verificationCount != 0) {
+            for (let i = 0; i < verificationCount; i++) {
+                this.heartNodeList.shift();
+            }
+        }
+
+        //验证完毕,可以绘制有效node
+        for (let i = 0; i < this.heartNodeList.length; i++) {
+            if (i == 0) {
+                this.Graphic.moveTo(this.heartNodeList[i].position.x, this.heartNodeList[i].position.y);
+            } else {
+                this.Graphic.lineTo(this.heartNodeList[i].position.x, this.heartNodeList[i].position.y);
+            }
+        }
+
+        //让所有node往左边移动一点
+        for (let i = 0; i < this.heartNodeList.length; i++) {
+            this.heartNodeList[i].position = cc.v2(this.heartNodeList[i].position.x - this.moveSpeed, this.heartNodeList[i].position.y);
+        }
+
+        // 添加一个新的中间点
+        let lerpNode = new heartNode(cc.v2(this.rootNode.width / 2, this.nowValue))
+        this.heartNodeList.push(lerpNode);
+
+        if (this.heartNodeList.length>=3) {
+        this.Graphic.stroke();
+            
+        }
+        
+    }
+}

+ 9 - 0
assets/js/heartBeat.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "532d41b9-5570-4efc-9460-a99e8078175f",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 246 - 158
assets/js/jump-0.3.js

@@ -27,6 +27,10 @@ Event.prototype.trigger = function () {
 		});
 	}
 };
+/**
+ * 公共部分计算参数
+ * 已时间为条件执行
+ */
 var jumpOpts = {
 	//是否上升的标志位
 	isDirectionUp: false,
@@ -59,7 +63,9 @@ var jumpOpts = {
 
 	//开始时间
 	startTime: 0,
-	endTime: 0
+	endTime: 0,
+
+	startResultant: 0
 }
 var ActionJump = function ActionJump() {
 
@@ -69,8 +75,18 @@ var ActionJump = function ActionJump() {
 	this.valleyOfWaveMinValue = 0;
 	this.valleyOfWaveMinValueCount = 0;
 	this.highestCount = 0;
+	//记录当前传入的数据
+	this.dataArray = [];
+	//获取一个判断数组的数据,比如触发点前后取一定帧数
+	//记录波形的个数,可重复添加
+	this.tempDataArray = [];
+
+
+	//记录一个加速计数组
+	this.oriAccArray = [];
 	//陀螺仪
 	this.oriGyroYArray = [];
+
 	this.event = new Event();
 	this.frameCapacity = 10;
 	this.frame = [];
@@ -88,6 +104,14 @@ var ActionJump = function ActionJump() {
 	}
 
 	this.frameLog = [];
+
+	this.LastMS = 0;
+	this.LastTime = 0;
+
+	this.xA = 0;
+	this.yA = 0;
+	this.zA = 0;
+
 }
 ActionJump.prototype.addEventListener = function (type, listener) {
 	this.event.addEventListener(type, listener);
@@ -138,7 +162,62 @@ ActionJump.prototype.updateJump = function () {
 	// oAccZ
 	// this.detectorNewStep(data.resultant, -lAccY, -lAccX, -lAccZ, -oAccY, -oAccX, -oAccZ, data.runIndex,
 	// 	_tempAxisData);
-	this.detectorNewStep(data);
+	//********传感器数值********
+	let { ax, ay, az } = data.acc;
+	let { gx, gy, gz } = data.gyro;
+	let { min, s, ms } = data;
+
+	let msGap = ms - this.LastMS;
+	if (msGap < 0) {
+		msGap += 1000;
+	}
+	this.LastMS = ms;
+	let _ax = data.acc.ax * 10;
+	let _ay = data.acc.ay * 10;
+	let _az = data.acc.az * 10;
+	//低通滤波分离重力
+	let curTime = new Date().getTime();
+	let alpha = 1000 / (1000 + msGap); // 0.8;
+	this.LastTime = curTime;
+	this.xA = alpha * this.xA + (1 - alpha) * _ax;
+	this.yA = alpha * this.yA + (1 - alpha) * _ay;
+	this.zA = alpha * this.zA + (1 - alpha) * _az;
+
+	//高通滤波获取线性速度
+	let linear_acceleration_x = _ax - this.xA;
+	let linear_acceleration_y = _ay - this.yA;
+	let linear_acceleration_z = _az - this.zA;
+
+	let _temp = {
+		oriAcc: {
+			oAccX: _ax,
+			oAccY: _ay,
+			oAccZ: _az
+		},
+		linearAcc: {
+			lAccX: linear_acceleration_x,
+			lAccY: linear_acceleration_y,
+			lAccZ: linear_acceleration_z
+		},
+		gravityAcc: {
+			gravityX: this.xA,
+			gravityY: this.yA,
+			gravityZ: this.zA
+		},
+		bLimitRebound: false,
+		resultant: Math.sqrt(_ax * _ax
+			+ _ay * _ay + _az * _az),
+		runIndex: data.BLEAccIndex,
+		//陀螺仪
+		oriGyro: {
+			oGyroX: gx,
+			oGyroY: gy,
+			oGyroZ: gz
+		},
+		bYAxis: data.isY
+	};
+
+	this.detectorNewStep(_temp);
 };
 
 
@@ -149,6 +228,15 @@ ActionJump.prototype.updateJump = function () {
 // ActionJump.prototype.detectorNewStep = function(resultant, linearX, linearY, linearZ, oriX, oriY, oriZ, _runIndex,
 // 	_oGyroY) 
 ActionJump.prototype.detectorNewStep = function (data) {
+
+	/**
+	 * 把數據返回
+	 */
+	this.event.trigger('resultant', {
+		type: "bUpdateDraw",
+		data: data
+	});
+
 	let {
 		oAccX,
 		oAccY,
@@ -159,182 +247,183 @@ ActionJump.prototype.detectorNewStep = function (data) {
 		oGyroY,
 		oGyroZ
 	} = data.oriGyro;
-	let {
-		bYAxis
-	} = data;
-	//oGyroX 在用的过程中方向相反,所以添加负号
-	let _oGyroY = bYAxis ? -oGyroX : oGyroY; //新设备直接使用oGyroY
-	let _judgmentValue = -oAccZ; //判断左右方向用z
 	let resultant = data.resultant; //合加速度
-	let _runIndex = data.runIndex; //下标
-
-	//判断resultant 一个阀值
-	let limitResultant = 12;
-	if (!this.jumpOpts.bStopJump) {
-		if (resultant > limitResultant && !this.jumpOpts.bUpState) {
-			//陀螺仪部分
-			// this.oriGyroYArray = [];
-			//开始更新。加入时间判断
-			this.jumpOpts.startTime = new Date().getTime();
-			let _diffTime = this.jumpOpts.startTime - this.jumpOpts.endTime; //开始时间和结束时间太小的话,不能开始
-			if (_diffTime < 150) {
-				return;
-			}
-			this.jumpOpts.bUpState = true;
-			this.event.trigger('resultant', {
-				type: "log",
-				logType: 'normal',
-				data: "开始时间:" + this.jumpOpts.startTime + ",resultant:" + resultant + ",bYAxis:" + bYAxis
-			});
-			this.highestCount = 0;
-			for (let i = 0; i < this.frame.length; i++) {
-				this.frame[i].maxValue = 0;
-				this.frame[i].gyroValue = 0;
-				this.frame[i].resultant = 0;
-				this.frame[i].index = -1;
-				this.frame[i].acc = null;
-				this.frame[i].gyro = null;
+
+	// 记录500个点
+	// 如果超过了,去除第一个点,加入最后一个元素
+	if (this.dataArray.length <= 500) {
+		this.dataArray.push(data);
+	} else {
+		this.dataArray.shift();
+		this.dataArray.push(data);
+	}
+
+	//判断resultant 一个阀值,简单的检测跳的动作触发幅度
+	let limitResultant = 20;
+	if (resultant > limitResultant && !this.jumpOpts.bUpState) {
+		let currTime = new Date().getTime(); //当前时间
+		// 清空触发的数值
+		this.tempDataArray = [];
+		let diffTime = currTime - this.jumpOpts.endTime; //当前时间减最初时间,得到当前时间差
+		if (Math.abs(diffTime) < 100) {
+			//前一帧到后一帧的间隔忽略 150 / 6 约25帧落地波动
+			return;
+		}
+		this.jumpOpts.bUpState = true;
+		//第一次触发的时间。记录开始时间
+		this.jumpOpts.startTime = new Date().getTime();
+		this.event.trigger('resultant', {
+			type: "log",
+			logType: 'normal',
+			data: "开始时间:" + this.jumpOpts.startTime + ",resultant:" + resultant
+		});
+		//取触发前一定帧数
+		let len = this.dataArray.length;
+		let total = 5;//取倒数5帧
+		if (len != 0) {
+			let newArr = [];
+			//长度超过
+			let limit = len - total;
+			if (limit > 0) {
+				for (let i = len; i > limit; i--) {
+					newArr.push(this.dataArray[i - 1]);
+				}
+				this.tempDataArray.push(newArr);
+			} else {
+				//直接添加数据
+				this.tempDataArray.push(this.dataArray.slice());
 			}
-			this.frameLog = [];
+
 		}
-		if (this.jumpOpts.bUpState) {
-			let currTime = new Date().getTime(); //当前时间
-			let diffTime = currTime - this.jumpOpts.startTime; //当前时间减最初时间,得到当前时间差
-			if (diffTime > 500) {
-				/**
-				 * 获取500毫秒内的数据
-				 * 如果超过限定时间,重置一下数据
-				 */
-				this.jumpOpts.startTime = currTime;
-				this.highestCount = 0;
-				for (let i = 0; i < this.frame.length; i++) {
-					this.frame[i].maxValue = 0;
-					this.frame[i].gyroValue = 0;
-					this.frame[i].resultant = 0;
-					this.frame[i].index = -1;
-					this.frame[i].acc = null;
-					this.frame[i].gyro = null;
+		console.log("start bUpState");
+	}
+	if (this.jumpOpts.bUpState) {
+
+		//取一个时间段为截取时间,计算时间段里面的数据
+		let currTime = new Date().getTime(); //当前时间
+		let diffTime = currTime - this.jumpOpts.startTime; //当前时间减最初时间,得到当前时间差
+		if (diffTime > 400) {
+			// console.log("diffTime:", diffTime);
+			//计算已出发的数据
+			// console.log(this.tempDataArray);
+			for (let i = 0; i < this.tempDataArray.length; i++) {
+				// 计算数据
+				this.resetAll();
+				let _frameMaxValue = 0,
+					_frameMinValue = 0,
+					_frameGyroValue = 0,
+					_frameGyroMinValue = 0;
+				for (let j = 0; j < this.tempDataArray[i].length; j++) {
+					let _data = this.tempDataArray[i][j];
+					if (j < 30) { //取前面30帧判断
+						let _judgmentValue = _data.linearAcc.lAccZ //_data.oriAcc.oAccZ; //判断左右方向用z
+						if (_judgmentValue > 1) {
+							_frameMaxValue += _judgmentValue;
+							if (_judgmentValue > this.peakOfWaveMaxValue) {
+								this.peakOfWaveMaxValue += _judgmentValue;
+								this.peakOfWaveMaxValueCount++;
+							}
+						} else if (_judgmentValue < -1) {
+							_frameMinValue += _judgmentValue;
+							if (_judgmentValue < this.valleyOfWaveMinValue) {
+								this.valleyOfWaveMinValue += _judgmentValue;
+								this.valleyOfWaveMinValueCount++;
+							}
+						}
+						if (_data.oriGyro.oGyroY > 5) {
+							_frameGyroValue += _data.oriGyro.oGyroY;
+						} else if (_data.oriGyro.oGyroY < -5) {
+							_frameGyroMinValue += _data.oriGyro.oGyroY;
+						}
+					}
+
 				}
-				this.frameLog = [];
-				// console.error("1************************************************************");
-				// console.log(this.frame);
-				// console.error("2************************************************************");
+				//后面通用使用这个类型传输数据
+				this.event.trigger('resultant', {
+					type: "stateDataOfJump",
+					currentMaxValue: _frameMaxValue,
+					currentMinValue: _frameMinValue,
+					peakOfWaveMaxValue: this.peakOfWaveMaxValue,
+					valleyOfWaveMinValue: this.valleyOfWaveMinValue,
+					oGyroValue: _frameGyroValue,
+					oGyroMinValue: _frameGyroMinValue,
+					// resultant: resultant,
+					tempIndex: i, //触发了多少次
+					// name: "highestCountEnd"
+				});
+				this.event.trigger('resultant', {
+					type: "stop",
+					tempDataArray: this.tempDataArray
+				});
 			}
-			// (this.frameOffset + this.frameLength) % this.frameCapacity
-			let newFrame = this.frame[this.frameOffset];
-			newFrame.index = _runIndex;
-			newFrame.acc = data.oriAcc;
-			newFrame.gyro = data.oriGyro;
+
+			this.jumpOpts.bUpState = false;
+			this.jumpOpts.endTime = new Date().getTime();
+
+			console.log("end bUpState");
+		} else {
+			//还在计算时间区间内,记录各帧的数据
+			for (let i = 0; i < this.tempDataArray.length; i++) {
+				let _dataArray = this.tempDataArray[i];
+				_dataArray.push(data);
+			}
+		}
+	}
+
+}
+
+ActionJump.prototype.setEndUpdate = function () {
+	for (let i = 0; i < this.tempDataArray.length; i++) {
+		// 计算数据
+		this.resetAll();
+		let _frameMaxValue = 0,
+			_frameMinValue = 0,
+			_frameGyroValue = 0;
+		for (let j = 0; j < this.tempDataArray[i].length; j++) {
+			let _data = this.tempDataArray[i][j];
+			let _judgmentValue = _data.oriAcc.oAccZ; //判断左右方向用z
 			if (_judgmentValue > 1) {
-				newFrame.maxValue = _judgmentValue;
+				_frameMaxValue += _judgmentValue;
 				if (_judgmentValue > this.peakOfWaveMaxValue) {
 					this.peakOfWaveMaxValue += _judgmentValue;
 					this.peakOfWaveMaxValueCount++;
 				}
 			} else if (_judgmentValue < -1) {
-				newFrame.maxValue = _judgmentValue;
+				_frameMinValue += _judgmentValue;
 				if (_judgmentValue < this.valleyOfWaveMinValue) {
 					this.valleyOfWaveMinValue += _judgmentValue;
 					this.valleyOfWaveMinValueCount++;
 				}
-			} else {
-				/**
-				 * 不符合条件设置为0
-				 */
-				newFrame.maxValue = 0;
 			}
-			if (Math.abs(_oGyroY) > 5) {
+			if (Math.abs(_data.oriGyro.oGyroY) > 5) {
 				// this.oriGyroYArray.push(_oGyroY);
-				newFrame.gyroValue = _oGyroY;
-			} else {
-				/**
-				 * 不符合条件设置为0
-				 */
-				newFrame.gyroValue = 0;
+				_frameGyroValue += _data.oriGyro.oGyroY;
 			}
-			newFrame.resultant = resultant;
-
-			//拷贝一个数据
-			this.frameLog.push(JSON.parse(JSON.stringify(newFrame)));
-			// console.log(JSON.parse(JSON.stringify(newFrame)));
-
-			//出现极值后
-			// Math.abs(linearZ) < 7 &&
-			if (Math.abs(resultant) < 7) {
-				this.highestCount++;
-				if (this.highestCount >= 2) {
-					//达到最高点,
-					this.jumpOpts.bStopJump = true;
-					this.jumpOpts.bUpdateTimeOfPeakCount = true;
-					let _frameMaxValue = 0,
-						_frameGyroValue = 0;
-					// let isPlus = false;
-					// if (this.peakOfWaveMaxValueCount >= this.valleyOfWaveMinValueCount) {
-					// 	isPlus = true;
-					// }
-					// console.log(this.frame);
-					// console.log(this.frameLog);
-					// this.sendLog(this.frameLog, 'socket');
-					for (let i = 0; i < this.frame.length; i++) {
-						_frameMaxValue += this.frame[i].maxValue;
-						_frameGyroValue += this.frame[i].gyroValue;
-						// if (isPlus && this.frame[i].maxValue > 0) {
-						// 	_frameMaxValue += this.frame[i].maxValue;
-						// 	_frameGyroValue += this.frame[i].gyroValue;
-						// } else if (!isPlus && this.frame[i].maxValue < 0) {
-						// 	_frameMaxValue += this.frame[i].maxValue;
-						// 	_frameGyroValue += this.frame[i].gyroValue;
-						// }
-					}
-					// console.log("frame:" + _frameMaxValue + " == " + _frameGyroValue);
-
-					//后面通用使用这个类型传输数据
-					this.event.trigger('resultant', {
-						type: "stateDataOfJump",
-						currentMaxValue: _frameMaxValue,
-						peakOfWaveMaxValue: this.peakOfWaveMaxValue,
-						valleyOfWaveMinValue: this.valleyOfWaveMinValue,
-						oGyroValue: _frameGyroValue,
-						resultant: resultant,
-						name: "highestCountEnd"
-					});
-					// this.jumpOpts.bUpState = false;
-					// this.jumpOpts.bStopJump = false;
-					this.event.trigger('resultant', {
-						type: "stop"
-					});
-					this.resetAll();
-				}
-			}
-			if ((this.frameOffset += 1) >= this.frameCapacity) {
-				this.frameOffset -= this.frameCapacity;
-			}
-		}
-	} else if (this.jumpOpts.bUpdateTimeOfPeakCount) {
-		// console.log("结束判断时候:" + resultant);
-		this.jumpOpts.timeOfPeakCount++;
-		//todo 如果直跳,可以调节更小的 limitTimeOfPeakCount 30
-		let limitTimeOfPeakCount = 10;
-		if (this.jumpOpts.timeOfPeakCount >= limitTimeOfPeakCount) {
-			this.jumpOpts.timeOfPeakCount = 0;
-			this.jumpOpts.bStopJump = false;
-			this.jumpOpts.bUpState = false;
-			// this.event.trigger('resultant', {
-			// 	type: "stop"
-			// });
-			// this.resetAll();
-			this.jumpOpts.bUpdateTimeOfPeakCount = false;
-			this.jumpOpts.endTime = new Date().getTime();
 		}
+		//后面通用使用这个类型传输数据
+		this.event.trigger('resultant', {
+			type: "stateDataOfJump",
+			currentMaxValue: _frameMaxValue,
+			currentMinValue: _frameMinValue,
+			peakOfWaveMaxValue: this.peakOfWaveMaxValue,
+			valleyOfWaveMinValue: this.valleyOfWaveMinValue,
+			oGyroValue: _frameGyroValue,
+			// resultant: resultant,
+			tempIndex: i, //触发了多少次
+			// name: "highestCountEnd"
+		});
+		this.event.trigger('resultant', {
+			type: "stop",
+			arrayData: this.dataArray
+		});
 	}
 
-	/**
-	 * 把數據返回
-	 */
-	this.event.trigger('resultant', {
-		type: "bUpdateDraw",
-		data: data
-	});
+	this.jumpOpts.bUpState = false;
+	// 清空触发的数值
+	this.tempDataArray = [];
+	this.jumpOpts.endTime = new Date().getTime();
+
+	console.log("end bUpState");
 }
 
 ActionJump.prototype.setBUpState = function (value) {
@@ -349,7 +438,6 @@ ActionJump.prototype.resetAll = function () {
 	this.peakOfWaveMaxValueCount = 0;
 	this.valleyOfWaveMinValue = 0;
 	this.valleyOfWaveMinValueCount = 0;
-	this.highestCount = 0;
 }
 
 /**

+ 4 - 0
assets/js/line.js

@@ -23,6 +23,10 @@ cc.Class({
 
         bPause: false,
 
+        /**
+         * 示波器
+         */
+
     },
 
     // LIFE-CYCLE CALLBACKS:

+ 337 - 301
assets/js/webview.js

@@ -237,11 +237,6 @@ cc.Class({
         bCalculation: false,
         calTimeout: null,
 
-
-
-
-
-
         //波动判断打击部分
         //记录打击的x 轴数据
         xArray: [],
@@ -340,6 +335,9 @@ cc.Class({
         rotate: { default: null, type: cc.Node },
 
         //记录当前数据
+        currentGameDataArray: [],
+        currentInterval: null,
+
         currentDataArray: [],
         //是否先手原始数据
         bShowOri: true,
@@ -361,25 +359,44 @@ cc.Class({
         },
         isY: true,
 
+        LastMS: 0,
+        LastTime: 0,
+
         /**
-      * 融合算法参数
-      */
+        * 融合算法部分使用的参数
+        */
         //记录时间
         timestamp: 0,
         //ms转s
         MS2S: 0.001,
-        //经过处理的总方向
+        //开始初始化bool
+        initState: true,
+        // angular speeds from gyro
+        gyro: new Array(3),
+        // rotation matrix from gyro data
         gyroMatrix: new Array(9),
         // orientation angles from gyro matrix
         gyroOrientation: new Array(3),
-
-        initState: true,
-        //加速计和磁力计融合值
+        // magnetic field vector
+        magnet: new Array(3),
+        // accelerometer vector
+        accel: new Array(3),
+        // orientation angles from accel and magnet
         accMagOrientation: new Array(3),
+        // final orientation angles from sensor fusion
+        fusedOrientation: new Array(3),
+        // accelerometer and magnetometer based rotation matrix
         rotationMatrix: new Array(9),
 
-        accel: new Array(3),
-        fusedOrientation: new Array(3),
+
+        /**
+         * 波形
+         */
+        drawX: {
+            default: null,
+            type: cc.Node,
+            tooltip: "绘制X节点",
+        },
     },
     onChangeAxis(event) {
         // console.log(event);
@@ -428,6 +445,8 @@ cc.Class({
 
         this.lineLinearY = this.drawNodeLinearY.getComponent("line");
 
+        this.drawXScript = this.drawX.getComponent("heartBeat");
+
 
         this.lineSqrt = this.drawNodeSqrt.getComponent("line");
 
@@ -455,20 +474,17 @@ cc.Class({
         /**
          * 算法初始参数
          */
+        this.gyroOrientation[0] = 0.0;
+        this.gyroOrientation[1] = 0.0;
+        this.gyroOrientation[2] = 0.0;
         // initialise gyroMatrix with identity matrix
         this.gyroMatrix[0] = 1.0; this.gyroMatrix[1] = 0.0; this.gyroMatrix[2] = 0.0;
         this.gyroMatrix[3] = 0.0; this.gyroMatrix[4] = 1.0; this.gyroMatrix[5] = 0.0;
         this.gyroMatrix[6] = 0.0; this.gyroMatrix[7] = 0.0; this.gyroMatrix[8] = 1.0;
 
-
-        this.gyroOrientation[0] = 0.0;
-        this.gyroOrientation[1] = 0.0;
-        this.gyroOrientation[2] = 0.0;
-
-
-
-
-
+        this.schedule(() => {
+            this.calculateFusedOrientationTask();
+        }, 0.03, 0, 1)
     },
 
     start() {
@@ -539,20 +555,39 @@ cc.Class({
                 // }
 
             } else if (e.type == 'stateDataOfJump') {
+                console.log('stateDataOfJump:', JSON.stringify(e));
+                // this.event.trigger('resultant', {
+                // 	type: "stateDataOfJump",
+                // 	currentMaxValue: _frameMaxValue,
+                // 	currentMinValue: _frameMinValue,
+                // 	peakOfWaveMaxValue: this.peakOfWaveMaxValue,
+                // 	valleyOfWaveMinValue: this.valleyOfWaveMinValue,
+                // 	oGyroValue: _frameGyroValue,
+                // 	resultant: resultant,
+                // 	tempIndex: i, //触发了多少次
+                // 	name: "highestCountEnd"
+                // });
+                console.log(Math.abs(e.currentMaxValue) > Math.abs(e.currentMinValue) ? "左方向" : "右方向");
+                console.log(Math.abs(e.oGyroValue) > Math.abs(e.oGyroMinValue) ? "右旋转" : "左旋转");
+                if (e.oGyroValue > 1000) {
+                    this.rotate.angle = 0;
+                } else if (e.oGyroMinValue < -1000) {
+                    this.rotate.angle = 180;
+                }
                 //发送给game,在game里面处理判断
-                if (this.gameScript)
-                    this.gameScript.listenStateDataOfJump(e, this.isY);
+                // if (this.gameScript)
+                // this.gameScript.listenStateDataOfJump(e, this.isY);
 
             } else if (e.type == 'bUpdateDraw') {
                 if (this.bAccDraw) {
                     let { lAccX, lAccY, lAccZ } = e.data.linearAcc;
                     let { oAccX, oAccY, oAccZ } = e.data.oriAcc;
-                    if (lAccX > 0)
-                        this.lineX.onUpdateDraw(lAccX);
-                    else
-                        this.lineX.onUpdateDrawFromColor(lAccX, cc.Color.WHITE, 2);
+                    // if (lAccX > 0)
+                    //     this.lineX.onUpdateDraw(lAccX);
+                    // else
+                    //     this.lineX.onUpdateDrawFromColor(lAccX, cc.Color.WHITE, 2);
 
-                    this.lineLinearX.onUpdateDrawFromColor(oAccX, "#00F0FF", 2);
+                    // this.lineLinearX.onUpdateDrawFromColor(oAccX, "#00F0FF", 2);
                     // this.z_k = mVector([e.linearZ]);
                     // this.KO.z_k = this.z_k;
                     // this.KM.update(this.KO);
@@ -563,20 +598,39 @@ cc.Class({
                     // else
                     //     this.lineZ.onUpdateDrawFromColor(this.KM.x_k.elements[0], cc.Color.WHITE, 2);
 
-                    if (lAccZ > 0)
-                        this.lineZ.onUpdateDraw(lAccZ);
-                    else
-                        this.lineZ.onUpdateDrawFromColor(lAccZ, cc.Color.WHITE, 2);
+                    // if (lAccZ > 0)
+                    // this.lineZ.onUpdateDraw(lAccZ);
+                    // else
+                    //     this.lineZ.onUpdateDrawFromColor(lAccZ, cc.Color.WHITE, 2);
+                    this.lineZ.onUpdateDraw(oAccZ);
 
-                    this.lineLinearZ.onUpdateDrawFromColor(oAccZ, "#00F0FF", 2);
+                    this.lineLinearZ.onUpdateDrawFromColor(lAccZ, "#00F0FF", 2);
 
                 }
             } else if (e.type == 'stop') {
+                console.log('stop');
+                this.onSaveData(this.currentGameDataArray);
+                this.lineX.clear();
+                this.lineY.clear();
+                this.lineLinearY.clear();
+                // 
+                let tempArray = e.tempDataArray[0];
+                for (let i = 0; i < tempArray.length; i++) {
+                    //绘制读取的数据
+                    this.lineY.onUpdateIndex();
+                    this.lineY.onUpdateDraw(tempArray[i].oriAcc.oAccZ);
+
+                    this.lineLinearY.onUpdateIndex();
+                    this.lineLinearY.onUpdateDraw(tempArray[i].linearAcc.lAccZ);
+
+                    if (i < 30) {
+                        this.lineX.onUpdateIndex();
+                        this.lineX.onUpdateDraw(tempArray[i].oriAcc.oAccZ);
+                    }
 
-                this.onClear();
-                // console.log('stop');
-            }
+                }
 
+            }
 
         })
 
@@ -594,65 +648,44 @@ cc.Class({
         }, 1000)
 
 
-        for (let i = 0; i < 3; i++) {
-            let box = {};
-            box["acc"] = {
-                ax: -i * Math.random() + 0.1,
-                ay: -i * Math.random() + 0.1,
-                az: i * Math.random() + 0.1
-            };
-            box["gyro"] = {
-                gx: -i * Math.random() + 0.1,
-                gy: -i * Math.random() + 0.1,
-                gz: i * Math.random() + 0.1
-            };
-            box["min"] = 0;
-            box["s"] = 0;
-            box["ms"] = 10 * i + 10;
-
-            this.onBLEBoxUpdate(box);
-        }
-    },
-    onLeft() {
-        let temp = {
-            gameData: {
-                xAxis: -10.5,
-                yAxis: 5,
-                zAxis: 0
-            }
-        }
-        this.onUpdateAcc(temp);
-    },
-    onRight() {
-        let temp = {
-            gameData: {
-                xAxis: 10.5,
-                yAxis: 5,
-                zAxis: 0
-            }
-        }
-        this.onUpdateAcc(temp);
-    },
-    onMid() {
-        let temp = {
-            gameData: {
-                xAxis: 0,
-                yAxis: 5,
-                zAxis: 100.5
-            }
-        }
-        this.onUpdateAcc(temp);
-    },
-
-    onStatic() {
-        let temp = {
-            gameData: {
-                xAxis: 0,
-                yAxis: 9.8,
-                zAxis: 0
-            }
-        }
-        this.onUpdateAcc(temp);
+        // for (let i = 0; i < 300; i++) {
+        //     let box = {};
+        //     box["acc"] = {
+        //         ax: -9 * Math.random() + 0.1,
+        //         ay: -9 * Math.random() + 0.1,
+        //         az: 9 * Math.random() + 0.1
+        //     };
+        //     box["gyro"] = {
+        //         gx: -9 * Math.random() + 0.1,
+        //         gy: -9 * Math.random() + 0.1,
+        //         gz: 9 * Math.random() + 0.1
+        //     };
+        //     box["min"] = 0;
+        //     box["s"] = 0;
+        //     box["ms"] = 10 * i + 10;
+
+        //     this.onBLEBoxUpdate(box);
+        // }
+        // let index = 0;
+        // this.schedule(() => {
+        //     let box = {};
+        //     box["acc"] = {
+        //         ax: -9 * Math.random() + 0.1,
+        //         ay: -9 * Math.random() + 0.1,
+        //         az: 9 * Math.random() + 0.1
+        //     };
+        //     box["gyro"] = {
+        //         gx: -9 * Math.random() + 0.1,
+        //         gy: -9 * Math.random() + 0.1,
+        //         gz: 9 * Math.random() + 0.1
+        //     };
+        //     box["min"] = 0;
+        //     box["s"] = 0;
+        //     box["ms"] = 10 * index + 10;
+        //     index ++ ;
+
+        //     this.onBLEBoxUpdate(box);
+        // }, 0.03)
     },
 
     //重置一下,记录的数据
@@ -690,7 +723,7 @@ cc.Class({
 
                 // console.log(gameData.data);
                 if (gameData.dataType == "Box") {
-                    webView.onBLEBoxUpdate(gameData.data);
+                    webView.onBLEBoxUpdate(gameData.data, true);
                 }
 
             } else if (name == "onDeviceUpdateJson") {
@@ -698,50 +731,40 @@ cc.Class({
                 if (gameData.dataType == "Json") {
                     webView.onBLEJsonUpdate(gameData.data);
                 }
-            }
-        });
-
-
-        // console.log(cc.sys.os);
-        // if (cc.sys.OS_WINDOWS === cc.sys.os || 'Android' === cc.sys.os) {
-
-        //     for (let i = 0; i < 100; i++) {
-        //         // setInterval(()=>{
-        //         let data = {
-        //             funName: 'onDeviceUpdateData',
-        //             gameData: {
-        //                 dataType: 'Box',
-        //                 data: {
-        //                     acc: { ax: Math.random(), ay: Math.random(), az: Math.random() },
-        //                     gyro: { gz: 1, gy: 1, gz: 1 },
-        //                     min: 1,
-        //                     s: 1,
-        //                     ms: 1
-        //                 }
-        //             }
-        //         }
-        //         notifyCenter.emit('webViewMessage', data);
-        //         // },20)
-        //     }
-
-        //     return;
-        //     // do something
-        // }
-        // uni.postMessage({
-        //     data: {
-        //         funName: "openAccelerometer",
-        //         gameData: {}
+            } else if (name == 'saveData') {
+                let gameData = data.gameData;
+                // console.log("saveData:", gameData.length);
+                //停止硬件更新
+                webView.onSendWriteBLEDataValue(null, 4);
+                let saveArrayData = gameData;
+                // for (let i = 0; i < saveArrayData.length; i++) {
+                //     console.log(saveArrayData[i]);
+                //     //绘制读取的数据
+                // }
+                if (this.currentInterval) {
+                    this.currentInterval = null;
+                    clearInterval(this.currentInterval);
+                }
+                let _index = 60;
+                let _length = saveArrayData.length - 370;
+                // this.currentInterval = setInterval(() => {
+                //     webView.onBLEBoxUpdate(saveArrayData[_index]);
+                //     _index++;
+                //     if (_index >= _length) {
+                //         clearInterval(this.currentInterval);
+                //     }
+                // }, 0, 0.006)
+
+                for (let i = _index; i < _length; i++) {
+                    //绘制读取的数据
+                    webView.onBLEBoxUpdate(saveArrayData[i]);
+                }
 
-        //     }
-        // })
+                this.actionJump.setEndUpdate();
+            }
 
-        // uni.postMessage({
-        //     data: {
-        //         funName: "openOrientation",
-        //         gameData: {}
+        });
 
-        //     }
-        // })
         // 监听蓝牙设备刷新
         uni.postMessage({
             data: {
@@ -791,165 +814,115 @@ cc.Class({
      * @param {*} gameData 
      * @returns 
      */
-    onBLEBoxUpdate(gameData) {
-        // console.log(gameData);
-        //********陀螺仪角速度********
-        let { gx, gy, gz } = gameData.gyro;
-        let { min, s, ms } = gameData;
-
-        //定义一个测试数据,加速计和磁力计的融合数据
-        // let accMagOrientation = new Array(0, 1, 0);
-        this.accel = [gx.gy, gz];
-        this.calculateAccMagOrientation(this.accel);
-        // initialisation of the gyroscope based rotation matrix
-        if (this.initState) {
-            let initMatrix = new Array(9);
-            initMatrix = this.getRotationMatrixFromOrientation(this.accMagOrientation);
-            let test = new Array(3);
-            this.getOrientation(initMatrix, test);
-            this.gyroMatrix = this.matrixMultiplication(this.gyroMatrix, initMatrix);
-            this.initState = false;
+    onBLEBoxUpdate(gameData, bAdd) {
+        //记录最近的500帧原始设备数据
+        if (bAdd) {
+            if (this.currentGameDataArray.length <= 500) {
+                this.currentGameDataArray.push(gameData);
+            } else {
+                this.currentGameDataArray.shift();
+                this.currentGameDataArray.push(gameData);
+            }
         }
 
-        // copy the new gyro values into the gyro array
-        // convert the raw gyro data into a rotation vector
-        let deltaVector = new Array(4);
-        // if (this.timestamp != 0) {
-
-        // }
-        let dT = (ms - this.timestamp) * this.MS2S;
-        this.getRotationVectorFromGyro([gx, gy, gz], deltaVector, dT / 2);
 
-        // measurement done, save current time for next interval
-        this.timestamp = ms;
-        // convert rotation vector into rotation matrix
-        let deltaMatrix = new Array(9);
-        // console.log("deltaVector1:" + deltaVector);
-        // console.log("deltaMatrix1:" + deltaMatrix);
-        this.getRotationMatrixFromVector(deltaMatrix, deltaVector);
-        // console.log("deltaVector2:" + deltaVector);
-        // console.log("deltaMatrix2:" + deltaMatrix);
-        // apply the new rotation interval on the gyroscope based rotation matrix
-        this.gyroMatrix = this.matrixMultiplication(this.gyroMatrix, deltaMatrix);
-        // console.log(this.gyroMatrix);
-        // console.log(this.gyroMatrix.length);
-        // get the gyroscope based orientation from the rotation matrix
-        this.getOrientation(this.gyroMatrix, this.gyroOrientation);
-
-        let FILTER_COEFFICIENT = 0.98;
-
-        let oneMinusCoeff = 1.0 - FILTER_COEFFICIENT;
-        this.fusedOrientation[0] =
-            FILTER_COEFFICIENT * this.gyroOrientation[0]
-            + oneMinusCoeff * this.accMagOrientation[0];
-
-        this.fusedOrientation[1] =
-            FILTER_COEFFICIENT * this.gyroOrientation[1]
-            + oneMinusCoeff * this.accMagOrientation[1];
-
-        this.fusedOrientation[2] =
-            FILTER_COEFFICIENT * this.gyroOrientation[2]
-            + oneMinusCoeff * this.accMagOrientation[2];
-
-        // overwrite gyro matrix and orientation with fused orientation
-        // to comensate gyro drift
-        this.gyroMatrix = this.getRotationMatrixFromOrientation(this.fusedOrientation);
-        // System.arraycopy(fusedOrientation, 0, gyroOrientation, 0, 3);
-
-        this.gyroOrientation[0] = this.fusedOrientation[0];
-        this.gyroOrientation[1] = this.fusedOrientation[1];
-        this.gyroOrientation[2] = this.fusedOrientation[2];
+        // console.log(gameData);
+        //********传感器数值********
+        let { ax, ay, az } = gameData.acc;
+        let { gx, gy, gz } = gameData.gyro;
+        let { min, s, ms } = gameData;
 
-        // this.oldOriBeta = gx;
-        // this.oldOriAlpha = gy;
-        // this.oldOriGamma = gz;
 
-        // let oriNew = Math.sqrt(this.oldOriBeta * this.oldOriBeta
-        //     + this.oldOriAlpha * this.oldOriAlpha + this.oldOriGamma * this.oldOriGamma);
 
-        // this.playerControScript.updateTime({ min: min, s: s, ms: ms });
-        // this.playerControScript.updateOri({ beta: gx, alpha: gy, gamma: gz });
+        // //更新
+        // //更新Accl
+        // this.accel = [ax, ay, az];
+        // this.calculateAccMagOrientation();
+        // //更新计算gyro
+        // this.gyroFunction([gx, gy, gz], ms);
 
         //更新index
         if (this.bAccDraw) {
-            this.lineX.onUpdateIndex();
+            // this.lineX.onUpdateIndex();
             this.lineZ.onUpdateIndex();
             // this.lineY.onUpdateIndex();
-
             this.lineLinearX.onUpdateIndex();
             // this.lineLinearY.onUpdateIndex();
             this.lineLinearZ.onUpdateIndex();
-
             this.lineSqrt.onUpdateIndex();
             this.lineOriSqrt.onUpdateIndex();
-
             // if (this.bGyroDraw) {
             //     this.lineX.onUpdateDrawOriBeta(gx);
             // this.lineX.onUpdateDrawOriGamma(gy);
             //     this.lineX.onUpdateDrawOriAlpha(gz);
             //     this.lineOriSqrt.onUpdateDraw(oriNew);
-
             // }
             // this.playerControScript.updateOriSqrt(oriNew);
-            // if (this.bGyroLog) {
-            //     console.log("gyro:" + JSON.stringify({ gx: gx, gy: gy, gz: gz }));
-            // }
-            //********手柄左右 */
-            // this.playerControScript.onHandleState(gameData.handle);
-        }
 
-        let _ax = gameData.acc.ax * 10;
-        let _ay = -gameData.acc.ay * 10;
-        let _az = -gameData.acc.az * 10;
-        //低通滤波分离重力
-        let alpha = 0.8;
-        this.xA = alpha * this.xA + (1 - alpha) * _ax;
-        this.yA = alpha * this.yA + (1 - alpha) * _ay;
-        this.zA = alpha * this.zA + (1 - alpha) * _az;
+        }
+        // var msGap = ms - this.LastMS;
+        // if (msGap < 0) {
+        //     msGap += 1000;
+        // }
+        // this.LastMS = ms;
+        // let _ax = gameData.acc.ax * 10;
+        // let _ay = gameData.acc.ay * 10;
+        // let _az = gameData.acc.az * 10;
+        // //低通滤波分离重力
+        // let curTime = new Date().getTime();
+        // let alpha = 1000 / (1000 + msGap); // 0.8;
+        // this.LastTime = curTime;
+        // this.xA = alpha * this.xA + (1 - alpha) * _ax;
+        // this.yA = alpha * this.yA + (1 - alpha) * _ay;
+        // this.zA = alpha * this.zA + (1 - alpha) * _az;
 
         //高通滤波获取线性速度
-        let linear_acceleration_x = _ax - this.xA;
-        let linear_acceleration_y = _az - this.zA;
-        let linear_acceleration_z = _ay - this.yA;
-
-        let _temp = {
-            linearAcc: {
-                lAccX: linear_acceleration_x,
-                lAccY: linear_acceleration_y,
-                lAccZ: linear_acceleration_z
-            }, //gameData.acc,
-            oriAcc: {
-                oAccX: _ax,
-                oAccY: _ay,
-                oAccZ: _az
-            },
-            gravityAcc: {
-                gravityX: this.xA,
-                gravityY: this.yA,
-                gravityZ: this.zA
-            },
-            bLimitRebound: false,
-            resultant: Math.sqrt(_ax * _ax
-                + _ay * _ay + _az * _az),
-            runIndex: this.BLEAccIndex,
-            //陀螺仪
-            oriGyro: {
-                oGyroX: gx,
-                oGyroY: gy,
-                oGyroZ: gz
-            },
-            //输入当前轴
-            bYAxis: this.isY,
-        };
-        this.actionJump.updateJump(_temp);
-        this.currentDataArray.push(_temp);
+        // let linear_acceleration_x = _ax - this.xA;
+        // let linear_acceleration_y = _ay - this.yA;
+        // let linear_acceleration_z = _az - this.zA;
+
+        // let _temp = {
+        //     oriAcc: {
+        //         oAccX: _ax,
+        //         oAccY: _ay,
+        //         oAccZ: _az
+        //     },
+        //     linearAcc: {
+        //         lAccX: linear_acceleration_x,
+        //         lAccY: linear_acceleration_y,
+        //         lAccZ: linear_acceleration_z
+        //     },
+        //     gravityAcc: {
+        //         gravityX: this.xA,
+        //         gravityY: this.yA,
+        //         gravityZ: this.zA
+        //     },
+        //     bLimitRebound: false,
+        //     resultant: Math.sqrt(_ax * _ax
+        //         + _ay * _ay + _az * _az),
+        //     runIndex: this.BLEAccIndex,
+        //     //陀螺仪
+        //     oriGyro: {
+        //         oGyroX: gx,
+        //         oGyroY: gy,
+        //         oGyroZ: gz
+        //     },
+        //     //输入当前轴
+        //     bYAxis: this.isY,
+        // };
+        gameData.BLEAccIndex = this.BLEAccIndex;
+        gameData.bYAxis = this.isY;
+        this.actionJump.updateJump(gameData);
+        // this.currentDataArray.push(_temp);
+
+        // this.drawXScript.addPoint(_temp.oriAcc.oAccX);
 
         if (this.bAccDraw) {
             //显示
             // this.playerControScript.updateAcc({ xAxis: _ax, yAxis: _ay, zAxis: _az });
             // this.playerControScript.updateAcc({ xAxis: deltaVector[0], yAxis: deltaVector[1], zAxis: deltaVector[2] });
             // this.playerControScript.updateStr(deltaVector[3]);
-            this.playerControScript.updateAcc({ xAxis: this.gyroOrientation[0], yAxis: this.gyroOrientation[1], zAxis: this.gyroOrientation[2] });
+            // this.playerControScript.updateAcc({ xAxis: this.gyroOrientation[0], yAxis: this.gyroOrientation[1], zAxis: this.gyroOrientation[2] });
             // this.playerControScript.updateSqrt(_temp.resultant);
 
             this.lineOriSqrt.onUpdateDraw(gy);
@@ -966,40 +939,8 @@ cc.Class({
 
 
         if (this.BLEAccIndex > 150) {
-
             this.onClear();
-
             this.bJump = false;
-
-            return;
-            if (!this.bJump) {
-                uni.postMessage({
-                    data: {
-                        funName: "writeBLEConnectionValue",
-                        gameData: {
-                            value: '4'
-                        }
-
-                    }
-                })
-
-                uni.postMessage({
-                    data: {
-                        funName: "writeBLEConnectionValue",
-                        gameData: {
-                            value: '6'
-                        }
-
-                    }
-                })
-
-
-            } else {
-                this.onClear();
-
-                this.bJump = false;
-            }
-
         }
         this.BLEAccIndex++;
 
@@ -1007,12 +948,12 @@ cc.Class({
     },
 
     onClear() {
-        this.lineX.clear();
+        // this.lineX.clear();
         this.lineZ.clear();
         // this.lineY.clear();
 
         this.lineLinearX.clear();
-        this.lineLinearY.clear();
+        // this.lineLinearY.clear();
         this.lineLinearZ.clear();
 
         this.lineSqrt.clear();
@@ -1057,6 +998,27 @@ cc.Class({
         console.log(this.gyroMatrix.length);
     },
 
+    onSaveData(data) {
+        uni.postMessage({
+            data: {
+                funName: "saveData",
+                gameData: {
+                    value: data
+                }
+
+            }
+        })
+    },
+
+    onGetData() {
+        uni.postMessage({
+            data: {
+                funName: "getData",
+                gameData: {}
+            }
+        })
+    },
+
     onOnlySendWriteBLEDataValue(event, data) {
         console.log(data);
         uni.postMessage({
@@ -1368,11 +1330,12 @@ cc.Class({
     },
 
 
-    calculateAccMagOrientation(accel) {
+    calculateAccMagOrientation() {
         // magnet
-        if (this.getRotationMatrix(this.rotationMatrix, null, accel, [1, 1, 1])) {
+        if (this.getRotationMatrix(this.rotationMatrix, null, this.accel, [1, 1, 1])) {
             this.getOrientation(this.rotationMatrix, this.accMagOrientation);
         }
+        // this.getOrientation(this.rotationMatrix, this.accel);
     },
 
     getRotationMatrix(R, I, gravity, geomagnetic) {
@@ -1445,5 +1408,78 @@ cc.Class({
             }
         }
         return true;
+    },
+
+    gyroFunction(gyroValues, timeMs) {
+        // don't start until first accelerometer/magnetometer orientation has been acquired
+        if (this.accMagOrientation == null)
+            return;
+
+        // initialisation of the gyroscope based rotation matrix
+        if (this.initState) {
+            let initMatrix = new Array(9);
+            initMatrix = this.getRotationMatrixFromOrientation(this.accMagOrientation);
+            let test = new Array(3);
+            this.getOrientation(initMatrix, test);
+            this.gyroMatrix = this.matrixMultiplication(this.gyroMatrix, initMatrix);
+            this.initState = false;
+        }
+
+        // copy the new gyro values into the gyro array
+        // convert the raw gyro data into a rotation vector
+        let deltaVector = new Array(4);
+        // if (this.timestamp != 0) {
+
+        // }
+        let dT = (timeMs - this.timestamp) * this.MS2S;
+        this.gyro = [];
+        gyroValues.forEach((item) => this.gyro.push(item));
+
+        this.getRotationVectorFromGyro(this.gyro, deltaVector, dT / 2.0);
+
+        // measurement done, save current time for next interval
+        this.timestamp = timeMs;
+        // convert rotation vector into rotation matrix
+        let deltaMatrix = new Array(9);
+        // console.log("deltaVector1:" + deltaVector);
+        // console.log("deltaMatrix1:" + deltaMatrix);
+        this.getRotationMatrixFromVector(deltaMatrix, deltaVector);
+        // console.log("deltaVector2:" + deltaVector);
+        // console.log("deltaMatrix2:" + deltaMatrix);
+        // apply the new rotation interval on the gyroscope based rotation matrix
+        this.gyroMatrix = this.matrixMultiplication(this.gyroMatrix, deltaMatrix);
+        // console.log(this.gyroMatrix);
+        // console.log(this.gyroMatrix.length);
+        // get the gyroscope based orientation from the rotation matrix
+        this.getOrientation(this.gyroMatrix, this.gyroOrientation);
+    },
+
+    /**
+     * 主要计算
+     */
+    calculateFusedOrientationTask() {
+
+        let FILTER_COEFFICIENT = 0.98;
+
+        let oneMinusCoeff = 1.0 - FILTER_COEFFICIENT;
+        this.fusedOrientation[0] =
+            FILTER_COEFFICIENT * this.gyroOrientation[0]
+            + oneMinusCoeff * this.accMagOrientation[0];
+
+        this.fusedOrientation[1] =
+            FILTER_COEFFICIENT * this.gyroOrientation[1]
+            + oneMinusCoeff * this.accMagOrientation[1];
+
+        this.fusedOrientation[2] =
+            FILTER_COEFFICIENT * this.gyroOrientation[2]
+            + oneMinusCoeff * this.accMagOrientation[2];
+
+        // overwrite gyro matrix and orientation with fused orientation
+        // to comensate gyro drift
+        this.gyroMatrix = this.getRotationMatrixFromOrientation(this.fusedOrientation);
+        // System.arraycopy(fusedOrientation, 0, gyroOrientation, 0, 3);
+        this.gyroOrientation = [];
+        this.fusedOrientation.forEach((item) => this.gyroOrientation.push(item));
+
     }
 });

+ 1 - 1
settings/project.json

@@ -12,7 +12,7 @@
     "3D Physics/Builtin",
     "SafeArea"
   ],
-  "last-module-event-record-time": 1631243745535,
+  "last-module-event-record-time": 1661097968229,
   "design-resolution-width": 960,
   "design-resolution-height": 640,
   "fit-width": false,

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff