void MyApp::setupScene() { int N_SPHERES = 8; float SKY_HEIGHT = 175.0f; float MIN_RAD = 5; float MAX_RAD = 15; int MIN_TESSFACTOR = 2; int MAX_TESSFACTOR = 7; float spheres_area = GRID_WIDTH; for (int i=0; i<N_SPHERES; i++) { Sphere s; s.setPos( rand() % (unsigned int)spheres_area - spheres_area / 2.0f, SKY_HEIGHT, rand() % (unsigned int)spheres_area - spheres_area / 2.0f ); s.setTargetPos(s.getPos().x, 25.0f, s.getPos().z); float rnd = rand() / (float)RAND_MAX; s.radius = MIN_RAD + rnd * (MAX_RAD - MIN_RAD); s.tessFactor = rand() % (MAX_TESSFACTOR - MIN_TESSFACTOR + 1) + MIN_TESSFACTOR; m_spheres.push_back(s); } // tess objects parameters for (int i=0; i<4; i++) { tessObjects[i].bWireframe = false; tessObjects[i].iEdgeFactor = 10; tessObjects[i].iInsideFactor = 10; tessObjects[i].partitioning = TessPartitioning::INTEGER; } }
//static bool Intersections::sphereAABBIntersection(Sphere s, AABB a){ Vector3 sphere_pos = s.getPos(); double sphere_radius = s.getRadius(); Vector3 aabb_bmin = a.getBmin(); Vector3 aabb_bmax = a.getBmax(); double r2 = sphere_radius * sphere_radius; double dmin = 0.0; //3 dimensions for( int i = 0; i < 3; i++ ) { if( sphere_pos[i] < aabb_bmin[i] ) { dmin += square( sphere_pos[i] - aabb_bmin[i] ); } else if( sphere_pos[i] > aabb_bmax[i] ) { dmin += square( sphere_pos[i] - aabb_bmax[i] ); } } return dmin <= r2; }
bool Intersections::pointInSphere(Vector3 point , Sphere s){ Vector3 sphere_pos = s.getPos(); double sphere_radius = s.getRadius(); return (sphere_pos - point).length() <= sphere_radius; }