• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Lafo

Rotating a Bitmap

14 posts in this topic

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

0

Share this post


Link to post
Share on other sites
That won't work if the hardware doesn't support it (DirectDraw won't emulate it).
0

Share this post


Link to post
Share on other sites
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

0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
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

0

Share this post


Link to post
Share on other sites
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).]

0

Share this post


Link to post
Share on other sites
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).]

0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.)

0

Share this post


Link to post
Share on other sites
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

0

Share this post


Link to post
Share on other sites
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

0

Share this post


Link to post
Share on other sites
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

0

Share this post


Link to post
Share on other sites