Mapconv/trees stuffs...

Mapconv/trees stuffs...

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Mapconv/trees stuffs...

Post by SinbadEV »

I was just thinking when I was trying to make a map... that having green on texture=trees is anoying cause it means you have to mess up your texture... maybe it could be done so that blue on the metal map=trees so than you could put trees where you actually wants them and have green in places where you don't want trees... I bet this is one of those things I could do myself if I bothered to install a compiler... yeah... I was just looking at the code and I can't figure it out...

http://cvs.sourceforge.net/viewcvs.py/s ... iew=markup

but I figure you'd just have to make the tree placer function work like the geo-vent placer function, minus the drawing to the maptexture bit...
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Post by SinbadEV »

Code: Select all

	//trees
	CBitmap metal(metalfile);		//use the blue channel for trees

	for(int y=0;y<metal.ysize;++y){
		for(int x=0;x<metal.xsize;++x){
			unsigned char c=metal.mem[((y+y2)*metal->xsize+x+x2)*4+2];

			if(c==255){
				int bx=x*xsize/metal.xsize;
				int by=y*ysize/metal.ysize;
				for(int tries=0;tries<1000;++tries){
					int x=bx+rand()*(40)/RAND_MAX-20;
					int y=by+rand()*(40)/RAND_MAX-20;
					if(x<5)
						x=5;
					if(x>xsize-5)
						x=xsize-5;
					if(y<5)
						y=5;
					if(y>ysize-5)
						y=ysize-5;

					float h=heightmap[y*mapx+x];
					if(h<5)
						continue;

					bool good=true;
					for(int y2=y-3;y2<=y+3;++y2){
						for(int x2=x-3;x2<=x+3;++x2){
							if(fabs(h-heightmap[(y2)*mapx+x2])>3)
								good=false;
						}
					}
					if(good){
						FeatureFileStruct ffs;
						ffs.featureType=(rand()*NUM_TREE_TYPES)/RAND_MAX;
						ffs.relativeSize=0.8f+float(rand())/RAND_MAX*0.4f;
						ffs.rotation=0;
						ffs.xpos=(float)x*8+4;
						ffs.ypos=0;
						ffs.zpos=(float)y*8+4;

						features.push_back(ffs);

						break;
					}
				}
			}
		}
	}
this is my guess, as I said... no compiler... and not really a programmer myself... at all really... just know... in general how to read code...
Post Reply

Return to “Engine”