-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVec3.js
42 lines (41 loc) · 828 Bytes
/
Vec3.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
38
39
40
41
42
function Vec3()
{
this.x;this.y;this.z;
this.dim = 3;
}
Vec3.prototype.length = function()
{
return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);
}
Vec3.prototype.normalize = function()
{
this.x = this.x/this.length();
this.y = this.y/this.length();
this.z = this.z/this.length();
}
Vec3.prototype.toVec4 = function()
{
var mvec4 = new Vec4();
mvec4.x = this.x; mvec4.y = this.y; mvec4.z = this.z;
mvec4.w = 1;
return mvec4;
}
Vec3.prototype.toArray = function()
{
var array = new Array(3);
array = [this.x,this.y,this.z];
return array;
}
Vec3.prototype.getFromArray = function(array)
{
this.x = array[0];
this.y = array[1];
this.z = array[2];
this.w = array[3];
}
Vec3.prototype.clone = function()
{
var clonedVec3 = new Vec3();
clonedVec3.getFromArray(this.toArray().clone());
return clonedVec3;
}