Important facts about commercial licenses

  • Licenses are perpetual. They do not expire and do not need to be renewed.
  • Licenses can be upgraded. You can upgrade to a more expensive license later paying only the difference in cost.
  • Pay attention to the distribution type - Hosted (sites / servers), binary (applications) or source (includes all the others). Choose according to your needs (more below).
  • All licenses allow commercial use unless otherwise indicated.
  • Read the full license by clicking on the icon.
  • Read more about licenses in our handy license guide.
$4

Personal License

1 application Binary restricted distribution
You need to log-in or create an account
  • Create an account
  • Log-in
  • Please use your real name.
  • Account activation link will be sent to this address.
  • Minimum 8 characters

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

2d vector handling class

2d vector handling class
Developed by vincenzo panella, Released May 14, 2011

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

C/C++

Tags: 2d , game programming , math , vector

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

User Reviews

No reviews have been submitted yet.

Questions & Comments


Or enter your name and Email
No comments have been posted yet.
You must be logged-in to vote. Log-in to your account or register now.