|
Post by tsh73 on Jun 8, 2018 3:16:32 GMT -5
It is known pie/piefilled bug that sides of sector drawn doesn't match with lines, calculated with R cos(a) .. R sin(a) formulas. But thing that this happens inconsistently - likely depending from starting position - is I believe new report. (it posed a problem then someone tried to create packman sprite - since sectors doesn't match, packman grew black teeth) open "pie bug" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down" pi = acs(-1) deg = pi/180 nomainwin
randomize .5
N=7 a=30 for i = 0 to 3 'x=10+rnd(0)*200 'y=50+rnd(0)*200 x=30+(i mod 2)*150 y=80+int(i/2)*150 #gr "place ";x;" ";y #gr "pie 200 200 ";0-a;" ";2*a #gr "line ";x;" ";y;" ";x+120*cos(a*deg);" ";y+120*sin(a*deg) #gr "line ";x;" ";y;" ";x+120*cos(0-a*deg);" ";y+120*sin(0-a*deg) next
#gr "flush" wait
[quit] close #gr end
|
|
|
Post by Carl Gundel on Jun 11, 2018 8:43:20 GMT -5
It is known pie/piefilled bug that sides of sector drawn doesn't match with lines, calculated with R cos(a) .. R sin(a) formulas. But thing that this happens inconsistently - likely depending from starting position - is I believe new report. (it posed a problem then someone tried to create packman sprite - since sectors doesn't match, packman grew black teeth)
You inspired me to go and look at the code, which is more or less calling the Windows API directly to draw the pies. At first glance I don't see any way to fix this, but perhaps I will find some cycles later to try it again.
|
|
|
Post by tsh73 on Jun 12, 2018 3:45:44 GMT -5
well, I don't exactly know but it looks like windows api looks like Declare Function Pie Lib "gdi32.dll" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long (from for example www.ssucet.org/~jgallaher/download/etec481/VbApiGuide.pdfpie function) So. Since center is always OK, then first four numbers is OK Problem is with x3 y3 x4 y4 Probably it uses too small a radius then calculating ray endpoint or it gets rounded wrong.
|
|
|
Post by Rod on Mar 11, 2019 6:10:10 GMT -5
I was playing with this trying to build on Anatoly's thoughts, are we using the pie API? don't want to waste too much time on that API if its not in use. You may have it covered.
nomainwin BackgroundColor$="darkgray" WindowWidth=550 WindowHeight=550 graphicbox #1.g, 5,5,500,500 open "PIE GDI" for window_nf as #1 #1 "trapclose [quit]" #1.g "down;size 1 ; color red ; backcolor blue" #1.g "line 0 250 500 250" #1.g "line 250 0 250 500 ; color green" #1.g "place 250 250 ; piefilled 250 250 90 90" 'origin should be x=250 y=250 actually drawn at x=249 y=249 error -1 -1 'start should be x=250 y=375 actually drawn at x=246 y=376 error -4 +1 'end should be x=125 y=250 actually drawn at x=246 y=125 error -4 0
h=hwnd(#1.g) 'gbox handle calldll #user32, "GetDC", h as ulong, hDC as ulong
Calldll #gdi32, "Rectangle",_ hDC as ulong,_ 'handle of device context 100 as long,_ 'upper left x origin 100 as long,_ 'upper left y origin 200 as long,_ 'lower right x extent point 200 as long,_ 'lower right y extent point result as ulong 'nonzero if successful
CallDll #gdi32, "Pie",_ hDC as ulong,_ 'device context 10 as long,_ 'upper left x origin 20 as long,_ 'upper left y origin 210 as long,_ 'lower right x extent point 120 as long,_ 'lower right y extent point 210 as long,_ 'start arc here X 70 as long, _ 'start arc here Y 110 as long,_ 'end arc here X 20 as long,_ 'end arc here Y result as ulong 'nonzero if successful
wait
[quit] calldll #user32, "ReleaseDC",_ h as ulong,_ hDC as ulong,_ re as long
close #1 end
|
|
|
Post by Rod on Mar 12, 2019 3:43:09 GMT -5
Or, is the AngleArc function which looks to use the parameters we normally provide to the pie drawing command
BOOL AngleArc( HDC hdc, int x, int y, DWORD r, FLOAT StartAngle, FLOAT SweepAngle );
|
|
|
Post by danteel on Mar 15, 2019 19:22:05 GMT -5
I know its not Liberty BASIC code, but heres what I use in C to do Pie and PieFilled operations if its any help
double d2r(double degrees){ return 0.017453*degrees; }
void __declspec(dllexport) _stdcall cmd_pie(HWND hwnd,int x,int y,int x2,int y2,int a1,int a2){ GFXSTRUCT* gfx=(GFXSTRUCT*)GetWindowLongPtr(hwnd,GWLP_USERDATA); if (gfx){ double w=x2-x; double h=y2-y; double centerX=w/2+x; double centerY=h/2+y; double rx1=cos(d2r(a1))*w/2+centerX; double ry1=sin(d2r(a1))*h/2+centerY; double rx2=cos(d2r(a2))*w/2+centerX; double ry2=sin(d2r(a2))*h/2+centerY; SetBkMode(gfx->scrollDC,TRANSPARENT); Arc(gfx->scrollDC,x,y,x2,y2,rx1,ry1,rx2,ry2); MoveToEx(gfx->scrollDC,centerX,centerY,NULL); LineTo(gfx->scrollDC,rx1,ry1); MoveToEx(gfx->scrollDC,centerX,centerY,NULL); LineTo(gfx->scrollDC,rx2,ry2); } }
void __declspec(dllexport) _stdcall cmd_pieFilled(HWND hwnd,int x,int y,int x2,int y2,int a1,int a2){ GFXSTRUCT* gfx=(GFXSTRUCT*)GetWindowLongPtr(hwnd,GWLP_USERDATA); if (gfx){ double w=x2-x; double h=y2-y; double centerX=w/2+x; double centerY=h/2+y; double rx1=cos(d2r(a1))*w/2+centerX; double ry1=sin(d2r(a1))*h/2+centerY; double rx2=cos(d2r(a2))*w/2+centerX; double ry2=sin(d2r(a2))*h/2+centerY; SetBkMode(gfx->scrollDC,TRANSPARENT); Pie(gfx->scrollDC,x,y,x2,y2,rx1,ry1,rx2,ry2); } }
|
|