🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

2D Rotation

Started by
22 comments, last by Blake 24 years, 8 months ago
Hi Blake !

Did you already check the resources of GameDev? Look at the section Programming-General/Graphics, where you will find an aricle titled "Texture Mapping". It explains the principle of linear texture mapping, wich is exactly what you need for 2d. http://www.gamedev.net/reference/programming/graphics/article366.asp

Advertisement
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).]

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

<b>/NJ</b>
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.

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

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

Lack
Christianity, Creation, metric, Dvorak, and BeOS for all!
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.

This topic is closed to new replies.

Advertisement