home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / documentation / documents / a252spr2 < prev    next >
Internet Message Format  |  1999-04-27  |  6KB

  1. From: jbye@acorn.co.uk (James)
  2. Subject: Re: sprite rotation
  3. Date: 15 Jun 92 10:06:01 GMT
  4.  
  5.  
  6. Under RISC OS 3 there are a couple of new SWI's that allow sprites to be
  7. transformed and subsequently painted.  The entry points for the SWI are as
  8. follows :-
  9.  
  10.  
  11. Transformed sprite SWIs
  12. -----------------------
  13.  
  14.         SWI OS_SpriteOp
  15.         In:     R0 = 55 (SpriteReason_PlotMaskTransformed) (+ 0, 256 or 512)
  16.                 R0 = 56 (SpriteReason_PutSpriteTransformed) (+ 0, 256 or 512)
  17.                 R1 -> sprite area (if R0 > 255)
  18.                 R2 -> sprite name or header (depends on R0)
  19.                 R3 = flag word:
  20.                         bit 0 set => R6 -> destination coords, else matrix
  21.                         bit 1 set => R4 -> source rectangle inside sprite
  22.                         bits 2..31 reserved (must be 0)
  23.                 R4 -> source rectangle coordinate block (if R3 bit 1 set):
  24.                         R4!0,4 = x0, y0 one corner in sprite (pixels)
  25.                         R4!8,12 = x1,y1 second corner in sprite (pixels)
  26.                 R5 = GCOL action (for PutSpriteTransformed)
  27.                           +8 if mask is to be used
  28.                 R6 -> matrix (if R3 bit 0 clear):
  29.                         R6!0,4,8,12,16,20 = matrix (as for Draw module)
  30.                 R6 -> destination coordinate block (if R3 bit 0 set):
  31.                         R6!0,4 = X0,Y0 on screen (1/256th OS unit)
  32.                         R6!8,12 = X1,Y1 on screen (1/256th OS unit)
  33.                         R6!16,20 = X2,Y2 on screen (1/256th OS unit)
  34.                         R6!24,28 = X3,Y3 on screen (1/256th OS unit)
  35.                 R7 -> translation table ( <= 0 => none)
  36.  
  37. The source coordinates are inclusive at the bottom-left, and exclusive at the
  38. top-right.
  39.  
  40. When specifying a destination parallelogram, the source rectangle is mapped
  41. onto the destination as follows:
  42.  
  43.         x0,y0   ->      X0,Y0
  44.         x1,y0   ->      X1,Y1
  45.         x1,y1   ->      X2,Y2
  46.         x0,y1   ->      X3,Y3
  47.  
  48. In future it may be possible to set the destination to an arbitrary
  49. quadrilateral, rather than a parallelogram.  In order to reserve this
  50. possibility, the current version returns a user-intelligible (-ish) error if
  51. the destination is not a parallelogram.
  52.  
  53. For PutSpriteTransformed, the sprite is plotted through its mask only
  54. if (a) it has one, and (b) R5 bit 3 is set.  R5 is ignored for
  55. PlotMaskTransformed.
  56.  
  57. The SWI returns an error if any of R3 bits 2..31 are set, to ensure
  58. that these are left clear by software developers.
  59.  
  60. The SWI covers exactly those pixels on the screen that a call to
  61. Draw_Fill would produce for a rectangle of the same size with the same
  62. transformation matrix, where it is filling to half-way through the boundary.
  63.                                                  
  64. When plotting using a destination parallelogram, the source rectangle must
  65. be entirely within the sprite. For plotting with a matrix, the source rectangle 
  66. will be clipped to the sprite boundaries prior to transformation.
  67.  
  68. If the source rectangle (after clipping, if using a matrix) has no area, i.e.
  69. x0=x1 OR y0=y1 then an error will be generated, as it is not possible to choose
  70. a colour in which to fill the destination.
  71.                                                
  72. Note that the SWI does allow x0>x1 or y0>y1 or both. When plotting with a matrix
  73. there is no difference between x0 and x1 swapped, or y0 and y1 swapped, but when
  74. specifying a destination parallelogram the image will be reflected.
  75.  
  76. Due to the mechanism of the routine the accuracy is not absolute. The SWI
  77. will always cover the same area as a Draw filled path, but not necessarily
  78. with the right source pixel data from the sprite. The worst possible error
  79. (in a fraction of a source pixel) at one end of the plotted area is given by
  80. <destination width or height>/65536.
  81.  
  82. The table beloe gives more information on the maximum errors attainable:    
  83.  
  84.    Destination size                     Worst possible error in source pixels
  85.          5                                              0.0000763
  86.          10                                             0.0001526
  87.          50                                             0.0007629
  88.         100                                             0.0015259
  89.         500                                             0.0076294
  90.        1000                                             0.0152588
  91.        5000                                             0.0762939
  92.       10000                                             0.1525879
  93. [ The largest output possible is 32767 pixels ]
  94. i.e. When plotting a sprite to a destination width of 5000 pixels, the worst
  95. error possible in the position in the source rectangle of the final pixel
  96. plotted is about 1/13 of a source pixel.
  97.  
  98. Note that if these errors (usually too small to notice) must be avoided then
  99. the sprite should be plotted in parts - perhaps by dividing the plotting
  100. into four areas.
  101.  
  102. Errors:
  103.         Attempt to set reserved flags
  104.                 Bits 2 to 31 of R0 must be zero in the current specification
  105.         Source rectangle area zero
  106.                 The area of the source rectangle must be non-zero, so the
  107.                 sprite routines will have some valid colour(s) to plot the
  108.                 output rectangle in. If the area is zero,
  109.                 there would be no valid colour(s) with which to plot the output.
  110.         Source rectangle not inside sprite
  111.                 The source rectangle must be totally inside the sprite
  112.         SpriteExtend can only do linear transformations
  113.                 The current version of the transformation routines can only
  114.                 perform linear transformations, and not any arbitrary
  115.                 rotation.
  116.                                      
  117.  
  118.  
  119. Hope this is of some help.
  120.  
  121. --James
  122.  
  123.  
  124.