﻿
Vector3.prototype.X = 0;
Vector3.prototype.Y = 0;
Vector3.prototype.Z = 0;

function Vector3(x, y, z)
{
	this.X = x;
	this.Y = y;
	this.Z = z;
}

Vector3.prototype.Normalize = function()
{
	var len = Math.sqrt(this.X*this.X + this.Y*this.Y + this.Z*this.Z);
	this.X /= len;
	this.Y /= len;
	this.Z /= len;
}

function Vector3_Dot(a, b)
{
	return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
}

function Vector3_Cross(a, b)
{
	var outVec = new Vector3(0, 0, 0);
	outVec.X = a.Y * b.Z - a.Z * b.Y;
	outVec.Y = a.Z * b.X - a.X * b.Z;
	outVec.Z = a.X * b.Y - a.Y * b.X;
	return outVec;
}

function Vector3_Transform(vSrc, mat)
{
	//dd("M11 = " + mat.M11 + "   M21 = " + mat.M21 + "   M31 = " + mat.M31 + "   M41 = " + mat.M41);
	var vDest = new Vector4(0, 0, 0, 0);
	vDest.X = vSrc.X * mat.M11 + vSrc.Y * mat.M21 + vSrc.Z * mat.M31 + mat.M41;
	vDest.Y = vSrc.X * mat.M12 + vSrc.Y * mat.M22 + vSrc.Z * mat.M32 + mat.M42;
	vDest.Z = vSrc.X * mat.M13 + vSrc.Y * mat.M23 + vSrc.Z * mat.M33 + mat.M43;
	vDest.W = vSrc.X * mat.M14 + vSrc.Y * mat.M24 + vSrc.Z * mat.M34 + mat.M44;

	return vDest;
}

