#Draw texture centered rotated scaled

7 messages · Page 1 of 1 (latest)

noble robin
#

Hey is there a "raylib ish" approach to draw centered & scaled texture?
Using this code:

void DrawTextureCenteredEx(Texture texture, Vector2 position, float angle, float scale)
{
  float w=(float)texture.width;
  float h=(float)texture.height;
  Rectangle src = {0,0,w,h};
  Rectangle dst = {position.x, position.y, w*scale, h*scale};
  DrawTexturePro(texture, src, dst, (Vector2){w/2, h/2}, angle, WHITE);
}

the texture is rotating on is own center but in orbit to the destination. I tried to rectify using trigonometry but I guess is there a better way.

the weird thing is that origin offset (displayed) is not a multiple of scale
Negative scale also makes the rotation backward

(green discs are just a reference)

there is the result

sly valley
#

The origin is in destination rect space, thus you'd want to scale it too

noble robin
#

Ok I'll watch that tonight, thank you

#

@sly valley

DrawTexturePro(texture, src, dst, (Vector2){(w*scale)/2.0f, (h*scale)/2.0f}, angle, WHITE);

I can't get it works corrently even with scaling origin

sly valley
#

the origin would just be half the destination width/height

#

no need to scale again