User Tools

Site Tools


converting_20graphics_20coordinates

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

converting_20graphics_20coordinates [2018/03/31 13:19]
127.0.0.1 external edit
converting_20graphics_20coordinates [2018/04/13 14:57] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Converting graphics coordinates===== =====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:\\ \\ +//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: 
 + 
 +<code bb4w> ​
         DEF PROCconvertBBCtoGDI(RETURN X%,RETURN Y%)         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         X%=(X%+@vdu%!0)DIV2:​Y%=@vdu%!212-1-(Y%+@vdu%!4)DIV2
         ENDPROC         ENDPROC
  
         DEF PROCconvertGDItoBBC(RETURN X%,RETURN Y%)         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         X%=X%*2-@vdu%!0:​Y%=(@vdu%!212-1-Y%)*2-@vdu%!4
         ENDPROC         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:\\ \\ +</​code>​ 
 + 
 +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: 
 + 
 +<code bb4w>
         MOVE xBBC%,yBBC%         MOVE xBBC%,yBBC%
 +        IF POS REM SDL thread sync (needed in BBCSDL only)
         xGDI% = @vdu.l.x%         xGDI% = @vdu.l.x%
         yGDI% = @vdu.l.y%         yGDI% = @vdu.l.y%
 +</​code>​
 +
 \\  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. \\  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.
converting_20graphics_20coordinates.txt · Last modified: 2018/04/13 14:57 by richardrussell