2D rotation/translation math , help needed

Started by
8 comments, last by Xeno 23 years, 8 months ago
hi! lets say i got a spaceship and can rotate the spaceship around the middle of the space ahip , so how can i move the spaceship to the direction the the spaceship point on? i mean , lets say the spaceship is rotated by 45 degrees , how can i move the spaceship in the same direction the its point now? (after the 45 degrees rotation)? i tought about to do that like in 3D , to set rotation matrix (2D matrix) and to multiply the 2D normal vector and the rotation matrix , so that will give me the direction vector.... but after i got the direction vector , i dont know how add it to the ship coordinates... , how should i do it? thanks roy.

------------------------------- Goblineye Entertainment------------------------------

Advertisement
RoateImage(Angle)
X = X + amount*cos(RAD(Angle))
Y = Y + amount*sin(RAD(Angle))

that''s how you move the ship.. for amount, you could use a value of 2 or 3, depending on the resolution of the screen.. it''s the velocity.. .basically..

-------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..
well , thanks anyway, but its not really working , and im sure that there is better way to do it with 2D matrix/normals , somebody knows how?

thanks

------------------------------- Goblineye Entertainment------------------------------

im working with D3D so movement should be done on 4 point not on one like in ddraw (the top left corner) , so that what i want to know , how to move the four points together...

lets say im doing what gladiator sayed:
                float objx , objy;		D3DVECTOR coord[4];		if(GetAsyncKeyState(VK_UP))		{			objx = objx - 5*cos(angle * g_DEGTORAD);			objy = objy - 5*cos(angle * g_DEGTORAD);		}		if(GetAsyncKeyState(VK_DOWN))		{			objx = objx + 5*cos(angle * g_DEGTORAD);			objy = objy + 5*cos(angle * g_DEGTORAD);		}		coord[0].x = objx;		coord[0].y = objy;		coord[0].z = 0;		coord[1].x = tex_width+objx;		coord[1].y = objy;		coord[1].z = 0;		coord[2].x = objx;		coord[2].y = tex_height+objy;		coord[2].z = 0;		coord[3].x = tex_width+objx;		coord[3].y = tex_height+objy;		coord[3].z = 0; 


tex_height and tex_width is the spaceship texture height and width.

am i doing it right?
if not , how should i do it?

------------------------------- Goblineye Entertainment------------------------------

Why would you wanna use matrices for such a simple task?!?! in fact, the calculation uses vectors (the magintude, and x & y components) to calculate the velocity... amount in the above formula is te velocity vector''s magnitude (or length)...

-------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..
Hi,

I''ve never used D3D at all, but here is something...

>>objx = objx - 5*cos(angle * g_DEGTORAD);
>>objy = objy - 5*cos(angle * g_DEGTORAD);

that''s wrong... the first should be COS and the second one (the Y value) should use a SIN... but you have COS on both...

and why do you need to move 4 points? why are you even using D3D for 2D stuff?!?! simply use DirectDraw, and do all of your 2D stuff there...

-------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..
ops , thats what heppans when u using cut and paste

im using d3d because i want to use some secial effects like alpha blending etc....
and its much more faster

------------------------------- Goblineye Entertainment------------------------------

hmmm.... mybe u right , now its working , but still seems that sometimes its a bit crapy , i mean , in some angles its moving in a straight line , and not to the direction its have to move...

------------------------------- Goblineye Entertainment------------------------------

I see... and are those 4 points the corners of your ship''s image? #:o)

the thing is, that 2D is 3D without the rotation around the X or Y axis.. in 2D you only rotate stuff around the z-axis... so.. i would think that you can only change the X and Y values of the image''s 4 corner points (vertices) and it would move (translate)... simply apply the formula above on all X,Y couples and it should work fine... i dont know why you''re even playing around with the texture height/width, etc... do textures have X & Y values? or something liek that?!?! i have n oidea how they work in D3D...

-------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..
can''t say much from the code you''ve posted #:o)

-------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..

This topic is closed to new replies.

Advertisement