Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef WAVEPACKET_2D_XFORM_H__
00035 #define WAVEPACKET_2D_XFORM_H__
00036
00037
00038 #include "geometry_2d.h"
00039
00040 #include <math.h>
00041
00042
00043
00044
00045
00046
00047 struct xform_2d_t {
00048 typedef point2d_t<float> point_t;
00049 typedef rect2d_t<float> rect_t;
00050
00051
00052 xform_2d_t(void) throw() { this->setIdentity(); }
00053 void clear(void) throw() { this->setIdentity(); }
00054 void setIdentity(void) throw() {
00055
00056 t00 = t11 = 1.0;
00057 t01 = t10 = 0.0;
00058 dx = dy = 0.0;
00059 }
00060 void setZRotate(IN float phi) throw() {
00061
00062
00063 t00 = t11 = cos(phi);
00064 t01 = -sin(phi);
00065 t10 = -t01;
00066 dx = dy = 0.0;
00067 }
00068 void setTranslate(IN float x, IN float y) throw() {
00069
00070 t00 = t11 = 1.0;
00071 t01 = t10 = 0.0;
00072 dx = x;
00073 dy = y;
00074 }
00075
00076 void scale(IN float r) throw() {
00077
00078 scaleX(r);
00079 scaleY(r);
00080 }
00081
00082 void scaleX(IN float rx) throw() {
00083
00084 t00 *= rx;
00085 t01 *= rx;
00086 dx *= rx;
00087 }
00088
00089 void scaleY(IN float ry) throw() {
00090
00091 t10 *= ry;
00092 t11 *= ry;
00093 dy *= ry;
00094 }
00095
00096 void setToProductOf(IN const xform_2d_t& left,
00097 IN const xform_2d_t& right) throw() {
00098
00099 t00 = left.t00 * right.t00 + left.t01 * right.t10;
00100 t01 = left.t00 * right.t01 + left.t01 * right.t11;
00101 t10 = left.t10 * right.t00 + left.t11 * right.t10;
00102 t11 = left.t10 * right.t01 + left.t11 * right.t11;
00103 dx = left.t00 * right.dx + left.t01 * right.dy + left.dx;
00104 dy = left.t10 * right.dx + left.t11 * right.dy + left.dy;
00105 }
00106
00107 void transformPoint(IN const point_t& in,
00108 OUT point_t& out) const throw() {
00109 out.x = t00 * in.x + t01 * in.y + dx;
00110 out.y = t10 * in.x + t11 * in.y + dy;
00111 }
00112
00113 void transformRect(IN const rect_t& in,
00114 OUT rect_t& out) const throw();
00115
00116 void setToInverseOf(IN const xform_2d_t& T) throw();
00117
00118 void dump(IN const char * title) const throw() {
00119 DPRINTF(" %s (2d transform):", title);
00120 DPRINTF(" [ %5.2f %5.2f %5.2f ]", t00, t01, dx);
00121 DPRINTF(" [ %5.2f %5.2f %5.2f ]", t10, t11, dy);
00122 }
00123
00124
00125 float t00;
00126 float t01;
00127 float t10;
00128 float t11;
00129 float dx;
00130 float dy;
00131 };
00132
00133
00134
00135 inline xform_2d_t::point_t operator *
00136 (IN const xform_2d_t& T, IN const xform_2d_t::point_t& p)
00137 throw()
00138 {
00139 xform_2d_t::point_t q;
00140 T.transformPoint(p, q);
00141 return q;
00142 }
00143
00144
00145
00146 #endif // WAVEPACKET_2D_XFORM_H__
00147