Untitled
By: a guest | Mar 19th, 2010 | Syntax:
C++ | Size: 1.68 KB | Hits: 148 | Expires: Never
#include "global.h"
Vector2D::Vector2D ( void ) {
x = y = 0;
}
Vector2D::Vector2D ( float x_in, float y_in ) {
x = x_in;
y = y_in;
}
/*
float Vector2D::getX ( void ) {
return x;
}
float Vector2D::getY ( void ) {
return y;
}
void Vector2D::setX ( float x_in ) {
x = x_in;
}
void Vector2D::setY ( float y_in ) {
y = y_in;
}
void Vector2D::setBoth ( float x_in, float y_in ) {
x = x_in;
y = y_in;
}
*/
Vector2D Vector2D::operator += ( float f_in ) {
x += f_in;
y += f_in;
return Vector2D ( x, y );
}
Vector2D Vector2D::operator -= ( float f_in ) {
x -= f_in;
y -= f_in;
return Vector2D ( x, y );
}
Vector2D Vector2D::operator *= ( float f_in ) {
x *= f_in;
y *= f_in;
return Vector2D ( x, y );
}
Vector2D Vector2D::operator /= ( float f_in ) {
x /= f_in;
y /= f_in;
return Vector2D ( x, y );
}
Vector2D Vector2D::operator += ( Vector2D temp ) {
x += temp.x;
y += temp.y;
return Vector2D ( x, y );
}
Vector2D Vector2D::operator -= ( Vector2D temp ) {
x -= temp.x;
y -= temp.y;
return Vector2D ( x, y );
}
Vector2D Vector2D::operator *= ( Vector2D temp ) {
x *= temp.x;
y *= temp.y;
return Vector2D ( x, y );
}
Vector2D Vector2D::operator /= ( Vector2D temp ) {
x /= temp.x;
y /= temp.y;
return Vector2D ( x, y );
}
void Vector2D::rotate ( float degrees ) {
float angle = ( degrees * ( PI / 180 ) );
x = ( x * cos(angle) ) - ( y * sin(angle) );
y = ( y * cos(angle) ) + ( x * sin(angle) );
}
void Vector2D::normalize ( void ) {
float magnitude = sqrt ( ( x * x ) + ( y * y ) );
x /= magnitude;
y /= magnitude;
}