Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/globalscripts/vector.js
Show All 24 Lines | |||||
Vector2D.prototype.set = function(x, y) | Vector2D.prototype.set = function(x, y) | ||||
{ | { | ||||
this.x = x; | this.x = x; | ||||
this.y = y; | this.y = y; | ||||
return this; | return this; | ||||
}; | }; | ||||
Vector2D.prototype.setFrom = function(v) | |||||
{ | |||||
this.x = v.x; | |||||
this.y = v.y; | |||||
return this; | |||||
}; | |||||
Vector2D.prototype.add = function(v) | Vector2D.prototype.add = function(v) | ||||
{ | { | ||||
this.x += v.x; | this.x += v.x; | ||||
this.y += v.y; | this.y += v.y; | ||||
return this; | return this; | ||||
}; | }; | ||||
Vector2D.prototype.sub = function(v) | Vector2D.prototype.sub = function(v) | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | Vector2D.sum = function(vectorList) | ||||
let sum = new Vector2D(); | let sum = new Vector2D(); | ||||
for (let i = 0; i < vectorList.length; ++i) | for (let i = 0; i < vectorList.length; ++i) | ||||
sum.add(vectorList[i]); | sum.add(vectorList[i]); | ||||
return sum; | return sum; | ||||
}; | }; | ||||
Vector2D.dot = function(v1, v2) | |||||
{ | |||||
return v1.x * v2.x + v1.y * v2.y; | |||||
}; | |||||
///////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////// | ||||
// Vector3D | // Vector3D | ||||
// | // | ||||
// Class for representing and manipulating 3D vectors | // Class for representing and manipulating 3D vectors | ||||
// | // | ||||
///////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////// | ||||
function Vector3D(x = 0, y = 0, z = 0) | function Vector3D(x = 0, y = 0, z = 0) | ||||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator