Fix getActiveSegmentsNum

Limit rotation to +-90 deg (swapping sin/cos & limit angle)
Shift palette shift
This commit is contained in:
Blaz Kristan 2024-01-22 19:38:13 +01:00
parent 29af62f956
commit 8a31c57bfa

View File

@ -1934,7 +1934,7 @@ uint16_t mode_palette() {
using wideMathType = int64_t; using wideMathType = int64_t;
using angleType = uint16_t; using angleType = uint16_t;
constexpr mathType sInt16Scale = 0x7FFF; constexpr mathType sInt16Scale = 0x7FFF;
constexpr mathType maxAngle = 0xFFFF; constexpr mathType maxAngle = 0x8000;
constexpr mathType staticRotationScale = 256; constexpr mathType staticRotationScale = 256;
constexpr mathType animatedRotationScale = 1; constexpr mathType animatedRotationScale = 1;
constexpr int16_t (*sinFunction)(uint16_t) = &sin16; constexpr int16_t (*sinFunction)(uint16_t) = &sin16;
@ -1944,7 +1944,7 @@ uint16_t mode_palette() {
using wideMathType = float; using wideMathType = float;
using angleType = float; using angleType = float;
constexpr mathType sInt16Scale = 1.0f; constexpr mathType sInt16Scale = 1.0f;
constexpr mathType maxAngle = M_TWOPI / 256.0; constexpr mathType maxAngle = M_PI / 256.0;
constexpr mathType staticRotationScale = 1.0f; constexpr mathType staticRotationScale = 1.0f;
constexpr mathType animatedRotationScale = M_TWOPI / double(0xFFFF); constexpr mathType animatedRotationScale = M_TWOPI / double(0xFFFF);
constexpr float (*sinFunction)(float) = &sin_t; constexpr float (*sinFunction)(float) = &sin_t;
@ -1952,7 +1952,7 @@ uint16_t mode_palette() {
#endif #endif
const bool isMatrix = strip.isMatrix; const bool isMatrix = strip.isMatrix;
const int cols = SEGMENT.virtualWidth(); const int cols = SEGMENT.virtualWidth();
const int rows = isMatrix ? SEGMENT.virtualHeight() : strip.getSegmentsNum(); const int rows = isMatrix ? SEGMENT.virtualHeight() : strip.getActiveSegmentsNum();
const int inputShift = SEGMENT.speed; const int inputShift = SEGMENT.speed;
const int inputSize = SEGMENT.intensity; const int inputSize = SEGMENT.intensity;
@ -1961,7 +1961,7 @@ uint16_t mode_palette() {
const bool inputAnimateRotation = SEGMENT.check2; const bool inputAnimateRotation = SEGMENT.check2;
const bool inputAssumeSquare = SEGMENT.check3; const bool inputAssumeSquare = SEGMENT.check3;
const int paletteOffset = (!inputAnimateShift) ? (inputShift) : (((strip.now * ((inputShift >> 3) +1)) & 0xFFFF) >> 8); const int paletteOffset = (!inputAnimateShift) ? (inputShift-128) : (((strip.now * ((inputShift >> 3) +1)) & 0xFFFF) >> 8);
const angleType theta = (!inputAnimateRotation) ? (inputRotation * maxAngle / staticRotationScale) : (((strip.now * ((inputRotation >> 4) +1)) & 0xFFFF) * animatedRotationScale); const angleType theta = (!inputAnimateRotation) ? (inputRotation * maxAngle / staticRotationScale) : (((strip.now * ((inputRotation >> 4) +1)) & 0xFFFF) * animatedRotationScale);
const mathType sinTheta = sinFunction(theta); const mathType sinTheta = sinFunction(theta);
@ -1975,14 +1975,14 @@ uint16_t mode_palette() {
const mathType maxYOut = !inputAssumeSquare ? maxY : mathType(1); const mathType maxYOut = !inputAssumeSquare ? maxY : mathType(1);
const mathType centerX = sInt16Scale * maxXOut / mathType(2); const mathType centerX = sInt16Scale * maxXOut / mathType(2);
const mathType centerY = sInt16Scale * maxYOut / mathType(2); const mathType centerY = sInt16Scale * maxYOut / mathType(2);
const mathType scale = std::abs(cosTheta) + (std::abs(sinTheta) * maxYOut / maxXOut); const mathType scale = std::abs(sinTheta) + (std::abs(cosTheta) * maxYOut / maxXOut);
const int yFrom = isMatrix ? 0 : strip.getCurrSegmentId(); const int yFrom = isMatrix ? 0 : strip.getCurrSegmentId();
const int yTo = isMatrix ? maxY : yFrom; const int yTo = isMatrix ? maxY : yFrom;
for (int y = yFrom; y <= yTo; ++y) { for (int y = yFrom; y <= yTo; ++y) {
const mathType ytSinTheta = mathType((wideMathType(sinTheta) * wideMathType(y * sInt16Scale - centerY * maxYIn))/wideMathType(maxYIn * scale)); const mathType ytCosTheta = mathType((wideMathType(cosTheta) * wideMathType(y * sInt16Scale - centerY * maxYIn))/wideMathType(maxYIn * scale));
for (int x = 0; x < cols; ++x) { for (int x = 0; x < cols; ++x) {
const mathType xtCosTheta = mathType((wideMathType(cosTheta) * wideMathType(x * sInt16Scale - centerX * maxXIn))/wideMathType(maxXIn * scale)); const mathType xtSinTheta = mathType((wideMathType(sinTheta) * wideMathType(x * sInt16Scale - centerX * maxXIn))/wideMathType(maxXIn * scale));
const mathType sourceX = xtCosTheta + ytSinTheta + centerX; const mathType sourceX = xtSinTheta + ytCosTheta + centerX;
int colorIndex = (std::min(std::max(sourceX, mathType(0)), maxXOut * sInt16Scale) * 255) / (sInt16Scale * maxXOut); int colorIndex = (std::min(std::max(sourceX, mathType(0)), maxXOut * sInt16Scale) * 255) / (sInt16Scale * maxXOut);
if (inputSize <= 128) { if (inputSize <= 128) {
colorIndex = (colorIndex * inputSize) / 128; colorIndex = (colorIndex * inputSize) / 128;
@ -2001,7 +2001,7 @@ uint16_t mode_palette() {
} }
return FRAMETIME; return FRAMETIME;
} }
static const char _data_FX_MODE_PALETTE[] PROGMEM = "Palette@Shift,Size,Rotation,,,Animate Shift,Animate Rotation,Physical Square;;!;12;c1=64,o1=1,o2=1,o3=0"; static const char _data_FX_MODE_PALETTE[] PROGMEM = "Palette@Shift,Size,Rotation,,,Animate Shift,Animate Rotation,Anamorphic;;!;12;c1=128,c2=128,c3=128,o1=1,o2=1,o3=0";
// WLED limitation: Analog Clock overlay will NOT work when Fire2012 is active // WLED limitation: Analog Clock overlay will NOT work when Fire2012 is active