tags:

views:

50

answers:

2

Hi, hope it's allowed to "crosspost" between stackexchange site... Does anyone know how to solve the following "math" problem ?

http://gamedev.stackexchange.com/questions/5041/correct-blitting-2-surface-problem

Thanks in advance

A: 

I'm not much of a graphics guy, but the way I've done something like this before was by having a mask and then the image, and you need to rotate and blit both of them. That is, you have a black turret-shaped "hole" that is rotated and blitted to match the rotation you want for your turret image.

Another issue is that the pixels in your rotated image won't line up with the pixels in your original image, so you have to do some interpolation to make it look right.

I would think though that there are probably libraries you can use that take care of this stuff for you.

Tim Goodman
+1  A: 

Your problem seems to be that you're blitting the turret with respect to its top left corner, when you actually want to blit it with respect to the center of the actual turret. Now, assuming your turret has its center at x_1, y_1, rotating it clockwise by theta degrees should give you a "new" center at x_2=x_1*cos(theta), y_2=y_1*sin(theta). You then have to line this up with the center of the turret hole, located at 13,13. This shouldn't be a problem (keep in mind I'm not very versed in C#, so this is probably syntactically incorrect):

Point posTurret = new Point(13 + this.X - x1*Math.cos(cannonangle),
                            13 + this.Y - y1*Math.sin(cannonangle));

Where x1 and y1 are the coordinates of the center of the turret in "tank_turret_long.png".

I'll crosspost this answer on gamedev as well.

You
Hi You, thanks. I blit the turret respect the tank. posTurret(13+this.X) ... "this" refer to TANK surface. With this new information, can you help me to "correct" the source to blit my turret in the "center" of the hole-tank ? (not the center of the tank.. but hole stay on 13,13). Thank you!
stighy
Basically, replace 13 with the center of the hole in the tank surface (because the center of that hole is not at 13,13), and replace `x1`/`y1` with the center of the actual turret in the turret surface, which looks to be roughy 11,11.
You