Thomas;

Thanks for sending this along and am happy to rewrite / send along some code. :)

-Will check back in on the 'morrow witcha! -I'm a sleepy girl now!…

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.
float Calculate::GetDirection (double x1, double z1, double x2, double z2)
{

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

// Subtract z1 from z2
 double z = z2 - z1;

// Calculate theta by the arc tangent
// of -x*z
 double theta = std::atan2 (-x, z);

// 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 vector.
float Calculate::GetX (double direction, double x, double velocity)
{

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

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

// Name: GetZ(double, double, double).
// Description: Calculates the next possible z vector.
float Calculate::GetZ (double direction, double z, double velocity)
{

// Calculate the next z vector by
// multiplying velocity by the cosine of
// direction*PI/180
 z += velocity * std::cos ((direction * PI) / 180);

// Return the new z vector
 return (float)z;
}

Now, looking at these functions I see I didn't use the Pythagorus
Theorem to normalize the distance which would in deed be part of the
problem. If you could remind me how to do this I'd appreciate it. In
fact, if you can rewrite the functions to do this correctly I'd
appreciate it. This will not only improve the SW game it will be a
nice little bug fix for MOTA which also uses the G3D engine too.

On 12/9/10, Cara Quinn <caraqu...@draconisentertainment.com> wrote:
> Thomas;
> 
> -Just a quickie for now;
> 
> How are you working out which direction you'd like to have Mara travel in?
> I'm assuming you're deciding based on a degree and then working out a vector
> from that? How are you creating your vector from your angle? (this might be
> the issue)
> 
> I.E. if you're supposed to be moving at 1 unit, then the proper vector
> length if you're moving at a 45 degree angle, should be something like
> 0.7174, 0.7174 or some such. :) It shouldn't be 1.0, 1.0.
> 
> If it's not less than 1 on each axis, then you'll need to normalize your
> vector using the Pythagorus Theorem to get it to a length of 1 unit.
> 
> Hope this makes sense and talk soon!…
> 
> Smiles,
> 
> Cara :)

---
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