#### Archived

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

# 2D Rotation

This topic is 6990 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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).]

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

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

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

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

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

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

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

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

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011702
• ### Who's Online (See full list)

There are no registered users currently online

×