[Solved] Rotating subregion of image

univrsal

Active Member
Hey there,

so far I've been getting away with trail and error when it came to finding out how the graphics api of obs works but I now need some help or at least a hint on how to do the following thing:
My plugin loads an image file, then selects a subregion of that file and draws it inside the source at different locations.
I'm currently doing it this way:
Code:
/* m_image is a gs_image_file_t* inside the source */

/* This is called in the render method of my source */
gs_effect_set_texture(gs_effect_get_param_by_name(effect, "image"), m_image->texture);
gs_matrix_push();
// Moves the subregion to the position that I want it to be
gs_matrix_translate3f((float)x, (float)y, 1.f);
// key is a struct that contains information about what subregion and where to place it in the source
gs_draw_sprite_subregion(m_image->texture, 0, key->texture_u, key->texture_v + key->h + 3, key->w + 1, key->h + 1);
gs_matrix_pop();
So for rotation I'd go with gs_matrix_rotaa4f(...), but it only rotates around the top left corner and therefore makes it impossible for me to rotate it around the center of a subregion and then move it to the location I want it to be.
Here's what's happening:
hdlodc.gif
Here's what I'd like to do:
xkinvs.png
So I'd need a way to get a subregion from the image then rotate it around the red dot and finally move the rotated part to a certain offset (not necessarily in that order).
If anyone can help me with that I'd gladly appreciate it since I don't have that much experience with this kind of stuff.

Thanks in advance!
 

univrsal

Active Member
Okay, so since no one answered (either because I badly explained it or no one knew an answer) I kept fiddling and got away with trail and error again.
Here's what I used:
Code:
        gs_matrix_translate3f(x + (key->w / 2.f),  y + (key->h / 2.f), 1.f); // Put it in position
        gs_matrix_translate3f((float)-(key->w / 2), (float)-(key->h / 2), 1.f); // Needed for rotation
        gs_matrix_rotaa4f(0.f, 0.f, 1.f, angle);
        gs_matrix_translate3f((float)-(key->w / 2), (float)-(key->h / 2), 1.f); // Needed for rotation
        gs_draw_sprite_subregion(m_image->texture, 0, key->texture_u, key->texture_v, key->w + 1, key->h + 1);
 
Top