#include "vector.h"

namespace ngObjects
{
	vector3D::vector3D(GLfloat newX, GLfloat newY, GLfloat newZ)
	{
		x = newX;
		y = newY;
		z = newZ;
	}

	vector3D vector3D::cross(vector3D otherVector)
	{
		vector3D normal;
		normal.x = ((y * otherVector.z) - (z * otherVector.y));
		normal.y = ((z * otherVector.x) - (x * otherVector.z));
		normal.z = ((x * otherVector.y) - (y * otherVector.x));
		return normal;
	}

	float vector3D::dot(vector3D otherVector)
	{
		float scalar;
		scalar = (x * otherVector.x)+(y * otherVector.y) + (z * otherVector.z);
		return scalar;
	}

	float vector3D::magnitude()
	{
		return (float)sqrt((x * x) + (y * y) + (z * z));
	}

	void vector3D::move(float newAngle, float acc)
	{
		float newX, newZ;	

		angle = newAngle-90;
		newX = (float)(acc * cos(angle * (3.14159 / 180)));
		newZ = (float)(acc * sin(angle *(3.14159 / 180)));

		x = x + (-1 * newX);
		z = z + newZ;
	}

	vector3D vector3D::operator *(float num)
	{
		return vector3D(num * x, num * y, num * z);
	}

	vector3D vector3D::operator *=(float num)
	{
		x *= num;
		y *= num;
		z *= num;

		return *this;
	}

	vector3D vector3D::operator +(vector3D addVector)
	{
		return vector3D(addVector.x + x, addVector.y + y, addVector.z + z);
	}

	vector3D vector3D::operator +=(vector3D addVector)
	{
		addVector.x += x;
		addVector.y += y;
		addVector.z += z;

		return *this;
	}

	vector3D vector3D::operator -(vector3D subVector)
	{
		return vector3D(subVector.x - x, subVector.y - y, subVector.z - z);
	}

	vector3D vector3D::operator -=(vector3D addVector)
	{
		addVector.x -= x;
		addVector.y -= y;
		addVector.z -= z;

		return *this;
	}

	vector3D vector3D::operator /(vector3D divVector)
	{
		return vector3D(divVector.x / x, divVector.y / y, divVector.z / z);
	}
}
