Jump to content

  • Log In with Google      Sign In   
  • Create Account

Rotating a Bitmap


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 Lafo   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 November 1999 - 12:24 PM

Yeah it's me again!?!?!?

I'm now looking for a way to rotate a bitmap(I don't want to make all these bitamps with photoshop: ~15~20 bitmaps for all direction * by all the animation = too many).

There's certainly a way to rotate a sprite, if someone can tell me how, I'll appreciate.

Lafo


Sponsor:

#2 The Madman   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 August 1999 - 07:06 PM

OK, I'm assuming you are using DirectX to do this crap, so here goes nothing. Assuming these variables:

// backbuffer (you'll flip it)
LPDIRECTDRAWSURFACE lpDrawOnMe;
// source bitmap
LPDIRECTDRAWSURFACE lpOhYES;
// DD blit effects structure
DDBLTFX ddbltfx;
// two rectangles, one source and one dest
RECT source;
RECT dest;

here's the procedure:

memset(&ddbltfx,0,sizeof(DDBLTFX);
ddbltfx.dwSize=sizeof(DDBLTFX);
ddbltfx.dwRotationAngle=rotate;

// now blit that sucker
lpDrawOnMe->Blt(&dest,lpOhYES,&source,DDBLT_ROTATIONANGLE, &ddbltfx);


There you go, hope that helps!

------------------
That's how you do it, but that's just the opinion of a MADMAN!!! BWAHAHAAHAHA! :D :D :D


#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 07 August 1999 - 08:27 AM

That won't work if the hardware doesn't support it (DirectDraw won't emulate it).

#4 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 07 August 1999 - 07:02 PM

What will work then?

#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 11 August 1999 - 06:24 PM

Did you also tell him the fun news that BLT will be 10% slower than bltfast?

You might as well do 3 things.

1: go 3d and save yourself now
or
2: draw the flipped object into another bmp and just load it when you need it.
or..
3: make another surface.. and after you load the bmp up.. you do you rotation.. and save the rotated surface into a new one.. and basically cache your image. So when you need to rotate the bmp you just load up the surface that you calc'd from before and display it.. this way the CPU calcs are done during game launch and not realtime each loop during the game.

-DL


#6 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 12 August 1999 - 03:55 AM

BLT is only 10% slower than BLTFAST if the display adapter doesn't support hardware blitting, almost all of today's display adapters do support hardware blitting

#7 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 23 November 1999 - 04:25 AM

I got the same problem as this guy.
There was a lot of replies on this issue, but the question remains: How the **** will i be able to rotate the sprite while blitting?? Yes, Madman's code shall work
IF THE GRAPHIC CARD SUPPORTS IT!!!
Supose i WON'T, then what?

#8 Gromit   Members   -  Reputation: 144

Like
Likes
Like

Posted 23 November 1999 - 05:28 AM

Write your own!
http://exaflop.org/docs/cgafaq/


#9 Mandrake   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 November 1999 - 06:53 AM

Here's what I found on rotating bitmaps in the faq that Gromit quoted above:
=====================================
Subject 3.01: How do I rotate a bitmap?
The easiest way, according to the comp.graphics faq, is to take the rotation transformation and invert it. Then you just iterate over the destination image, apply this inverse transformation and find which source pixel to copy there. A much nicer way comes from the observation that the rotation
matrix:

R(T) = { { cos(T), -sin(T) }, { sin(T), cos(T) } }
is formed my multiplying three matrices, namely:

R(T) = M1(T) * M2(T) * M3(T)
where

M1(T) = { { 1, -tan(T/2) },
{ 0, 1 } }
M2(T) = { { 1, 0 },
{ sin(T), 1 } }
M3(T) = { { 1, -tan(T/2) },
{ 0, 1 } }
Each transformation can be performed in a separate pass, and because these transformations are either row-preserving or column-preserving, anti-aliasing is quite easy.
=====================================
Now, the question is for those who are just learning, is this enough information to "write your own!"? Maybe, but maybe not for some people. I really tire of supposed experts on subjects yelling at newbies and throwing a URL at them telling them to figure it out for themself. Some people are able to take the above and make something out of it. Some people need more help, perhaps a code example doing something similar. If you are an expert and can't be bothered to help teach, don't yell at the students who are looking for such a teacher.

Cya,
Dave


#10 Splat   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 November 1999 - 10:34 AM

Gromit does seem a little egdey today, as that locked message on the general forum proves, but I see his point. No, that extract from the FAQ alone may not be enough information for some people. But the whole point of this (programming, writing games, etc.) is to learn.

Sometimes its nice to be able to tell a black box (DirectDraw) to blit something for you and just assume the result will happen, but when the time comes to do something unique, unless you actively learn topics of interest like 2D bitmap rotation, you will have no basis on which to implement it. You will come running back to this forum and forums like it to ask your question and get your code most everytime. This is not the way to program. The sharing of knowledge is only really useful when you learn from your mistakes.

Its this knowledge I think that seperates the true hobbyists from those who probably could, if they so please, go into programming professionally (or already are). I certainly will go into programming, hopefully *crosses fingers* game programming, as soon as I get out of high school and finish my education in college.

- Splat

[This message has been edited by Splat (edited November 23, 1999).]


#11 Splat   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 November 1999 - 10:44 AM

Oh yeah, forgot to help you

The above rotation matrix (2x2) is used to rotate a pixel coordinate around the origin a certain amount (depends on what your trig functions take as a parameter, radians, degrees, etc.).

However, if you were to just go over the source image each pixel, and use that to figure out where that pixel goes, you would have many gaps in the destrination image where the pixels were not filled in. The alternative, much better solution is to invert the matrix (look that one up, not enough space to explain) so that you have a matrix that, when multiplied by a 2D coordinate, will tell you which source pixel was rotated to get there.

So essentially, take the inverted matrix, go through each destination pixel, and copy the source data from the pixel indicated by the matrix operation. That is the simple rotation. However, the source pixel indicated will generally by a floating point (ie not integer). You can get away with simply rounding the result, but that does not look as good as combining the pixels around the subpixel in the source image in proportion to the amount that the floating point coordinate indicates. That will get you more accurate results, and is not THAT slow.

Calculating the rotations in-game is not the best method however. You'd be best calculating a bunch of images with the orientation of the image in the upper right quadrant, maybe at 5 degree increments (that would yield 18 images), then flip it in-game to get it pointing at the other 3 quadrants. Flipping across the X and Y axises is VERY fast and has perfect reproduction, because you are simply swapping pixels.

- Splat

[This message has been edited by Splat (edited November 23, 1999).]


#12 Freeride Designs   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 November 1999 - 11:19 AM

Hey Splat thanks for the idea of just drawing the upper right quadrant and flipping it. I was looking up how to rotate bitmaps, because I didn't want to store a huge bitmap, but this idea is an excellent compromise.

#13 Gromit   Members   -  Reputation: 144

Like
Likes
Like

Posted 23 November 1999 - 11:21 AM

Sorry if I sounded a bit over the edge. By no means am I even close to becoming an expert, or even a intermediate game programmer. I don't even have a job! (argh! still looking for that right one.. or any one.)

But, I feel that the *best* way to learn, is to *try* and figure it out for yourself. The second best is to read a text book on the subject (or an faq). And as a last resort, ask someone on a message board.

I find that just asking someone doesn't really help you in the long run, and thier answer doesn't not mean that it is the right answer or the best.

When you start your on your way as a game developer, you can't just ask people how to do something evertime you run into a problem. I have once spent two weeks trying to figure out a solution to a problem, (to no avail) and finally I looking it up on a web page. Even though I didn't do it myself, atleast I now know the complexity and general nature of the problem. So maybe next time, I will be able to do it myself, and it might be a better solution then the one I got from a web page.

So sorry everyone if I offended. =(

Now to get back on the proper topic... ummm.. direct draws bitmap rotation sucks.


ps. why was my message locked? and what does that mean? (see, I'm a newbie too.)


#14 Splat   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 November 1999 - 11:51 AM

Gromit: As you can see from my message above, I in part agree with the look before ask ideology for programming.

Reg. direct draw rotation: Never used or plan on using. Using pre-rotated images or optimized, hand-written rotations that are calculated at initialization and NOT at blit are the way to go.

Reg. the locking of your message, the moderators obviously did not want a flame-war of sorts to explode under that topic. But it was on topic and not mean, so they couldn't (in good conscience) delete it. So they locked it so people could see but not respond.

- Splat


#15 Splat   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 November 1999 - 12:24 PM

Freeride: I must admit, the idea of quadrant flipping is NOT mine, it is (I believe) the general consensus that this is the best method, rather than rendering all 360 degrees. The slight increase in speed by rendering all 360 degrees is simply not worth the increase in size, memory useage, time spent in a drawing program (assuming you don't use a 3D modeller to do the grunt work of rotating for you) etc.

- Splat





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS