PocketMatrix forums

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

Rotation Questions

I'm playing around with rotation now.

Am I correct that I must use Blt and not BltFast?

Let's say I have a source image that is rectangular, and I want to rotate 30 degrees. So I specify 3000 rotation angle (100ths of degrees).

I want to rotate around the center of the image. I assume that is what the rotation angle specifies, though I haven't tried it yet. I don't want scaling or anything else, just rotation and keysrc transparency.

How do I specify the destination? Blt seems to take a destination rectangle, not a point. How do I compute my destination rectangle? It has to be bigger than the source rectangle, but how much?

Can't I just specify the source image, the rotation center, the rotation angle, and a destination point (that is the center of rotation in my destination surface)? That's all I need to specify my rotations.

If I don't use a destination rectangle, the rotation looks great but is merely centered on the screen, not what I need.

Also, that single rotation appears to take about 3ms on my iPAQ 3970. I am only using 14x71 from a source image. The only other flag is the keysrc. Is that typical performance or am I doing something wrong?
Let me give a concrete example.

Let's say I have a source image that is 200x50, which really is two 100x50 tiles side by side.

I want to blit the second tile which is source rect 100,0,200,50.

I want to rotate it around point 20,20 in the tile, which is point 120,20 in the source image.

And I want it to be centered around point 150,200 in the dest surface (the back buffer). So point 120,20 in the source image is point 150,200 in the dest surface.

Let's say I rotate 30 degrees.

Do I have to compute my own destination rectangle?
How do I specify the destination? Blt seems to take a destination rectangle, not a point. How do I compute my destination rectangle? It has to be bigger than the source rectangle, but how much?


You can just use NULL to use the entire destination surface. If you want to set a center point for rotation, you can use the rotation center parameter in BLTFX.

Can't I just specify the source image, the rotation center, the rotation angle, and a destination point (that is the center of rotation in my destination surface)? That's all I need to specify my rotations.


Yes, you can do so.. source image = source surface. destination point = rotationcenter parameter in BLTFX. rotation angle = rotationangle parameter in BLTFX.
You cannot however specify rotation center of the SOURCE surface.

Please note however that for performance reasons, it's better to change and move and move around the destination rectangle.. Rotation will always be centered to the destination rectangle...
So what is the rotation point in the source rect then? Is it 0,0?
It's in the center.. width>>1, height>>1
OK don't worry about me I got it working now.

My models rotate about their origin, which isn't necessarily in their center. Hence my problem finding the destination center of rotation. But I already had my rotated bounds in world coordinates, so I just used that as my destination rectangle, it's exactly the correct size and placement.

Now I have rotated animated entities bouncing around my world quite nicely.