View difference between Paste ID: tyGW20Z0 and hu5EQxpH
SHOW: | | - or go back to the newest paste.
1
void Surface::blit(Surface *src, int x, int y, float rotation, float sx, float sy, int ox, int oy, bool smooth) {
2
3
	SDL_Surface *temp;
4
	temp = rotozoomSurfaceXY(
5
							src->getSDL_Surface(),
6
							rotation,
7
							sx, sy,
8
							smooth ? SMOOTHING_ON : SMOOTHING_OFF
9
							);
10
	assert(temp);
11
12
	float w_no_rot = src->getWidth() * sx;
13
	float h_no_rot = src->getHeight() * sy;
14
15
	float cos_rot = cos(math::DEG_RAD_R * rotation);
16
	float sin_rot = sin(math::DEG_RAD_R * rotation);
17
18
	Vector2D v1(w_no_rot, -h_no_rot);
19
	Vector2D v2(w_no_rot, 0);
20
21
	v1.rotate(math::DEG_RAD_R * rotation);
22
	v2.rotate(math::DEG_RAD_R * rotation);
23
24
	int fx, fy;
25
26
	fx = x - ox * sx;
27
	fy = y - oy * sy;
28
	//fx = x;
29
	//fy = y;
30
31
	rotation = fmod(rotation, 360.0f);
32
	if (rotation >= 0 && rotation < 90) {
33
		fy -= v2.getY();
34
	}
35
	else
36
	if (rotation >= 90 && rotation < 180) {
37
		fx += v2.getX();
38
		fy -= v1.getY();
39
	}
40
	else
41
	if (rotation >= 180 && rotation < 270) {
42
		fx += v1.getX();
43
		fy += h_no_rot * cos_rot;
44
	}
45
	else {
46
		fx += h_no_rot * sin_rot;
47
	}
48
49
	SDL_Rect dest_rect = {Sint16(fx), Sint16(fy), Uint16(temp->w), Uint16(temp->h)};
50
51
	SDL_BlitSurface(temp, 0, getSDL_Surface(), &dest_rect);
52
53
	SDL_FreeSurface(temp);
54
}