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 __ [email protected]
If you want to leave the list, send E-mail to [email protected].
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/[email protected].
If you have any questions or concerns regarding the management of the list,
please send E-mail to [email protected].