15 {
16
18 if (is_identity()) {
20 }
25 }
28 }
29
32
33 const bool has_rotation = (rotation != 0.0f);
34
35 if (has_rotation) {
39 float x_rotated =
x * cos_theta -
y * sin_theta;
40 float y_rotated =
x * sin_theta +
y * cos_theta;
41 return vec2f(x_rotated, y_rotated);
42 }
44}
45
46Transform16 Transform16::ToBounds(alpha16 max_value)
FL_NO_EXCEPT {
47 Transform16 tx;
48
49
50 alpha16 scale16 = 0;
51 if (max_value) {
52
53 u32 numer = static_cast<u32>(max_value) << 16;
54
55 u32 scale32 = numer / 0xFFFF;
56 scale16 = static_cast<alpha16>(scale32);
57 }
58 tx.scale_x = scale16;
59 tx.scale_y = scale16;
60 tx.offset_x = 0;
61 tx.offset_y = 0;
62 tx.rotation = 0;
63 return tx;
64}
65
66Transform16 Transform16::ToBounds(
const vec2<alpha16> &
min,
68 Transform16 tx;
69
70
71 alpha16 scale16 = 0;
73
74 u32 numer =
static_cast<u32
>(
max.x -
min.x) << 16;
75
76 u32 scale32 = numer / 0xFFFF;
77 scale16 = static_cast<alpha16>(scale32);
78 }
79 tx.scale_x = scale16;
81
82 u32 numer =
static_cast<u32
>(
max.y -
min.y) << 16;
83
84 u32 scale32 = numer / 0xFFFF;
85 scale16 = static_cast<alpha16>(scale32);
86 }
87 tx.scale_y = scale16;
90 tx.rotation = rotation;
91 return tx;
92}
93
94vec2<alpha16> Transform16::transform(
const vec2<alpha16> &
xy)
const FL_NO_EXCEPT {
95 vec2<alpha16> out =
xy;
96
97
98 if (rotation != 0) {
99 constexpr i32 MID = 0x7FFF;
100
101
102 i32
x = i32(out.x) - MID;
103 i32
y = i32(out.y) - MID;
104
105
106 i32 c = cos16(rotation);
107 i32 s = sin16(rotation);
108
109
110 i32 xr = (
x * c -
y * s) >> 15;
111 i32 yr = (
x * s +
y * c) >> 15;
112
113
114 out.x = alpha16(xr + MID);
115 out.y = alpha16(yr + MID);
116 }
117
118
122 }
126 }
127
128
129 if (offset_x)
130 out.x = alpha16(out.x + offset_x);
131 if (offset_y)
132 out.y = alpha16(out.y + offset_y);
133
134 return out;
135}
136
138
142}
143
144bool TransformFloatImpl::is_identity() const
FL_NO_EXCEPT {
146 offset_y == 0.0f && rotation == 0.0f);
147}
148
149Matrix3x3f TransformFloat::compile() const
FL_NO_EXCEPT {
150 Matrix3x3f out;
153 out.m[0][2] = offset_x();
156 out.m[1][2] = offset_y();
157 out.m[2][2] = 1.0f;
158 return out;
159}
160
161}
uint32_t scale_y[NUM_LAYERS]
uint32_t scale_x[NUM_LAYERS]
fl::UISlider scale("Scale", 4,.1, 4,.1)
unsigned int xy(unsigned int x, unsigned int y)
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Memory functions are available in fl:: namespace via fl/stl/cstring.h Using declarations cannot work ...
constexpr T radians(T deg) FL_NO_EXCEPT
u16 map32_to_16(u32 x) FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
float sinf(float value) FL_NO_EXCEPT
float cosf(float value) FL_NO_EXCEPT