#include <string>
#include "example_common.h"
#include <iostream>
#include <math.h>
#include "example.hxx"
bool verifyResult(const std::string & objI, const std::string & objJ,
double distance,
void display (void);
void Example::initializeUniverse()
{
sObj.addObject(poly);
objName.push_back("poly");
sObj.addObject(stp1);
sObj.addObject(stp2);
objName.push_back("stp1");
objName.push_back("stp2");
}
bool Example::unittest()
{
int collisionNbr = sObj.sceneProximityQuery();
std::cout<<"Complex objects" << std::endl;
std::cout<<"Number of objects: " << sObj.size() << std::endl;
std::cout<<"Number of pairs: " << sObj.size()*(sObj.size()-1)/2<< std::endl;
for (unsigned i=0; i<sObj.size(); ++i)
{
std::cout <<
"Object "<<i<<
" type:"<< ptr->
getType() << std::endl;
}
std::cout<< std::endl<<"Number of collisions: "<< collisionNbr << std::endl;
bool comparison = true;
for (unsigned i=0; i<sObj.size(); ++i)
{
for (unsigned j=0; j<i; ++j)
{
std::cout << "The pair " << j <<" - "<< i <<std::endl;
double distance = sObj.getWitnessPoints(i,j,p1,p2);
std::cout << "Distance " << distance << std::endl;
std::cout <<"Witness points: " << std::endl;
std::cout <<" P1: "<< p1 << std::endl;
std::cout <<" P2: "<< p2 << std::endl;
if(!verifyResult(objName[i], objName[j], distance, p1, p2))
comparison = false;
std::cout << std::endl;
}
}
return comparison;
}
void Example::displayScene()
{
sObj.sceneProximityQuery();
display();
}
bool verifyResult(const std::string & objI, const std::string & objJ,
double distance,
{
double dd(0);
if(objJ== "poly" && objI == "stp1")
{
#ifdef SCH_BUILD_BSD
dd = 0.;
dp1.Set(0.121221802197878, 0.759159100278684162432796, 0.8579643029474862681027);
dp2.Set(0.131381168845752, 0.628304262885003295124874, 0.8892843622212902587875);
#else
dd = -0.003622207057881;
dp1.Set( 0.157367547718, 0.68942718023, 0.891961713557);
dp2.Set(0.0986621048016, 0.691217002621, 0.905102283015);
#endif
}
else if(objJ == "poly" && objI == "stp2")
{
dd = 1.052877530262;
dp1.Set(0.113009188603, 0.657740931859, 0.866412634224);
dp2.Set(0.404379849329, 0.0191152898235, 0.117988985704);
}
else if(objJ == "stp1" && objI == "stp2")
{
dd = 0.7165631886362;
dp1.Set(0.167062414197, 0.581943658784, 0.704052592159);
dp2.Set(0.404383200422, 0.0191578029975, 0.117951821311);
}
bool res = true;
res = compare(distance, dd, "distance ("+objI +", "+objJ+"): ") && res;
res = compare(p1, dp1, "p1 ("+objI +", "+objJ+"): ") && res;
res = compare(p2, dp2, "p2 ("+objI +", "+objJ+"): ") && res;
return res;
}