Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 19th, 2010 | Syntax: C++ | Size: 1.68 KB | Hits: 148 | Expires: Never
Copy text to clipboard
  1. #include "global.h"
  2.  
  3. Vector2D::Vector2D ( void ) {
  4.  
  5.         x = y = 0;
  6.  
  7. }
  8.  
  9. Vector2D::Vector2D ( float x_in, float y_in ) {
  10.  
  11.         x = x_in;
  12.         y = y_in;
  13.  
  14. }
  15.  
  16. /*
  17. float Vector2D::getX ( void ) {
  18.  
  19.         return x;
  20.  
  21. }
  22.  
  23. float Vector2D::getY ( void ) {
  24.  
  25.         return y;
  26.  
  27. }
  28.  
  29. void Vector2D::setX ( float x_in ) {
  30.  
  31.         x = x_in;
  32.  
  33. }
  34.  
  35. void Vector2D::setY ( float y_in ) {
  36.  
  37.         y = y_in;
  38.  
  39. }
  40.  
  41. void Vector2D::setBoth ( float x_in, float y_in ) {
  42.  
  43.         x = x_in;
  44.         y = y_in;
  45.  
  46. }
  47. */
  48.  
  49. Vector2D Vector2D::operator += ( float f_in ) {
  50.  
  51.         x += f_in;
  52.         y += f_in;
  53.         return Vector2D ( x, y );
  54.  
  55. }
  56.  
  57. Vector2D Vector2D::operator -= ( float f_in ) {
  58.  
  59.         x -= f_in;
  60.         y -= f_in;
  61.         return Vector2D ( x, y );
  62.  
  63. }
  64.  
  65. Vector2D Vector2D::operator *= ( float f_in ) {
  66.  
  67.         x *= f_in;
  68.         y *= f_in;
  69.         return Vector2D ( x, y );
  70.  
  71. }
  72.  
  73. Vector2D Vector2D::operator /= ( float f_in ) {
  74.  
  75.         x /= f_in;
  76.         y /= f_in;
  77.         return Vector2D ( x, y );
  78.  
  79. }
  80.  
  81. Vector2D Vector2D::operator += ( Vector2D temp ) {
  82.  
  83.         x += temp.x;
  84.         y += temp.y;
  85.         return Vector2D ( x, y );
  86.  
  87. }
  88.  
  89. Vector2D Vector2D::operator -= ( Vector2D temp ) {
  90.  
  91.         x -= temp.x;
  92.         y -= temp.y;
  93.         return Vector2D ( x, y );
  94.  
  95. }
  96.  
  97. Vector2D Vector2D::operator *= ( Vector2D temp ) {
  98.  
  99.         x *= temp.x;
  100.         y *= temp.y;
  101.         return Vector2D ( x, y );
  102.  
  103. }
  104.  
  105. Vector2D Vector2D::operator /= ( Vector2D temp ) {
  106.  
  107.         x /= temp.x;
  108.         y /= temp.y;
  109.         return Vector2D ( x, y );
  110.  
  111. }
  112.  
  113. void Vector2D::rotate ( float degrees ) {
  114.  
  115.         float angle = ( degrees * ( PI / 180 ) );
  116.  
  117.         x = ( x * cos(angle) ) - ( y * sin(angle) );
  118.         y = ( y * cos(angle) ) + ( x * sin(angle) );
  119.  
  120. }
  121.  
  122. void Vector2D::normalize ( void ) {
  123.  
  124.         float magnitude = sqrt ( ( x * x ) + ( y * y ) );
  125.         x /= magnitude;
  126.         y /= magnitude;
  127.  
  128. }