Thomas;

I have a question for you. By removing the + in the getX and getY functions, I 
may have taken out a feature you wanted. Were you just wanting to calculate the 
new vector or actually change Mara's position with the two functions? If you 
simply want to calculate the new movement vector, then the changes I made are 
what you want. If you're wanting to also apply the new vector to Mara's current 
coordinates, then the += are what you want. Sorry if I misinterpreted. :)

The reversal of sine and cosine is still correct though, but I wanted to make 
sure I know what you're after and what code you're using for what. :)

 I personally split up my code into less complex functions and combine them 
rather than placing a lot of  steps in one method. For example, I have one 
method to simply get the angle the player is facing and another method to set 
the angle. So naturally, these really basic functions get called in other 
methods in the course of doing more complex calculations.

Depending on what you want to do, you may not want to normalize as in my second 
note. Normalizing is good if you need to keep a particular vector but change 
its length. I.E. change velocity on a game object.

This brings up an interesting point, in that a vector is not a point. The 
player's position in space can be represented by a point, but their movement 
can be represented with a vector. A vector is in essence, a point's movement in 
a direction over time. the confusion can come because you can represent a 
vector as it's end point. So it's not always easy to tell what someone's code 
is meant to do in this regard. -Know what I mean?… If you project a vector on 
to a point, then you end up with the same vector but another end point. If you 
project a vector on to another vector, you have a third vector. -Confused yet?… 
lol!

Anyway, hope the changes to the code work well.

As a note, my use of X and Y is meant with a positive Z in the up direction.

Smiles,

Cara :)
On Dec 11, 2010, at 10:23 AM, Cara Quinn wrote:

Hi again Thomas;

-A couple of things I forgot to mention in my last note. Firstly, before you 
send x or y to your getX or getY methods, the vector should already be 
normalized. I overlooked this before as I was only looking at what your methods 
were returning.

You can normalize your current vector of travel by doing the following:

• subtract the start and end points of your vector, as in: x2 - x1, y2 - y1, 
and z2 - z1.

• get the length (len) of the vector by first getting the square root of x^2 + 
y^2 + z^2.

• and then divide the vector by the length as in: x = x / len, y = y / len, and 
z = z / len.

• this is your new normalized vector, which you can then magnify (multiply) by 
a desired move rate or some such number to get a proper end point.

HTH!

Cara :)

Hi Thomas;

I'll comment and adapt your code below.

These methods should all return normal vectors anyway, so you shouldn't need to 
normalize. I just did a few tweaks as that's all they seem to need. changed z 
to y for consistency. Let me know how it goes, K?…

Smiles,

Cara :)

On Dec 9, 2010, at 7:22 PM, Thomas Ward wrote:

Hi Cara,

Sure no problem. below is the functions I'm using to calculate the
angle and vector Mara will travel to reach her next coordinates on the
map. However, before you ask the reason the calculations don't have a
fps or time parameter that's because I assume 1 as the frames per
second which is a slow frame rate I know. Here goes.

// Name: GetDirection (double, double, double, double).
// Description: Calculates the angle between
//  two game objects.
// CQ
// will switch your z to y so i can think straight :)

float Calculate::GetDirection (double x1, double y1, double x2, double y2)
{

// CQ
// changing this so both subtractions are in the same order
// as this changes the result

// Subtract x1 from x2
double x = x2 - x1;

// Subtract y1 from y2

double y = y2 - y1;

// CQ
// this should be y over x

// Calculate theta by the arc tangent
// of -y/x

double theta = std::atan2 (y,x);

// Now, multiply theta by 180
// and divide by PI
double direction = (theta * 180) / PI;

// Return the direction
return (float)direction;
}

// Name: GetX(double, double, double).
// Description: Calculates the next possible x component.
float Calculate::GetX (double direction, double x, double velocity)
{

// Calculate the next x component by
// multiplying velocity by the cosine of
// direction*PI/180

// CQ
// switched this to cos and changed calculation slightly

x = velocity * std::cos ((direction * PI) / 180));

// Return the new x component
return (float)x;
}

// Name: GetY(double, double, double).
// Description: Calculates the next possible y component.
float Calculate::GetY (double direction, double y, double velocity)
{

// Calculate the next y component by
// multiplying velocity by the sine of
// direction*PI/180
y = velocity * std::sin ((direction * PI) / 180);

// Return the new y component
return (float)y;
}


---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gam...@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.


---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gam...@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.

Reply via email to