Fixed issue with handedness and rotation and move tool

This commit is contained in:
2025-11-18 11:39:12 -05:00
parent d810ce70ea
commit 2259a411a6
4 changed files with 24 additions and 11 deletions

View File

@@ -18,6 +18,7 @@ namespace anm2ed
LAYERS,
NULLS,
SPRITESHEETS,
TEXTURES,
EVENTS,
ANIMATIONS,
ITEMS,

View File

@@ -648,20 +648,32 @@ namespace anm2ed::imgui
: ImGuiMouseCursor_NotAllowed;
ImGui::SetMouseCursor(cursor);
ImGui::SetKeyboardFocusHere();
if (useTool != tool::MOVE) isMoveDragging = false;
switch (useTool)
{
case tool::PAN:
if (isMouseDown || isMouseMiddleDown) pan += mouseDelta;
if (isMouseDown || isMouseMiddleDown) pan += vec2(mouseDelta.x, mouseDelta.y);
break;
case tool::MOVE:
if (!frame) break;
if (isBegin) document.snapshot("Frame Position");
if (isMouseDown) frame->position = mousePos;
if (isBegin)
{
document.snapshot("Frame Position");
if (isMouseClicked)
{
moveOffset = mousePos - frame->position;
isMoveDragging = true;
}
}
if (isMouseDown && isMoveDragging)
{
frame->position = ivec2(mousePos - moveOffset);
}
if (isLeftPressed) frame->position.x -= step;
if (isRightPressed) frame->position.x += step;
if (isUpPressed) frame->position.y -= step;
if (isDownPressed) frame->position.y += step;
if (isMouseReleased) isMoveDragging = false;
if (isEnd) document.change(Document::FRAMES);
if (isDuring)
{
@@ -679,7 +691,7 @@ namespace anm2ed::imgui
if (isBegin) document.snapshot("Frame Scale");
if (isMouseDown)
{
frame->scale += mouseDelta;
frame->scale += vec2(mouseDelta.x, mouseDelta.y);
if (isMod) frame->scale = {frame->scale.x, frame->scale.x};
}
if (isLeftPressed) frame->scale.x -= step;

View File

@@ -18,12 +18,14 @@ namespace anm2ed::imgui
float savedZoom{};
glm::vec2 savedPan{};
int savedOverlayIndex{};
glm::ivec2 mousePos{};
glm::vec2 mousePos{};
glm::vec2 checkerPan{};
glm::vec2 checkerSyncPan{};
float checkerSyncZoom{};
bool isCheckerPanInitialized{};
bool hasPendingZoomPanAdjust{};
bool isMoveDragging{};
glm::vec2 moveOffset{};
std::vector<resource::Texture> renderFrames{};
public:

View File

@@ -11,10 +11,7 @@ namespace anm2ed::util::math
constexpr auto FLOAT_FORMAT_EPSILON = 1e-7f;
constexpr float FLOAT_FORMAT_POW10[] = {1.f, 10.f, 100.f, 1000.f, 10000.f, 100000.f, 1000000.f, 10000000.f};
float round_nearest_multiple(float value, float multiple)
{
return (roundf((value) / (multiple)) * (multiple));
}
float round_nearest_multiple(float value, float multiple) { return (roundf((value) / (multiple)) * (multiple)); }
int float_decimals_needed(float value)
{
@@ -51,12 +48,13 @@ namespace anm2ed::util::math
vec2 scaleSign = glm::sign(scale);
vec2 pivotScaled = pivot * scaleAbsolute;
vec2 sizeScaled = size * scaleAbsolute;
float handedness = (scaleSign.x * scaleSign.y) < 0.0f ? -1.0f : 1.0f;
mat4 model(1.0f);
model = glm::translate(model, vec3(position - pivotScaled, 0.0f));
model = glm::translate(model, vec3(pivotScaled, 0.0f));
model = glm::scale(model, vec3(scaleSign, 1.0f));
model = glm::rotate(model, glm::radians(rotation), vec3(0, 0, 1));
model = glm::rotate(model, glm::radians(rotation) * handedness, vec3(0, 0, 1));
model = glm::translate(model, vec3(-pivotScaled, 0.0f));
model = glm::scale(model, vec3(sizeScaled, 1.0f));
return model;