AGSurface ball() { int w=64; VoxelView v(w,w*2,Pos3D(0,0,0),false); int x,y,z; float r=w/2; for(x=0;x<w;x++) for(y=0;y<w;y++) for(z=0;z<w;z++) { int mx=x-w/2; int my=y-w/2; int mz=z-w/2; float d=sqrt((float)(mx*mx+my*my+mz*mz)); if(d<r+3) { float a=r-d; if(a<0) a=0; if(a>0) v.set(Pos3D(x,y,z),Color(0,0,1,std::max(1.0f,a))); } } return v.getSurface(); }
AGSurface makeWaterTileOld() { int w=TILE_WIDTH; VoxelView v(w,w*2,Pos3D(0,0,0),true); float a=12; SplineMapD wh((int)a,(int)a,5,1,6); for(int x=0; x<w; x++) for(int z=0; z<w; z++) { float mx=x-z+w/2; float mz=x+z-w/2; float h=wh.get(a*float(mx)/w,a*float(mz)/w)+6; for(int y=std::max(0,(int)(h)-3); y<h; y++) { float f=std::min(1.0f,h-y); v.set(Pos3D(x,y,z),Color(0,0,0xAA,f)); } } return v.getSurface(); }
VoxelImage *makeTree() { int vw=256; FastVoxelView vv(vw,vw,Pos3D(256,512,0),false,1); drawPlane(vv,vw); drawTree(vv,Pos3D(128,0,128),140); return new VoxelImage(vv.getSurface(),Pos3D(0,0,0)); }
Pos2D projectShadow(const Pos3D &p) { #ifdef SHADOW_DOWN return Pos2D(p.x,p.z); #else //return Pos2D((int)(p*Pos3D(0,0,1)),(int)(p*Pos3D(1,1,0))); // return Pos2D((int)(p.z),(int)(VOXELHEIGHT-p.y-p.x-1)); return Pos2D((int)(p*Pos3D(1,0,-1)),(int)(p*Pos3D(1,1,1))); // return Pos2D((int)(p.z-p.x),(int)(VOXELHEIGHT-p.y-p.x-1)); #endif }
int depthShadow(const Pos3D &p) { #ifdef SHADOW_DOWN return (int)(VOXELHEIGHT-p.y); #else // SHADOW to back right return (int)(VOXELHEIGHT+p*Pos3D(1,-1,1)); #endif return (int)(p*Pos3D(1,-1,1)); }
Box::Box(Pos3D _origin, double _length) { origin = _origin; length = _length/2; // std::vector<double> _vec; // _vec.push_back(_origin.x); // _vec.push_back(_origin.y); // _vec.push_back(_origin.z); // // std::sort(_vec.begin(), _vec.end(), std::less<double>()); // // auto min_value = _vec[0]; // auto max_value = _vec[2]; // // if (min_value < - world_limit || max_value + _length > world_limit) { // std::cerr << "Your object exceeds the world limit." << std::endl; // } if (_length >= world_limit) { std::cerr << "Your object exceeds the world limit." << std::endl; } /* set all 8 vertices of the cube box */ ppos[0] = Pos3D(origin.x - length, origin.y - length, origin.z - length); ppos[1] = Pos3D(origin.x - length, origin.y + length, origin.z - length); ppos[2] = Pos3D(origin.x - length, origin.y + length, origin.z + length); ppos[3] = Pos3D(origin.x - length, origin.y - length, origin.z + length); ppos[4] = Pos3D(origin.x + length, origin.y - length, origin.z - length); ppos[5] = Pos3D(origin.x + length, origin.y + length, origin.z - length); ppos[6] = Pos3D(origin.x + length, origin.y + length, origin.z + length); ppos[7] = Pos3D(origin.x + length, origin.y - length, origin.z + length); }
VoxelImage *makeWaterTile() { int w=TILE_WIDTH; FastVoxelView v(w,w*2,Pos3D(0,0,0),true); /** add water **/ srand(0); { float a=18; SplineMapD wh((int)a,(int)a,3,1,3,true); for(int x=0; x<w; x++) for(int z=0; z<w; z++) { float mx=x-z+w/2; float mz=x+z-w/2; mx/=w; mz/=w; while(mx>1) mx-=1; while(mx<0) mx+=1; while(mz>1) mz-=1; while(mz<0) mz+=1; float h=wh.get(a*float(mx),a*float(mz))+6; for(int y=0; y<h; y++) { float f=std::min(1.0f,h-y); v.set(Pos3D(x,y,z),Color(0,0,0xAA,f)); } } } /** till here */ AGSurface s= v.getSurface(); return new VoxelImage(s,Pos3D(0,0,0)); }
Pos3D getRandPos(int s) { int s2=s*2; return Pos3D((rand()%s2)/float(s)-1, (rand()%s2)/float(s)-1, (rand()%s2)/float(s)-1); }
void drawPlane(FastVoxelView &vv,int vw) { int x,y; for(x=0;x<vw;x++) for(y=0;y<vw;y++) vv.set(Pos3D(x,0,y),Color(1,1,1,1)); }
void drawBall(FastVoxelView &vv,Pos3D mp,float s,Color c) { int x,y,z; int x0=mp.x-s; int y0=mp.y-s; int z0=mp.z-s; int x1=mp.x+s; int y1=mp.y+s; int z1=mp.z+s; float x5=-s;//+(int(-s)+s); float y5=-s; float z5=-s; float xd,yd,zd; float s2=s*s; for(x=x0,xd=x5;x<=x1;x++,xd++) for(y=y0,yd=y5;y<=y1;y++,yd++) for(z=z0,zd=z5;z<=z1;z++,zd++) { float diff=sqrt(xd*xd+yd*yd+zd*zd); if(diff<s+3) { float a=s-diff; if(a<0) a=0; c.a=a; if(a>0) vv.set(Pos3D(x,y,z),c); } } }
void MiniMap::update() { // CTRACE; mustUpdate=true; AGSurfacePainter p(mSurface); float zoom=2; float mx,my; Pos2D maxPos=mMap->getMaxPos(); for(int x=0;x<mSurface.width();x++) { for(int y=0;y<mSurface.height();y++) { mx=float(x)/mSurface.width()*maxPos.x; my=float(y)/mSurface.height()*maxPos.y; Pos3D normal=mMap->getNormal(mx,my); float l=normal*Pos3D(1,1,-1).normalized(); l+=3; l*=0.25; if(mMap->getHeight(Pos2D(mx,my))<10) p.putPixel(x,mSurface.height()-1-y,AGColor(0,0,(int)(0xFF*l),MINIMAP_ALPHA)); else p.putPixel(x,mSurface.height()-1-y,AGColor(0,(int)(MINIMAP_GREEN*l),0,MINIMAP_ALPHA)); } } }
bool VoxelView::hasShadow(Pos3D p) { while(isIn(p)) { p=p+Pos3D(-1,1,0); if(mSpace.get(p).a>0) return true; } return false; }
void VoxelView::calcShadow() { return; int x,y; int m; Pos3D p(0,0,0); float light; for(x=-h;x<w;x++) for(y=0;y<w;y++) { m=0; p=Pos3D(x,h-1,y); light=1.0f; for(;m<h+10;m++) { Color c=mSpace.get(p); if(c.a>0) { // if(shadow>0.01f) { // cdebug(p.x<<","<<p.y<<","<<p.z<<":"<<int(shadow)); mSpace.set(p,c.light((-80.0f+80.0f*light)/0xFF)); } // cdebug(shadow); light*=(1.0f-c.a); } p=p+Pos3D(1,-1,0); // mSpace.set(p,Color(1,0,0)); } } }
AGSurface test1() { int w=128; VoxelView v(w,w,Pos3D(0,0,0),false); int x,y,z; int s=0; for(x=s;x<w;x++) for(y=0;y<1;y++) for(z=s;z<w;z++) v.set(Pos3D(x,y,z),Color(0,0,1.0)); s=10; for(x=s;x<w-s;x++) for(y=0;y<1;y++) for(z=s;z<w-s;z++) v.set(Pos3D(x,y+10,z),Color(0,0,1.0)); return v.getSurface(); }
VoxelImage::VoxelImage(const std::string &pFilename): AVItem(Pos3D(0,0,0)) { mTexture=getTextureCache()->get(TILEDIR+pFilename+".png"); // FIXME: Check this Pos2D c=getVoxelID()->getCenter(pFilename); if(c==Pos2D(0,0)) { c=Pos2D(mTexture.width()/2,mTexture.height()-mTexture.width()/4); } setCenter(c);//Pos2D(mTexture.width()/2,mTexture.height()-mTexture.width()/4)+c); }
// moving about bool EditIsoView::eventDragBy(const AGEvent *event,const AGPoint &pDiff) { if(!mEditing) return CompleteIsoView::eventDragBy(event,pDiff); const AGSDLEvent *e=reinterpret_cast<const AGSDLEvent*>(event); if(e) { if(getButtonState()==SDL_BUTTON(SDL_BUTTON_MIDDLE)) { mPos=Pos3D(mPos.x-pDiff.x,mPos.y+pDiff.y,mPos.z); shallUpdate=true; // delay update til drawing - as this may be called several times a frame return true; } } return false; }
void IsoView::initTileCache() { maxPos.x=(mMap->width()/2-4)*TILE_WIDTH-width(); maxPos.y=(mMap->height()-8)*TILE_WIDTH/4-height(); // FIXME: this should be called only once and updates done incrementally // first clear old tile cache std::map<IVTile,AVItem*>::iterator k=mTileCache.begin(); for(;k!=mTileCache.end();k++) delete k->second; mTileCache.clear(); int mw,mh; // goes to max of map mw=mMap->width()/2-3; mh=mMap->height()-6; for(int y=0;y<mh;y++) // 40 { for(int x=0;x<mw;x++) // 13 for 800x600 { int mx=x*(POINTS_PER_TILE); int my=y*(POINTS_PER_TILE/2); if(y&1) mx+=(POINTS_PER_TILE/2); // cdebug("mx:"<<mx<<"//"<<my); SplineMapD h=mMap->getPatchH(mx,my); SplineMapD g=mMap->getPatchG(mx,my); VoxelImage *i=getSurface(h,g); i->setPosition(Pos3D(mx*TILE_WIDTH/POINTS_PER_TILE,0,my*TILE_WIDTH/POINTS_PER_TILE)); IVTile tile; tile.x=mx; tile.y=my; mTileCache[tile]=i; } } }
bool CompleteIsoView::eventDragBy(const AGEvent *event,const AGPoint &pDiff) { const AGSDLEvent *e=reinterpret_cast<const AGSDLEvent*>(event); if(e) { if(getButtonState()==SDL_BUTTON(SDL_BUTTON_RIGHT)) { mPos=Pos3D(mPos.x-pDiff.x,mPos.y+pDiff.y,mPos.z); if(mPos.x<0) mPos.x=0; if(mPos.y<0) mPos.y=0; if(mPos.x>maxPos.x) mPos.x=maxPos.x; if(mPos.y>maxPos.y) mPos.y=maxPos.y; //update();//checkView(); shallUpdate=true; // delay update til drawing - as this may be called several times a frame return true; } } return false; }
Pos3D AntargisMap::getPos3D(const Pos2D &p) const { return Pos3D(p.x,getHeight(p),p.y); }
int main(int argc,char *argv[]) { AGMain main; MyApp app; AntargisView *av=new AntargisView(0,AGRect(0,0,100,100),Pos3D(0,0,0)); int x,y,z; int w=64; int s=0; Terrain t(16,16); AGSurface ms; int test=4; if(argc>1) test=atoi(argv[1]); if(test==1) { ms=test1(); av->insert(new VoxelImage(ms,Pos3D(0,0,0))); } if(test==2) { ms=ball(); av->insert(new VoxelImage(ms,Pos3D(0,0,0))); } else if(test==3) { ms=getTerrain(t.getInfo(2,0)); av->insert(new VoxelImage(ms,Pos3D(0,0,0))); } else if(test==4) { ms=getTerrain(t.getInfo(1,0)); av->insert(new VoxelImage(ms,Pos3D(0,0,0))); ms=getTerrain(t.getInfo(2,0)); av->insert(new VoxelImage(ms,Pos3D(64,0,0))); ms=getTerrain(t.getInfo(1,1)); av->insert(new VoxelImage(ms,Pos3D(32,0,-32))); ms=getTerrain(t.getInfo(2,1)); av->insert(new VoxelImage(ms,Pos3D(64+32,0,-32))); } else if(test==5) { int x,y; for(int x=0;x<4;x++) for(int y=0;y<4;y++) { ms=getTerrain(t.getInfo(x,y)); av->insert(new VoxelImage(ms,Pos3D(x*64+(y%2)*32,0,-y*32))); } } else if(test==6) { SplineMap<float> m(16,16,50); SplineMap<float> gm(16,16,20); int w=64; VoxelView v(w,w*2,Pos3D(0,0,0),true); for(int x=0;x<w;x++) for(int z=0;z<w;z++) { float mx=x/16.0; float mz=z/16.0; float h=m.get(mx,mz); for(int y=0;y<h;y++) { float a=std::min(1.0f,h-y); // cdebug(a); v.set(Pos3D(x,y,z),Color(0xAA,0xAA,0,a)); } // grass above float gh=rand()%int(gm.get(mx,mz)); if(gh>0) for(int y=0;y<gh;y++) { float a=1.0f-(y/gh); // cdebug(a); v.set(Pos3D(x,y+h,z),Color(0,0xAA,0,a)); } } /* // small ball above for(int x=0;x<8;x++) for(int y=0;y<8;y++) for(int z=0;z<8;z++) { int mx=x-4; int my=y-4; int mz=z-4; if(sqrt(mx*mx+my*my+mz*mz)<4) v.set(Pos3D(x+10,y+40,z+20),Color(0xAA,0,0)); } */ av->insert(new VoxelImage(v.getSurface(),Pos3D(0,0,0))); } else if(test==7) { float v0=-20; float v1=60; float v2=60; float v3=-20; float v4=0; float v5=0; float v6=0; int x; SDL_Surface *s=getScreen().surface(); Color c(0,0,1); for(x=0;x<32;x++) { int y=spline2(x/32.0,v0,v1,v2);//,v3); sge_PutPixel(s,x,y+50,c.toColor(s)); } for(x=0;x<32;x++) { int y=spline2(x/32.0,v1,v2,v3);//,v4); sge_PutPixel(s,x+32,y+50,c.toColor(s)); } for(x=0;x<32;x++) { int y=spline2(x/32.0,v2,v3,v4);//,v5); sge_PutPixel(s,x+64,y+50,c.toColor(s)); } for(x=0;x<32;x++) { int y=spline2(x/32.0,v3,v4,v5);//,v6); sge_PutPixel(s,x+96,y+50,c.toColor(s)); } SDL_Flip(s); // SDL_Delay(1000); } else if(test==8) { float v0=-20; float v1=60; float v2=60; float v3=-20; float v4=0; float v5=0; float v6=0; int x; SDL_Surface *s=getScreen().surface(); Color c(1,0,1); for(x=0;x<32;x++) { int y=spline3(x/32.0,v0,v1,v2,v3); sge_PutPixel(s,x,y+50,c.toColor(s)); } for(x=0;x<32;x++) { int y=spline3(x/32.0,v1,v2,v3,v4); sge_PutPixel(s,x+32,y+50,c.toColor(s)); } for(x=0;x<32;x++) { int y=spline3(x/32.0,v2,v3,v4,v5); sge_PutPixel(s,x+64,y+50,c.toColor(s)); } for(x=0;x<32;x++) { int y=spline3(x/32.0,v3,v4,v5,v6); sge_PutPixel(s,x+96,y+50,c.toColor(s)); } SDL_Flip(s); // SDL_Delay(1000); } else if(test==9) { SplineMap<float> m(64,64,50); int w=64; VoxelView v(w,w*2,Pos3D(0,0,0),false); int z=0; for(int x=0;x<w;x++) { float h=20+x/16.0; for(int y=0;y<h;y++) { float a=std::min(1.0f,h-y); // if(a<1) if(a>0) { cdebug(a); v.set(Pos3D(x,y,z),Color(0xFF,0xFF,0xFF,a));//Color(0xAA*a,0xAA*a,0));//,a)); } } } av->insert(new VoxelImage(v.getSurface(),Pos3D(0,0,0))); } else if(test==10) { SDL_Surface *s=getScreen().surface(); for(int x=0;x<100;x++) { float h=20+x/16.0; for(int y=0;y<h;y++) { float a=std::min(1.0f,h-y); if(a>0) { sge_PutPixelAlpha(s,x,100-y,SDL_MapRGBA(s->format,0xFF,0xFF,0xFF,a*0xFF),a*0xFF); } } } SDL_Flip(s); SDL_Delay(1000); } else if(test==11 || test==12) { int w=8; SplineMap<float> m(POINTS_PER_TILE*(w+2),POINTS_PER_TILE*(w+2),40); SplineMap<float> gm(POINTS_PER_TILE*(w+2),POINTS_PER_TILE*(w+2),10); if(test==12) w=2; for(int y=0;y<w;y++) for(int x=0;x<w;x++) { int mx=x*(POINTS_PER_TILE); int my=y*(POINTS_PER_TILE/2); if(y&1) mx+=(POINTS_PER_TILE/2); av->insert(new VoxelImage(makeTerrainTile(m,gm,mx,my),Pos3D(mx*TILE_WIDTH/POINTS_PER_TILE,0,my*TILE_WIDTH/POINTS_PER_TILE))); } } else if(test==13) { AGSurface s=makeWaterTile(); av->insert(new VoxelImage(s,Pos3D(64,0,0))); av->insert(new VoxelImage(s,Pos3D(0,0,0))); av->insert(new VoxelImage(s,Pos3D(64+32,0,32))); av->insert(new VoxelImage(s,Pos3D(32,0,32))); av->insert(new VoxelImage(s,Pos3D(64+32,0,-32))); av->insert(new VoxelImage(s,Pos3D(32,0,-32))); } else if(test==14) { AGSurface s=makeWaterTile(); std::string ms=toPNG(s.surface()); s=fromPNG(ms); av->insert(new VoxelImage(s,Pos3D(64,0,0))); } app.setMainWidget(av); app.run(); }
VoxelImage *makeTerrainTile(const SplineMapD &m,const SplineMapD &gm,int px,int py) //ComplexVoxelImage *makeTerrainTile(const SplineMap<float> &m,const SplineMap<float> &gm,int px,int py) { gDrawingTerrain=true; Uint32 t1=SDL_GetTicks(); int w=TILE_WIDTH; FastVoxelView v(w,w*4,Pos3D(0,0,0),true); if(true) { for(int x=0; x<w; x++) for(int z=0; z<w; z++) // for(int z=w/2-4;z<w/2;z++) { float mx=float(x*POINTS_PER_TILE)/w+px; float mz=float(z*POINTS_PER_TILE)/w+py; // cdebug(mx<<" "<<mz); float h=m.get(mx,mz); for(int y=std::max(0,(int)(h-3)); y<h; y++) { if(y>WATER_HEIGHT) { float a=std::min(1.0f,h-y); int n=rand()%50; v.set(Pos3D(x,y,z),Color(0xAA-n,0xAA-n,0,a)); } } // grass above int mgh=(int)gm.get(mx,mz); if(mgh>0) { float gh=rand()%int(mgh); if(gh>0) for(int y=0; y<gh; y++) { float a=1.0f-(y/gh); int mh=(int)(y+h); // cdebug(a); if(mh>WATER_HEIGHT) v.set(Pos3D(x,mh,z),Color(0,0xAA,0,a)); } } /* if(rand()%60<2) { int w=10; int w2=w/2; float x1=(rand()%w)-w2; float z1=(rand()%w)-w2; float x2=(rand()%w)-w2; float z2=(rand()%w)-w2; float steps=15; // paint a longer leaf for(int i=0;i<steps;i++) { int ax=(int)bezier2(i/steps,float(x),x1+x,x2+x); int az=(int)bezier2(i/steps,float(z),z1+z,z2+z); int ay=(int)bezier2(i/steps,0.0f,steps/4,steps/2); v.set(Pos3D(ax,int(ay+h),az),Color(0,0xAA,0,i/steps)); } } */ } /* for(int x=0;x<8;x++) for(int y=0;y<8;y++) for(int z=0;z<8;z++) { int mx=x-4; int my=y-4; int mz=z-4; if(sqrt(mx*mx+my*my+mz*mz)<4) v.set(Pos3D(x+10,y+40,z+20),Color(0xAA,0,0)); } */ } /** add water **/ srand(0); if(false) // skip water { float a=18; SplineMapD wh((int)a,(int)a,3,1,3,true); for(int x=0; x<w; x++) for(int z=0; z<w; z++) { float mx=x-z+w/2; float mz=x+z-w/2; mx/=w; mz/=w; while(mx>1) mx-=1; while(mx<0) mx+=1; while(mz>1) mz-=1; while(mz<0) mz+=1; float h=wh.get(a*float(mx),a*float(mz))+6; for(int y=0; y<h; y++) { float f=std::min(1.0f,h-y); v.set(Pos3D(x,y,z),Color(0,0,0xAA,f)); } } } /** till here */ Uint32 t2=SDL_GetTicks(); cdebug("TIME:"<<t2-t1); AGSurface s= v.getSurface(); t1=SDL_GetTicks(); cdebug("TIME:"<<t1-t2); // SDL_SaveBMP(s.surface(),"hupe.bmp"); //return new ComplexVoxelImage(Pos3D(0,0,0),s,v.getDepthMap(),v.getShadowMap()); gDrawingTerrain=false; return new VoxelImage(s,Pos3D(0,0,0)); }
Pos3D Pos3D::operator*(float p) const { return Pos3D(x*p,y*p,z*p); }
void drawTree(FastVoxelView &vv,Pos3D base,float h) { Pos3D p1(0,0,0),p2(0,0,0),p3(0,0,0); Color c(0x99,0x69,0); Color bc(0,0xAA,0); p1=base; p2=base+Pos3D(0,1,0)*h*0.25; p3=base+Pos3D(0,1,0)*h*0.5; cdebug(p1<<p2<<p3); Trunk t(p1,p2,p3,7,5); std::list<Trunk> tlist,nlist; tlist.push_back(t); int rw=h/4; float angle=M_PI/1.5; // 30 degrees int last=5; for(int i=0;i<=last;i++) { std::cout<<"_______________"<<std::endl; std::list<Trunk>::iterator k=tlist.begin(); for(;k!=tlist.end();k++) { Pos3D dir=k->p3 - k->p2; int count=4; std::list<Pos3D> l=splitDir(dir,count,angle,M_PI/count/8.0,0);//M_PI/count,angle/3); std::list<Pos3D>::iterator j=l.begin(); for(;j!=l.end();j++) { Pos3D r=*j; r=r*rw; int mi=i+1; // c=Color(mi&1,(mi>>1)&1,(mi>>2)&1); /* drawBall(vv,k->p1,4,c); drawBall(vv,k->p2,3,c); drawBall(vv,k->p3,2,c);*/ draw3Line(vv,k->p1,k->p2,k->p3,c,40,k->w1,k->w2); if(i==last) draw3Line(vv,k->p1,k->p2,k->p2,bc,4,2,1); float start=0.6; start+=getRandEq()*0.3; Pos3D sp=bezier(start, k->p1,k->p2,k->p3); // Pos3D np(k->p3*2-k->p2+Pos3D(rx,ry,rz)); Pos3D np(k->p3*2-k->p2+r); Trunk nt(sp, sp*0.5+np*0.5+getRandPos(rw), np, k->w2,k->w2-1); nlist.push_back(nt); } } rw*=0.9; tlist.clear(); cdebug(nlist.size()); tlist=nlist; nlist.clear(); } // roots std::list<Pos3D> l=splitDir(Pos3D(0,-1,0),4,M_PI/4,0,0); std::list<Pos3D>::iterator j=l.begin(); for(;j!=l.end();j++) { Pos3D n=*j * 10 + base; draw3Line(vv,base,base*0.5+n*0.5,n,c,40,t.w1,t.w2); } }
void IsoView::init() { CTRACE; // screen size int mw=width()/64+2; int mh=height()/16+4; // 800x600 0<=x<13 0<=y<40 // 1400x1024 0<=x<23 0<=y<74 int sx=0; int sy=0; sx=(int)(mPos.x/TILE_WIDTH); if(sx<0) sx=0; sy=(int)(mPos.y/(TILE_WIDTH/4))-4; if(sy<0) sy=0; mh+=4; for(int y=sy;y<mh+sy;y++) // 40 { for(int x=sx;x<mw+sx;x++) // 13 for 800x600 { int mx=x*(POINTS_PER_TILE); int my=y*(POINTS_PER_TILE/2); if(y&1) mx+=(POINTS_PER_TILE/2); AVItem *i; // insert water tile i=getWaterTile(); i->setPosition(Pos3D(mx*TILE_WIDTH/POINTS_PER_TILE,0,my*TILE_WIDTH/POINTS_PER_TILE)); i->setVirtualY(-42); insert(i); // now insert terrain (that it's after water) // cdebug("mx:"<<mx<<"//"<<my); // insert terrain tile SplineMapD h=mMap->getPatchH(mx,my); // insert water tile i=getWaterTile(); i->setPosition(Pos3D(mx*TILE_WIDTH/POINTS_PER_TILE,0,my*TILE_WIDTH/POINTS_PER_TILE)); i->setVirtualY(-42); insert(i); SplineMapD g=mMap->getPatchG(mx,my); IVTile tile; tile.x=mx; tile.y=my; i=mTileCache[tile]; // get AVItem from cache if(i) { i->setVirtualY(-32); insert(i); mTiles[i]=tile; } } } // insert entities std::list<AntEntity*> ents=mMap->getEntities(AntRect(0,0,1000,1000)); // FIXME: use reasonable rect std::list<AntEntity*>::iterator i=ents.begin(); for(;i!=ents.end();i++) { VoxelImage *image=(*i)->getSurface(); mEntities[image]=*i; mEntitiesInv[*i]=image; insert(image); } }
Pos3D Pos3D::operator-(const Pos3D &p) const { return Pos3D(x-p.x,y-p.y,z-p.z); }
Pos3D VoxelView::unwind(Pos3D p) { return Pos3D(p.x,int((h-1)-p.y-p.z/2.0),p.z); }
void VoxelView::calcShadow() { //return; int x,y; int m; Pos3D p(0,0,0); float shadow; for(x=-h;x<w;x++) for(y=0;y<w;y++) { m=0; p=Pos3D(x,h-1,y); shadow=0.0f; for(;m<h+10;m++) { Color c=mSpace.get(p); if(c.a>0) { if(shadow>0.01f) { // cdebug(p.x<<","<<p.y<<","<<p.z<<":"<<int(shadow)); mSpace.set(p,c.light(-80.0f/0xFF*shadow)); } // cdebug(shadow); shadow+=c.a; if(shadow>1.0) shadow=1.0; } p=p+Pos3D(1,-1,0); // mSpace.set(p,Color(1,0,0)); } } return; // top light for(x=0;x<w;x++) for(y=-w;y<w;y++) { m=0; p=Pos3D(x,h-1,y); shadow=0.0f; for(;m<h+10;m++) { Color c=mSpace.get(p); if(c.a>0) { if(shadow>0.01f) { // cdebug(p.x<<","<<p.y<<","<<p.z<<":"<<int(shadow)); mSpace.set(p,c.light(-80.0f/0xFF*shadow)); } // cdebug(shadow); shadow+=c.a; if(shadow>1.0) shadow=1.0; } p=p+Pos3D(0,-1,0); // mSpace.set(p,Color(1,0,0)); } } }
virtual AGWidget *create(AGWidget *pParent,const AGRect &pRect,const xmlpp::Node &pNode) { EditIsoView *w=new EditIsoView(pParent,pRect,Pos3D(0,0,0),getMap()); return w; }
Pos3D Pos3D::operator+(const Pos3D &p) const { return Pos3D(x+p.x,y+p.y,z+p.z); }