Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. bool doSimplex(std::vector<vector4D> &simplex, vector4D &direction)
  2. {
  3. vector4D A;
  4. vector4D B;
  5. vector4D C;
  6. vector4D D;
  7.  
  8. vector4D AO;
  9. vector4D AB;
  10. vector4D AC;
  11. vector4D AD;
  12.  
  13. vector4D ABC;
  14.  
  15. std::vector<vector4D> newSimplex;
  16.  
  17. bool ABCcheck = false;
  18. bool ACDcheck = false;
  19. bool ADBcheck = false;
  20.  
  21. switch(simplex.size())
  22. {
  23. case(2):
  24. A = simplex[1];
  25. B = simplex[0];
  26.  
  27. AO = vector4D(0, 0, 0) - A;
  28. AB = B - A;
  29.  
  30. if(AB.dot(AO) > 0)
  31. {
  32. direction = (AB.cross(AO)).cross(AB);
  33. }
  34. else
  35. {
  36. simplex.clear();
  37. simplex.push_back(A);
  38. //*simplex = newSimplex;
  39. direction = AO;
  40. }
  41.  
  42. break;
  43.  
  44. case(3):
  45. A = simplex[2];
  46. B = simplex[1];
  47. C = simplex[0];
  48.  
  49. AO = vector4D(0, 0, 0) - A;
  50. AB = B - A;
  51. AC = C - A;
  52.  
  53. ABC = AB.cross(AC);
  54.  
  55. if((ABC.cross(AC)).dot(AO) > 0)
  56. {
  57. if(AC.dot(AO) > 0)
  58. {
  59. simplex.clear();
  60. simplex.push_back(A);
  61. simplex.push_back(C);
  62. //*simplex = newSimplex;
  63. direction = (AC.cross(AO)).cross(AC);
  64. }
  65. else
  66. {
  67. if(AB.dot(AO) > 0)
  68. {
  69. simplex.clear();
  70. simplex.push_back(A);
  71. simplex.push_back(B);
  72. //*simplex = newSimplex;
  73. direction = (AB.cross(AO)).cross(AB);
  74. }
  75. else
  76. {
  77. simplex.clear();
  78. simplex.push_back(A);
  79. //*simplex = newSimplex;
  80. direction = AO;
  81. }
  82. }
  83. }
  84. else
  85. {
  86. if((AB.cross(ABC)).dot(AO) > 0)
  87. {
  88. if(AB.dot(AO) > 0)
  89. {
  90. simplex.clear();
  91. simplex.push_back(A);
  92. simplex.push_back(B);
  93. //*simplex = newSimplex;
  94. direction = (AB.cross(AO)).cross(AB);
  95. }
  96. else
  97. {
  98. simplex.clear();
  99. simplex.push_back(A);
  100. //*simplex = newSimplex;
  101. direction = AO;
  102. }
  103. }
  104. else
  105. {
  106. if(ABC.dot(AO) > 0)
  107. {
  108. simplex.clear();
  109. simplex.push_back(A);
  110. simplex.push_back(B);
  111. simplex.push_back(C);
  112. //*simplex = newSimplex;
  113. direction = ABC;
  114. }
  115. else
  116. {
  117. simplex.clear();
  118. simplex.push_back(A);
  119. simplex.push_back(C);
  120. simplex.push_back(B);
  121. //*simplex = newSimplex;
  122. direction = vector4D(0, 0, 0) - ABC;
  123. }
  124. }
  125. }
  126.  
  127. break;
  128.  
  129. case(4):
  130.  
  131. A = simplex[3];
  132. B = simplex[2];
  133. C = simplex[1];
  134. D = simplex[0];
  135.  
  136. AB = B - A;
  137. AC = C - A;
  138. AD = D - A;
  139.  
  140. if((AB.cross(AC)).dot(AO) >= 0)
  141. {
  142. ABCcheck = true;
  143. }
  144.  
  145. if((AC.cross(AD)).dot(AO) >= 0)
  146. {
  147. ACDcheck = true;
  148. }
  149.  
  150. if((AD.cross(AB)).dot(AO) >= 0)
  151. {
  152. ADBcheck = true;
  153. }
  154.  
  155. if(ABCcheck && ACDcheck && ADBcheck)
  156. {
  157. return true;
  158. }
  159. else if(!ABCcheck)
  160. {
  161. simplex.clear();
  162. simplex.push_back(A);
  163. simplex.push_back(C);
  164. simplex.push_back(B);
  165. //*simplex = newSimplex;
  166. direction = AC.cross(AB);
  167.  
  168. }
  169. else if(!ACDcheck)
  170. {
  171. simplex.clear();
  172. simplex.push_back(A);
  173. simplex.push_back(D);
  174. simplex.push_back(C);
  175. //*simplex = newSimplex;
  176. direction = AD.cross(AC);
  177. }
  178. else
  179. {
  180. simplex.clear();
  181. simplex.push_back(A);
  182. simplex.push_back(B);
  183. simplex.push_back(D);
  184. //*simplex = newSimplex;
  185. direction = AB.cross(AD);
  186. }
  187.  
  188. break;
  189.  
  190. default:
  191. printf("Something went very wrong.");
  192. break;
  193. }
  194.  
  195. return false;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement