Jump to content

  • Log In with Google      Sign In   
  • Create Account

2D Rotation


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
23 replies to this topic

#1 Blake   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 September 1999 - 04:37 PM

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?

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 19 September 1999 - 09:04 AM

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


#3 Blake   Members   -  Reputation: 122

Like
Likes
Like

Posted 19 September 1999 - 12:53 PM

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


#4 Niels   Members   -  Reputation: 122

Like
Likes
Like

Posted 19 September 1999 - 10:42 PM

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


#5 Mike   Members   -  Reputation: 140

Like
Likes
Like

Posted 20 September 1999 - 12:35 PM

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.

#6 PyroFragger   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 September 1999 - 02:18 PM


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)

#7 Mike   Members   -  Reputation: 140

Like
Likes
Like

Posted 20 September 1999 - 03:56 PM

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.

#8 Blake   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 September 1999 - 06:40 PM

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


#9 Zenroth   Members   -  Reputation: 127

Like
Likes
Like

Posted 20 September 1999 - 10:01 PM

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.

#10 LackOfKnack   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 September 1999 - 12:19 AM

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


#11 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 21 September 1999 - 08:22 AM

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.

#12 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 21 September 1999 - 12:11 PM

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


#13 LackOfKnack   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 September 1999 - 12:26 PM

Then what the heck was I talking about? Mine seems to work when I use it...

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

Lack


#14 Zenroth   Members   -  Reputation: 127

Like
Likes
Like

Posted 21 September 1999 - 07:46 PM

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?

#15 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 23 September 1999 - 01:23 AM

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!?


#16 Niels   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 September 1999 - 02:19 AM

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


#17 Sphet   Members   -  Reputation: 631

Like
Likes
Like

Posted 23 September 1999 - 08:26 AM

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.

#18 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 23 September 1999 - 10:31 AM

Niels: Your game looks really cool!!

#19 Zenroth   Members   -  Reputation: 127

Like
Likes
Like

Posted 23 September 1999 - 12:23 PM

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.


#20 Blake   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 September 1999 - 06:06 PM

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





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