Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Surface::blit(Surface *src, int x, int y, float rotation, float sx, float sy, int ox, int oy, bool smooth) {
- SDL_Surface *temp;
- temp = rotozoomSurfaceXY(
- src->getSDL_Surface(),
- rotation,
- sx, sy,
- smooth ? SMOOTHING_ON : SMOOTHING_OFF
- );
- assert(temp);
- float w_no_rot = src->getWidth() * sx;
- float h_no_rot = src->getHeight() * sy;
- float cos_rot = cos(math::DEG_RAD_R * rotation);
- float sin_rot = sin(math::DEG_RAD_R * rotation);
- Vector2D v1(w_no_rot, -h_no_rot);
- Vector2D v2(w_no_rot, 0);
- v1.rotate(math::DEG_RAD_R * rotation);
- v2.rotate(math::DEG_RAD_R * rotation);
- int fx, fy;
- fx = x - ox * sx;
- fy = y - oy * sy;
- //fx = x;
- //fy = y;
- rotation = fmod(rotation, 360.0f);
- if (rotation >= 0 && rotation < 90) {
- fy -= v2.getY();
- }
- else
- if (rotation >= 90 && rotation < 180) {
- fx += v2.getX();
- fy -= v1.getY();
- }
- else
- if (rotation >= 180 && rotation < 270) {
- fx += v1.getX();
- fy += h_no_rot * cos_rot;
- }
- else {
- fx += h_no_rot * sin_rot;
- }
- SDL_Rect dest_rect = {Sint16(fx), Sint16(fy), Uint16(temp->w), Uint16(temp->h)};
- SDL_BlitSurface(temp, 0, getSDL_Surface(), &dest_rect);
- SDL_FreeSurface(temp);
- }
Add Comment
Please, Sign In to add comment