diff options
Diffstat (limited to 'scale.cpp')
-rw-r--r-- | scale.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scale.cpp b/scale.cpp new file mode 100644 index 0000000..ba0cff0 --- /dev/null +++ b/scale.cpp @@ -0,0 +1,38 @@ +#include "scale.h" + +#include <iostream> + +void updateTransform4x4(const LinearScale<float> &sx, + const LinearScale<float> &sy, + float transform[4][4]) +{ + float fsx = 2.0f * sx.slope(); + float ftx = 2.0f * sx.offset() - 1.0f; + float fsy = 2.0f * sy.slope(); + float fty = 2.0f * sy.offset() - 1.0f; + + // The transform matrix should be this, but we have it transposed + // in memory: + // + // [ sx 0.0f 0.0f tx ] + // [ 0.0f sy 0.0f ty ] + // [ 0.0f 0.0f 0.0f 0.0f ] + // [ 0.0f 0.0f 0.0f 1.0f ] + // + // It is already initialized with 0s and bottom-right 1 + transform[0][0] = fsx; + transform[1][1] = fsy; + transform[3][0] = ftx; + transform[3][1] = fty; +} + +void updateTransform4x4(LinearScale<float> &sx, + LinearScale<float> &sy, + float offsetX, + float offsetY, + float transform[4][4]) +{ + sx.setRange(offsetX, 1.0f - offsetX); + sy.setRange(1.0f - offsetY, offsetY); + updateTransform4x4(sx, sy, transform); +} |