Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MENTAL

Vectors

This topic is 6701 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way to calculate the life of a vector? I have created a function that will create a vector according to it''s speed, but I dont know how to calculate how long it has to go along for! example below. struct CVector { float X, Y, Z; int Life; // frames remaining }; void CreateVector(CVertex Cur, CVertex Dest, CVector *Vector, float Speed) { CVertex->X = (Cur.X - Dest.X) / Speed; CVertex->Y = (Cur.Y - Dest.Y) / Speed; CVertex->Z = (Cur.Z - Dest.Z) / Speed; CVertex->Life = ????? } With regards to the life, it would be better if the vector overshot the destination rather than not reach it. i know this is probably obvious, but please help! MENTAL

Share this post


Link to post
Share on other sites
Advertisement
The vector dissipates at whatever rate you want. Perhaps you can set it to 100 make it a float and go

#define Dissipation 0.95

Life = Life * Dissipation

Each frame you do this and it should go down to 0. If you want to do frames remaining, then caluclating the length of frames depends on the time. For instance, if you want the vector to last 3 seconds, you go

Life = 3 * CurrentFrameRate

That should make it last three seconds. Determining how long the vector lasts depends on what the vector is.

Share this post


Link to post
Share on other sites
The "life" of a vector has no meaning. A vector by definition is a magnitude & a direction. Its nothing more.

It sounds like what you might want to do is create a normalized vector (that is, a vector in the direction you want, with a magnitude of 1.0). At a higher level in the code, you would use the vector and the speed to calculate what you''re looking for.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!