// Vector2D.h: interface for the Vector2D class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_VECTOR2D_H__10DC890D_E8A3_4287_9377_95C7E6012455__INCLUDED_)
#define AFX_VECTOR2D_H__10DC890D_E8A3_4287_9377_95C7E6012455__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <d3dx9.h>

//const float PI = 3.14159f;

class Vector2D
{
public:
	
	Vector2D operator- () const;

	//Vector2D& operator=  (const D3DXVECTOR2& A){x = A.x; y = A.y;};
	Vector2D& operator+= (const Vector2D& A);
	Vector2D& operator-= (const Vector2D& A);
	Vector2D& operator*= (float F);
	Vector2D& operator/= (float F);
	
	Vector2D operator+ (const Vector2D& A) const;
	Vector2D operator- (const Vector2D& A) const;
	friend Vector2D operator* (const Vector2D& A, float B);
	friend Vector2D operator/ (const Vector2D& A, float B);
	friend Vector2D operator* (const float A, const Vector2D& B);

	friend float CrossProduct(const Vector2D& A, const Vector2D& B);
	friend float DotProduct(const Vector2D& A, const Vector2D& B);

    void setPolar(float angle, float mag);
	void setMagnitude(float mag);
	float squared_magnitude() const;
	float magnitude() const;
	Vector2D normalized() const;
	float angle() const;
	float angle(const Vector2D& A); // angle between this vector and A

	Vector2D(float newx, float newy);
	Vector2D(const D3DXVECTOR2& A){x = A.x; y = A.y;};
	Vector2D(){};
	virtual ~Vector2D(){};

	float x,y;
};

inline Vector2D Vector2D::operator- () const
{
	return Vector2D(-x, -y);
}

inline Vector2D& Vector2D::operator+= (const Vector2D& A)
{
	x += A.x;
	y += A.y;
	return *this;
}

inline Vector2D& Vector2D::operator-= (const Vector2D& A)
{
	x -= A.x;
	y -= A.y;
	return *this;
}

inline Vector2D& Vector2D::operator*= (float F)
{
	x *= F;
	y *= F;
	return *this;
}

inline Vector2D& Vector2D::operator/= (float F)
{
	x /= F;
	y /= F;
	return *this;
}

inline Vector2D Vector2D::operator+ (const Vector2D& A) const
{
	return Vector2D(A.x+x, A.y+y);
}

inline Vector2D Vector2D::operator- (const Vector2D& A) const
{
	return Vector2D(x-A.x, y-A.y);
}

inline Vector2D operator* (const Vector2D& A, float B)
{
	return Vector2D(A.x * B, A.y * B);
}

inline Vector2D operator/ (const Vector2D& A, float B)
{
	return Vector2D(A.x / B, A.y / B);
}

inline Vector2D operator* (const float A, const Vector2D& B)
{
	return Vector2D(B.x * A, B.y * A);
}

inline float Vector2D::squared_magnitude() const
{
	return (x*x + y*y);
}

inline float CrossProduct(const Vector2D& A, const Vector2D& B)
{
	return (A.x * B.y - B.x * A.y);
}

inline float DotProduct(const Vector2D& A, const Vector2D& B)
{
	return (A.x * B.x + A.y * B.y);
}

#endif // !defined(AFX_VECTOR2D_H__10DC890D_E8A3_4287_9377_95C7E6012455__INCLUDED_)
