-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vec4.js
37 lines (37 loc) · 806 Bytes
/
Vec4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function Vec4()
{
this.x;this.y;this.z;this.w;
this.dim = 4;
}
Vec4.prototype.toArray = function()
{
var array = [this.x,this.y,this.z,this.w];
return array;
}
Vec4.prototype.getFromArray = function(array)
{
this.x = array[0];this.y = array[1];this.z = array[2];this.w = array[3];
}
Vec4.prototype.clone = function()
{
var clonedVec4 = new Vec4();
clonedVec4.getFromArray(this.toArray().clone());
return clonedVec4;
}
Vec4.prototype.toVec3 = function()
{
var mvec3 = new Vec3();
mvec3.x = this.x;
mvec3.y = this.y;
mvec3.z = this.z;
return mvec3;
}
Vec4.prototype.vecMul = function(vec)
{
var result;
if(vec.dim == 3)
result.getFromArray([vec.x*this.x,vec.y*this.y,vec.z*this.z,this.w]);
else
result.getFromArray([vec.x*this.x,vec.y*this.y,vec.z*this.z,vec.w*this.w]);
return result;
}