Rotating lots of using cos and sin

03-21-2002, 12:32 AM
In my game i am turning the spaceship around by using

cos and sin to find the x and y of where my ship is facing

what i want to do is draw a ship using a series of i would have 2 points per line.

basically i would rotate these points with the ship direction and in effect you would get a drawn spaceship turning around etc

so how would i get my points (that iam using to draw the lines) to rotate while staying one pixel next to each other.
heres a picture that i am using for my spaceship.
it is drawn by a series of lines

03-21-2002, 01:03 AM
If you are using DirectX then this can be done in real time, but hard to program...

But I gather you ain't using DirextX and so what I would suggest is you use a paint program and rotate the missiles like 22.5 degrees each time so that you end up with 16 copies of the rocket, then simply paste which one you need at the time in the program.

If you draw the rocket pixel by pixel each time, it will be a very slow process....

03-21-2002, 01:18 AM
ah, its just that i am also using a few of the points to make a region which i am using for collision detection

03-21-2002, 01:56 AM
You should still be able to use those points for collision detection, just change the routine over from drawing the whole ship to bitblting a pic down, but you can see use the sine and cosine to check for hotspots....

Maybe someone else might have a better idea on this... :)

03-21-2002, 07:12 AM
You can create the pictures at different angles and check to see if the picture touches an enemy(?).
If you are just using the front point, you can probably get a value for the end of the rocket point and see if the point touches an enemy(?).

Does the picture touch the enemy or just the point?:-\

03-21-2002, 07:49 AM
You can rotate a ship made with lines & points without using DirectX. I did it in my Asteroids clone. Each object (ship, asteroids, shots) is a combination of points and lines, able to rotate freely 360 degrees, not just 16 directions. Take a look.

(You'll have to scroll down in the thread to find the attachment)

03-21-2002, 08:15 AM
Oops my mistake...

Sorry Andreww, I misread your post, I thought you were drawing a bitmap.... (Heaven's knows why. :p) So what you are actually after is a vector drawn ship...

The only simple way I can think of getting a full coloured-in ship is to change the drawwidth of the line to 2. This may make the drawing a little bit pixelated around the edges, but will fill in all the gaps. :)

Have fun...

03-23-2002, 01:45 AM
using the x=cos(degree)*radius and y=sin(degree)*radius

i want to know what degree to type in and what radius to type in for each point. As each line drawing the picture has to be next to each other. I cant just guess to angles and have them to draw a triangle, i just think of 3 degrees equal distance or whatever.

what i thought of doing is making a program to find the distance the point is from the middle point the rocket will be rotating on and use the atn function to find the degree

the program would output the necessary code, but the program keeps coming up with errors like overflow etc

03-23-2002, 07:38 PM
I'm thinking you should learn matrix math and do some transforms....

Let me see if I can dust off my old 3.5" disks and find some code....

03-24-2002, 12:47 AM
Well....I couldn't find my old 3D matrix functions, but I made up some 2D ones....

I've attached a program that demonstrates the technique. You could just use a function like:

newX = (OldX-CenterX)*Cos(Angle) - (OldY-CenterY)*Sin(Angle) + CenterX
newY = (OldX-CenterX)*Sin(Angle) + (OldY-CenterY)*Cos(Angle) +CenterY

but the matrix method is somewhat more flexible since you can use the basic method to add rotation on rotation. In the example, I use 2 rotation matrices to describe a carotid curve. You can also extend the basic mechanism to 3D quite easily.

Plus I hear you can also use matrix math for colour scaling.

Anyway, see if you find it useful. I may put together a tutorial on this if you do....

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum