home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / dreamscape / source / Dreamscape / Headers / abstract / h / transform < prev   
Encoding:
Text File  |  1996-09-22  |  2.7 KB  |  80 lines

  1.  
  2. // abstract.h.transform
  3.  
  4. // Dreamscape - C++ class library for RISC OS
  5. // Copyright (c) 1996 Mark Seaborn <mseaborn@argonet.co.uk>
  6. //
  7. // This library is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU Library General Public
  9. // License as published by the Free Software Foundation; either
  10. // version 2 of the License, or (at your option) any later version.
  11. // See the Dreamscape documentation for more information.
  12.  
  13. #ifndef dreamscape_transform_H
  14. #define dreamscape_transform_H
  15.  
  16. #include "algorithm.h"
  17.  
  18. #include "coords.h"
  19.  
  20. template <class Type, class ScaleType, class System>
  21. class TransformMatrix {
  22. public:
  23.   TransformMatrix(): xx(1), xy(0), yx(0), yy(1) {}
  24.   TransformMatrix(const Coords<Type, System> &c):
  25.     move(c), xx(1), xy(0), yx(0), yy(1) {}
  26.   TransformMatrix(ScaleType scale): xx(scale), xy(0), yx(0), yy(scale) {}
  27.   TransformMatrix(const Coords<Type, System> &c, ScaleType scale):
  28.     move(c), xx(scale), xy(0), yx(0), yy(scale) {}
  29.   TransformMatrix(const TransformMatrix &m):
  30.     move(m.move), xx(m.xx), xy(m.xy), yx(m.yx), yy(m.yy) {}
  31.  
  32.   TransformMatrix &scale(ScaleType scale)
  33.     { xx = yy = scale;
  34.       xy = yx = 0;
  35.       return *this; }
  36.   TransformMatrix &rotate(double o)
  37.     { xx = cos(o); yx = sin(o);
  38.       xy = -sin(o); yy = cos(o);
  39.       return *this; }
  40.   TransformMatrix &scale_rotate(ScaleType scale, double o)
  41.     { xx = cos(o) * scale; yx = sin(o) * scale;
  42.       xy = -sin(o) * scale; yy = cos(o) * scale;
  43.       return *this; }
  44.  
  45.   Coords<Type, System> transform(const Coords<Type, System> &coords) const
  46.     { return Coords<Type, System>((Type) (coords.x * xx + coords.y * xy +
  47.         move.x), (Type) (coords.x * yx + coords.y * yy + move.y)); }
  48.  
  49.   BBox<Type, System> transform(const BBox<Type, System> &bbox) const
  50.     { int i;
  51.       Coords<Type, System> c[4];
  52.       c[0] = bbox.topleft();
  53.       c[1] = bbox.topright();
  54.       c[2] = bbox.bottomleft();
  55.       c[3] = bbox.bottomright();
  56.       for(i=0; i<4; ++i) c[i] = transform(c[i]);
  57.       BBox<Type, System> temp(c[0].x, c[0].y, c[0].x, c[0].y);
  58.       for(i=1; i<4; ++i)
  59.       { temp.min.x = min(temp.min.x, c[i].x);
  60.         temp.min.y = min(temp.min.y, c[i].y);
  61.         temp.max.x = max(temp.max.x, c[i].x);
  62.         temp.max.y = max(temp.max.y, c[i].y); }
  63.       return temp; }
  64.  
  65.   Coords<Type, System> move;
  66.   ScaleType xx, xy, yx, yy;
  67.  
  68.   // Low-level
  69.   void fill_in_os_block(struct os_trfm *block) const
  70.     { ((int *) block)[0] = (int) (xx * (1<<16));
  71.       ((int *) block)[1] = (int) (yx * (1<<16));
  72.       ((int *) block)[2] = (int) (xy * (1<<16));
  73.       ((int *) block)[3] = (int) (yy * (1<<16));
  74.       ((int *) block)[4] = (int) (move.x * (1<<8));
  75.       ((int *) block)[5] = (int) (move.y * (1<<8)); }
  76.  
  77. };
  78.  
  79. #endif
  80.