|
@@ -68,6 +68,8 @@ var jumpOpts = {
|
|
|
valleyOfWave: 0,
|
|
|
//检测到极快的波动的次数
|
|
|
timeOfPeakCount: 0,
|
|
|
+ //开始添加
|
|
|
+ bUpdateTimeOfPeakCount: false,
|
|
|
//开始更新的次数
|
|
|
startCount: 0,
|
|
|
//停止跳
|
|
@@ -89,6 +91,8 @@ var ActionJump = function ActionJump() {
|
|
|
//陀螺仪
|
|
|
this.oriGyroYArray = [];
|
|
|
|
|
|
+ this.isJumpTop = false;
|
|
|
+
|
|
|
this.event = new Event();
|
|
|
|
|
|
}
|
|
@@ -133,7 +137,6 @@ ActionJump.prototype.updateJump = function() {
|
|
|
* */
|
|
|
ActionJump.prototype.detectorNewStep = function(resultant, linearX, linearY, linearZ, oriX, oriY, oriZ, _runIndex,
|
|
|
_oGyroY) {
|
|
|
- let bUpdate = true;
|
|
|
let _judgmentValue = oriZ;
|
|
|
if (this.jumpOpts.gravityOld == 0) {
|
|
|
this.jumpOpts.gravityOld = _judgmentValue;
|
|
@@ -146,72 +149,87 @@ ActionJump.prototype.detectorNewStep = function(resultant, linearX, linearY, lin
|
|
|
value
|
|
|
} = this.detectorPeakOfWaveAndValleyOfWave(_judgmentValue, this.jumpOpts.gravityOld);
|
|
|
if (bState) {
|
|
|
- this.jumpOpts.bUpState = true;
|
|
|
- let _temp = {
|
|
|
- type: bType,
|
|
|
- oldValue: value,
|
|
|
- value: resultant,
|
|
|
- lastIndex: _runIndex - 1
|
|
|
- };
|
|
|
- this.event.trigger('resultant', _temp);
|
|
|
- bUpdate = false;
|
|
|
+ if (!this.jumpOpts.bUpState) {
|
|
|
+ this.jumpOpts.bUpState = true;
|
|
|
+ this.isJumpTop = false;
|
|
|
+ this.highestCount = 0;
|
|
|
+ //陀螺仪部分
|
|
|
+ this.oriGyroYArray = [];
|
|
|
+ this.jumpOpts.startCount = 0;
|
|
|
+ }
|
|
|
+ // let _temp = {
|
|
|
+ // type: bType,
|
|
|
+ // oldValue: value,
|
|
|
+ // // value: resultant,
|
|
|
+ // lastIndex: _runIndex - 1
|
|
|
+ // };
|
|
|
+ // this.event.trigger('resultant', _temp);
|
|
|
//记录最高点和最低点数组
|
|
|
if (bType == 'peakOfWave') {
|
|
|
- this.peakOfWaveArray.push(_temp);
|
|
|
- if (value > this.peakOfWaveMaxValue)
|
|
|
- this.peakOfWaveMaxValue = value;
|
|
|
-
|
|
|
- console.log("peakOfWave=",value,this.peakOfWaveMaxValue);
|
|
|
+ this.peakOfWaveArray.push(value);
|
|
|
+ // if (value > this.peakOfWaveMaxValue)
|
|
|
+ this.peakOfWaveMaxValue += value;
|
|
|
} else if (bType == 'valleyOfWave') {
|
|
|
- this.valleyOfWaveArray.push(_temp);
|
|
|
- if (value < this.valleyOfWaveMinValue)
|
|
|
- this.valleyOfWaveMinValue = value;
|
|
|
-
|
|
|
- console.log("valleyOfWave=",value,this.valleyOfWaveMinValue);
|
|
|
+ this.valleyOfWaveArray.push(value);
|
|
|
+ // if (value < this.valleyOfWaveMinValue)
|
|
|
+ this.valleyOfWaveMinValue += value;
|
|
|
}
|
|
|
- this.highestCount = 0;
|
|
|
- //陀螺仪部分
|
|
|
- this.oriGyroYArray = [];
|
|
|
-
|
|
|
- this.jumpOpts.startCount = 0;
|
|
|
-
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.jumpOpts.bUpState) {
|
|
|
+ if(Math.abs(_oGyroY)>10)
|
|
|
+ this.oriGyroYArray.push(_oGyroY);
|
|
|
+ // this.jumpOpts.startCount++;
|
|
|
+ // if (this.jumpOpts.startCount >= 7 ) {
|
|
|
+ // console.log("startCount peakOfWaveArray", JSON.stringify(this.peakOfWaveArray));
|
|
|
+ // console.log("startCount valleyOfWaveArray", JSON.stringify(this.valleyOfWaveArray));
|
|
|
+ // if (this.peakOfWaveArray.length !== 0 || this.valleyOfWaveArray.length !== 0) {
|
|
|
+ // let _currentMaxValue = 0;
|
|
|
+ // if (this.peakOfWaveMaxValue > 5) {
|
|
|
+ // _currentMaxValue = this.peakOfWaveMaxValue;
|
|
|
+ // } else if (this.valleyOfWaveMinValue < -5) {
|
|
|
+ // _currentMaxValue = this.valleyOfWaveMinValue;
|
|
|
+ // }
|
|
|
+ // let allOGyroValue = 0;
|
|
|
+ // for (let i = 0; i < this.oriGyroYArray.length; i++) {
|
|
|
+ // allOGyroValue += this.oriGyroYArray[i];
|
|
|
+ // }
|
|
|
+ // allOGyroValue /= this.oriGyroYArray.length;
|
|
|
+ // //这里相当于处理识别到跳,但是没有判断出什么动作。
|
|
|
+ // this.event.trigger('resultant', {
|
|
|
+ // type: "stateDataOfJump",
|
|
|
+ // currentMaxValue: _currentMaxValue,
|
|
|
+ // oGyroValue: allOGyroValue,
|
|
|
+ // resultant: resultant,
|
|
|
+ // name: "startCountEnd"
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // 如果加过一定数量。判断没有触发,重置状态
|
|
|
+ // this.jumpOpts.bUpState = false;
|
|
|
+ // this.jumpOpts.bStopJump = true;
|
|
|
+ // this.jumpOpts.bUpdateTimeOfPeakCount = true;
|
|
|
+ // this.resetAll();
|
|
|
+ // }
|
|
|
|
|
|
- this.oriGyroYArray.push(_oGyroY);
|
|
|
-
|
|
|
- this.jumpOpts.startCount++;
|
|
|
- if (this.jumpOpts.startCount >= 15) {
|
|
|
- //如果加过一定数量。判断没有触发,重置状态
|
|
|
- this.jumpOpts.bUpState = false;
|
|
|
- this.resetAll();
|
|
|
- this.jumpOpts.startCount = 0;
|
|
|
-
|
|
|
- let allOGyroValue = 0;
|
|
|
- for (let i = 0; i < this.oriGyroYArray.length; i++) {
|
|
|
- allOGyroValue += this.oriGyroYArray[i];
|
|
|
- }
|
|
|
- allOGyroValue /= this.oriGyroYArray.length;
|
|
|
-
|
|
|
- //这里相当于处理识别到跳,但是没有判断出什么动作。
|
|
|
- this.event.trigger('resultant', {
|
|
|
- type: "stateDataOfJump",
|
|
|
- currentMaxValue: 0,
|
|
|
- oGyroValue: allOGyroValue,
|
|
|
- resultant: resultant
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
//出现极值后
|
|
|
if (Math.abs(linearZ) < 7 && Math.abs(resultant) < 7) {
|
|
|
+ // this.isJumpTop = true;
|
|
|
this.highestCount++;
|
|
|
if (this.highestCount >= 2) {
|
|
|
//达到最高点,
|
|
|
this.jumpOpts.bStopJump = true;
|
|
|
+ this.jumpOpts.bUpdateTimeOfPeakCount = true;
|
|
|
+ // this.isJumpTop = false;
|
|
|
|
|
|
let _currentMaxValue = 0;
|
|
|
+ console.log("highestCount peakOfWaveArray", JSON.stringify(this.peakOfWaveArray));
|
|
|
+ console.log("highestCount valleyOfWaveArray", JSON.stringify(this.valleyOfWaveArray));
|
|
|
+ console.log("达到最高点时候数值 Max:", this.peakOfWaveMaxValue, " min:", this.valleyOfWaveMinValue);
|
|
|
+ //(Math.abs(this.peakOfWaveMaxValue) > 5 && Math.abs(this.valleyOfWaveMinValue) - Math
|
|
|
+ // .abs(this.peakOfWaveMaxValue) < 10) ||
|
|
|
if (Math.abs(this.peakOfWaveMaxValue) > Math.abs(this.valleyOfWaveMinValue)) {
|
|
|
_currentMaxValue = this.peakOfWaveMaxValue;
|
|
|
} else {
|
|
@@ -256,21 +274,19 @@ ActionJump.prototype.detectorNewStep = function(resultant, linearX, linearY, lin
|
|
|
this.event.trigger('resultant', {
|
|
|
type: "stateDataOfJump",
|
|
|
currentMaxValue: _currentMaxValue,
|
|
|
+ peakOfWaveMaxValue: this.peakOfWaveMaxValue,
|
|
|
+ valleyOfWaveMinValue: this.valleyOfWaveMinValue,
|
|
|
oGyroValue: allOGyroValue,
|
|
|
- resultant: resultant
|
|
|
+ resultant: resultant,
|
|
|
+ name: "highestCountEnd"
|
|
|
});
|
|
|
-
|
|
|
- // bUpdate = false;
|
|
|
this.jumpOpts.bUpState = false;
|
|
|
- this.resetAll();
|
|
|
-
|
|
|
-
|
|
|
- console.log("resetAll:", this.jumpOpts.startCount);
|
|
|
+ // this.resetAll();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
+ } else if (this.jumpOpts.bUpdateTimeOfPeakCount) {
|
|
|
this.jumpOpts.timeOfPeakCount++;
|
|
|
if (this.jumpOpts.timeOfPeakCount >= 30) {
|
|
|
this.jumpOpts.timeOfPeakCount = 0;
|
|
@@ -280,8 +296,10 @@ ActionJump.prototype.detectorNewStep = function(resultant, linearX, linearY, lin
|
|
|
});
|
|
|
console.log("timeOfPeakCount >=30");
|
|
|
this.resetAll();
|
|
|
+ this.jumpOpts.bUpdateTimeOfPeakCount = false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// let result = Math.atan2(averX, averZ) * 180 / (Math.PI);
|
|
|
// result = Math.round(result);
|
|
|
// let curAngle = result > 0 ? result : (360 + result);
|
|
@@ -314,7 +332,7 @@ ActionJump.prototype.detectorPeakOfWaveAndValleyOfWave = function(newValue, oldV
|
|
|
this.jumpOpts.continueDownCount++;
|
|
|
}
|
|
|
if (!this.jumpOpts.isDirectionUp && this.jumpOpts.lastStatus && this.jumpOpts.continueUpFormerCount >= 2 && Math
|
|
|
- .abs(oldValue) >= 5) {
|
|
|
+ .abs(oldValue) > 4) {
|
|
|
this.jumpOpts.peakOfWave = oldValue;
|
|
|
return {
|
|
|
value: oldValue,
|
|
@@ -322,7 +340,7 @@ ActionJump.prototype.detectorPeakOfWaveAndValleyOfWave = function(newValue, oldV
|
|
|
bState: true
|
|
|
};
|
|
|
} else if (!this.jumpOpts.lastStatus && this.jumpOpts.isDirectionUp && this.jumpOpts.continueDownFormerCount >=
|
|
|
- 2 && Math.abs(oldValue) >= 5) {
|
|
|
+ 2 && Math.abs(oldValue) > 4) {
|
|
|
this.jumpOpts.valleyOfWave = oldValue;
|
|
|
return {
|
|
|
value: oldValue,
|
|
@@ -351,6 +369,8 @@ ActionJump.prototype.resetAll = function() {
|
|
|
this.jumpOpts.continueDownCount = 0;
|
|
|
this.jumpOpts.continueUpFormerCount = 0;
|
|
|
this.jumpOpts.continueUpCount = 0;
|
|
|
+
|
|
|
+ // this.jumpOpts.gravityOld = 0;
|
|
|
}
|
|
|
|
|
|
if (typeof module === "object" && typeof module.exports === "object") {
|