=====Converting graphics coordinates===== //by Richard Russell, January 2007//\\ \\ If your program outputs its graphics using only BBC BASIC graphics statements then all the coordinates need to be supplied in BBC BASIC units, that is (0,0) is at the bottom left-hand corner of the graphics viewport and each pixel corresponds to //two// graphics units. Positive X is to the right and positive Y is upwards, as is conventional for graphs.\\ \\ If your program outputs its graphics using only Windows API (GDI) functions then all the coordinates need to be supplied in Windows units, that is (0,0) is at the top left-hand corner of your window's **client area** and each pixel corresponds to to one unit. Positive X is to the right and positive Y is //downwards//.\\ \\ If you mix BBC BASIC graphics statements with Windows API functions then you will need to convert between these coordinate systems. The procedures below perform the conversion taking into account the current window size and graphics origin: DEF PROCconvertBBCtoGDI(RETURN X%,RETURN Y%) IF POS REM SDL thread sync (needed in BBCSDL only) X%=(X%+@vdu%!0)DIV2:Y%=@vdu%!212-1-(Y%+@vdu%!4)DIV2 ENDPROC DEF PROCconvertGDItoBBC(RETURN X%,RETURN Y%) IF POS REM SDL thread sync (needed in BBCSDL only) X%=X%*2-@vdu%!0:Y%=(@vdu%!212-1-Y%)*2-@vdu%!4 ENDPROC For consistent results you should ensure that the BBC BASIC graphics coordinates (and the ORIGIN coordinates) are //even// numbers.\\ \\ An alternative approach to converting BBC BASIC units to Windows units, if you don't mind moving the current 'graphics position', is as follows: MOVE xBBC%,yBBC% IF POS REM SDL thread sync (needed in BBCSDL only) xGDI% = @vdu.l.x% yGDI% = @vdu.l.y% \\ Note that these routines are appropriate for use with GDI functions which take integer (pixel) coordinates. They should not be used with **GDI Plus** antialiased graphics, which can take non-integer coordinates. The [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#gdiplib|GDIPLIB library]] contains its own conversion routine from BBC BASIC coordinates to Windows coordinates.