new position with vector
im trying to work out the new x,y position for my space ship..
ive been looking on the forum and tried using atan2..
float angle = atan2(vecx, vecy); //this is the angle
double distance=sqrt(pow(vecx, 2)+pow(vecy, 2));
int resulta = acos( x /distance)* 3.14/180;
int resultb = asin( y /distance)* 3.14/180;
x += cos(resulta) ;
y += sin(resultb) ;
but ive tried different combinations.. i have the original X,Y of the spaceship and 2 vectors vx and vy but im trying to make them move...
they seem to move too fast :S
ive been looking on the forum and tried using atan2..
float angle = atan2(vecx, vecy); //this is the angle
double distance=sqrt(pow(vecx, 2)+pow(vecy, 2));
int resulta = acos( x /distance)* 3.14/180;
int resultb = asin( y /distance)* 3.14/180;
x += cos(resulta) ;
y += sin(resultb) ;
but ive tried different combinations.. i have the original X,Y of the spaceship and 2 vectors vx and vy but im trying to make them move...
they seem to move too fast :S
1) atan2 wants the y component first: atan2f (vecy, vecx)
2) I'm really, really not sure what you're doing here.
You already have the direction vector for the ship, right? So what you want to do is to normalize that vector (divide each component with "distance"), multiply it with its speed, and then add that new vector to the ship's position.
There are several threads on here about vector movement, so just search the forums.
2) I'm really, really not sure what you're doing here.
You already have the direction vector for the ship, right? So what you want to do is to normalize that vector (divide each component with "distance"), multiply it with its speed, and then add that new vector to the ship's position.
There are several threads on here about vector movement, so just search the forums.
This might help: http://www.sacredsoftware.net/tutorials/...tors.xhtml
Well, what your basically doing is:
x = x + cos(acos(blah))
so you may as well just do
x = x + blah
Also, cos expects arguments to be in radians and acos returns angles in radians. What your doing by multiplying by (3.14/180) is using the formula for converting degrees to radians, and applying it to something that is already in radians (It's like taking a measurement in inches and multiplying it by twelve). What you want is something like this.
This makes it easy to change your physics system later because you can specify what the velocity vectors are (you can make them exhibit acceleration and inertia).
x = x + cos(acos(blah))
so you may as well just do
x = x + blah
Also, cos expects arguments to be in radians and acos returns angles in radians. What your doing by multiplying by (3.14/180) is using the formula for converting degrees to radians, and applying it to something that is already in radians (It's like taking a measurement in inches and multiplying it by twelve). What you want is something like this.
Code:
float magnitude = sqrt(x*x + y*y);
float dx = x/magnitude*SPEED*delta_t; // or you could just insert your own
float dy = y/magnitude*SPEED*delta_t; // velocity vector components
x += dx;
y += dy;
This makes it easy to change your physics system later because you can specify what the velocity vectors are (you can make them exhibit acceleration and inertia).
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Using a matrix to generate a new vector position  imikedaman  6  6,579 
Jul 16, 2006 01:17 PM Last Post: imikedaman 

geting window position  marko  2  3,753 
Jul 24, 2005 02:32 AM Last Post: marko 