void RayModel::computeBoundingTree(int maxDepth) { CubeModel* cubeModel = createPrevious<CubeModel>(); if (!isMoving() && !cubeModel->empty()) return; // No need to recompute BBox if immobile Vector3 minElem, maxElem; cubeModel->resize(size); if (!empty()) { for (int i=0; i<size; i++) { Ray r(this, i); const Vector3& o = r.origin(); const Vector3& d = r.direction(); const SReal l = r.l(); for (int c=0; c<3; c++) { if (d[c]<0) { minElem[c] = o[c] + d[c]*l; maxElem[c] = o[c]; } else { minElem[c] = o[c]; maxElem[c] = o[c] + d[c]*l; } } cubeModel->setParentOf(i, minElem, maxElem); } cubeModel->computeBoundingTree(maxDepth); } }
void PlaneModel::MakeRudder(){ //######################################################################################## //Rudder GroupModel* rudder = new GroupModel(); vec3 rudderSize = vec3(0.07f,1.15f, 1.0f); vec3 rudderColor = vec3(1,0,0); if(1){//Right GroupModel* group = new GroupModel(); CubeModel* model = new CubeModel(rudderColor); model->SetPosition(vec3(0.0f,0.5f,-2.0f)); model->SetRotation(vec3(1.0f,0.0f,0.0f), -30.0f); model->SetScaling(rudderSize); group->AddChild(model); group->SetRotation(vec3(0,0,1), 45.0f); rudder->AddChild(group); } if(1){//Left GroupModel* group = new GroupModel(); CubeModel* model = new CubeModel(rudderColor); model->SetPosition(vec3(0.0f,0.5f,-2.0f)); model->SetRotation(vec3(1.0f,0.0f,0.0f), -30.0f); model->SetScaling(rudderSize); group->AddChild(model); group->SetRotation(vec3(0,0,1), -45.0f); rudder->AddChild(group); } rudder->SetRotation(vec3(0.0f,0.0f,1.0f), 0.0f); AddChild("rudder",rudder); //*//////////////////////////////////////////////////// //$#%^$#$^Y$T#%^&%$#W$^&$#%^&%$#%^&&%^$#$%^&%%$#$$^%#$% //Model Testing :: Transforms on multiple layers //######################################################################################## }
void CubeModel::handleBeginContact(q3Box * box){ if (mBreakable){ std::cout << "Breakable model contact" << std::endl; // Queue this object's removal World::GetInstance()->RemoveModel(this); // break into 8 evenly sized pieces vec3 size = mScaling / 2.0f; vec3 pos = size / 2.0f; for (int x = 0; x < 2; ++x){ for (int y = 0; y < 2; ++y){ for (int z = 0; z < 2; ++z){ CubeModel *shard = new CubeModel(); shard->SetPosition(mPosition + glm::vec3( pos.x * (x ? 1 : -1), pos.y * (y ? 1 : -1), pos.z * (z ? 1 : -1) )); shard->SetScaling(size); shard->SetPhysicsType(Dynamic); shard->SetBreakable(false); auto body = new q3BodyDef(shard->GetBodyDef()); auto box = new q3BoxDef(shard->GetBoxDef()); auto transform = mBody->GetTransform(); transform.position = { 0, 0, 0 }; box->Set(transform, g2q(size)); World::GetInstance()->AddModel(shard, body, box); } } } } }
void World::LoadScene(const char * scene_path) { // Using case-insensitive strings and streams for easier parsing ci_ifstream input; input.open(scene_path, ios::in); // Invalid file if(input.fail() ) { fprintf(stderr, "Error loading file: %s\n", scene_path); getchar(); exit(-1); } ci_string item; while( std::getline( input, item, '[' ) ) { ci_istringstream iss( item ); ci_string result; if( std::getline( iss, result, ']') ) { if( result == "cube" ) { // Box attributes CubeModel* cube = new CubeModel(); cube->Load(iss); mModel.push_back(cube); } else if( result == "sphere" ) { SphereModel* sphere = new SphereModel(); sphere->Load(iss); mModel.push_back(sphere); } else if( result == "path" ) { Path* path = new Path(); path->Load(iss); mPath.push_back(path); } else if( result == "spline" ) { BSpline* path = new BSpline(); path->Load(iss); mSpline.push_back(path); } else if ( result.empty() == false && result[0] == '#') { // this is a comment line } else { fprintf(stderr, "Error loading scene file... !"); getchar(); exit(-1); } } } input.close(); // Set PATH vertex buffers for (vector<Path*>::iterator it = mPath.begin(); it < mPath.end(); ++it) { // Draw model (*it)->CreateVertexBuffer(); } // Set B-SPLINE vertex buffers for (vector<BSpline*>::iterator it = mSpline.begin(); it < mSpline.end(); ++it) { // Draw model (*it)->CreateVertexBuffer(); } //LOAD DAT OBJ MODEL YO vector<OBJModel*> pokemon = PokemonGenerator::GeneratePokemon(); for (int i = 0; i < pokemon.size(); i++) mModel.push_back(pokemon[i]); srand(20); OBJModel* grass = new OBJModel("../Models/Grass_02.obj"); for (int i = 0; i < 50; i++){ OBJModel* newgrass = new OBJModel(*grass); newgrass->SetPosition(vec3(rand() % 150 - 75, 0, rand() % 150 - 75)); newgrass->SetScaling(vec3(1, 1, 1)); mModel.push_back(newgrass); } // DAYTIME - default groundDay = new SkyboxModel("../Models/cube.obj"); groundDay->SetSwitch(true); groundDay->SetPosition(vec3(0, -2.5, 0)); groundDay->SetScaling(vec3(150, 5, 150)); mModel.push_back(groundDay); skyboxDay = new SkyboxModel("../Models/ds.obj"); skyboxDay->SetSwitch(true); skyboxDay->SetPosition(vec3(0, 60, 0)); skyboxDay->SetScaling(vec3(80, 80, 80)); mModel.push_back(skyboxDay); // NIGHTTIME groundNight = new SkyboxModel("../Models/cube2.obj"); groundNight->SetSwitch(false); groundNight->SetPosition(vec3(0, -2.5, 0)); groundNight->SetScaling(vec3(150, 5, 150)); mModel.push_back(groundNight); skyboxNight = new SkyboxModel("../Models/ns.obj"); skyboxNight->SetSwitch(false); skyboxNight->SetPosition(vec3(0, 60, 0)); skyboxNight->SetScaling(vec3(80, 80, 80)); mModel.push_back(skyboxNight); LoadCameras(); }
void World::LoadScene(const char * scene_path) { // Using case-insensitive strings and streams for easier parsing ci_ifstream input; input.open(scene_path, ios::in); // Invalid file if(input.fail() ) { fprintf(stderr, "Error loading file: %s\n", scene_path); getchar(); exit(-1); } ci_string item; while( std::getline( input, item, '[' ) ) { ci_istringstream iss( item ); ci_string result; if( std::getline( iss, result, ']') ) { if( result == "cube" ) { // Box attributes CubeModel* cube = new CubeModel(); cube->Load(iss); mModel.push_back(cube); } else if( result == "tank" ) { // Box attributes tank = new TankModel(); tank->Load(iss); mModel.push_back(tank); mCamera.at(0)->setTarget(tank); mCamera.at(1)->setTarget(tank); } else if (result == "alien") { // Box attributes AlienModel* alien = new AlienModel(); Missile* mis = new Missile(tank); AlienCubeModel* pos = new AlienCubeModel(); pos->SetMissile(mis); pos->Load(iss); alien->Load(iss); mModel.push_back(mis); mModel.push_back(pos); mModel.push_back(alien); } else if( result == "vehicle" ) { // Box attributes VehicleModel* vehicle = new VehicleModel(); vehicle->Load(iss); mModel.push_back(vehicle); } else if( result == "sphere" ) { SphereModel* sphere = new SphereModel(); sphere->Load(iss); mModel.push_back(sphere); } else if( result == "light" ) { LightModel* light = new LightModel(); light->Load(iss); mLightModels.push_back(light); } else if( result == "sun" ) { SunModel* sun = new SunModel(); sun->Load(iss); mModel.push_back(sun); LightModel* light = new LightModel(sun); light->Load(iss); mLightModels.push_back(light); } else if( result == "moon" ) { MoonModel* moon = new MoonModel(); moon->Load(iss); mModel.push_back(moon); } else if( result == "bspline" ) { BSpline* bSpline = new BSpline(); bSpline->Load(iss); mBSplineModels.push_back(bSpline); } else if (result == "textured_cube") { TexturedCube* texturedCube = new TexturedCube(); texturedCube->Load(iss); mModel.push_back(texturedCube); } else if (result == "triangle") { TriangleModel* triangle = new TriangleModel(); triangle->Load(iss); mModel.push_back(triangle); } else if (result == "particleEmitter") { ParticleEmitter* particleEmitter = new ParticleEmitter(vec4(1.0f, 0.0f, 0.0f, 0.0f), vec4(1.0f, 0.0f, 0.0f, 0.0f)); particleEmitter->Load(iss); mModel.push_back(particleEmitter); mParticleEmitterModels.push_back(particleEmitter); particleEmitter->SetLightSource(mLightModels.back()); particleEmitter->GenerateParticles(); } else if (result == "cubesm") { CubeModelSM* cubesm = new CubeModelSM(); cubesm->Load(iss); mModel.push_back(cubesm); } else if ( result.empty() == false && result[0] == '#') { // this is a comment line } else { fprintf(stderr, "Error loading scene file... !"); getchar(); exit(-1); } } } input.close(); for (vector<Model*>::iterator it = mModel.begin(); it < mModel.end(); ++it) { // Temporary for single light source (*it)->SetLightSource(mLightModels.back()); } }
void World::LoadScene(const char * scene_path) { // Using case-insensitive strings and streams for easier parsing ci_ifstream input; input.open(scene_path, ios::in); // Invalid file if (input.fail()) { fprintf(stderr, "Error loading file: %s\n", scene_path); getchar(); exit(-1); } ci_string item; while (std::getline(input, item, '[')) { ci_istringstream iss(item); ci_string result; if (std::getline(iss, result, ']')) { if (result == "player") { // Box attributes PlayerModel* player = new PlayerModel(); player->Load(iss); mModel.push_back(player); mPlayerModel = player; } else if (result == "discoball") { // Box attributes Discoball* discoBallz = new Discoball(); discoBallz->Load(iss); mModel.push_back(discoBallz); } else if (result == "bunnny") { // Box attributes BunnyModel* bunny = new BunnyModel(); bunny->Load(iss); mModel.push_back(bunny); } else if (result == "barrel") { // Box attributes BarrelModel* barrel = new BarrelModel(); barrel->Load(iss); mModel.push_back(barrel); } else if (result == "cube") { // Box attributes CubeModel* cube = new CubeModel(); cube->Load(iss); mModel.push_back(cube); } else if (result == "sphere") { SphereModel* sphere = new SphereModel(); sphere->Load(iss); mModel.push_back(sphere); } else if (result == "animationkey") { AnimationKey* key = new AnimationKey(); key->Load(iss); mAnimationKey.push_back(key); } else if (result == "animation") { Animation* anim = new Animation(); anim->Load(iss); mAnimation.push_back(anim); } else if (result.empty() == false && result[0] == '#') { // this is a comment line } else { fprintf(stderr, "Error loading scene file... !"); getchar(); exit(-1); } } } input.close(); if (DRAW_ANIM_PATH) { for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it) { (*it)->CreateVertexBuffer(); } } }
void TriangleOctreeModel::computeBoundingTree(int maxDepth) { const helper::vector<topology::Triangle>& tri = *triangles; if(octreeRoot) { delete octreeRoot; octreeRoot=NULL; } CubeModel* cubeModel = createPrevious<CubeModel>(); updateFromTopology(); if (!isMoving() && !cubeModel->empty()) return; // No need to recompute BBox if immobile int size2=mstate->getSize(); pNorms.resize(size2); for(int i=0; i<size2; i++) { pNorms[i]=defaulttype::Vector3(0,0,0); } defaulttype::Vector3 minElem, maxElem; maxElem[0]=minElem[0]=mstate->read(core::ConstVecCoordId::position())->getValue()[0][0]; maxElem[1]=minElem[1]=mstate->read(core::ConstVecCoordId::position())->getValue()[0][1]; maxElem[2]=minElem[2]=mstate->read(core::ConstVecCoordId::position())->getValue()[0][2]; cubeModel->resize(1); // size = number of triangles for (int i=1; i<size; i++) { Triangle t(this,i); pNorms[tri[i][0]]+=t.n(); pNorms[tri[i][1]]+=t.n(); pNorms[tri[i][2]]+=t.n(); const defaulttype::Vector3* pt[3]; pt[0] = &t.p1(); pt[1] = &t.p2(); pt[2] = &t.p3(); t.n() = cross(*pt[1]-*pt[0],*pt[2]-*pt[0]); t.n().normalize(); for (int p=0; p<3; p++) { for(int c=0; c<3; c++) { if ((*pt[p])[c] > maxElem[c]) maxElem[c] = (*pt[p])[c]; if ((*pt[p])[c] < minElem[c]) minElem[c] = (*pt[p])[c]; } } } cubeModel->setParentOf(0, minElem, maxElem); // define the bounding box of the current triangle cubeModel->computeBoundingTree(maxDepth); for(int i=0; i<size2; i++) { pNorms[i].normalize(); } #if 0 if(!pTri.size()) { /*creates the list of triangles that are associated to a point*/ pTri.resize(size2); for(int i=0; i<size; i++) { pTri[tri[i][0]].push_back(i); pTri[tri[i][1]].push_back(i); pTri[tri[i][2]].push_back(i); } } #endif }
VehicleModel::VehicleModel() { angularSpeedXAxis = 900.0f; angularSpeedYAxis = 720.0f; // @TODO 5 - Layout your vehicle in a hierarchy CubeModel * mBody = new CubeModel(this); CubeModel * mFront = new CubeModel(mBody); CubeModel * mTail = new CubeModel(mBody); CubeModel * mTailWing = new CubeModel(mTail); CubeModel * mShaft = new CubeModel(mBody); CubeModel * mBlade1 = new CubeModel(mShaft); CubeModel * mBlade2 = new CubeModel(mShaft); CubeModel * mTailBlade1 = new CubeModel(mTailWing); CubeModel * mTailBlade2 = new CubeModel(mTailWing); // Body container.push_back(mBody); // Front mFront->SetPosition(glm::vec3(0.0f, -0.25f, 0.75f)); mFront->SetScaling(glm::vec3(1.0f, 0.5f, 0.75f)); container.push_back(mFront); // Tail mTail->SetPosition(glm::vec3(0.0f, -0.0f, -1.4f)); mTail->SetScaling(glm::vec3(0.25f, 0.5f, 1.9f)); container.push_back(mTail); // Tail Wing mTailWing->SetPosition(glm::vec3(0.0f, 0.25f, -0.7f)); mTailWing->SetScaling(glm::vec3(1.0f, 1.5f, 0.4f)); container.push_back(mTailWing); // Shaft mShaft->SetPosition(glm::vec3(0.0f, 0.55f, 0.0f)); mShaft->SetScaling(glm::vec3(0.1f, 0.5f, 0.1f)); container.push_back(mShaft); // Blade1 mBlade1->SetPosition(glm::vec3(0.0f, 0.5f, 0.0f)); mBlade1->SetScaling(glm::vec3(35.0f, 0.1f, 1.0f)); container.push_back(mBlade1); rotatingYAxis.push_back(mBlade1); // Blade2 mBlade2->SetPosition(glm::vec3(0.0f, 0.5f, 0.0f)); mBlade2->SetScaling(glm::vec3(1.0f, 0.1f, 35.0f)); container.push_back(mBlade2); rotatingYAxis.push_back(mBlade2); // TailBlade1 mTailBlade1->SetPosition(glm::vec3(0.65f, 0.35f, -0.35f)); mTailBlade1->SetScaling(glm::vec3(0.2f, 2.25f, 0.15f)); container.push_back(mTailBlade1); rotatingXAxis.push_back(mTailBlade1); // TailBlade2 mTailBlade2->SetPosition(glm::vec3(0.65f, 0.35f, -0.35f)); mTailBlade2->SetScaling(glm::vec3(0.2f, 0.15f, 2.25f)); container.push_back(mTailBlade2); rotatingXAxis.push_back(mTailBlade2); }
void World::LoadScene(const char * scene_path) { // Using case-insensitive strings and streams for easier parsing ci_ifstream input; input.open(scene_path, ios::in); // Invalid file if (input.fail()) { fprintf(stderr, "Error loading file: %s\n", scene_path); getchar(); exit(-1); } ci_string item; while (std::getline(input, item, '[')) { ci_istringstream iss(item); ci_string result; if (std::getline(iss, result, ']')) { if (result == "cube") { CubeModel* cube = new CubeModel(); cube->Load(iss); mModel.push_back(cube); } else if (result == "sphere") { #if defined(PLATFORM_OSX) int sphereTextureID = TextureLoader::LoadTexture("Textures/moonTexture.jpg"); #else int sphereTextureID = TextureLoader::LoadTexture("../Assets/Textures/moonTexture.jpg"); #endif SphereModel* moon = new SphereModel(sphereTextureID, vec3(10.0f, 10.0f, 10.0f)); moon->Load(iss); mModel.push_back(moon); } else if (result == "animationkey") { AnimationKey* key = new AnimationKey(); key->Load(iss); mAnimationKey.push_back(key); } else if (result == "animation") { Animation* anim = new Animation(); anim->Load(iss); mAnimation.push_back(anim); } else if (result.empty() == false && result[0] == '#') { // this is a comment line } else { fprintf(stderr, "Error loading scene file... !"); getchar(); exit(-1); } } } input.close(); // Set Animation vertex buffers for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it) { // Draw model (*it)->CreateVertexBuffer(); } }
void CubeModel::computeBoundingTree(int maxDepth) { // if(maxDepth <= 0) // return; //sout << ">CubeModel::computeBoundingTree("<<maxDepth<<")"<<sendl; std::list<CubeModel*> levels; levels.push_front(createPrevious<CubeModel>()); for (int i=0; i<maxDepth; i++) levels.push_front(levels.front()->createPrevious<CubeModel>()); CubeModel* root = levels.front(); //if (isStatic() && root->getPrevious() == NULL && !root->empty()) return; // No need to recompute BBox if immobile if (root->empty() || root->getPrevious() != NULL) { // Tree must be reconstructed //sout << "Building Tree with depth "<<maxDepth<<" from "<<size<<" elements."<<sendl; // First remove extra levels while(root->getPrevious()!=NULL) { core::CollisionModel::SPtr m = root->getPrevious(); root->setPrevious(m->getPrevious()); if (m->getMaster()) m->getMaster()->removeSlave(m); //delete m; m.reset(); } // Then clear all existing levels { for (std::list<CubeModel*>::iterator it = levels.begin(); it != levels.end(); ++it) (*it)->resize(0); } // Then build root cell //sout << "CubeModel: add root cube"<<sendl; root->addCube(Cube(this,0),Cube(this,size)); // Construct tree by splitting cells along their biggest dimension std::list<CubeModel*>::iterator it = levels.begin(); CubeModel* level = *it; ++it; int lvl = 0; while(it != levels.end()) { //sout << "CubeModel: split level "<<lvl<<sendl; CubeModel* clevel = *it; clevel->elems.reserve(level->size*2); for(Cube cell = Cube(level->begin()); level->end() != cell; ++cell) { const std::pair<Cube,Cube>& subcells = cell.subcells(); int ncells = subcells.second.getIndex() - subcells.first.getIndex(); //sout << "CubeModel: level "<<lvl<<" cell "<<cell.getIndex()<<": current subcells "<<subcells.first.getIndex() << " - "<<subcells.second.getIndex()<<sendl; if (ncells > 4) { // Only split cells with more than 4 childs // Find the biggest dimension int splitAxis; Vector3 l = cell.maxVect()-cell.minVect(); int middle = subcells.first.getIndex()+(ncells+1)/2; if(l[0]>l[1]) if (l[0]>l[2]) splitAxis = 0; else splitAxis = 2; else if (l[1]>l[2]) splitAxis = 1; else splitAxis = 2; // Separate cells on each side of the median cell #if defined(__GNUC__) && (__GNUC__ == 4) // && (__GNUC_MINOR__ == 1) && (__GNUC_PATCHLEVEL__ == 1) // there is apparently a bug in std::sort with GCC 4.x if (splitAxis == 0) qsort(&(elems[subcells.first.getIndex()]), subcells.second.getIndex()-subcells.first.getIndex(), sizeof(elems[0]), CubeSortPredicate::sortCube<0>); else if (splitAxis == 1) qsort(&(elems[subcells.first.getIndex()]), subcells.second.getIndex()-subcells.first.getIndex(), sizeof(elems[0]), CubeSortPredicate::sortCube<1>); else qsort(&(elems[subcells.first.getIndex()]), subcells.second.getIndex()-subcells.first.getIndex(), sizeof(elems[0]), CubeSortPredicate::sortCube<2>); #else CubeSortPredicate sortpred(splitAxis); //std::nth_element(elems.begin()+subcells.first.getIndex(),elems.begin()+middle,elems.begin()+subcells.second.getIndex(), sortpred); std::sort(elems.begin()+subcells.first.getIndex(),elems.begin()+subcells.second.getIndex(), sortpred); #endif // Create the two new subcells Cube cmiddle(this, middle); int c1 = clevel->addCube(subcells.first, cmiddle); int c2 = clevel->addCube(cmiddle, subcells.second); //sout << "L"<<lvl<<" cell "<<cell.getIndex()<<" split along "<<(splitAxis==0?'X':splitAxis==1?'Y':'Z')<<" in cell "<<c1<<" size "<<middle-subcells.first.getIndex()<<" and cell "<<c2<<" size "<<subcells.second.getIndex()-middle<<"."<<sendl; //level->elems[cell.getIndex()].subcells = std::make_pair(Cube(clevel,c1),Cube(clevel,c2+1)); level->elems[cell.getIndex()].subcells.first = Cube(clevel,c1); level->elems[cell.getIndex()].subcells.second = Cube(clevel,c2+1); } } ++it; level = clevel; ++lvl; } if (!parentOf.empty()) { // Finally update parentOf to reflect new cell order for (int i=0; i<size; i++) parentOf[elems[i].children.first.getIndex()] = i; } } else { // Simply update the existing tree, starting from the bottom int lvl = 0; for (std::list<CubeModel*>::reverse_iterator it = levels.rbegin(); it != levels.rend(); ++it) { //sout << "CubeModel: update level "<<lvl<<sendl; (*it)->updateCubes(); ++lvl; } } //sout << "<CubeModel::computeBoundingTree("<<maxDepth<<")"<<sendl; }
void World::LoadScene(const char * scene_path){ // Using case-insensitive strings and streams for easier parsing ci_ifstream input; input.open(scene_path, ios::in); // Invalid file if(input.fail() ){ fprintf(stderr, "Error loading file: %s\n", scene_path); getchar(); exit(-1); } ci_string item; while( std::getline( input, item, '[' ) ){ ci_istringstream iss( item ); ci_string result; if( std::getline( iss, result, ']') ){ if( result == "cube" ){ // Box attributes //CubeModel* cube = new CubeModel(); ourGuy->Load(iss); mModel.push_back(ourGuy); } else if( result == "ground" ){ // Box attributes CubeModel* cube = new CubeModel(); cube->Load(iss); mModel.push_back(cube); } else if( result == "sphere" ){ //SphereModel* sphere = new SphereModel(); ourSphere->Load(iss); mModel.push_back(ourSphere); } else if ( result == "animationkey" ){ AnimationKey* key = new AnimationKey(); key->Load(iss); mAnimationKey.push_back(key); } else if (result == "animation"){ Animation* anim = new Animation(); anim->Load(iss); mAnimation.push_back(anim); }//*/ else if (result == "bspline"){ BSpline* spline = new BSpline(); spline->Load(iss); mBSpline.push_back(spline); }//*/ else if ( result.empty() == false && result[0] == '#'){ // this is a comment line } else{ fprintf(stderr, "Error loading scene file... !"); getchar(); exit(-1); } } } input.close(); // Set Animation vertex buffers for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it) // Draw model (*it)->CreateVertexBuffer(); }
void TetrahedronModel::computeBoundingTree(int maxDepth) { CubeModel* cubeModel = createPrevious<CubeModel>(); if (!mstate || !_topology) return; if (!isMoving() && !cubeModel->empty()) return; // No need to recompute BBox if immobile Vector3 minElem, maxElem; const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue(); for (int i=0; i<size; i++) { Tetrahedron t(this,i); const Vector3& pt1 = x[t.p1Index()]; const Vector3& pt2 = x[t.p2Index()]; const Vector3& pt3 = x[t.p3Index()]; const Vector3& pt4 = x[t.p4Index()]; Matrix3 m, minv; m[0] = pt2-pt1; m[1] = pt3-pt1; m[2] = pt4-pt1; m.transpose(); minv.invert(m); elems[i].coord0 = pt1; elems[i].bary2coord = m; elems[i].coord2bary = minv; } if (maxDepth == 0) { // no hierarchy if (empty()) cubeModel->resize(0); else { cubeModel->resize(1); minElem = x[0]; maxElem = x[0]; for (unsigned i=1; i<x.size(); i++) { const Vector3& pt1 = x[i]; if (pt1[0] > maxElem[0]) maxElem[0] = pt1[0]; else if (pt1[0] < minElem[0]) minElem[0] = pt1[0]; if (pt1[1] > maxElem[1]) maxElem[1] = pt1[1]; else if (pt1[1] < minElem[1]) minElem[1] = pt1[1]; if (pt1[2] > maxElem[2]) maxElem[2] = pt1[2]; else if (pt1[2] < minElem[2]) minElem[2] = pt1[2]; } cubeModel->setLeafCube(0, std::make_pair(this->begin(),this->end()), minElem, maxElem); // define the bounding box of the current Tetrahedron } } else { cubeModel->resize(size); // size = number of Tetrahedrons if (!empty()) { for (int i=0; i<size; i++) { Tetrahedron t(this,i); const Vector3& pt1 = x[t.p1Index()]; const Vector3& pt2 = x[t.p2Index()]; const Vector3& pt3 = x[t.p3Index()]; const Vector3& pt4 = x[t.p4Index()]; for (int c = 0; c < 3; c++) { minElem[c] = pt1[c]; maxElem[c] = pt1[c]; if (pt2[c] > maxElem[c]) maxElem[c] = pt2[c]; else if (pt2[c] < minElem[c]) minElem[c] = pt2[c]; if (pt3[c] > maxElem[c]) maxElem[c] = pt3[c]; else if (pt3[c] < minElem[c]) minElem[c] = pt3[c]; if (pt4[c] > maxElem[c]) maxElem[c] = pt4[c]; else if (pt4[c] < minElem[c]) minElem[c] = pt4[c]; } cubeModel->setParentOf(i, minElem, maxElem); // define the bounding box of the current Tetrahedron } cubeModel->computeBoundingTree(maxDepth); } } }