Jump to content
  • Advertisement


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


vector library

This topic is 6718 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

I am building a vector library and here are some of the things I am doing. Any comments? I am writing a basic definition, usually a macro, and having another program create several variations of each function with strict naming conventions. For example the average function which computes the average of 2 vectors or points would have all the possible combinations: avrg2 avrg2m avrg3 avrg3m avrg3p avrg3pm The number represents the dimension. The p represents ''projected'' and takes 2 additional arguments, i1 and i2, which define the indices we want projected, ignoring the other index. The m, if present, means modify the 1st argument, instead of placing the result in a 3rd term. All arguments are passed in as pointers to indexed arrays. All functions return the pointer to the resulting vector, or a single value, if that is all that is calculated. Here are some of the functions I have come up with: abs of a vector index of min component of a vector value of min component of a vector index of max component of a vector value of max component of a vector initialize a vector copy a vector swap 2 vectors dot product lerp between 2 vectors or points (linear interpolation) average of 2 vectors squared magnitude of a vector magnitude of a vector addition of 2 vectors subtraction of 1 veector from another scale a vector (multiply) divide a vector (inverse of scale) normalize a vector flip a vector (make it 180 degeres of vector) compute a vector from point 1 to point 2 angle between 2 vectors in radians angle between 2 vectors in degrees make a vector face forward in left hand cs make a vector face forward in right hand cs make a vector face backwards in left hand cs make a vector face backward in right hand cs rotate a point on x axis rotate a point on y axis rotate a point on z axis get cross product for left hand cs get cross product for right hand cs get incident vector get refracted vector get a random unit vector get a random unit vector with a distribution biased towards another vector because vectors can also be thought of as rgb colors, some other functions are also useful such as: clamp the components of a vector Any comments or additions to the list?

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!