aboutsummaryrefslogtreecommitdiff
path: root/scale.cpp
blob: ba0cff0f2c6a9c24d2b56c6db21b75cbcb3ffa82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
}