home *** CD-ROM | disk | FTP | other *** search
-
- // abstract.h.transform
-
- // Dreamscape - C++ class library for RISC OS
- // Copyright (c) 1996 Mark Seaborn <mseaborn@argonet.co.uk>
- //
- // This library is free software; you can redistribute it and/or
- // modify it under the terms of the GNU Library General Public
- // License as published by the Free Software Foundation; either
- // version 2 of the License, or (at your option) any later version.
- // See the Dreamscape documentation for more information.
-
- #ifndef dreamscape_transform_H
- #define dreamscape_transform_H
-
- #include "algorithm.h"
-
- #include "coords.h"
-
- template <class Type, class ScaleType, class System>
- class TransformMatrix {
- public:
- TransformMatrix(): xx(1), xy(0), yx(0), yy(1) {}
- TransformMatrix(const Coords<Type, System> &c):
- move(c), xx(1), xy(0), yx(0), yy(1) {}
- TransformMatrix(ScaleType scale): xx(scale), xy(0), yx(0), yy(scale) {}
- TransformMatrix(const Coords<Type, System> &c, ScaleType scale):
- move(c), xx(scale), xy(0), yx(0), yy(scale) {}
- TransformMatrix(const TransformMatrix &m):
- move(m.move), xx(m.xx), xy(m.xy), yx(m.yx), yy(m.yy) {}
-
- TransformMatrix &scale(ScaleType scale)
- { xx = yy = scale;
- xy = yx = 0;
- return *this; }
- TransformMatrix &rotate(double o)
- { xx = cos(o); yx = sin(o);
- xy = -sin(o); yy = cos(o);
- return *this; }
- TransformMatrix &scale_rotate(ScaleType scale, double o)
- { xx = cos(o) * scale; yx = sin(o) * scale;
- xy = -sin(o) * scale; yy = cos(o) * scale;
- return *this; }
-
- Coords<Type, System> transform(const Coords<Type, System> &coords) const
- { return Coords<Type, System>((Type) (coords.x * xx + coords.y * xy +
- move.x), (Type) (coords.x * yx + coords.y * yy + move.y)); }
-
- BBox<Type, System> transform(const BBox<Type, System> &bbox) const
- { int i;
- Coords<Type, System> c[4];
- c[0] = bbox.topleft();
- c[1] = bbox.topright();
- c[2] = bbox.bottomleft();
- c[3] = bbox.bottomright();
- for(i=0; i<4; ++i) c[i] = transform(c[i]);
- BBox<Type, System> temp(c[0].x, c[0].y, c[0].x, c[0].y);
- for(i=1; i<4; ++i)
- { temp.min.x = min(temp.min.x, c[i].x);
- temp.min.y = min(temp.min.y, c[i].y);
- temp.max.x = max(temp.max.x, c[i].x);
- temp.max.y = max(temp.max.y, c[i].y); }
- return temp; }
-
- Coords<Type, System> move;
- ScaleType xx, xy, yx, yy;
-
- // Low-level
- void fill_in_os_block(struct os_trfm *block) const
- { ((int *) block)[0] = (int) (xx * (1<<16));
- ((int *) block)[1] = (int) (yx * (1<<16));
- ((int *) block)[2] = (int) (xy * (1<<16));
- ((int *) block)[3] = (int) (yy * (1<<16));
- ((int *) block)[4] = (int) (move.x * (1<<8));
- ((int *) block)[5] = (int) (move.y * (1<<8)); }
-
- };
-
- #endif
-