home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / graphics / b109_1 / !3D_Utils / !Help < prev    next >
Text File  |  1994-01-15  |  11KB  |  279 lines

  1. version=1.07
  2.  
  3. The 3D_utils module provides some useful and very fast swi's to draw 3d
  4. graphics in 256 colour modes. It can draw dithered quadrangles 10 to 20 times
  5. as fast as the OS, can take care of rotating vectors, adding perspective and
  6. showing simple 3d objects.
  7.  
  8. Question: Why would you use such a routine
  9. Answer:    - It is much faster as the OS-routines. It is made of optimised
  10.       machine code. I think I can garantee it is at least 2.5x as fast as
  11.       the OS routine for any convex quadrangle. In normal use it will be
  12.       about 10 times as fast.
  13.     - It provides dithering without any speed decrement, thus giving more
  14.       colours. If I remember correctly you have 1704 shades.
  15.     - It is easy to use.
  16.  
  17. Question: Why not to use such a routine
  18. Answer:    - You are restricted to >=256 color modes.
  19.     - It has problems with very large quadrangles (but so has the OS)
  20.     - There may be some bugs
  21.  
  22. It provides the following SWI's:
  23.  
  24. SWI "TD_ScreenAddress",r0
  25.     Sets the screenaddress, which is needed by the module.
  26.     r0=ScreenAddress (of the top-left point)
  27.     The current screenaddress can be asked by:
  28.     DIM p 8:p!0=149:p!4=-1:SYS"OS_ReadVduVariables",p,p:ScreenAd=!p
  29.     Note that the screenaddress changes when scrolling happens
  30.  
  31. SWI "TD_QuadrangleList",r0,r1
  32.     draws a number of quadrangles.
  33.     r0=pointer to first data structure. The structure must be word-aligned
  34.     and looks like this:
  35.         x0,y0,x1,y1,x2,y2,x3,y3,16bit colour
  36.         The origin is on the middle of the screen, x and y are in
  37.         OS-units. The 16bit colour allows you to dither two colours;
  38.         colour=256*colour0+colour1, where colour0,1 is the 'poke-
  39.         colour' which varies from 0 to 255. Each structure takes 36
  40.         bytes of memory. More in the general notes on drawing
  41.         quadrangles.
  42.     r1=number of data structures. Checked to be smaller than 65536.
  43.  
  44. SWI "TD_Rotate",r0,r1,r2,r3,r4
  45.     rotates a number of 3 dimensional integer vectors
  46.     r0=pointer to data to be rotated. The data consist of a number of
  47.         vectors, looking like:x0,y0,z0, x1,y1,z1, x2,y2,z2, etc.
  48.     r1=pointer to place rotated points
  49.     r2=pointer to the rotation matrix. This consist of 9 integers:
  50.         a0,a1,a2,b0,b1,b2,c0,c1,c2
  51.         The new coordinates are calculated as follows:
  52.         x'=a0*x+a1*y+a2*z
  53.         y'=b0*x+b1*y+b2*z
  54.         z'=c0*x+c1*y+c2*z
  55.         Be aware of overflows! Look at the demo for a nice matrix.
  56.     r3=number of points to be rotated. Checked to be smaller than 65536.
  57.     r4=right shift factor
  58.         after calculation, the values for x and y are right shifted by
  59.         this value.
  60.  
  61. SWI "TD_ClrScreen",r0
  62.     Fills the screen with a certain colour.
  63.     r0=16 bit colour
  64.  
  65. SWI "TD_Quadrangle",x0,y0,x1,y1,x2,y2,x3,y3,16b colour
  66.     Draws one quadrangle. Read the general notes on drawing quadrangles.
  67.  
  68. SWI "TD_Point",x,y,8b colour
  69.     Places one point.
  70.  
  71. SWI "TD_Perspective",r0,r1,r2,r3,r4
  72.     Does a simple perspective transformation on 3d integer vectors.
  73.     x'=(x+x0)*(2^r2-z)*2^-r2
  74.     y'=(y+y0)*(2^r2-z)*2^-r2
  75.     z'=z
  76.     r0=pointer to rotated points: array of (x,y,z)
  77.     r1=number of points
  78.     r2=perspective factor (in bits)
  79.     r3=X movement position (x0)
  80.     r4=Y movement position (y0)
  81.     Look at the demo for an example on its use.
  82.  
  83. SWI "TD_DrawSimple",r0,r1,r2
  84.     Displays convex 3-dimensional objects. In no way the polygons are
  85.     sorted. The first in the list is the first to be drawn. Still this
  86.     allows you to draw open or closed convex objects. (Elite uses only
  87.     such objects) Even some closed, concave objects may be drawn by the
  88.     swi, if you sort the polygons in the right way.
  89.     r0=pointer to list of vectors (X, Y, and Z) X and Y are screen
  90.         coordinates, Z is not used. 12 bytes per vector.
  91.     r1=pointer to list of quadrangles. The quadrangles must be flat. Only
  92.         polygons that are positively orientated are drawn. This means
  93.         that each polygon has a front and a back. The back is never
  94.         drawn. The orientation is calculated from points 1,2  and 3.
  95.         data structure:    char reference to point1
  96.                 char reference to point2
  97.                 char reference to point3
  98.                 char reference to point4, or if you want a
  99.                     triangle equal to point3
  100.                 char colour 1
  101.                 char colour 2
  102.                 The case (colour1=254 and colour2<128) is
  103.                 reserved for future use.
  104.         the structure takes up 6 bytes.
  105.     r2=number of quadrangles to be drawn
  106.  
  107. SWI "TD_CurrentScreen"
  108.     Sets the screenaddress to the currently displayed screen.
  109.  
  110. SWI "TD_GetInfo" TO R0
  111.     Gives some info about the module
  112.     r0=pointer to infoblock:
  113.         struct infoblock {
  114.         ( 0) int version*100
  115.         ( 4) int screenmode
  116.         ( 8) int arm optimisation
  117.         (12) int offset               /*screen offset */
  118.         (16) int x0,y0,x1,y1          /*original working window in
  119.                         pixels*/
  120.         (32) int screensize           /*in bytes*/
  121.         (36) int X os units/pixel, Y os units/pixel
  122.         (44) int count                /*number of quadrangles drawn
  123.                                         since startup*/
  124.         (48) void *debug              /*pointer to debug field*/
  125.         (52) int flags                /*bit field of flags 0 is false,
  126.                                         1 is true.
  127.                              bit 0:a test for convexivity
  128.                                    is done.
  129.                              bit 1:this module is a special
  130.                                    hack. It may behave un-
  131.                                    defined. */
  132.         (56) int swicount             /*number of times a SWI was
  133.                                         invoked*/
  134.         (60) int colourbits           /*bits per pixel: 1,2,4,8 or 16*/
  135.              }
  136.  
  137. SWI "TD_PointList",R0,R1
  138.     Plots a number of points
  139.     r0=pointer to first data structure. The structures must be word-
  140.     aligned and looks like this: struct pointlist {int x,int y,int color}.
  141.     The color is an 8 bit value.
  142.     r1=number of structures, checked to be smaller than 524288.
  143.  
  144. SWI "TD_RGBto16bit",R0,R1,R2 TO R0
  145.     converts RGB values to a 16 bit number which can be used by this
  146.     module. If you use another palette than the default, or you don't
  147.     like the colour the swi gives, feel free to change it yourself.
  148.     R0=red value, in the range 0 to 255
  149.     R1=green value, in the range 0 to 255
  150.     R2=blue value, in the range 0 to 255
  151.     R0 on exit=16 bit colour. It is (in this version) not garanteed that
  152.         this is the best fitting colour in the palette.
  153.  
  154. SWI "TD_Decompress",R0,R1
  155.     decompresses a piece of memory which was compressed with TD_Compress
  156.     (does not exists [yet]) Be careful with its use.
  157.     R0=pointer to place decompressed data
  158.     R1=pointer to read compressed data
  159.  
  160. SWI "TD_DrawSorted",R0,R1,R2,R3
  161.     As TD_DrawSimple, but now the polygons are sorted according to its
  162.     distance in the Z-direction. Although this will draw more objects
  163.     correctly than TD_DrawSimple, this is still not enough to draw complex
  164.     objects.
  165.     R3=0 (reserved)
  166.  
  167. SWI "TD_SetWindow",R0,R1,R2,R3 TO R0,R1,R2,R3
  168.     Sets the graphic window for TD_Point and TD_Line. The values are not
  169.     checked to fit the screen; this is your responsibility.
  170.     R0=X of point left-under
  171.     R1=Y of point left-under
  172.     R2=X of point top-right
  173.     R3=Y of point top-right
  174.     If you set one or more of the coordinates larger than 65535, that
  175.     coordinate will not change.
  176.     On exit, R0 to R3 will contain the current value of the corresponding
  177.     window coordinate.
  178.  
  179. SWI "TD_Line",R0,R1,R2,R3,R4
  180.     Draws a line
  181.     R0,R1,R2,R3 coordinates
  182.     R4 colour of the line (8 bit)
  183.  
  184. SWI "TD_LineList",R0,R1
  185.     R0=pointer to line structure: struct linelist {
  186.     int x0,int y0,int x1,int y1,int colour}.
  187.     R1=number of structures, checked to be smaller than 524288.
  188.  
  189. Look at the demo program for examples on their use.
  190.  
  191. All pointers are checked to be larger than &8000.
  192.  
  193. --- DRAWING QUADRANGLES ---
  194. Quadrangles need not to be convex. You may give coordinates in a random order.
  195. Note however that you can compile a module that does not check the
  196. order/convexivity of the coordinates, in order to get a faster routine.
  197. Drawing concave quadrangles will go slower than convex ones as the quadrangle
  198. will be split in two triangles. Of the 16 bit colour you should leave the
  199. top 16 bits set to 0, because these are reserved for future expansions. (Did
  200. I say spritemapping?) There is a swi for calculating 16 bit colour; use it, so
  201. it will be compatible with 16 bit true colour screen modes and different
  202. palettes. You can also draw triangles by taking two points the same.
  203. By default take the third and the fourth the same, but you are free to choose
  204. otherwise.
  205.  
  206. Restrictions on drawing quadrangles by default compiling options:
  207. 1)  X-coordinates must be smaller than 32768 pixels, otherwise you get strange
  208.     effects. (I think the x-coordinates are cyclic)
  209. 2)  The height of the quadrangles should be smaller than 1,024 pixels,
  210.     otherwise quadrangles may be drawn inaccurate or not be drawn at all.
  211.  
  212. In normal use, you will never encounter these restrictions. Also if you would
  213. use (heaven forbid) the OS-routines, you will have worse restrictions.
  214.  
  215. --- DRAWING LINES ---
  216. The quadrangle routine will also draw lines; By default, take the last three
  217. points the same, but you are free to do otherwise. However, the quadrangle
  218. routine has no dedicated line drawing code, so it will be rather slow. (It
  219. will still beat the hell out of the OS routines). The lines will be fairly
  220. good, but not perfect.
  221.  
  222. --- COMPILING THE MODULE ---
  223. To compile a module, load the file '<3D_Utils$Dir>.MakeModule' to a BASIC
  224. editor and change the variables in the first few lines to get the desired
  225. options. The quadrangle module may be compiled for most 256 colour
  226. screenmodes, including mode 10 (Set b16=TRUE). You may compile the module for
  227. all other modes with 2,4 and 16 colours, but the colours will be messed up,
  228. and the outlines are still drawn with an accuracy of one byte (that is 8
  229. pixels in mode 0). It can be compiled to work in a fixed graphics window.
  230. Optimizing can be either for the arm2 and arm3 processor. The origin is by
  231. default the middle of screen. Coordinates are in OS-units. For specific
  232. requirements (arm 700?, mode 32, etc) you can ask me. The program can be
  233. easily adapted for 16 and 32 bit colour modes, the code is already written,
  234. but never tested.
  235.  
  236. --- BUGS ---
  237. :-(  outlines may be drawn slightly wrong if dx/dy does not change sign over a
  238.      corner. You will probably never notice this.
  239.  
  240. --- THINGIES ---
  241. For use in C there is the file 'h.3D_Utils', for use in basic there is the
  242. file 'DefVars' which defines variables with the swi numbers. You can use it to
  243. get much faster access (20 x) to the SWI's.
  244.  
  245. The module automatically checks if any virus has attached itself to the module
  246. on startup. If it finds any, the module will warn you, but start up anyway. I
  247. never checked if it really works, cause I don't have virusses and want to keep
  248. it that way.
  249.  
  250. Most of the routines were written in 1991 on an arm2 A3000. The module and
  251. improvements were written on an 2 MB arm3 based A3000 with RO3.10 and should
  252. work on all systems.
  253.  
  254. --- CREDITS ---
  255.  - Steven de Rooy for his fast division routine.
  256.    <not used yet>
  257.  
  258. --- PLANNED ---
  259.  - Set window, at least in Y direction
  260.  - Draw complex (concave) objects
  261.  - Draw convex/concave polygons          ?
  262.  - Spritemapping                        ??
  263.  
  264. COPYRIGHT NOTICE:you are free to distribute and use this software for private
  265. use, shareware programs and public domain software. If you want to use it in
  266. commercial software you need permission from me, which I will give for some
  267. amount of money (say £150). On every distribution this copyright notice must
  268. be included.
  269.  
  270. If you distribute this module in pd-software, I would like to know.
  271.  
  272. Now go write some games/demos !
  273.  
  274. Michel Grimminck
  275. Email:grimmink@phys.uva.nl
  276. Westerstraat 155²
  277. 1015 MA  Amsterdam
  278. The Netherlands
  279.