• 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.

Blake

2D Rotation

23 posts in this topic

Thanks for the reply, I wasn't quite sure where to begin looking. I'm working exclusively in 2D and that seemed to be under a 3D category. It is very helpful, however it assumes that I already know how to draw and rotate polygons. I only want to draw and rotate 2D rectangular or square polygon. Do you know of any documentation that explains this?

Blake

[This message has been edited by Blake (edited September 19, 1999).]

0

Share this post


Link to post
Share on other sites
There is a few books you need to get hold of:

Abrash: Black book of graphics programming (a must-have)

The bible: Computer graphics, principles and practice

And the less theory, more code series: Graphics Gems 1-(whatever)...

You will be amazed by the knowledge compiled into these books ..

/NJ

0

Share this post


Link to post
Share on other sites
Well, I can give you the source code to rotate a 2D image ( 8, 15/16, 24/32 bits), but I'm not to good at explaining things. If you want the source code (sparcly commented) let me know via E-mail.
0

Share this post


Link to post
Share on other sites

I think it would be best to have pre-rotated bitmaps and set it up so that when theuser presses the left arrow key, it rotates it 15 degrees to the left (or some other increment you can count by)
0

Share this post


Link to post
Share on other sites
I dissagree with the idea of drawing a bunch of pictures at varous angles. If you have an object with five frame of animation, and you need to have each of those frames drawn for every 15 degrees, that a good deal of wasted space.
0

Share this post


Link to post
Share on other sites
No kidding! I have about 16 frames of animation and I am not going to draw 240 separate frames for 1 object! In theory this should be very simple:

1) Setup a rectangular polygon (4 vectors)
2) rotate vectors clockwise or counterclockwise
3) Blit pixels line by line onto polygon

Voila!

Simple simple simple but I don't know enough trigonometry to be able to rotate points. That's all I need to know how to do.

I went and bought a cheap trig book today and I can already tell the book explains exactly what it is I'm trying to do. I will post the fruits of my labor in the form of a tutorial when I am successful. However, I still welcome any examples. My e-mail is blake@cyberstation.net.

Thanks to all that replied!

Blake

0

Share this post


Link to post
Share on other sites
I say go with pre rotated bitmaps to. Simple reason speed speed speed. Sure you make huge memory footprint but you get speed. Why do you think all theese games like starcraft,warcraft ect use prerendered frames for speed. 1 rotating ship thing on a polygon in like 640x480 wont hurt that bad you get 100 on the screen i doubt you have any frame rate left. Only way to do rotation where it works well is use a direct3d or opengl map the texture onto a triangle stript and use 3d acceleration.
0

Share this post


Link to post
Share on other sites
I have to disagree. Does anyone have Grand Theft Auto? All those cars an people would take up 360x the memory they do, but they don't because they just rotate them. I think a tiny bit of slowdown is worth the memory... GTA runs pretty fast, and they have tons of rotated objects flying around.

The calculation I use for finding an angle is:

x = Sin((90 + ang) * pi / 180) * rad
y = Sin(ang * pi / 180) * rad

This may or may not be what you're looking for. You feed it pi, rad(the radius) and ang(the angle) and it gives you the x,y relative to 0,0.

Oh, and that was in VB. I don't know exactly what it would be in C, sorry. Should be a staright-forward conversion though.

Hope this helps.

BTW- does anyone know how to do the blitting on an angle, but in DirectX? Or do you just read each pixel and rotate it yourself?

------------------

Lack

0

Share this post


Link to post
Share on other sites
You can pre-calculate the rotation angles for your ship and put them into a lookup table. That will speed up your rotation at run time.
0

Share this post


Link to post
Share on other sites
The formula to rotate a point n radians is:

new_x = x * cos(n) - y * sin(n);
new_y = y * cos(n) + x * sin(n);

Taken from Andre Lamothe's "Tricks of the Game Programming Gurus", so don't bitch at me if you think it's wrong

0

Share this post


Link to post
Share on other sites
True rotation has it uses but alot of time you can get away with only 40 angles or less. In which case i think it saves alot of speed. Plus you can have more detail because i havnt seen a rotator yet that you dont loss detail or get jagged edges. Besides with pre rotated in 2d you can make it look alot more 3d but i guess it depends on your game view style. But starcraft,warcraft,and alot of your commercial games do not there has to be some reason?
0

Share this post


Link to post
Share on other sites
You seem to forget that stacrcraft is no 2d shooter. in starcraft it's enough to have (let's say) 16 directions but in a 2d shooter you need to have a lot more angles for targeting and exact movement.
of course you could calculate the dirs more exact then you draw them but wouldn't it look stupid if you shoot in another direction then your gun points to?

and BTW: lets say one sprite is 40*40 * 40directions * 16 frames * 2bytes =2.048 mb!?

0

Share this post


