FastLED 3.9.15
Loading...
Searching...
No Matches

◆ transform()

vec2< alpha16 > fl::Transform16::transform ( const vec2< alpha16 > & xy) const

Definition at line 92 of file transform.cpp.

92 {
93 vec2<alpha16> out = xy;
94
95 // 1) Rotate around the 16‑bit center first
96 if (rotation != 0) {
97 constexpr int32_t MID = 0x7FFF; // center of 0…0xFFFF interval
98
99 // bring into signed centered coords
100 int32_t x = int32_t(out.x) - MID;
101 int32_t y = int32_t(out.y) - MID;
102
103 // Q15 cosine & sine
104 int32_t c = cos16(rotation); // [-32768..+32767]
105 int32_t s = sin16(rotation);
106
107 // rotate & truncate
108 int32_t xr = (x * c - y * s) >> 15;
109 int32_t yr = (x * s + y * c) >> 15;
110
111 // shift back into [0…0xFFFF]
112 out.x = alpha16(xr + MID);
113 out.y = alpha16(yr + MID);
114 }
115
116 // 2) Then scale in X/Y (Q16 → map32_to_16)
117 if (scale_x != 0xFFFF) {
118 uint32_t tx = uint32_t(out.x) * scale_x;
119 out.x = map32_to_16(tx);
120 }
121 if (scale_y != 0xFFFF) {
122 uint32_t ty = uint32_t(out.y) * scale_y;
123 out.y = map32_to_16(ty);
124 }
125
126 // 3) Finally translate
127 if (offset_x)
128 out.x = alpha16(out.x + offset_x);
129 if (offset_y)
130 out.y = alpha16(out.y + offset_y);
131
132 return out;
133}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
unsigned int xy(unsigned int x, unsigned int y)
LIB8STATIC int16_t cos16(uint16_t theta)
Fast 16-bit approximation of cos(x).
Definition trig8.h:148
#define sin16
Platform-independent alias of the fast sin implementation.
Definition trig8.h:103
LIB8STATIC_ALWAYS_INLINE uint16_t map32_to_16(uint32_t x)
Definition intmap.h:43
uint16_t alpha16
Definition transform.h:21
alpha16 scale_x
Definition transform.h:42
alpha16 scale_y
Definition transform.h:43
alpha16 rotation
Definition transform.h:46
alpha16 offset_x
Definition transform.h:44
alpha16 offset_y
Definition transform.h:45

References cos16(), map32_to_16(), offset_x, offset_y, rotation, scale_x, scale_y, sin16, fl::vec2< T >::x, x, xy(), fl::vec2< T >::y, and y.

+ Here is the call graph for this function: