Jagware

# Making Rotations With The Blitter!

## Recommended Posts

Hello,

I'll try to translate my post of yesterday in the french speaking zone. (see http://www.jagware.org/index.php?showtopic=255)

So, as I said, I played a little with the blitter and discovered how to make rotations with it

Actually, the method is (vaguely) described in the Atari documentation but I understood it once I reinvented the method

And by the way, the authors of the Jaguar Underground Documentation hadn't understood how to do... because it is not possible to have holes as they say.

The idea is to use A2 as the destination register. We will simply scan the zone where we want to write the rotated data and we will fetch the corresponding graphics data with A1 which will scan the source sprite.

I define W as being the width of the sprite and H its height.

So, imagine we want to rotate a sprite of an angle alpha. If we define X',Y' as being the new coordinates and X,Y being the old ones (where the coordinates are expressed from the centre of the rotation at CX,CY and with axis parallel to the screen)

you probably remember from your maths course that

X = X' cos(alpha) - Y' sin(alpha)

Y = X' sin(alpha) + Y' cos(alpha)

now, what happens if X' change by one (ie becomes X'+1)

then X becomes X+cos(alpha)

and Y becomes Y+sin(alpha)

so here we get the increment to use in the inner loop!

Thus, we have

INC,FINC_X = cos(alpha)

INC,FINC_Y = sin(alpha)

well, good point!

Now, what happens if Y' becomes Y'+1 and X' changes by -W

In this case, we have X' becomes X' -W * cos(alpha) - sin(alpha)

and Y' becomes Y - W*sin(alpha) + cos(alpha)

This gives us the value to put in step values for the outer loop!

STEP,FSTEP_X = -W*cos(alpha) - sin(alpha)

STEP,FSTEP_Y = -W*sin(alpha) + cos(alpha)

Now, we do not want to write garbage data when the A1 pointer leaves out the original sprite, so we use clipping

We set:

CLIP_X = W

CLIP_Y = H

and the last thing to compute is the coordinate where to start for A1

after computation, we get

PIXEL,FPIXEL_X = CY*sin(alpha) - CX*cos(alpha) + CX

PIXEL,FPIXEL_Y = CY - (CX*sin(alpha) + CY*cos(alpha))

In case, I have not been clear enough, see the source code I have posted in the french speaking zone

the function get_cos_and_sin takes in d1 the angle and returns the value 16.16 of the cosinus (d1) and the sinus (d2) for that angle.

FInally, feel free to ask any questions if this remains obfuscated for you

Seb

##### Share on other sites

Great work as always from SebRmV

##### Share on other sites

Beeing one of the "forgotten" I just want to say that I think it is good for poeple to get another, more detailed, description of what is going on when doing rotations & how to do it.

So people can understand that the jaguar can do rotations pritty easy!

The only thing "bad" about it is that the rotated bitmap will use more space in memory.. (depending on form of object, sometime the width will be as wide as the diagonal).

And to do this easy you either need to make extra space from the beginning (if you use obejcts). Or you will need to have an elaborate mem management scheme... OR easiest way is if you use a framebuffer....

But its good & usefull information! =)

salut

btw... "forgotten" ..theres a new group name.. perhapps i should change

/Symmetry of the Forgotten

##### Share on other sites
ggn    1

BUMP!

:hug:s to Seb for this thread - you saved me a few days of total frustration and head scratching (plus having to use some pen and paper and write down the equations needed ). I now have my rotator up and running - some tables are generated offline, unlike your version. Also thanks to Zerosquare for bringing this thread to my attention!

There's only one weird thing I haven't managed to solve yet. Seems that my routine is working perfectly on vjag and PT. But depending on the width and height of my bitmap, it may or may not work on the real Jaguar. It sounds like phrase alignment, but I'm not sure. Any ideas?

##### Share on other sites
ggn    1

Just a small update here.. It seems that the general set-up code I use is at fault - looking into it. Just wanted to say that I can rotate a 256x256x8bpp object at 30FPS

##### Share on other sites

Nice to hear that it helped you!

##### Share on other sites

By the way, you may be interested by looking at the source code of the renderer I have written for my library.

I have learnt a lot of things about the blitter while doing this (especially Gouraud/Zbuffer/...)

Unfortunately, I am too lazy (for the moment) to rewrite a more efficient a renderer (ideas are written on paper though).

##### Share on other sites
ggn    1
By the way, you may be interested by looking at the source code of the renderer I have written for my library.

I have learnt a lot of things about the blitter while doing this (especially Gouraud/Zbuffer/...)

Unfortunately, I am too lazy (for the moment) to rewrite a more efficient a renderer (ideas are written on paper though).

Okay, will do!

Unfortunately, as you say, the only way to get the best out of the blitter is to write a couple of renderers, learning from the mistakes/experience of the previous ones.

(OT: maybe it would benefit all to make a semi manual/semi tutorial doc for the blitter? I.E. Explaining in simple words what the registers do and some sample programs like "if you want to do ....., then use this source as base)

##### Share on other sites
(OT: maybe it would benefit all to make a semi manual/semi tutorial doc for the blitter? I.E. Explaining in simple words what the registers do and some sample programs like "if you want to do ....., then use this source as base)

That's what I planned when I started Jagopedia (http://jagopedia.atari.org)

If you wish to contribute, I open an account for you.

##### Share on other sites
ggn    1
That's what I planned when I started Jagopedia (http://jagopedia.atari.org)

If you wish to contribute, I open an account for you.

Well it could be nice documenting the things I learn about the Jaguar and write them down somewhere. If you allow this, I can start from quoting the official Atari docs and then refining them as I go along.

##### Share on other sites
Well it could be nice documenting the things I learn about the Jaguar and write them down somewhere. If you allow this, I can start from quoting the official Atari docs and then refining them as I go along.

Why not? This could be a good start, even if it infriges a bit the "do not submit copyrighted work" policy.

If I remember correcltly, you wan ask for an account directly on Jagopedia website. I'll validate your subscription afterwards.

(Otherwise, we'll see by PM maybe)

##### Share on other sites

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoticons maximum are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×