TLDR: I need help rotating a hitbox Rectangle ‘dest’ around its Vector2 origin (bottom-left) using mouse position, possibly with rlgl functionality, hereby also rotating the weapon texture on top of it.
I’ve been working on a new weapon swing mechanic in my project and by referring to the moving eyes example on the Raylib site, have come up with a weapon that swings around my player. The rectangle ‘dest’ sits on top of a small invisible circle which follows the mouse as it rotates within a larger invisible circle around my player, representing his arm swing length if you will, so a portion of my code is similar to that Raylib example. I’m pretty happy with this and it looks good - however, the rectangle ‘dest’ itself does not rotate, so at the moment the sword texture faces the same direction regardless of rotation, with sword hilt at the bottom left and blade tip at the top right.
~ ‘dest’ in black, with a white line protruding from ‘origin’ towards the centre of the invisible circle
I want to rotate this of course to follow and face the mouse while the circle it sits on also follows the mouse, but changing the float ‘rotation’ will no longer achieve the desired result, instead the texture will rotate away from the whole shape. This is simply due to how it’s all built up, so rotating the texture itself won’t work. My reasoning is that if I can rotate the rectangle ‘dest’, around it’s new bottom-left origin, then the texture sitting on top of it will also rotate.
I’ve done some online searching into rlgl functionality which I read is required to rotate shapes around it’s origin but unfortunately I’ve hit a brick wall and can freely admit I have no idea how the rlgl functions work. (https://www.reddit.com/r/raylib/comments/mgjgbl/how_do_you_rotate_a_shape_around_its_origin_in/)
My results on attempting to use rlPushMatrix() followed by rlTranslate(), rlRotate() and then rlPopMatrix() have been the following:
- No rotation whatsoever.
- The entire map texture rotating instead of the Rectangle ‘dest’.
- Minimal, barely noticeable rotation/movement of other line shapes that are not the Rectangle ‘dest’.
So my rlgl code is just greened out until I can get it to work.
I need some direction. I notice some apparent solutions for DrawPoly() in this example https://github.com/raysan5/raylib/issues/2251 but I don’t see a Rectangle equivalent for shapes that aren’t filled with colour. I thought about opting for drawing a lined polygon for the ‘dest’ Rectangle but I don’t know how to put a texture on top of that with DrawTexturePro() when that function expects two Rectangles.
Do I have to make a new function? Or is there a simple solution out there that I just haven’t learned yet? Any help would be appreciated.