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
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
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.
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.