2d vector handling class

2d vector handling class

Released 4 years ago , Last update 4 years ago

Fast 2d vector handling class by templated operators overload. Useful for game development, or math programming.

This class manages 2d vectors by templated , overloaded operators. Common operations included are scaling, sum, subtraction, dotproduct, modulus, distance , squared distance and others, angle beetween vectors , also templated types for the most used numeric formats are included.

Usage examples :

CVec2f v1,v2,v3;

float d,l;

v1.set( 10,20 );            // initialise vectors

v2.set( 30,40 );            // initialise vectors

v3=v1-v2;                    // subtraction

v3=v1+v2;                   // addition

v3=-v1-v2;                  // sign before vector argument

v3+=v1;                      // increment

v3-=v1;                       // decrement

v1=v2*10.0f;               // scaling

v1*=10.0f;                   // scaling

v2=v3/10.0f;               // inverse scaling

v3/=5.0f;                    // inverse scaling


v3=lerp( v1,v2,0.5 );  // linear interpolation between vectors


v3= project ( v1,v2 ); // Calculates the projection of  v1 onto v2

v3=perpendicular( v1,v2 ); // Calculates the component of v1 perpendicular to v2

v3=orthogonalize( v1,v2 );   // orthogonalization

v3 = cross ( v2,v1 );  // vectorial cross product

v3=reflect( v1, v2 ); // reflect vector v1 respect v2

d= dot( v1,v2 );         // dot product

v3.normalize();         // normalize vector

l=v1.length();            // lenght of vector

l=v1.squaredlength();   // squared lenght

v2.zero();          // sets all vector components to zero

v1.fabsf(); // absoulte values for each vector components

// logic comparisons

if ( v2!=v1 ) cout << "vectors are different";
if ( v2==v1 ) cout << "vectors are identical";
if ( v2>=v1 ) cout << "vectors v2 is greater or equal than v1";
if ( v2<=v1 ) cout << "vectors v2 is smaller or equal than v1";
if ( v2>v1 ) cout << "vectors v2 is greater than v1";
if ( v2

Pricing

$4.99

Personal License

  • Perpetual license

  • 1 application

  • Can distribute binary products only

  • Commercial use

1 license From » $4.99 View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.


Or enter your name and Email
No comments have been posted yet.