|
@@ -15,7 +15,7 @@ module.exports = {
|
|
|
this.frameOffset = 0;
|
|
|
|
|
|
this.frameHitCapacity = 11;
|
|
|
- this.frameHit = [];//打击后的n帧
|
|
|
+ this.frameHit = []; //打击后的n帧
|
|
|
|
|
|
for (var i = 0; i < this.frameCapacity; ++i) {
|
|
|
var o = new Object();
|
|
@@ -49,9 +49,9 @@ module.exports = {
|
|
|
var newDirectionDistance = newDirection.length;
|
|
|
if (directionDistance < newDirectionDistance) {
|
|
|
directionDistance = newDirectionDistance;
|
|
|
- direction = newDirection.multiply(this.frameHit[this.frameHit.length - 1].time - this.frameHit[0].time);
|
|
|
- }
|
|
|
- else {
|
|
|
+ direction = newDirection.multiply(this.frameHit[this.frameHit.length - 1].time -
|
|
|
+ this.frameHit[0].time);
|
|
|
+ } else {
|
|
|
//cout << "false" << endl;
|
|
|
}
|
|
|
}
|
|
@@ -79,18 +79,22 @@ module.exports = {
|
|
|
if (this.stableCount < this.stableCountMax) {
|
|
|
this.stableCount += 1;
|
|
|
}
|
|
|
- this.stableAcc = this.stableAcc.multiply((this.stableCount - 1.0) / this.stableCount).plus(rawAcc.multiply(1 / this.stableCount));
|
|
|
- this.stableGyr = this.stableGyr.multiply((this.stableCount - 1.0) / this.stableCount).plus(rawGyr.multiply(1 / this.stableCount));
|
|
|
+ this.stableAcc = this.stableAcc.multiply((this.stableCount - 1.0) / this.stableCount).plus(
|
|
|
+ rawAcc.multiply(1 / this.stableCount));
|
|
|
+ this.stableGyr = this.stableGyr.multiply((this.stableCount - 1.0) / this.stableCount).plus(
|
|
|
+ rawGyr.multiply(1 / this.stableCount));
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
newFrame.accFixed = newFrame.acc.length * 100;
|
|
|
|
|
|
if (newFrame.accFixed < lastFrame.accFixed * 0.85) {
|
|
|
newFrame.accFixed = lastFrame.accFixed * 0.85;
|
|
|
}
|
|
|
- lastFrame.accFixed = Math.max(lastFrame.accFixed, Math.min(newFrame.accFixed, last2Frame.accFixed), Math.min(newFrame.accFixed, last3Frame.accFixed));
|
|
|
+ lastFrame.accFixed = Math.max(lastFrame.accFixed, Math.min(newFrame.accFixed, last2Frame
|
|
|
+ .accFixed), Math.min(newFrame.accFixed, last3Frame.accFixed));
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
//newFrame.pos = lastFrame.pos.plus(lastFrame.acc.plus(newFrame.acc).multiply(timeGap/60)).multiply(Math.max(1-timeGap/200,0));
|
|
|
- newFrame.pos = lastFrame.pos.plus(newFrame.acc.multiply(timeGap / 30)).multiply(Math.max(1 - timeGap / 1000, 0));
|
|
|
+ newFrame.pos = lastFrame.pos.plus(newFrame.acc.multiply(timeGap / 30)).multiply(Math.max(1 -
|
|
|
+ timeGap / 1000, 0));
|
|
|
////////////////////////////////////////////
|
|
|
newFrame.accSlope = Math.max(newFrame.accFixed - lastFrame.accFixed, 0);
|
|
|
|
|
@@ -101,8 +105,10 @@ module.exports = {
|
|
|
var t4 = newFrame.timeGap + t3;
|
|
|
|
|
|
newFrame.predict = new o0.Vector2(
|
|
|
- new o0.QuadraticEquation(0, this.frame[lastI - 2].pos.x, t2, this.frame[lastI - 1].pos.x, t3, this.frame[lastI].pos.x).y(t4),
|
|
|
- new o0.QuadraticEquation(0, this.frame[lastI - 2].pos.y, t2, this.frame[lastI - 1].pos.y, t3, this.frame[lastI].pos.y).y(t4));/** */
|
|
|
+ new o0.QuadraticEquation(0, this.frame[lastI - 2].pos.x, t2, this.frame[lastI - 1].pos
|
|
|
+ .x, t3, this.frame[lastI].pos.x).y(t4),
|
|
|
+ new o0.QuadraticEquation(0, this.frame[lastI - 2].pos.y, t2, this.frame[lastI - 1].pos
|
|
|
+ .y, t3, this.frame[lastI].pos.y).y(t4)); /** */
|
|
|
|
|
|
newFrame.shake = o0.distance2(newFrame.predict, newFrame.pos) * 100;
|
|
|
|
|
@@ -114,25 +120,29 @@ module.exports = {
|
|
|
newFrame.shakeFixed = lastFrame.shakeFixed * 0.85;
|
|
|
if (newFrame.shake > newFrame.shakeFixed) {
|
|
|
newFrame.shakeFixed = newFrame.shake;
|
|
|
- }/* */
|
|
|
- lastFrame.shakeFixed = Math.max(lastFrame.shakeFixed, Math.min(newFrame.shakeFixed, last2Frame.shakeFixed), Math.min(newFrame.shakeFixed, last3Frame.shakeFixed));
|
|
|
+ } /* */
|
|
|
+ lastFrame.shakeFixed = Math.max(lastFrame.shakeFixed, Math.min(newFrame.shakeFixed, last2Frame
|
|
|
+ .shakeFixed), Math.min(newFrame.shakeFixed, last3Frame.shakeFixed));
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
newFrame.shakeSlope = Math.max(newFrame.shakeFixed - lastFrame.shakeFixed, 0);
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
var direction = undefined;
|
|
|
|
|
|
- if (lastFrame.hit == 0
|
|
|
- && last2Frame.hit == 0
|
|
|
- && last3Frame.hit == 0
|
|
|
- && last4Frame.hit == 0
|
|
|
- && last5Frame.hit == 0
|
|
|
- && (newFrame.accSlope >= 15 || lastFrame.accSlope >= 20)
|
|
|
- && (newFrame.shakeSlope >= 20 || lastFrame.shakeSlope >= 40)) {
|
|
|
+ //15 20 20 40 , 13 17 17 35
|
|
|
+ let slopeArr = [15, 20, 20, 40];
|
|
|
+ if (lastFrame.hit == 0 &&
|
|
|
+ last2Frame.hit == 0 &&
|
|
|
+ last3Frame.hit == 0 &&
|
|
|
+ last4Frame.hit == 0 &&
|
|
|
+ last5Frame.hit == 0 &&
|
|
|
+ (newFrame.accSlope >= slopeArr[0] || lastFrame.accSlope >= slopeArr[1]) &&
|
|
|
+ (newFrame.shakeSlope >= slopeArr[2] || lastFrame.shakeSlope >= slopeArr[3])) {
|
|
|
newFrame.hit = 1;
|
|
|
- if (this.frameHit.length < this.frameHitCapacity && this.frameHit.length != 0) {//判断到第二次hit,但还未输出第一次hit的方向,强制输出方向
|
|
|
+ if (this.frameHit.length < this.frameHitCapacity && this.frameHit.length !=
|
|
|
+ 0) { //判断到第二次hit,但还未输出第一次hit的方向,强制输出方向
|
|
|
direction = this.GetDirection();
|
|
|
- }/**/
|
|
|
+ } /**/
|
|
|
this.frameHit = [];
|
|
|
|
|
|
/*
|
|
@@ -160,7 +170,7 @@ module.exports = {
|
|
|
//o.gyr = this.frameHit[this.frameHit.length-1].gyr.plus(newFrame.gyr);
|
|
|
o.gyr = newFrame.gyr;
|
|
|
this.frameHit.push(o);
|
|
|
- if (this.frameHit.length == this.frameHitCapacity) {//累计达到设定的延迟帧数,输出方向
|
|
|
+ if (this.frameHit.length == this.frameHitCapacity) { //累计达到设定的延迟帧数,输出方向
|
|
|
direction = this.GetDirection();
|
|
|
}
|
|
|
}
|
|
@@ -171,39 +181,39 @@ module.exports = {
|
|
|
}
|
|
|
|
|
|
getTempValue(curDirection) {
|
|
|
- let result = Math.atan2(curDirection.y,curDirection.x) * 180 / (Math.PI);
|
|
|
- result = Math.round(result);
|
|
|
- let curAngle = result > 0 ? result:(360 + result);
|
|
|
-
|
|
|
+ let result = Math.atan2(curDirection.y, curDirection.x) * 180 / (Math.PI);
|
|
|
+ result = Math.round(result);
|
|
|
+ let curAngle = result > 0 ? result : (360 + result);
|
|
|
+
|
|
|
let directionPunch = "all",
|
|
|
name = "击中",
|
|
|
ename = "hit";
|
|
|
-
|
|
|
- if (curAngle < 110 && curAngle >= 70) {
|
|
|
+ let positiveMidSlope = [72.5,107.5];//min max
|
|
|
+ let negativeMidSlope = [252.5,287.5];//min max
|
|
|
+ if (curAngle < positiveMidSlope[1] && curAngle >= positiveMidSlope[0]) {
|
|
|
directionPunch = "straightPunch";
|
|
|
name = "正向的直拳";
|
|
|
ename = "front-straight";
|
|
|
- } else if (curAngle < 70 && curAngle >= 0) {
|
|
|
+ } else if (curAngle < positiveMidSlope[0] && curAngle >= 0) {
|
|
|
directionPunch = "rightPunch";
|
|
|
name = "正向的右拳";
|
|
|
ename = "front-right";
|
|
|
- } else if (curAngle >= 110 && curAngle <= 180) {
|
|
|
+ } else if (curAngle <= 180 && curAngle >= positiveMidSlope[1]) {
|
|
|
directionPunch = "leftPunch";
|
|
|
name = "正向的左拳";
|
|
|
ename = "front-left";
|
|
|
}
|
|
|
//相反方向击打
|
|
|
//正方向
|
|
|
- else if (curAngle > 180 && curAngle <= 250) {
|
|
|
- directionPunch = "rightPunch";
|
|
|
- name = "负向的右拳";
|
|
|
- ename = "back-right";
|
|
|
- }
|
|
|
- else if (curAngle > 250 && curAngle <= 290) {
|
|
|
+ else if (curAngle <= negativeMidSlope[1] && curAngle > negativeMidSlope[0]) {
|
|
|
directionPunch = "straightPunch";
|
|
|
name = "负向的直拳";
|
|
|
ename = "back-straight";
|
|
|
- } else if (curAngle > 290 && curAngle <= 360) {
|
|
|
+ } else if (curAngle <= negativeMidSlope[0] && curAngle > 180) {
|
|
|
+ directionPunch = "rightPunch";
|
|
|
+ name = "负向的右拳";
|
|
|
+ ename = "back-right";
|
|
|
+ } else if (curAngle <= 360 && curAngle > negativeMidSlope[1]) {
|
|
|
directionPunch = "leftPunch";
|
|
|
name = "负向的左拳";
|
|
|
ename = "back-left";
|
|
@@ -229,4 +239,4 @@ module.exports = {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-};
|
|
|
+};
|