PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Possible rotation bug, I'm not sure

I have an 18x18 image that I rotate to orient in the eight compass point directions (i.e., 45 degrees, 90 degrees, 135 degrees, etc.) depending on the direction this object is traveling.

Any time it is rotated to 0-180 degrees, it seems that the right-most pixels (those that are actually on the top of the image of course) are either distorted or cut off (they appear to be cut off at 90 degrees and 180 degrees, anything else is a distortion).

Now, the distortion is hard to see, and it could frankly be expected with a rotation, but the cutting off obviously shouldn't occur.

Here is the code I'm using for the 90 degrees position (other positions are identical except for the rotation angle, as you would expect):

Code:

// POINT player_pos;
// game_surface is a surface created before this, which is
// blitted to the physical screen down the line.
// player_img is a previously loaded surface with a
// transparent color RGB(255, 128, 255)
RECT rect;
SetRect(▭, player_pos.x, player_pos.y, player_pos.x + 18, player_pos.y + 18);
GDBLTFX gdbltfx;
gdbltfx.dwRotationAngle = 9000;
game_surface->Blt(▭, player_img, NULL,
GDBLTFAST_KEYSRC | GDBLT_ROTATIONANGLE, &gdbltfx;);

Pretty much standard stuff I think. Any ideas what might be causing it? Could it be a bug, or just something I don't know yet? Thanks!
Looks like your typical subpixel accuracy problem here.

Johan, what are you using as the pivot in this case? Assuming (9,9), does that represent the line between the pixels (8,8), (8,9), (9,8) and (9,9) or the middle of pixel (9,9)? If you get that part wrong, this is exactly what would happen.
Thierry: That is probably it.. I don't have access to the code right now, but will check on Monday... I'll try and change it and include the fix in 2.02...
Well, until it's resolved my giant space-dwelling squirrel doesn't have a head when moving right.

(Don't ask, you DON'T want to know! :) )
I had a remotely similar problem in Varium with rotating meshes at load time. So instead of using a generic free rotation algorithm, I use a specialized technique for rotations that are multiples of 90 degrees. Not only is it faster, but it is perfectly accurate.

Dan East