TPitchLineCircle.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. #include "TPitchLineCircle.h"
  2. #include <algorithm>
  3. #include "memctrl.h"
  4. int TPitchLineCircle::s_eType;
  5. void Intersect(float a1, float a2, float a3, float a4, float& a5, float& a6) {
  6. LOGE("Intersect%x%x%x%x%x%x", a1, a2, a3, a4, a5, a6);
  7. }
  8. //-------------------------------------------------------------------------------------------------
  9. // 001BE194 经过单元测试,功能正常
  10. //^_^---
  11. // 001BE1BA开始的三条指令的顺序不同
  12. // 001BE1DE开始的三条指令的顺序不同
  13. //寄存器不同
  14. int LineCircleIntersection(CFTTVector32 cfttvector32_r0_begin,
  15. CFTTVector32 cfttvector32_r3_begin, float f_arg_8,
  16. CFTTVector32 cfttvector32_arg_c_begin,
  17. float f_arg_18, float* p_f_arg_1c) {
  18. LOGE("%x%x%x", cfttvector32_r0_begin.float_0, cfttvector32_r0_begin.float_4,
  19. cfttvector32_r0_begin.float_8);
  20. LOGE("%x%x%x", cfttvector32_r3_begin.float_0, cfttvector32_r3_begin.float_4,
  21. cfttvector32_r3_begin.float_8);
  22. LOGE("%x%x%x", cfttvector32_arg_c_begin.float_0,
  23. cfttvector32_arg_c_begin.float_4, cfttvector32_arg_c_begin.float_8);
  24. LOGE("%f%f%f%x", f_arg_8, f_arg_18, *p_f_arg_1c, p_f_arg_1c);
  25. return rand();
  26. }
  27. //-------------------------------------------------------------------------------------------------
  28. // 001BE690
  29. // TPitchLineCircle::~TPitchLineCircle() {
  30. // //delete this;
  31. // }
  32. //-------------------------------------------------------------------------------------------------
  33. // 001BE184
  34. int TPitchLineCircle::GetType() { return TPitchLineCircle::s_eType; }
  35. //-------------------------------------------------------------------------------------------------
  36. // 001BD85C
  37. /**
  38. * 它将一个圆圈夹在一条线上。
  39. *
  40. * @param cVec32_arg1 圆的向量
  41. *
  42. * @return 一条线和一个圆的交点。
  43. */
  44. void TPitchLineCircle::Clamp(CFTTVector32 cVec32_arg1) {
  45. float s0 = -0.5f; // 001BD866
  46. float s2 = 0.5f; // 001BD86C
  47. float s4 = cVec32_arg1.float_0; // 001BD872
  48. float s6 = cVec32_arg1.float_8; // 001BD878
  49. float s18 = s4 * s0; // 001BD888
  50. float s16 = s4 * s2; // 001BD88C
  51. s0 = s6 * s0; // 001BD890
  52. s2 = s6 * s2; // 001BD894
  53. float s8, s10, s12, s17, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28,
  54. s29, s30;
  55. int i_sp_20;
  56. int i_sp_24 = 0; // 001BD8EC
  57. uint8 i_sp_28 = 0; // 001BD8F0
  58. float f_sp_2C;
  59. int i_sp_30;
  60. int i_sp_3C;
  61. float f_sp_40;
  62. float f_sp_44;
  63. float f_sp_48[2]; // 48 4C;
  64. float f_sp_50[2]; // 50 54
  65. // float f_sp_58;
  66. // float f_sp_5C;
  67. uchar c_sp_5E[2];
  68. float f_sp_60[2]; // 60 64
  69. CFTTVector32 cVec32_sp_68; // 68 6C 70
  70. CFTTVector32 cVec32_sp_74; // 74 78 7C
  71. CFTTVector32 cVec32_sp_80[4];
  72. cVec32_sp_80[0].float_0 = s18; // 001BD898 80
  73. cVec32_sp_80[0].float_4 = 0; // 001BD870 84
  74. cVec32_sp_80[0].float_8 = s0; // 001BD89C 88
  75. cVec32_sp_80[1].float_0 = s16; // 001BD8A0 8C
  76. cVec32_sp_80[1].float_4 = 0; // 001BD876 90
  77. cVec32_sp_80[1].float_8 = s0; // 001BD8A4 94
  78. cVec32_sp_80[2].float_0 = s16; // 001BD8A8 98
  79. cVec32_sp_80[2].float_4 = 0; // 001BD87C 9C
  80. cVec32_sp_80[2].float_8 = s2; // 001BD8AC A0
  81. cVec32_sp_80[3].float_0 = s18; // 001BD8B0 A4
  82. cVec32_sp_80[3].float_4 = 0; // 001BD87E A8
  83. cVec32_sp_80[3].float_8 = s2; // 001BD8B4 AC
  84. s4 = this->vec32_4.float_8; // 001BD8B8
  85. s20 = this->vec32_4.float_0; // 001BD8BC
  86. i_sp_20 = (s0 <= s4 ? 1 : 0) & (s4 <= s2 ? 1 : 0); // 001BD8DC
  87. int i_r4 = 0;
  88. while (i_r4 != 4) {
  89. // cVec32_sp_68 = cVec32_sp_80[i_r4];
  90. float d16_0 = cVec32_sp_80[i_r4].float_0; // 001BD900
  91. float d16_4 = cVec32_sp_80[i_r4].float_4;
  92. cVec32_sp_68.float_8 = cVec32_sp_80[i_r4].float_8;
  93. cVec32_sp_68.float_0 = d16_0;
  94. cVec32_sp_68.float_4 = d16_4;
  95. i_r4++; // 001BD8FA
  96. // cVec32_sp_74 = cVec32_sp_80[i_r4 & 3];
  97. d16_0 = cVec32_sp_80[i_r4 & 3].float_0;
  98. d16_4 = cVec32_sp_80[i_r4 & 3].float_4;
  99. cVec32_sp_74.float_8 = cVec32_sp_80[i_r4 & 3].float_8;
  100. cVec32_sp_74.float_0 = d16_0;
  101. cVec32_sp_74.float_4 = d16_4;
  102. s23 = cVec32_sp_74.float_4; // 001BD926
  103. s25 = cVec32_sp_68.float_4; // 001BD92A
  104. s19 = cVec32_sp_74.float_0; // 001BD92E
  105. s17 = s23 - s25; // 001BD932
  106. s24 = cVec32_sp_68.float_0; // 001BD932
  107. s21 = cVec32_sp_74.float_8; // 001BD93A
  108. s28 = s19 - s24; // 001BD93E
  109. s26 = cVec32_sp_68.float_8; // 001BD942
  110. s30 = s21 - s26; // 001BD946
  111. s0 = s17 * s17; // 001BD94A
  112. s0 = s0 + s28 * s28; // 001BD94E
  113. s0 = s0 + s30 * s30; // 001BD952
  114. s22 = sqrtf(s0); // 001BD968
  115. float f_r6 = this->vec32_4.float_0;
  116. float f_r10 = this->vec32_4.float_4;
  117. float f_r11 = this->vec32_4.float_8;
  118. s27 = f_r10; // 001BD97A
  119. s29 = f_r11; // 001BD97E
  120. s0 = s25 - s27; // 001BD982
  121. s25 = f_r6; // 001BD986 VMOV S25, R6 ;
  122. // vec32_4.float_0
  123. s4 = s24 - s25; // 001BD98A VSUB.F32 S4, S24, S25
  124. s24 = this->field_14; // 001BD98E VLDR S24,
  125. // [R0,#0x92+var_80+2] ; this->field_14
  126. s2 = s0 * s0; // 001BD992 VMUL.F32 S2, S0, S0
  127. s0 = s26 - s29; // 001BD996 VSUB.F32 S0, S26, S29
  128. s26 = this->field_10; // 001BD99A VLDR S26,
  129. // [R0,#0x92+var_84+2] ; this->field_10
  130. s2 = s2 + s4 * s4; // 001BD99E VMLA.F32 S2, S4, S4
  131. s2 = s2 + s0 * s0; // 001BD9A2 VMLA.F32 S2, S0, S0
  132. s0 = sqrtf(s2); // 001BD9B8
  133. s2 = s23 - s27; // 001BD9C0 VSUB.F32 S2, S23, S27
  134. // cVec32_sp_60.float_0 = s0; //001BD9C4 VSTR S0,
  135. // [SP,#0xF0+var_92_vec32_94+2] ; sp+0x60,
  136. f_sp_60[0] = s0; // 001BD9C4 VSTR S0,
  137. // [SP,#0xF0+var_92_vec32_94+2] ; sp+0x60,
  138. s4 = s19 - s25; // 001BD9C8 VSUB.F32 S4, S19, S25
  139. s6 = s21 - s29; // 001BD9CC VSUB.F32 S6, S21, S29
  140. s2 = s2 * s2; // 001BD9D0 VMUL.F32 S2, S2, S2
  141. s2 = s2 + s4 * s4; // 001BD9D4 VMLA.F32 S2, S4, S4
  142. s2 = s2 + s6 * s6; // 001BD9D8 VMLA.F32 S2, S6, S6
  143. s4 = sqrtf(s2); // 001BD9EE
  144. s0 = s17 / s22; // 001BD9F6 VDIV.F32 S0, S17, S22
  145. // cVec32_sp_60.float_4 = s4; //001BD9FE VSTR S4,
  146. // [SP,#0xF0+var_92_vec32_94+6] ; sp+0x64
  147. f_sp_60[1] = s4; // 001BD9FE VSTR S4,
  148. // [SP,#0xF0+var_92_vec32_94+6] ; sp+0x64
  149. int i_r0 = 0; // 001BD9FC
  150. while (i_r0 != 2) {
  151. // 001BDA04
  152. char c_r2 = f_sp_60[i_r0] > s24 ? 2 : 1;
  153. if (f_sp_60[i_r0] < s26) {
  154. c_r2 = 0;
  155. }
  156. c_sp_5E[i_r0] = c_r2; // 001BDA24
  157. i_r0++; // 001BDA26
  158. }
  159. s2 = s30 / s22; // 001BDA2C VDIV.F32 S2, S30, S22
  160. uint c_r2 = c_sp_5E[0]; // 001BDA30 LDRB.W R2,
  161. // [SP,#0xF0+var_92_vec32_94] ; sp_5E
  162. uint c_r0 = c_sp_5E[1]; // 001BDA34 LDRB.W R0,
  163. // [SP,#0xF0+var_92_vec32_94+1] ; sp_5F
  164. s4 = s28 / s22; // 001BDA3A VDIV.F32 S4, S28, S22
  165. uint c_r1;
  166. if (c_r2 > c_r0) {
  167. // LOGI("clamp 3");
  168. s2 = -s2; // 001BDA40
  169. s0 = -s0; // 001BDA46
  170. d16_0 = cVec32_sp_68.float_0; // 001BDA4A
  171. d16_4 = cVec32_sp_68.float_4;
  172. s4 = -s4; // 001BDA4E
  173. float d17_0 = cVec32_sp_74.float_0;
  174. float d17_4 = cVec32_sp_74.float_4;
  175. f_sp_50[0] = cVec32_sp_68.float_8; // 001BDA5C
  176. // f_sp_50[1] = cVec32_sp_68.float_8; //001BDA5C
  177. cVec32_sp_68.float_8 = cVec32_sp_74.float_8; // 001BDA5E
  178. cVec32_sp_68.float_0 = d17_0; // 001BDA60
  179. cVec32_sp_68.float_4 = d17_4;
  180. cVec32_sp_74.float_8 = f_sp_50[0]; // 001BDA64
  181. c_r1 = c_sp_5E[0]; // 001BDA66
  182. c_sp_5E[0] = c_r0 /*c_r0_sp_5F*/; // 001BDA68
  183. f_sp_48[0] = d16_0; // 001BDA6C
  184. f_sp_48[1] = d16_4;
  185. cVec32_sp_74.float_0 = d16_0; // 001BDA70
  186. cVec32_sp_74.float_4 = d16_4;
  187. c_sp_5E[1] = c_r2; // 001BDA74
  188. } else {
  189. c_r1 = c_sp_5E[1]; // c_r0_sp_5F;
  190. c_r0 = c_sp_5E[0]; // c_r2_sp_5E;
  191. }
  192. float LR = s4; // 001BDA7E
  193. // float f_r5;
  194. uint8 r0_v38 = 0;
  195. if (c_r1 | c_r0) {
  196. // 001BDA94
  197. if (c_r0 == 0 && c_r1 == 1) {
  198. r0_v38 = 1;
  199. } else if (c_r0 == 0 && c_r1 == 2) {
  200. r0_v38 = 2;
  201. } else if (c_r0 == 1 && c_r1 == 1) {
  202. r0_v38 = 3;
  203. } else if (c_r0 == 1 && c_r1 == 2) {
  204. r0_v38 = 4;
  205. } else {
  206. // 001BDAC0
  207. if ((c_r0 ^ 2) | (c_r1 ^ 2)) {
  208. r0_v38 = -1;
  209. } else
  210. r0_v38 = 5;
  211. }
  212. } else {
  213. // 001BDA9E
  214. r0_v38 = 0;
  215. }
  216. // 001BDAE0 loc_1BDAE0
  217. i_sp_3C = r0_v38; // 001BDAE0
  218. // 001BDB0A
  219. CFTTVector32 vec_2;
  220. vec_2.float_0 = LR;
  221. vec_2.float_4 = s0;
  222. vec_2.float_8 = s2;
  223. i_sp_30 = LineCircleIntersection(cVec32_sp_68, vec_2, s22, this->vec32_4,
  224. s26, &f_sp_48[0]);
  225. // f_sp_44 = LR; // 001BDB06
  226. // 001BDB2E
  227. // vec_2.float_0 = f_sp_44;
  228. // vec_2.float_4 = s0;
  229. // vec_2.float_8 = s2;
  230. int ret_r0 = LineCircleIntersection(cVec32_sp_68, vec_2, s22, this->vec32_4,
  231. s24, &f_sp_50[0]);
  232. if (((uint)(-3 + (uchar)r0_v38)) >= 2) {
  233. // 001BDB48
  234. if (((uchar)r0_v38) == 5) {
  235. // 001BDB52
  236. if ((i_sp_30 != 2) && (ret_r0 != 2)) {
  237. // if (ret_r0 != 2) {
  238. if (((ret_r0 ^ 2) | i_sp_30) != 0) i_sp_24 = i_sp_24 + 1;
  239. /*if ((ret_r0 ^ 2) | ret_sp_30 ) {
  240. i_sp_24 += 1;
  241. }*/
  242. //}
  243. }
  244. } else {
  245. // 001BDB6E
  246. i_sp_28 = (r0_v38 /*i_sp_3C*/ << 0x18) == 0 ? i_sp_28 + 1 : i_sp_28;
  247. }
  248. }
  249. }
  250. // 001BDB80
  251. int r1_v45 = s18 <= s20 ? 1 : 0;
  252. int r2_v46 = s20 <= s16 ? 1 : 0;
  253. // int i_r3 = (uint32)((uint8)i_sp_24) != 4 ? 1 : -4 +
  254. // (uint32)((uint8)i_sp_24);
  255. uint8 i_r3 = i_sp_24 != 4 ? 1 : -4 + (uchar)i_sp_24;
  256. // if ((uint32)((uint8)i_sp_28) != 4) {
  257. if ((uchar)i_sp_28 != 4) { // 001BDBB8
  258. r1_v45 &= r2_v46;
  259. r1_v45 &= i_sp_20;
  260. if ((r1_v45 | i_r3) == 0) {
  261. this->f_1C = 0;
  262. return;
  263. }
  264. } else {
  265. // if (r1_v45 | i_r3) {
  266. // this->f_1C = 0;
  267. // return;
  268. // }
  269. this->f_1C = 0;
  270. return;
  271. }
  272. if (r1_v45 == 0) {
  273. // 001BDBD4
  274. s18 = atan2f(-(this->vec32_4.float_8) ,
  275. -(this->vec32_4.float_0) );
  276. s16 = 6.28318548f; // 001BDBEA
  277. s20 = s18 + s16; // 001BDBF2
  278. // float* ptrFloat_r4 = &cVec32_sp_80[0].float_8; //001BDBF6
  279. float ptrR6_sp68[4];
  280. for (int i_r5 = 0; i_r5 != 4; i_r5++) {
  281. s4 = cVec32_sp_80[i_r5].float_8; //*ptrFloat_r4;
  282. s6 = cVec32_sp_80[i_r5].float_0; //*(ptrFloat_r4 - 2);
  283. s0 = this->vec32_4.float_0;
  284. s2 = this->vec32_4.float_8;
  285. s0 = s6 - s0;
  286. s2 = s4 - s2;
  287. // 001BDC20
  288. s0 = atan2f(s2, s0);
  289. ptrR6_sp68[i_r5] = s0 < 0.0f ? s0 + s16 : s0;
  290. }
  291. s0 = -6.28318548f; // 001BDC4C
  292. int i_r0 = 0;
  293. if (s18 < 0.0f) {
  294. s18 = s20; // 001BDC5A
  295. }
  296. while (i_r0 != 4) {
  297. s2 = ptrR6_sp68[i_r0]; // 001BDC62
  298. s8 = s2 + s0;
  299. s4 = s2 + s16;
  300. s6 = s2 - s18;
  301. s10 = s8 - s18;
  302. s12 = s4 - s18;
  303. s4 = fabsf(s6); // 001BDC7A
  304. s10 = fabsf(s10); // 001BDC7E
  305. s6 = fabsf(s12); // 001BDC82
  306. if (s10 < s4) {
  307. s2 = s8;
  308. s8 = s2 + s16;
  309. if (s6 < s4) {
  310. s2 = s8;
  311. }
  312. ptrR6_sp68[i_r0] = s2; // 001BDCB0
  313. }else{
  314. if (s6 < s4) {
  315. s2 = s8;
  316. }
  317. ptrR6_sp68[i_r0] = s2; // 001BDCB0
  318. }
  319. i_r0++;
  320. }
  321. s0 = 0.0f; // 001BDCBA
  322. i_r0 = 0;
  323. while (i_r0 != 4) {
  324. s2 = ptrR6_sp68[i_r0];
  325. s4 = s0 > s2 ? s0 : s2;
  326. s0 = s4;
  327. if (s16 > s2) {
  328. s16 = s2;
  329. }
  330. i_r0++;
  331. }
  332. // s2 = 6.28318548f;
  333. // s4 = s0 + 6.28318548f; //s2;
  334. // s2 = s16 + 6.28318548f; //s2;
  335. if (s16 < 0.0f) {
  336. s0 = s0 + 6.28318548f; // s4;
  337. s16 = s16 + 6.28318548f; // s2;
  338. }
  339. s0 = s0 - s16; // 001BDD12
  340. Intersect(this->field_18, this->f_1C, s16, s0, this->field_18, this->f_1C);
  341. }
  342. }
  343. //-------------------------------------------------------------------------------------------------
  344. // 001BE378
  345. bool TPitchLineCircle::Identical(TPitchLineGen*) { return false; }
  346. //-------------------------------------------------------------------------------------------------
  347. // 001BE490
  348. void TPitchLineCircle::Render() {}
  349. //-------------------------------------------------------------------------------------------------
  350. // 001BDDE0
  351. void TPitchLineCircle::Transform(uchar) {}
  352. //-------------------------------------------------------------------------------------------------
  353. // 001BD846 //^_^
  354. void TPitchLineCircle::Translate(CFTTVector32 vec32) {
  355. CFTTVector32 vec32_14 = vec32;
  356. vec32_4 -= vec32_14;
  357. }
  358. //-------------------------------------------------------------------------------------------------
  359. // 001BDD48 //^_^
  360. bool TPitchLineCircle::Valid() { return f_1C != 0.0; }
  361. //-------------------------------------------------------------------------------------------------
  362. // 001BE650
  363. TPitchLineGen* TPitchLineCircle::Clone() {
  364. TPitchLineCircle* pCircle = new TPitchLineCircle;
  365. return (TPitchLineGen*)pCircle;
  366. }
  367. //-------------------------------------------------------------------------------------------------