YSRESULT YsClipLineSeg2(YsVec2 &c1,YsVec2 &c2,const YsVec2 &l1,const YsVec2 &l2,const YsVec2 &range1,const YsVec2 &range2) { c1=l1; c2=l2; if(YsClipLineSegByTopSide(c1,c2,YsGreater(range1.y(),range2.y()))==YSOK && YsClipLineSegByBottomSide(c1,c2,YsSmaller(range1.y(),range2.y()))==YSOK && YsClipLineSegByRightSide(c1,c2,YsGreater(range1.x(),range2.x()))==YSOK && YsClipLineSegByLeftSide(c1,c2,YsSmaller(range1.x(),range2.x()))==YSOK) { return YSOK; } else { return YSERR; } }
void YsBoundingBoxMaker2::Add(const YsVec2 &vec) { if(first!=YSTRUE) { min.Set (YsSmaller(min.x(),vec.x()), YsSmaller(min.y(),vec.y())); max.Set (YsGreater(max.x(),vec.x()), YsGreater(max.y(),vec.y())); } else { Begin(vec); } }
int main(int ac,char *av[]) { if(4>ac) { printf("Eg. ysmakebmptile pattern.png 1024 1024 bmp1.png bmp2.png bmp3.png ...\n"); return 1; } const YsString outFn(av[1]); const int allWid=atoi(av[2]); const int allHei=atoi(av[3]); printf("Output File Name : %s\n",outFn.Txt()); printf("Output Width : %d\n",allWid); printf("Output Width : %d\n",allHei); YsBitmap bmp; bmp.PrepareBitmap(allWid,allHei); bmp.Clear(0,0,0,0); int curX=0,curY=0,nextY=0; for(int i=4; i<ac; ++i) { YsBitmap tile; const YsString inFn(av[i]); YsString ext; inFn.GetExtension(ext); ext.Capitalize(); if(0==strcmp(ext,".PNG")) { tile.LoadPng(inFn); } else if(0==strcmp(ext,".BMP")) { tile.LoadBmp(inFn); } nextY=YsGreater(nextY,curY+tile.GetHeight()); if(allWid<curX+tile.GetWidth()) { curX=0; curY=nextY; } bmp.Copy(tile,curX,curY); curX+=tile.GetWidth(); } YsRawPngEncoder encoder; encoder.EncodeToFile(outFn,bmp.GetWidth(),bmp.GetHeight(),8,6,bmp.GetRGBABitmapPointer()); return 0; }
/* virtual */ void FsLazyWindowApplication::Interval(void) { int wid,hei; FsGetWindowSize(wid,hei); int lb,mb,rb,mx,my; auto evt=FsGetMouseEvent(lb,mb,rb,mx,my); if(0!=lb && (mx!=prevMx || my!=prevMy)) { double denom=(double)YsGreater(wid,hei); double dx=2.0*(double)(prevMx-mx)/denom; double dy=2.0*(double)(prevMy-my)/denom; drawEnv.RotateView(dx,dy); } if(evt==FSMOUSEEVENT_LBUTTONDOWN) { drawEnv.SetWindowSize(wid,hei); drawEnv.SetViewportByTwoCorner(0,0,wid,hei); drawEnv.TransformScreenCoordTo3DLine(lastClick[0],lastClick[1],mx,my); lastClick[1]*=80.0; lastClick[1]+=lastClick[0]; cellVtx.clear(); auto itscIdx=ltc.GetIntersectingBlock(lastClick[0],lastClick[1]-lastClick[0]); for(auto i : itscIdx) { YsVec3 min,max; ltc.GetBlockRange(min,max,i); auto cen=(min+max)/2.0; cellVtx.push_back(cen.xf()); cellVtx.push_back(cen.yf()); cellVtx.push_back(cen.zf()); } if(true!=ltc.ClipLine(lastClick[0],lastClick[1],lastClick[0],lastClick[1]-lastClick[0])) { printf("No intersection.\n"); } } prevMx=mx; prevMy=my; auto key=FsInkey(); if(FSKEY_ESC==key) { SetMustTerminate(true); } needRedraw=true; }
/* virtual */ void FsLazyWindowApplication::Interval(void) { int wid,hei; FsGetWindowSize(wid,hei); int lb,mb,rb,mx,my; auto evt=FsGetMouseEvent(lb,mb,rb,mx,my); if(0!=lb && (mx!=prevMx || my!=prevMy)) { double denom=(double)YsGreater(wid,hei); double dx=2.0*(double)(prevMx-mx)/denom; double dy=2.0*(double)(prevMy-my)/denom; drawEnv.RotateView(dx,dy); } if(evt==FSMOUSEEVENT_LBUTTONDOWN) { double x=(double)mx/(double)wid; double y=(double)(hei-my)/(double)hei; x=x*2.0-1.0; y=y*2.0-1.0; lastClick[0].Set(x,y,-1.0); lastClick[1].Set(x,y, 1.0); for(auto &p : lastClick) { drawEnv.GetProjectionMatrix().MulInverse(p,p,1.0); drawEnv.GetViewMatrix().MulInverse(p,p,1.0); } } prevMx=mx; prevMy=my; auto key=FsInkey(); if(FSKEY_ESC==key) { SetMustTerminate(true); } needRedraw=true; }