var vector = function(x, y, z) {
this[0] = x || 0;
this[1] = y || 0;
this[2] = z || 0;
};
vector.prototype = new Float32Array(3);
vector.prototype.getLength = function() {
return Math.sqrt(Math.pow(this[0],2)+Math.pow(this[1],2)+Math.pow(this[2],2));
};
The vector is a float32array with 3 elements. I have no idea why it doesn't work. If I run this code, I get an error: 'vec3.length' is not a function
var vec3 = new vector(3,4,5);
alert(vec3.getLength());
Edit: I replaced length
with getLength
. Now it works everywhere except in firefox.