int main(int argc, char **argv) { double x[] = { 0, 1, 3, 5, 7, 10 }; double y[] = { 15, 15, 2, -6, 5, 10 }; double y2[] = { 0, 0, 0, 0, 0, 0 }; float X[7]; float Y[7]; float Y2[7]; float SY; double sy; int sx; int i; mySplineSnd(x, y, 6, 14, 20, y2); for (i = 0; i < 6; i++) { printf("%.14f\n", y2[i]); X[i + 1] = x[i]; Y[i + 1] = y[i]; } printf("\n"); spline2(X, Y, 6, 14, 20, Y2); for (i = 0; i < 6; i++) { printf("%.14f\n", Y2[i + 1]); } printf("\n"); for (sx = -4; sx < 12; ++sx) { splint(X, Y, Y2, 6, sx, &SY); mySplintCube(x, y, y2, 6, sx, &sy); printf("Cubic: %.14f =?= %.14f Linear: ", SY, sy); mySplintLine(x, y, 6, sx, &sy); printf("%.14f\n", sy); } }
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(); }
McoStatus FindBlack::findMinMaxOpt(double *lab, double *Kmin,double *Kmax,double *Kopt) { int32 i,km,kp,c; double *gammutSurfaceManyBlack; double *gammutSurfaceManyBlackL; double x23[2]; double lch[3]; double x11[101]; // find 100 black values double y[101]; double x2n[50]; double y2n[GAM_DIM_K*50]; Boolean start = TRUE; double best_s; double Kmint,Kmaxt; Kmint = -1; Kmaxt = -1; labtolch(lab,lch); km = floor(*Kmin); kp = ceil(*Kmax); if ((lab[1]*lab[1]+lab[2]*lab[2]) <= 1.0) { for (i=0; i<50; i++) x2n[i] = (double)i*2; for (i=km; i<=kp; i++) x11[i] = (double)i/100; c = 1+kp-km; spline2(x1,x2n,neutralmins,GAM_DIM_K,50,y2n); splint2_clip(x1,x2n,neutralmins,y2n,GAM_DIM_K,50,lab[0],x11,c,y); } else { gammutSurfaceManyBlack = (double*)McoLockHandle(_gammutSurfaceManyBlackH); gammutSurfaceManyBlackL = (double*)McoLockHandle(_gammutSurfaceManyBlackLH); x23[0] = lch[2]; x23[1] = lab[0]; for (i=km; i<=kp; i++) x11[i] = (double)i/100; c = 1+kp-km; splint3_s3_clip(x1,x2,gammutSurfaceManyBlackL,gammutSurfaceManyBlack,y2a,GAM_DIM_K,72,50,x23,x11,c,y); McoUnlockHandle(_gammutSurfaceManyBlackH); McoUnlockHandle(_gammutSurfaceManyBlackLH); } best_s = 0; c = 0; for (i=km; i<=kp; i++) { if ((y[c] > 0) && (y[c] + 0.8 > lch[1])) // insert a small tolerence here { if (start) { Kmint = (double)i; start = FALSE; } Kmaxt = (double)i; } if (y[c] > best_s) { best_s = y[c]; *Kopt = (double)i; } c++; } *Kmin = Kmint; *Kmax = Kmaxt; if (*Kmin == -1) *Kmin = *Kopt; if (*Kmax == -1) *Kmax = *Kopt; return MCO_SUCCESS; }