Link to post
Share on other sites
I personally have 8 directions pre-rendered but allow units to shoot in any angle. Since I use isometric view, rotation is not really an option.
But you're right it would look better if the units pointed in the exact direction of the shot, but thats a trade-off I can live with.

(Check it out at http://www.image.dk/~noshit/scrshots.html if you like)

/NJ

0

Share this post


Link to post
Share on other sites
I think it really comes down to the taste of the designer. It is impossible to do rotation with anti-aliasing, so your rotation is going to get the "jaggies" as it turns about. Pre-rendered images DO take a lot more ram, but they have the added benefit of speed and looks - you can use a 3D program to render the object in 36 frames as it spins once around the axis, and if you setup the light right, you get a good feeling of depth as the object moves - shadows are cast across the object's surface realisticly, etc. The other nice thing is that if you combine prerendered images with colour keying you can use the same bitmaps to draw multiple vessles with maybe, the windows or ensignias on the wings changing colour for each player. I REALLY hate the jaggies (one of the reasons I avoid 3D games), so I would opt for pre-rendered.
0

Share this post


Link to post
Share on other sites
Perhaps im a bit old fashion,but i myself say 8 angles is enough to do anything. Only a few types of games need more in my opnion.

I mean i am working on a isometric/action type game and you well be having 8-way movement.

As far as not being able to shoot any direction just move the ship ect over a pixel and your on a new angle for your shots.

0

Share this post


Link to post
Share on other sites
Has anyone out there played HellFighter? That game is really cool and it uses 2D textured polygons. Not only that, but I have been in situations where there were like 20-30 ships on the same screen with no compromise to speed. And the textures look just fine at any angle.

Now, I've put together some of the things that you have all posted and now I have a simple polygon rotation demo. What nobody mentioned was that you have to draw your rectangle's vertices in each of the 4 quadrants:


|
II | I
|
-----------
|
III | IV
|

Also, the formula(s) posted expect RADIANS instead of DEGREES. Other than that, my question has been pretty much answered. If you want to see the little demo I put together, download it here. Hopefully this weekend I will have some code to render a texture to the polygon.

Thanks to all that have posted.

Blake

[This message has been edited by Blake (edited September 24, 1999).]

0

Share this post


Link to post
Share on other sites
I now have a much much better example of rotating a 2D polygon - Download it here!.

It now includes direct surface manipulations for pixel and line drawing on DirectX surfaces (16bit surfaces). Even if you aren't interested in rotating polygons, you may want to look at the code just to see how direct surface manipulations are done. There is a good pixel plotting function and an interpretation of Bres's Line Drawing function.

Pasting a texture to the polygon at this point should be a walk in the park. I'll repost an example as soon as I sit down and work it out.

Blake

0

Share this post


Link to post
Share on other sites
hi,
It depends on which type of texture
mapping you wanna do, there are several
ways and optimizations. if you want to
texture map a quadrangle i offer you
to download the ABUSE source code
(it's a side scrolling game), i have
got this source from x2ftp.oulu.fi
There's a nice texture mapper function
among too many other useful functions.

If you want just to rotate a texture
map, for example a tile based game in
which the tile mapped ground rotates
there are some optimizations to do,
Have you ever seen the Seek 'n Destroy
game from Safari? they have done such
thing, the rotate the tile mapped
ground, the method they used was to
divide a whole 360 degrees of rotation
into some steps, for example each
10 degrees, then they have precalced
and saved the result so there is no
texture calculations done in runtime,
it's all precalced

I'm a game developer, we have developed
a game like Seek 'n Destroy but with
too much better quality and features,
it supports not only rotations but scaling
as the chop moves up or down there
are some tricks to do in such engines.

Some ideas are :

First notice that if you want to
texture map a quadrangle, which is
symetric around it's center ,you can
only calculate the pixels for half
of your quad the other half can be
calced using the first half.

If you do just rotate a bitmap
(no scaling) the best way is to
precalculate the pixel offsets and
save them as your game data.

And a really big optimization is :
if you want to texture map several
quads with the same rotation angle and
the same size (like a tiled ground)
you can texture map only one tile in
a buffer and use the same pixel offsets
for all other quads (tiles).

Our game uses the last method and
runs fast in 640x480x256 mode under
windows (with Direct X). if you want
some screen shots from the game please
email me.

Hope you are making a great game

0

Share this post


Link to post
Share on other sites
You don't need to have 360 precalced pictures to have rotation in accuracy of 1 angles. You can have only 90 because 90 degree rotations are fast to do. And of course it would propably be enough to have accuracy of 5 angles to have smooth animation, that would be total of 18 precalced pictures.

------------------
"Tank, I need an exit. Fast!"

0

Share this post


Link to post
Share on other sites
I am working on a 2D shooter with 16bit color and I want to rotate my ship. I know I need to draw a polygon and map a texture to it, but where do I begin? Can anyone reference some good documentation?
0

Share this post


Link to post
Share on other sites