Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool doSimplex(std::vector<vector4D> &simplex, vector4D &direction)
- {
- vector4D A;
- vector4D B;
- vector4D C;
- vector4D D;
- vector4D AO;
- vector4D AB;
- vector4D AC;
- vector4D AD;
- vector4D ABC;
- std::vector<vector4D> newSimplex;
- bool ABCcheck = false;
- bool ACDcheck = false;
- bool ADBcheck = false;
- switch(simplex.size())
- {
- case(2):
- A = simplex[1];
- B = simplex[0];
- AO = vector4D(0, 0, 0) - A;
- AB = B - A;
- if(AB.dot(AO) > 0)
- {
- direction = (AB.cross(AO)).cross(AB);
- }
- else
- {
- simplex.clear();
- simplex.push_back(A);
- //*simplex = newSimplex;
- direction = AO;
- }
- break;
- case(3):
- A = simplex[2];
- B = simplex[1];
- C = simplex[0];
- AO = vector4D(0, 0, 0) - A;
- AB = B - A;
- AC = C - A;
- ABC = AB.cross(AC);
- if((ABC.cross(AC)).dot(AO) > 0)
- {
- if(AC.dot(AO) > 0)
- {
- simplex.clear();
- simplex.push_back(A);
- simplex.push_back(C);
- //*simplex = newSimplex;
- direction = (AC.cross(AO)).cross(AC);
- }
- else
- {
- if(AB.dot(AO) > 0)
- {
- simplex.clear();
- simplex.push_back(A);
- simplex.push_back(B);
- //*simplex = newSimplex;
- direction = (AB.cross(AO)).cross(AB);
- }
- else
- {
- simplex.clear();
- simplex.push_back(A);
- //*simplex = newSimplex;
- direction = AO;
- }
- }
- }
- else
- {
- if((AB.cross(ABC)).dot(AO) > 0)
- {
- if(AB.dot(AO) > 0)
- {
- simplex.clear();
- simplex.push_back(A);
- simplex.push_back(B);
- //*simplex = newSimplex;
- direction = (AB.cross(AO)).cross(AB);
- }
- else
- {
- simplex.clear();
- simplex.push_back(A);
- //*simplex = newSimplex;
- direction = AO;
- }
- }
- else
- {
- if(ABC.dot(AO) > 0)
- {
- simplex.clear();
- simplex.push_back(A);
- simplex.push_back(B);
- simplex.push_back(C);
- //*simplex = newSimplex;
- direction = ABC;
- }
- else
- {
- simplex.clear();
- simplex.push_back(A);
- simplex.push_back(C);
- simplex.push_back(B);
- //*simplex = newSimplex;
- direction = vector4D(0, 0, 0) - ABC;
- }
- }
- }
- break;
- case(4):
- A = simplex[3];
- B = simplex[2];
- C = simplex[1];
- D = simplex[0];
- AB = B - A;
- AC = C - A;
- AD = D - A;
- if((AB.cross(AC)).dot(AO) >= 0)
- {
- ABCcheck = true;
- }
- if((AC.cross(AD)).dot(AO) >= 0)
- {
- ACDcheck = true;
- }
- if((AD.cross(AB)).dot(AO) >= 0)
- {
- ADBcheck = true;
- }
- if(ABCcheck && ACDcheck && ADBcheck)
- {
- return true;
- }
- else if(!ABCcheck)
- {
- simplex.clear();
- simplex.push_back(A);
- simplex.push_back(C);
- simplex.push_back(B);
- //*simplex = newSimplex;
- direction = AC.cross(AB);
- }
- else if(!ACDcheck)
- {
- simplex.clear();
- simplex.push_back(A);
- simplex.push_back(D);
- simplex.push_back(C);
- //*simplex = newSimplex;
- direction = AD.cross(AC);
- }
- else
- {
- simplex.clear();
- simplex.push_back(A);
- simplex.push_back(B);
- simplex.push_back(D);
- //*simplex = newSimplex;
- direction = AB.cross(AD);
- }
- break;
- default:
- printf("Something went very wrong.");
- break;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement