void ProjectView::addTree(KileProjectItem *projitem, ProjectViewItem *projvi) { KILE_DEBUG() << "projitem=" << projitem << "projvi=" << projvi; ProjectViewItem * item = add(projitem, projvi); if(projitem->firstChild()) { addTree(projitem->firstChild(), item); } if (projitem->sibling()) { addTree(projitem->sibling(), projvi); } }
void node *addTree(struct node *p, char *word) { int cond; if(p==NULL) { p = talloc(); p->ngrm = strdup(word); p->count = 1; p->left = p->right = NULL; } else if ((cond = strcmp(w,p->ngrm)) == 0){ p->count++ } else if(cond < 0) p->left = addTree(p->left,word); else p->right = addTree(p->right,word); return p; }
void ProjectView::refreshProjectTree(const KileProject *project) { KILE_DEBUG() << "\tProjectView::refreshProjectTree(" << project->name() << ")"; ProjectViewItem *parent= projectViewItemFor(project->url()); //clean the tree if(parent) { KILE_DEBUG() << "\tusing parent projectviewitem " << parent->url().fileName(); parent->setFolder(-1); QList<QTreeWidgetItem*> children = parent->takeChildren(); for(QList<QTreeWidgetItem*>::iterator it = children.begin(); it != children.end(); ++it) { delete(*it); } } else { return; } //create the non-sources dir //ProjectViewItem *nonsrc = new ProjectViewItem(parent, i18n("non-sources")); //parent->setNonSrc(nonsrc); QList<KileProjectItem*> list = project->rootItems(); for(QList<KileProjectItem*>::iterator it = list.begin(); it != list.end(); ++it) { addTree(*it, parent); } parent->sortChildren(0, Qt::AscendingOrder); // seems to be necessary to get a correct refreh (Qt 4.4.3) bool expanded = parent->isExpanded(); parent->setExpanded(!expanded); parent->setExpanded(expanded); }
void binomial_queue<T>::push(const T& value) { qty++; tree_reference treeToAdd(new binomial_tree<T>(value)); addTree(treeToAdd); updateTop(); check(); }
LRESULT TreePropertySheet::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /* bHandled */) { if(ResourceManager::getInstance()->isRTL()) SetWindowLongPtr(GWL_EXSTYLE, GetWindowLongPtr(GWL_EXSTYLE) | WS_EX_LAYOUTRTL); hideTab(); addTree(); fillTree(); return 0; }
LRESULT TreePropertySheet::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /* bHandled */) { if(ResourceManager::getInstance()->isRTL()) SetWindowLongPtr(GWL_EXSTYLE, GetWindowLongPtr(GWL_EXSTYLE) | WS_EX_LAYOUTRTL); tree_icons.CreateFromImage(IDB_O_SETTINGS_DLG, 16, 25, CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION | LR_SHARED); hideTab(); addTree(); fillTree(); return 0; }
void binomial_queue<T>::pop() { if (empty()) std::runtime_error("queue is already empty"); qty--; trees.erase(top_tree); for (auto child: top_tree->split()) addTree(child); updateTop(); check(); }
static void genTree (int NN, int* T, stack* stack, tree_t* TREE) { double v; pair p; int Z, D, N, J, TD, M, more; N = NN; while (1) { while (N > 2) { v = (N-1)*T[N]; Z = v*drand(); D = 0; more = 1; do { D++; TD = D*T[D]; M = N; J = 0; do { J++; M -= D; if (M < 1) break; Z -= T[M]*TD; if (Z < 0) more = 0; } while (Z >= 0); } while (more); push(stack, J, D); N = M; } addTree (TREE, N); while (1) { p = pop(stack); N = p.d; if (N != 0) { push(stack,p.j,0); break; } J = p.j; if (J > 1) treeDup (TREE, J); if (treeTop(TREE) == NN) return; treePop(TREE); } } }
void Chunk::stepByStepCreation(){ switch(stepCreation){ case 1: addLava(); break; case 2: addWater(); break; case 3: addSand(); break; case 4: addStone(); break; case 5: addDirt(); break; case 6: addTree(); break; case 7: // to avoid errors checkSizeChunk(); // checkVisibleBlocks(); saveChunkInFile(); break; default: // start if(!readChunkFromFile()){ // fail to open file, it's time to generate a new one checkSizeChunk(); // fill Chunk with zero }else{ stepCreation = 6; // almost end of the generation } break; } stepCreation++; }
void ngram(char *word, int n) { char *p = NULL; char *q = NULL; char *padding = NULL; char *buffer = NULL; int i=0; int b = n-1; if((buffer = (char*) malloc(n+1)) == NULL) { fprintf(stderr,"%s:Error Failed malloc\n", PACKAGE); } if((padding = (char*) malloc(strlen(word)+n+2)) == NULL) { fprintf(stderr,"%s:Error: Failed malloc \n",PACKAGE); } sprintf(padding,"_%s",word); for(i=0;i<n-1;i++) { strcat(padding,"_"); } p = padding; q = buffer; i = 0; while(*p) { if(n==1) { *q++ = '\0'; root = addTree(root,buffer); i=0; p = p-b; q = buffer; } else { *q++ = *p++; i++; } free(padding); free(buffer); } }
static osg::Geode* createObjects( osg::HeightField * grid, unsigned int density ) { osg::Geode* geode = new osg::Geode; // set up the texture of the base. osg::StateSet* stateset = new osg::StateSet(); osg::Image * image = new osg::Image(); image->setImage( 64,64,1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, orderBytes( objectTexture, sizeof( objectTexture ) ), osg::Image::NO_DELETE ); osg::Texture2D* texture = new osg::Texture2D; texture->setImage(image); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); stateset->setMode( GL_BLEND,osg::StateAttribute::ON ); stateset->setAttributeAndModes( new osg::CullFace() ); stateset->setAttributeAndModes( new osg::Depth( osg::Depth::LESS, 0.f, 1.f, true ) ); stateset->setAttributeAndModes( new osg::AlphaFunc( osg::AlphaFunc::GEQUAL, 0.5f ) ); geode->setStateSet( stateset ); osg::Geometry* geometry = new osg::Geometry; geode->addDrawable(geometry); osg::Vec3Array* vertices = new osg::Vec3Array; geometry->setVertexArray(vertices); osg::Vec3Array* normals = new osg::Vec3Array; geometry->setNormalArray(normals); geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); osg::Vec2Array* texCoords = new osg::Vec2Array; geometry->setTexCoordArray(0, texCoords); osg::Vec4Array* colours = new osg::Vec4Array; geometry->setColorArray(colours); geometry->setColorBinding(osg::Geometry::BIND_OVERALL); colours->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); for( unsigned int x = 0; x < grid->getNumColumns() - 1; x++ ) { for( unsigned int y = 0; y < grid->getNumRows() - 1; y++ ) { float z00 = grid->getHeight( x,y ); float z01 = grid->getHeight( x,y+1 ); float z10 = grid->getHeight( x+1,y ); float z11 = grid->getHeight( x+1,y+1 ); float z = 0.25 * ( z00 + z10 + z11 + z01 ); if( z < 400 ) continue; if( z > 500 ) continue; osg::Vec3 o( float(x) * grid->getXInterval(), float(y) * grid->getYInterval(), 0.0f ); o += grid->getOrigin(); for( unsigned int d = 0; d < density; d++ ) { osg::Vec3 p( float( rand() ) / RAND_MAX, float( rand() ) / RAND_MAX, 0 ); z = ( 1.f - p[0] ) * ( 1.f - p[1] ) * z00 + ( 1.f - p[0] ) * ( p[1] ) * z01 + ( p[0] ) * ( p[1] ) * z11 + ( p[0] ) * ( 1.f - p[1] ) * z10; osg::Vec3 pos(o + osg::Vec3(p.x() * grid->getXInterval(), p.y() * grid->getYInterval(), z)); if( rand() % 3 > 0 ) addTree( pos, vertices, normals, texCoords ); else addHouse( pos, vertices, normals, texCoords ); } } } geometry->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, vertices->size())); geode->addDrawable(geometry); return geode; }
void sceneMountain() { /* First, allocates enough space for all the structures.*/ int i; noObjects = 114; noLights = 2; objects = new Object *[noObjects]; lights = new Light[noLights]; /* Back wall: the sky..*/ vector normalOne = {0, 0, -1}; Plane *plane = new Plane(0,0,10000, normalOne, 0.55,0.27,0.075); (*plane).setReflection(0.0); (*plane).setShininess(50); (*plane).setSpecular(0.1, 0.1, 0.1); (*plane).setRefraction(0); objects[0] = plane; /* Ground. */ vector normalZero = {0, 1, 0}; plane = new Plane(0,0,0, normalZero, 0.35,0.27,0.075); (*plane).setReflection(0.0); (*plane).setShininess(20); (*plane).setSpecular(0.6, 0.6, 0.6); (*plane).setRefraction(0.0); objects[1] = plane; /* Cubes initialization. */ Cube *cube; for (i = 2; i <= 35; i++) { if (i <= 35/6) addMountainBlock(i, i, 0.0, 50*(i-1), 1500.0, 3000 - (3000.0/35)*i*4,100, 1000 - (1000.0/35)*i*4, 0.1423, 0.00894, 0.1471, 0.00894, 0.1499, 0.00890); else addMountainBlock(i, i, 0.0, 50*(i-1), 1500.0, 5000/i,100, 2000/i, 0.1423, 0.00894, 0.1471, 0.00894, 0.1499, 0.00890); } for (i = 2; i <= 21; i++) addMountainBlock(i+34, i, 1500.0, 50*(i-1), 1000.0, 2000/i, 100, 700/i, 0.2323, 0.00984, 0.2371, 0.00984, 0.2399, 0.00980); for (i = 2; i <= 21; i++) addMountainBlock(i+54, i, 100.0, 50*(i-1), 500.0, 2000/i, 100, 700/i, 0.2323, 0.00984, 0.2371, 0.00984, 0.2399, 0.00980); for (i = 2; i <= 14; i++) addMountainBlock(i+74, i, 1200.0, 50*(i-1), 600.0, 1200/i, 100, 300/i, 0.2523, 0.00994, 0.2571, 0.00994, 0.2599, 0.00990); /* After adding all the mountains, we still add some blocks to join the * bottoms of each. */ cube = new Cube(900.0, 30, 400.0, 800, 60, 250, 0.36, 0.25, 0.2); (*cube).setReflection(0.0); (*cube).setShininess(50); (*cube).setSpecular(1, 1, 1); (*cube).setRefraction(0.0); objects[89] = cube; cube = new Cube(-750.0, 30, 800.0, 250, 60, 800, 0.36, 0.25, 0.2); (*cube).setReflection(0.0); (*cube).setShininess(50); (*cube).setSpecular(1, 1, 1); (*cube).setRefraction(0.0); objects[90] = cube; /* And now the water in the middle of the mountains. */ cube = new Cube(200.0, 20, 1000.0, 1800, 40, 850, 0.5, 0.3, 0.8); (*cube).setReflection(1.0); (*cube).setShininess(10); (*cube).setSpecular(0, 0, 0); (*cube).setRefraction(0.0); objects[91] = cube; /* Adding some trees to the scenario. */ addTree(92, -50.0, 220.0); addTree(98, 200.0, 70.0); addTree(102, 290.0, 200.0); addTree(94, 500.0, 90.0); addTree(96, 700.0, 140.0); addTree(106, 950.0, 200.0); addTree(108, 1150.0, 50.0); addTree(100, 1500.0, 135.0); addTree(104, 1750.0, 270.0); addTree(110, 1800.0, 500.0); addTree(112, 1450.0, 380.0); /* Lights initialization. */ //lights[0] = Light(300,10000,6000, 1.0, 1, 1, 1); lights[0] = Light(600,4000,-1000, 1.0, 1, 0.5, 0.5); lights[1] = Light(4000,800,500, 1.0, 1, 0.5, 0.5); }
void binomial_queue<T>::mergeTrees(tree_reference merging, tree_reference merged) { trees.erase(merging); merging->mergeWithTree(merged); addTree(merging); }
void selection::analyze(size_t childid /* this info can be used for printouts */){ /* * This skeleton analyser runs directly on the Delphes output. * It can be used to create histograms directly or a skim. * If a skim is created, a new input configuration will be written automatically * and stored in the output directory together with the ntuples. * The skim can contain delphes objects again or can be flat. This is up * to the user. * Examples for both are given here. * * The same skeleton can be used to read the skim. Please refer to the comments * marked with "==SKIM==" * * These parts are commented, since the code is supposed to work as an example without * modifications on Delphes output directly. */ /* * Define the branches that are to be considered for the analysis * This branch handler (notice the "d") * is used to run directly in Delphes output. * For skimmed ntuples, see below */ d_ana::dBranchHandler<Electron> elecs(tree(),"Electron"); /* ==SKIM== * * If a skim of the Delphes outout was created in a way indicated * further below, use the tBranchHandler (please notive the "t") * to access vectors of objects... * */ // d_ana::tBranchHandler<std::vector<Electron> > electrons(tree(),"Electrons"); /*==SKIM== * * Or an object directly * */ //d_ana::tBranchHandler<MissingET> met(tree(),"MET"); /* * Always use this function to add a new histogram (can also be 2D)! * Histograms created this way are automatically added to the output file */ TH1* histo=addPlot(new TH1D("histoname1","histotitle1",100,0,100),"p_{T} [GeV]","N_{e}"); /* * If (optionally) a skim or a flat ntuple is to be created, please use the following function to initialize * the tree. * The output files will be written automatically, and a config file will be created. */ TTree* myskim=addTree(); /* * Add a simple branch to the skim */ Double_t elecPt=0; myskim->Branch("elecPt", &elecPt); /* * Or store a vector of objects (also possible to store only one object) */ std::vector<Electron> skimmedelecs; myskim->Branch("Electrons",&skimmedelecs); size_t nevents=tree()->entries(); if(isTestMode()) nevents/=100; for(size_t eventno=0;eventno<nevents;eventno++){ /* * The following two lines report the status and set the event link * Do not remove! */ reportStatus(eventno,nevents); tree()->setEntry(eventno); /* * Begin the event-by-event analysis */ for(size_t i=0;i<elecs.size();i++){ histo->Fill(elecs.at(i)->PT); } /* * Or to fill the skim */ skimmedelecs.clear(); for(size_t i=0;i<elecs.size();i++){ //flat info elecPt=elecs.at(i)->PT; if(elecs.at(i)->PT < 20) continue; //or objects skimmedelecs.push_back(*elecs.at(i)); } myskim->Fill(); /*==SKIM== * Access the branches of the skim */ //std::vector<Electron> * skimelecs=electrons.content(); //for(size_t i=0;i<skimelecs->size();i++){ // histo->Fill(skimelecs->at(i).PT); //} } /* * Must be called in the end, takes care of thread-safe writeout and * call-back to the parent process */ processEndFunction(); }
int main(int argc, char *argv[]) { #ifdef Q_WS_X11 XInitThreads(); #endif Engine engine(argc, argv,"demo_game/media/"); SceneGraph* sg = engine.getScenegraph_TEMPORARY(); QList<InputManager::Control> controls; controls.push_back(InputManager::Control(false,"avance")); controls.push_back(InputManager::Control(false,"recule")); controls.push_back(InputManager::Control(false,"gauche")); controls.push_back(InputManager::Control(false,"droite")); INPUT_MANAGER.addControls(controls); INPUT_MANAGER.addBinding("KB_Z","avance"); INPUT_MANAGER.addBinding("KB_Up","avance"); INPUT_MANAGER.addBinding("KB_S","recule"); INPUT_MANAGER.addBinding("KB_Down","recule"); INPUT_MANAGER.addBinding("KB_Q","gauche"); INPUT_MANAGER.addBinding("KB_Left","gauche"); INPUT_MANAGER.addBinding("KB_D","droite"); INPUT_MANAGER.addBinding("KB_Right","droite"); Node* nTerrain = new Node("Terrain"); Node* nBase = new Node("Base"); Node* nRot = new Node("Rotating node"); Node* nLight = new Node("Light"); Node* nPlane = new Node("Plane"); Node* nCentre = new Node("Centre"); Node* nCamFollow = new Node("Camera Follow"); Texture heightmap; if(argc>1) { heightmap = TEXTURE_MANAGER.get(argv[1]); } else { heightmap = TEXTURE_MANAGER.get("heightmap_island.tga"); } Mesh sphere = MESH_MANAGER.get("Sphere_16_32"); Mesh palm = MESH_MANAGER.get("palm"); Mesh mesh = MESH_MANAGER.get("duckplane"); Material mat = MATERIAL_MANAGER.get("palm"); Material duckmat = MATERIAL_MANAGER.get("duckplane"); Material terrain = MATERIAL_MANAGER.get("terrain_test"); PhysicObject::Properties prop; prop.is_kinematic = false; prop.mass = 100.0; prop.restitution = 0.1; //prop.linDamping = 0.6; //prop.angDamping = 0.3; prop.shape = PhysicObject::MESH; prop.mesh_name = "duckplane"; sg->link(nCentre); nCentre->link(nPlane); nCentre->move(Vector3f(512.0,50.0,512.0)); nPlane->addProperty(new MeshRenderer(mesh,duckmat)); nPlane->rotate(Vector3f(0.0,0.0,1.0), 20.0); nPlane->move(Vector3f(286.0,20.0,0.0)); //nPlane->setScale(Vector3f(5.0,5.0,5.0)); nCentre->addProperty(new DummyUpdatable(0.1)); Camera* cam = new Camera(90,1,1024); nCamFollow->addProperty(cam); nCamFollow->move(Vector3f(0,2,5)); nCamFollow->rotate(Vector3f(-1,0,0),15); nPlane->link(nCamFollow); Light* light = new Light(true); light->setAttenuation(0,1.f/512.f,0); //light->setAttenuation(0.1,0,0); light->setType(Light::SUN); nLight->addProperty(light); /* nLight->move(Vector3f(512.0, 75.0, 512.0)); nLight->rotate(Vector3f(0.0, 0.0, 1.0),35); */ nLight->lookAt(Vector3f(4.3,13,10)); nLight->rotate(nLight->apply(Vector3f(0,1,0)),90); nLight->moveTo(25*Vector3f(4.3,13,10) + Vector3f(512,50,512)); //nLight->lookAt(Vector3f(512,50,512)); //nLight->rotate(Vector3f(0,1,0),-90); /* cam = new Camera(90,1,1024); nLight->addProperty(cam); */ nBase->rotate(Vector3f(1,0,0),90); nBase->rotate(Vector3f(0,1,0),-45); nTerrain->addProperty(new TerrainRenderer(heightmap, terrain, 70.0f, 2.f,20.f)); nTerrain->setScale(Vector3f(1,3,1)); sg->link(nTerrain); sg->link(nLight); nBase->link(nRot); sg->link(nBase); addTree(sg,Vector3f(502.7,39.2,616.7),135); addTree(sg,Vector3f(494.8,37.2,628.1),45); addTree(sg,Vector3f(520.6,40.2,612.8),12); addTree(sg,Vector3f(513.1,38.2,622.6),286); addTree(sg,Vector3f(520.5,37.2,632.2),124); RenderManager::Background background; background.type = RenderManager::Background::COLOR; background.color = Vector3f(0,0,0); background.sunDirection = Vector3f(4.3,13,10); background.textures[0] = TEXTURE_MANAGER.get("interstellar_lf.tga"); background.textures[1] = TEXTURE_MANAGER.get("interstellar_ft.tga"); background.textures[2] = TEXTURE_MANAGER.get("interstellar_rt.tga"); background.textures[3] = TEXTURE_MANAGER.get("interstellar_bk.tga"); background.textures[4] = TEXTURE_MANAGER.get("interstellar_up.tga"); background.textures[5] = TEXTURE_MANAGER.get("interstellar_dn.tga"); background.type = RenderManager::Background::SKYBOX; RENDER_MANAGER.setBackground(background); //RENDER_MANAGER.setCurrentCamera(cam); RENDER_MANAGER.setAmbient(Vector3f(0.1,0.2,0.15)); COMMAND_MANAGER.readFile("config.cfg"); int ret = engine.start(); return ret; }
Tree *createtree(void) { Tree *Tree1; Tree *root = NULL; List *List1 ; int i = 0 , j=0, found = 0; char temp; char name[20]; char number[15]; while (1==1){ List1 = NULL ; scanf("%19s", name); i = 0, j = 0 ; while ( name[i] != '\0' ) { name[i] = toupper( name[i] ) ; i++ ; } if (name[0] == '.') break; for ( i = 0 ; i <15 ; i++ ) { number[i] = '\0'; } scanf("%14s", number); while (number[j] != '\0') { j++; } number[j] = '\n'; i = 0 ; Tree1 = root ; if ( Tree1 == 0 ) { while (number[i] != '\0') { List1 = addList(number[i], List1); i++; } List1->pre = NULL ; Tree1 = addTree(Tree1, name, List1) ; root = Tree1 ; Tree1->right = NULL ; Tree1->left = NULL ; }else{ while ( Tree1->left != 0 || Tree1->right != 0 ) { if ( strcmp( name, Tree1->name ) < 0 ) { if (Tree1->left != NULL ) { Tree1 = Tree1->left ; } else break ; } else { if ( strcmp( name, Tree1->name ) > 0 ) { if ( Tree1->right != NULL ) { Tree1 = Tree1->right ; } else break ; } else { found = 1 ; break ; } } } if ( Tree1->left == 0 && Tree1->right == 0 ) { if ( strcmp( name, Tree1->name ) == 0 ) { found = 1 ; } else { found = 0 ; } } if (found==0) { Tree1 = root ; while ( Tree1->left != 0 || Tree1->right != 0 ) { if( strcmp( name, Tree1->name ) < 0 ) { Search = 0 ; if ( Tree1->left != NULL ) { Tree1 = Tree1->left; } else { break ; } } else { Search = 1; if ( Tree1->right != NULL ) { Tree1 = Tree1->right; } else { break ; } } } if( strcmp( name, Tree1->name ) < 0 ) { Search = 0 ; } else Search = 1 ; while (number[i] != '\0') { List1 = addList(number[i], List1); i++; } List1->pre = NULL ; Tree1 = addTree(Tree1, name, List1) ; } else { List1 = Tree1->numbers ; while (number[i] != '\0') { List1 = addList(number[i], List1); i++; } List1->pre = NULL ; } Tree1->numbers = List1; } } Tree1 = root ; return Tree1; }
bool PmVegetation::generateVegetation(VBORenderManager& rendManager, const std::vector<Block>& blocks){ const float deltaZ = 2.0f; rendManager.removeAllStreetElementName("streetLamp"); rendManager.removeAllStreetElementName("tree"); float treesPerSqMeter = 0.04f;// 0.002f; //used for trees in parcels // generate trees in blocks (park) for (int bN = 0; bN < blocks.size(); bN++) { if (blocks[bN].isPark) { for (int cN = 0; cN < blocks[bN].blockContours.size(); ++cN) { BBox bbox = blocks[bN].blockContours[cN].envelope(); int numTrees = blocks[bN].blockContours[cN].area() * treesPerSqMeter; for (int i = 0; i < numTrees; ++i) { QVector3D pos; while (true) { pos.setX(Util::genRand(bbox.minPt.x(), bbox.maxPt.x())); pos.setY(Util::genRand(bbox.minPt.y(), bbox.maxPt.y())); pos.setZ(deltaZ); if (blocks[bN].blockContours[cN].contains(pos)) { break; } } rendManager.addStreetElementModel("tree", addTree(pos)); } } } else { for (int pN = 0; pN < blocks[bN].parcels.size(); ++pN) { if (blocks[bN].parcels[pN].isPark) { BBox bbox = blocks[bN].parcels[pN].parcelContour.envelope(); int numTrees = blocks[bN].parcels[pN].parcelContour.area() * treesPerSqMeter; for (int i = 0; i < numTrees; ++i) { QVector3D pos; while (true) { pos.setX(Util::genRand(bbox.minPt.x(), bbox.maxPt.x())); pos.setY(Util::genRand(bbox.minPt.y(), bbox.maxPt.y())); pos.setZ(deltaZ); if (blocks[bN].parcels[pN].parcelContour.contains(pos)) { break; } } rendManager.addStreetElementModel("tree", addTree(pos)); } } else { // for the parcel with building, put trees in the remaining area outside the footprint BBox bbox = blocks[bN].parcels[pN].parcelContour.envelope(); int numTrees = (blocks[bN].parcels[pN].parcelContour.area() - blocks[bN].parcels[pN].building.buildingFootprint.area()) * treesPerSqMeter; for (int i = 0; i < numTrees; ++i) { QVector3D pos; while (true) { pos.setX(Util::genRand(bbox.minPt.x(), bbox.maxPt.x())); pos.setY(Util::genRand(bbox.minPt.y(), bbox.maxPt.y())); pos.setZ(deltaZ); if (blocks[bN].parcels[pN].parcelContour.contains(pos) && !blocks[bN].parcels[pN].building.buildingFootprint.contains(pos)) { break; } } rendManager.addStreetElementModel("tree", addTree(pos)); } } } } } float distanceBetweenLamps = 50.0f;//23 N 15.0f; //used for trees along streets // generate trees along streets float tree_setback = G::getFloat("tree_setback"); for (int i = 0; i < blocks.size(); ++i) { const Loop3D contour = blocks[i].sidewalkContour.contour; float distLeftOver = tree_setback; for (int j = 0; j < contour.size(); ++j) { QVector3D ptThis = contour[j]; QVector3D ptNext = contour[(j + 1) % contour.size()]; QVector3D segmentVector = ptNext - ptThis; float segmentLength = segmentVector.length(); segmentVector /= segmentLength; QVector3D perpV = QVector3D(segmentVector.y(), -segmentVector.x(), 0); ptThis = ptThis - perpV * tree_setback; float distFromSegmentStart = distLeftOver; while (true) { if (distFromSegmentStart > segmentLength - tree_setback) { distLeftOver = distFromSegmentStart - segmentLength; break; } if (j == contour.size() - 1) { // For the last segment, don't place a tree close to the last end point if (segmentLength - distFromSegmentStart < distanceBetweenLamps * 0.5f) break; } QVector3D pos = ptThis + segmentVector * distFromSegmentStart; pos.setZ(deltaZ); rendManager.addStreetElementModel("streetLamp", addStreetLap(pos, segmentVector)); distFromSegmentStart += distanceBetweenLamps * Util::genRand(0.4, 0.6); } } } return true; }