From 0fb517f282c81d5410a0a8502d03aaab23469043 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 26 Jun 2026 17:43:45 +0200 Subject: [PATCH] position fixed finally --- src/button.h | 6 +++--- src/vmath.h | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/button.h b/src/button.h index 86f9204..dde5db0 100644 --- a/src/button.h +++ b/src/button.h @@ -14,9 +14,9 @@ inline bool ViButton(Vec2Df mp, float x, float y, float radius, Color color){ inline bool ViTexButton(Vec2Df mp, Vec2Df position, float rotation, float radius, Texture2D tex, Color color){ float scale = (radius*2.0f) / (float)tex.width; - Vec2Df center_pos = (position + Vec2Df((tex.width*scale) / 2.0f, 0.0f)).orbitAtAngle(radius, -rotation*DEG2RAD); //- Vec2Df(0, (tex.width*scale) / 2.0f).rotate(rotation); - DrawTextureEx(tex, center_pos, rotation, scale, color); - + Vec2Df start_position = position - Vec2Df((tex.width*scale) / 2.0f, (tex.height*scale) / 2.0f); + Vec2Df center_pos = start_position.rotateAround(position, rotation); + DrawTexturePro(tex, Rectangle(0.0, 0.0, tex.width, tex.height), Rectangle(center_pos.x, center_pos.y, tex.width*scale, tex.height*scale), Vec2Df(0,tex.height*scale/2.0f), rotation, color); return (Vector2Distance(mp, position) < radius && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)); } diff --git a/src/vmath.h b/src/vmath.h index ffabb80..e0adc42 100644 --- a/src/vmath.h +++ b/src/vmath.h @@ -60,6 +60,10 @@ namespace VISEQ::VMATH{ Vec2D rotate(float deg){ return Vec2D(cos(deg*DEG2RAD) * x, sin(deg*DEG2RAD) * y); }; + + Vec2D rotateAround(Vec2D v, float deg){ + return Vec2D(cos(deg*DEG2RAD) * (x - v.x), sin(deg*DEG2RAD) * (y-v.y)) + v; + }; Vec2D norm() { return *this / length();};