testWebview.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. // window.onWebViewMessage = function (data) {
  2. // let name = data.funName;
  3. // if (name == "onWatchAccelerometer") {
  4. // /**
  5. // * 返回加速计的数据
  6. // * {
  7. // * xAxis
  8. // * yAxis
  9. // * zAxis
  10. // * }
  11. // */
  12. // testWeb.onUpdateAcc(data);
  13. // } else if (name == "onWatchOrientation") {
  14. // /**
  15. // * 返回加速计的数据
  16. // * {
  17. // * xAxis
  18. // * yAxis
  19. // * zAxis
  20. // * }
  21. // */
  22. // testWeb.onUpdateOri(data);
  23. // } else if (name == "onBoxingPostHit") {
  24. // console.log(data);
  25. // testWeb.onUpdateBoxingPostHit(data.gameData);
  26. // } else if (name == "updateAccAndGyro") {
  27. // // console.log(data.gameData);
  28. // testWeb.onUpdateAccAndGyro(data.gameData);
  29. // }
  30. // }
  31. import notifyCenter from '../utils/global';
  32. var o0 = require('o0');
  33. var o0Project = require('o0Project');
  34. // var o0ProjectRelease = require('o0ProjectRelease');
  35. var o0ProjectRelease = require('o0ProjectRelease0.1');
  36. cc.Class({
  37. extends: cc.Component,
  38. properties: {
  39. count: 10,
  40. mass: {
  41. default: 50,
  42. type: cc.Integer,
  43. tooltip: "物体质量/kg",
  44. serializable: true,
  45. },
  46. LCount: {
  47. default: 0,
  48. type: cc.Integer,
  49. tooltip: "左勾拳打击次数",
  50. visible: false,
  51. serializable: false,
  52. },
  53. RCount: {
  54. default: 0,
  55. type: cc.Integer,
  56. tooltip: "右勾拳打击次数",
  57. visible: false,
  58. serializable: false,
  59. },
  60. ZCount: {
  61. default: 0,
  62. type: cc.Integer,
  63. tooltip: "直拳打击次数",
  64. visible: false,
  65. serializable: false,
  66. },
  67. showLCount: {
  68. default: null,
  69. type: cc.Label,
  70. serializable: true
  71. },
  72. showLPower: {
  73. default: null,
  74. type: cc.Label,
  75. serializable: true
  76. },
  77. showRCount: {
  78. default: null,
  79. type: cc.Label,
  80. serializable: true
  81. },
  82. showRPower: {
  83. default: null,
  84. type: cc.Label,
  85. serializable: true
  86. },
  87. showMCount: {
  88. default: null,
  89. type: cc.Label,
  90. serializable: true
  91. },
  92. showMPower: {
  93. default: null,
  94. type: cc.Label,
  95. serializable: true
  96. },
  97. showOriLabel: {
  98. default: null,
  99. type: cc.Label,
  100. serializable: true
  101. },
  102. showAccLabel: {
  103. default: null,
  104. type: cc.Label,
  105. serializable: true
  106. },
  107. showCalLabel: {
  108. default: null,
  109. type: cc.Label,
  110. serializable: true
  111. },
  112. xA: {
  113. default: 0,
  114. type: cc.Float,
  115. tooltip: "x轴负向",
  116. visible: false,
  117. serializable: false,
  118. },
  119. yA: {
  120. default: 0,
  121. type: cc.Float,
  122. tooltip: "y轴负向",
  123. visible: false,
  124. serializable: false,
  125. },
  126. zA: {
  127. default: 0,
  128. type: cc.Float,
  129. tooltip: "z轴负向",
  130. visible: false,
  131. serializable: false,
  132. },
  133. xO: {
  134. default: 0,
  135. type: cc.Float,
  136. tooltip: "以x方向为轴心的旋转角度,beta",
  137. visible: false,
  138. serializable: false,
  139. },
  140. yO: {
  141. default: 0,
  142. type: cc.Float,
  143. tooltip: "以y方向为轴心的旋转角度, gamma",
  144. visible: false,
  145. serializable: false,
  146. },
  147. zO: {
  148. default: 0,
  149. type: cc.Float,
  150. tooltip: "以z方向为轴心的旋转角度,alpha",
  151. visible: false,
  152. serializable: false,
  153. },
  154. calZVector: {
  155. default: 0,
  156. type: cc.Float,
  157. tooltip: "通过陀螺仪计算的z轴加速度分量",
  158. visible: false,
  159. serializable: false,
  160. },
  161. oldZ: {
  162. default: 0,
  163. type: cc.Float,
  164. tooltip: "相等时候,重置旧的值",
  165. visible: false,
  166. serializable: false,
  167. },
  168. oldXL: {
  169. default: 0,
  170. type: cc.Float,
  171. tooltip: "相等时候,重置旧的值",
  172. visible: false,
  173. serializable: false,
  174. },
  175. //检测左手打击
  176. bCanXL: {
  177. default: false,
  178. visible: false,
  179. serializable: true
  180. },
  181. oldXLArr: {
  182. default: [],
  183. visible: false,
  184. serializable: true,
  185. },
  186. oldXLOriArr: {
  187. default: [],
  188. visible: false,
  189. serializable: true,
  190. },
  191. oldXLTempZArr: {
  192. default: [],
  193. visible: false,
  194. serializable: true,
  195. },
  196. oldXLTempArr: {
  197. default: [],
  198. visible: false,
  199. serializable: true,
  200. },
  201. // 检测右手打击
  202. bCanXR: {
  203. default: false,
  204. visible: false,
  205. serializable: true
  206. },
  207. oldXRAccArr: {
  208. default: [],
  209. visible: false,
  210. serializable: true,
  211. },
  212. oldXROriArr: {
  213. default: [],
  214. visible: false,
  215. serializable: true,
  216. },
  217. oldXRTempArr: {
  218. default: [],
  219. visible: false,
  220. serializable: true,
  221. },
  222. oldXRTempZArr: {
  223. default: [],
  224. visible: false,
  225. serializable: true,
  226. },
  227. bCanZ: {
  228. default: false,
  229. visible: false,
  230. serializable: true
  231. },
  232. oldXR: {
  233. default: 0,
  234. type: cc.Float,
  235. tooltip: "相等时候,重置旧的值",
  236. visible: false,
  237. serializable: false,
  238. },
  239. oldGamma: {
  240. default: 0,
  241. type: cc.Float,
  242. tooltip: "旧的y旋转值",
  243. visible: false,
  244. serializable: false,
  245. },
  246. calXVector: {
  247. default: 0,
  248. type: cc.Float,
  249. tooltip: "加速度矢量计算的x分量",
  250. visible: false,
  251. serializable: false,
  252. },
  253. // 打一拳,大约消耗的热量,是450*4/60=1.875 焦耳。
  254. // 因为打拳一小时,需要消耗的热量是450大卡,而一分钟约打一下,一大卡是4焦耳。
  255. calorie: {
  256. default: 0,
  257. type: cc.Float,
  258. tooltip: "x轴负向",
  259. visible: false,
  260. serializable: false,
  261. },
  262. showCalorieLabel: {
  263. default: null,
  264. type: cc.Label,
  265. serializable: true
  266. },
  267. //ori基准值
  268. oriRefValue: {
  269. default: null,
  270. visible: false,
  271. serializable: false,
  272. },
  273. audioNode: {
  274. default: null,
  275. type: cc.Node,
  276. serializable: true,
  277. },
  278. audioScript: {
  279. default: null,
  280. visible: false,
  281. },
  282. accAndGyroLabel: {
  283. default: null,
  284. type: cc.Label,
  285. serializable: true
  286. },
  287. Filter: null,
  288. LastTime: new Date().getTime(),
  289. },
  290. // LIFE-CYCLE CALLBACKS:
  291. onLoad() {
  292. window.testWeb = this;
  293. this.audioScript = this.audioNode.getComponent("testAudio");
  294. // this.Filter = new o0Project.Filter();
  295. this.Filter = new o0ProjectRelease.SandbagAlgorithm();
  296. },
  297. start() {
  298. this.oriRefValue = {
  299. "alpha": 0,
  300. "beta": 0,
  301. "gamma": 0,
  302. }
  303. this.onBind();
  304. },
  305. onResetRef() {
  306. // this.xO = o.beta;
  307. // this.zO = o.alpha;
  308. // this.yO = o.gamma;
  309. this.oriRefValue["alpha"] = this.zO;
  310. this.oriRefValue["beta"] = this.xO;
  311. this.oriRefValue["gamma"] = this.yO;
  312. },
  313. onBind() {
  314. uni.postMessage({
  315. data: {
  316. funName: "openAccelerometer",
  317. gameData: {}
  318. }
  319. })
  320. // uni.postMessage({
  321. // data: {
  322. // funName: "openOrientation",
  323. // gameData: {}
  324. // }
  325. // })
  326. // console.log("onBind");
  327. // uni.postMessage({
  328. // data: {
  329. // funName: "bindHitBoxingPost",
  330. // gameData: {}
  331. // }
  332. // })
  333. notifyCenter.on('webViewMessage', (data) => {
  334. // console.log(data);
  335. let name = data.funName;
  336. if (name == "onWatchAccelerometer") {
  337. /**
  338. * 返回加速计的数据
  339. * {
  340. * xAxis
  341. * yAxis
  342. * zAxis
  343. * }
  344. */
  345. testWeb.onUpdateAcc(data);
  346. } else if (name == "onWatchOrientation") {
  347. /**
  348. * 返回加速计的数据
  349. * {
  350. * xAxis
  351. * yAxis
  352. * zAxis
  353. * }
  354. */
  355. testWeb.onUpdateOri(data);
  356. } else if (name == "onBoxingPostHit") {
  357. console.log(data);
  358. testWeb.onUpdateBoxingPostHit(data.gameData);
  359. } else if (name == "updateAccAndGyro") {
  360. // console.log(data.gameData);
  361. testWeb.onUpdateAccAndGyro(data.gameData);
  362. }
  363. });
  364. // uni.postMessage({
  365. // data: {
  366. // funName: "onStartAccAndGyro",
  367. // gameData: {}
  368. // }
  369. // })
  370. console.log("onStartAccAndGyro");
  371. },
  372. onUnBind() {
  373. notifyCenter.off('webViewMessage');
  374. // uni.postMessage({
  375. // data: {
  376. // funName: "onStopAccAndGyro",
  377. // gameData: {}
  378. // }
  379. // })
  380. // uni.postMessage({
  381. // data: {
  382. // funName: "unbindHitBoxingPost",
  383. // gameData: {}
  384. // }
  385. // })
  386. uni.postMessage({
  387. data: {
  388. funName: "closeAccelerometer",
  389. gameData: {}
  390. }
  391. })
  392. // uni.postMessage({
  393. // data: {
  394. // funName: "closeOrientation",
  395. // gameData: {}
  396. // }
  397. // })
  398. },
  399. onResetXL() {
  400. this.bCanXL = false;
  401. this.oldXLArr = [];
  402. this.oldXLOriArr = [];
  403. this.oldXLTempArr = [];
  404. this.oldXLTempZArr = [];
  405. },
  406. onResetXR() {
  407. this.bCanXR = false;
  408. this.oldXRAccArr = [];
  409. this.oldXROriArr = [];
  410. this.oldXRTempArr = [];
  411. this.oldXRTempZArr = [];
  412. },
  413. onUpdateAcc(data) {
  414. let a = data.gameData;
  415. this.xA = a.xAxis;
  416. this.yA = a.yAxis;
  417. this.zA = a.zAxis;
  418. },
  419. onPlayAudio() {
  420. this.audioScript.onPlayBoxingTip(0);
  421. },
  422. onUpdateOri(data) {
  423. let o = data.gameData;
  424. this.showAccLabel.string = "x:" + this.xA.toFixed(2) + "\ny:" + this.yA.toFixed(2) + "\nz:" + this.zA.toFixed(2);
  425. this.showOriLabel.string = "Orientation\nz-Alpha:" + o.alpha + "\nx-Beta:" + o.beta + "\ny-Gamma:" + o.gamma;
  426. this.xO = o.beta;
  427. this.zO = o.alpha;
  428. this.yO = o.gamma;
  429. //1.求出z 和 x 的加速度矢量
  430. //z轴的重力加速度矢量分量
  431. this.calZVector = (Math.cos(this.xO / 180 * Math.PI) * 9.8);
  432. //x轴的重力加速度的矢量分量
  433. if (this.yA > 9.8)
  434. this.yA = 9.8;
  435. let tempXVector = Math.pow(9.8, 2) - (Math.pow(this.calZVector, 2) + Math.pow(this.yA, 2));
  436. this.calXVector = Math.sqrt(Math.abs(tempXVector));
  437. //2.当前的加速度矢量减去分量,就是打击的加速度
  438. let tempZ = Math.abs(this.zA) - Math.abs(this.calZVector);
  439. let tempX = Math.abs(this.xA) - Math.abs(this.calXVector);
  440. //3.判断 那个轴的打击方向,就走哪个轴的计算流程
  441. //左勾拳,手机的左边受力,向右运动 && this.oldXLArr.length < 5 && this.xA < -1
  442. let tempValue = 2;
  443. //|| (this.yO > this.oriRefValue["gamma"] + tempValue && this.xO < this.oriRefValue["beta"] + tempValue)
  444. if ((this.xA > tempValue && this.zA < tempValue)) {
  445. if (this.bCanXL) {
  446. setTimeout(() => {
  447. this.onResetXL();
  448. }, 1000);
  449. return;
  450. }
  451. this.bCanXL = true;
  452. let _endPower = (Math.abs(tempX) + Math.abs(tempZ)) * this.mass;
  453. if (Math.abs(tempZ) > 3) {
  454. this.LCount++;
  455. this.showLCount.string = "L击中次数" + this.LCount;
  456. // this.showLPower.string = _endPower.toFixed(3) + " kg";
  457. this.showCalLabel.string = _endPower.toFixed(1) + " 斤";
  458. this.audioScript.onPlayBoxingTip(0);
  459. }
  460. // this.oldXLArr.push(this.xA);
  461. // this.oldXLOriArr.push(this.yO);
  462. // this.oldXLTempArr.push(tempX);
  463. // this.oldXLTempZArr.push(tempZ);
  464. // //如果记录第一次时候,只有一个值
  465. // if (this.oldXLArr.length == 1) {
  466. // // setTimeout(() => {
  467. // if (this.bCanXL) return;
  468. // this.bCanXL = true;
  469. // //去第一帧受力,和 记录的最大值 gamma 角度 方向相同
  470. // let _max = Math.max.apply(null, this.oldXLOriArr);
  471. // let _maxIndex = 0;
  472. // for (var i = 0; i < this.oldXLOriArr.length - 1; i++) {
  473. // if (this.oldXLOriArr[i] == _max) {
  474. // _maxIndex = i;
  475. // break;
  476. // }
  477. // }
  478. // let _power = this.oldXLTempArr[_maxIndex] ? this.oldXLTempArr[_maxIndex].toFixed(3) : 0;
  479. // let _zPower = this.oldXRTempZArr[_maxIndex] ? this.oldXRTempZArr[_maxIndex].toFixed(3) : 0;
  480. // if (_power != 0) {
  481. // this.LCount++;
  482. // this.showLCount.string = "L击中次数" + this.LCount;
  483. // let _endPower = (Math.abs(_power) + Math.abs(_zPower)) * this.mass;
  484. // this.showLPower.string = _endPower.toFixed(3) + " kg";
  485. // }
  486. // // console.log(this.oldXLArr, this.oldXLOriArr);
  487. // // }, 100);
  488. // }
  489. }
  490. //右勾拳,手机右边受力,向左运动 && this.oldXRAccArr.length < 5 && this.xA > 2
  491. // ||
  492. // (this.yO < this.oriRefValue["gamma"] - tempValue && this.xO < this.oriRefValue["beta"] - tempValue)
  493. if ((this.xA < -tempValue && this.zA < tempValue)) {
  494. if (this.bCanXR) {
  495. setTimeout(() => {
  496. this.onResetXR();
  497. }, 1000);
  498. return;
  499. }
  500. this.bCanXR = true;
  501. // console.log("有力量啊:", tempX, tempZ);
  502. let _endPower = (Math.abs(tempX) + Math.abs(tempZ)) * this.mass;
  503. if (Math.abs(tempZ) > 3) {
  504. this.RCount++;
  505. this.showRCount.string = "R击中次数" + this.RCount;
  506. // this.showRPower.string = _endPower.toFixed(3) + " kg";
  507. this.showCalLabel.string = _endPower.toFixed(1) + " 斤";
  508. this.audioScript.onPlayBoxingTip(2);
  509. }
  510. // this.oldXRAccArr.push(this.xA);
  511. // this.oldXROriArr.push(this.yO);
  512. // this.oldXRTempArr.push(tempX);
  513. // this.oldXRTempZArr.push(tempZ);
  514. // console.log("tempX", tempX);
  515. //如果记录第一次时候,只有一个值
  516. // if (this.oldXRAccArr.length == 1) {
  517. // // setTimeout(() => {
  518. // if (this.bCanXR) return;
  519. // this.bCanXR = true;
  520. // //去第一帧受力,和 记录的最大值 gamma 角度 方向相同
  521. // let _max = Math.max.apply(null, this.oldXROriArr);
  522. // let _maxIndex = 0;
  523. // for (var i = 0; i < this.oldXROriArr.length - 1; i++) {
  524. // if (this.oldXROriArr[i] == _max) {
  525. // _maxIndex = i;
  526. // console.log("==_maxIndex:", _maxIndex);
  527. // break;
  528. // }
  529. // }
  530. // let _power = this.oldXRTempArr[_maxIndex] ? this.oldXRTempArr[_maxIndex].toFixed(3) : 0;
  531. // let _zPower = this.oldXRTempZArr[_maxIndex] ? this.oldXRTempZArr[_maxIndex].toFixed(3) : 0;
  532. // if (_power != 0) {
  533. // console.log("有力量啊:", this.oldXRTempArr[_maxIndex]);
  534. // this.RCount++;
  535. // this.showRCount.string = "R击中次数" + this.RCount;
  536. // let _endPower = (Math.abs(_power) + Math.abs(_zPower)) * this.mass;
  537. // this.showRPower.string = _endPower.toFixed(3) + " kg";
  538. // }
  539. // // console.log("R=", this.oldXRAccArr, this.oldXROriArr, this.oldXRTempArr[_maxIndex], _maxIndex);
  540. // // }, 100);
  541. // }
  542. }
  543. //直拳判断 && Math.abs(tempZ) > 0.5
  544. if (this.zA > 2 && Math.abs(this.xA) < tempValue) {
  545. // if (Math.abs(this.yO - this.oriRefValue["gamma"]) > 2 || this.xO > this.oriRefValue["beta"]) return;
  546. if (this.bCanZ) {
  547. setTimeout(() => {
  548. this.bCanZ = false;
  549. }, 1000);
  550. return;
  551. }
  552. this.bCanZ = true;
  553. let _endPower = Math.abs(tempZ) * this.mass;
  554. if (Math.abs(tempZ) > 3) {
  555. this.ZCount++;
  556. this.showMCount.string = "击中" + this.ZCount;
  557. // this.showMPower.string = _endPower.toFixed(3) + " kg";
  558. this.showCalLabel.string = _endPower.toFixed(1) + " 斤";
  559. this.audioScript.onPlayBoxingTip(1);
  560. }
  561. //如果当前的加速度大于旧的值,并且 差值为 deltaV,判断打击
  562. // let deltaV = 3;
  563. // if (tempZ > this.oldZ + deltaV) {
  564. // this.oldZ = tempZ;
  565. // if (this.bCanZ) return;
  566. // this.bCanZ = true;
  567. // this.ZCount++;
  568. // this.showMCount.string = "击中" + this.ZCount;
  569. // this.showMPower.string = tempZ.toFixed(1) * this.mass + " kg";
  570. // setTimeout(() => {
  571. // this.oldZ = 0;
  572. // this.bCanZ = false;
  573. // console.log("重置this.oldZ", this.oldZ);
  574. // }, 200);
  575. // }
  576. }
  577. // if (this.yO < 0 && Math.abs(_yo) > 2 && this.xA < 0 && Math.abs(tempX) > 0.3) {
  578. // // if (this.yO >= 0) return;
  579. // if (this.xO > 95) return;
  580. // if (this.bCanXL) return;
  581. // //用陀螺仪判断立柱的方向,静止或者方向是正确方向
  582. // //记录 矢量的最大值
  583. // if (tempX > this.oldXR) {
  584. // this.oldXR = tempX;
  585. // if (this.bCanR) return;
  586. // this.bCanR = true;
  587. // // console.log(this.xA + " R= " + this.calXVector.toFixed(2) + " = " + tempX.toFixed(2));
  588. // this.RCount++;
  589. // this.showRCount.string = "R击中次数" + this.RCount;
  590. // this.showRPower.string = tempX.toFixed(1) * this.mass + " kg";
  591. // setTimeout(() => {
  592. // this.oldXR = 0;
  593. // this.bCanR = false;
  594. // console.log("重置this.oldXR", this.oldXR);
  595. // }, 1000);
  596. // }
  597. // }
  598. // let _yo = this.yO - this.oldGamma;
  599. // if (Math.abs(_yo) > 2)
  600. // if (this.xO < 95)
  601. //直拳判断
  602. // if (this.zA > 0 && Math.abs(tempZ) > 0.5) {
  603. // if (Math.abs(this.yO) > 3 || this.xO > 95) return;
  604. // //如果当前的加速度大于旧的值,并且 差值为 deltaV,判断打击
  605. // let deltaV = 5;
  606. // if (tempZ > this.oldZ + deltaV) {
  607. // this.oldZ = tempZ;
  608. // if (this.bCanZ) return;
  609. // this.bCanZ = true;
  610. // this.ZCount++;
  611. // this.showMCount.string = "击中" + this.ZCount;
  612. // this.showMPower.string = tempZ.toFixed(1) * this.mass + " kg";
  613. // setTimeout(() => {
  614. // this.oldZ = 0;
  615. // this.bCanZ = false;
  616. // console.log("重置this.oldZ", this.oldZ);
  617. // }, 800);
  618. // }
  619. // }
  620. let allCount = this.ZCount + this.LCount + this.RCount;
  621. //打一拳,大约消耗的热量,是450*4/60=1.875 焦耳。
  622. //因为打拳一小时,需要消耗的热量是450大卡,而一分钟约打一下,一大卡是4焦耳。
  623. this.showCalorieLabel.string = Math.floor((allCount * 1.875) / 4) + "大卡";
  624. },
  625. onUpdateBoxingPostHit(gamedata) {
  626. let gdata = gamedata;
  627. if (gdata.direction == "leftPunch") {
  628. this.LCount++;
  629. this.showLCount.string = "L击中次数" + this.LCount;
  630. this.showCalLabel.string = gdata.hitPower.toFixed(1) + " 斤";
  631. this.audioScript.onPlayBoxingTip(0);
  632. } else if (gdata.direction == "rightPunch") {
  633. this.RCount++;
  634. this.showRCount.string = "R击中次数" + this.RCount;
  635. this.showCalLabel.string = gdata.hitPower.toFixed(1) + " 斤";
  636. this.audioScript.onPlayBoxingTip(2);
  637. } else if (gdata.direction == "straightPunch") {
  638. this.ZCount++;
  639. this.showMCount.string = "击中" + this.ZCount;
  640. this.showCalLabel.string = gdata.hitPower.toFixed(1) + " 斤";
  641. this.audioScript.onPlayBoxingTip(1);
  642. }
  643. },
  644. onUpdateAccAndGyro(gameData) {
  645. let { ax, ay, az } = gameData.acc;
  646. let { gx, gy, gz } = gameData.gyro;
  647. this.showAccLabel.string = "acc\nx:" + (ax / 10).toFixed(2) + "\ny:" + (ay / 10).toFixed(2) + "\nz:" + (az / 10).toFixed(2);
  648. this.showOriLabel.string = "gyro\nx:" + (gx * 100).toFixed(2) + "\ny:" + (gy * 100).toFixed(2) + "\nz:" + (gz * 100).toFixed(2);
  649. if (this.count > 0) {
  650. console.log(gameData);
  651. this.count--;
  652. }
  653. let [hit, dir] = this.Filter.Update(ax / 10, az / 10, gz, -gx, gameData.ms);
  654. if (dir != undefined) {
  655. console.log("X " + dir.x + " Y " + dir.y + ' == ' + dir.length);
  656. var result = Math.atan2(dir.y, dir.x) * 180 / (Math.PI);
  657. result = Math.round(result);
  658. let curAngle = result > 0 ? result : (360 + result);
  659. console.log("result=" + result + " , curAngle = " + curAngle);
  660. this.accAndGyroLabel.string = "result=" + result + " , curAngle = " + curAngle;
  661. let res = this.Filter.getTempValue(dir);
  662. let temp = {
  663. direction: res.direction,
  664. angle: res.angle,
  665. name: res.name,
  666. ename: res.ename,
  667. value: res.hit,
  668. mass: 10, //质量
  669. hitPower: res.hit //计算的力
  670. }
  671. this.onUpdateBoxingPostHit(temp);
  672. }
  673. // if (hit != 0) {
  674. // console.log("Release Hit " + hit);
  675. // }
  676. // let temp = this.Filter.Update(ax / 10, ay / 10, gx, gy, gameData.ms, (res) => {
  677. // });//我自己的更新acc的函数
  678. // console.log(temp);
  679. // this.Filter.Update(new o0.Vector3(ax/10, -ay/10, -az/10), gameData.ms, new o0.Vector3(gx*100, -gy*100, -gz*100),(res)=>{
  680. // let temp = {
  681. // direction: res.direction,
  682. // angle:res.angle,
  683. // name: res.name,
  684. // ename: res.ename,
  685. // value: res.hit,
  686. // mass: 10, //质量
  687. // hitPower: res.hit //计算的力
  688. // }
  689. // this.onUpdateBoxingPostHit(temp);
  690. // console.log(temp);
  691. // this.accAndGyroLabel.string = res.angle;
  692. // });
  693. }
  694. // update(dt) {
  695. // },
  696. });