cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
297 lines (296 loc) • 7 kB
JavaScript
import vec4 from "../glmatrix/vec4.mjs";
var Vector4 = function(x, y, z, w) {
x = x || 0;
y = y || 0;
z = z || 0;
w = w || 0;
this.array = vec4.fromValues(x, y, z, w);
this._dirty = true;
};
Vector4.prototype = {
constructor: Vector4,
add: function(b) {
vec4.add(this.array, this.array, b.array);
this._dirty = true;
return this;
},
set: function(x, y, z, w) {
this.array[0] = x;
this.array[1] = y;
this.array[2] = z;
this.array[3] = w;
this._dirty = true;
return this;
},
setArray: function(arr) {
this.array[0] = arr[0];
this.array[1] = arr[1];
this.array[2] = arr[2];
this.array[3] = arr[3];
this._dirty = true;
return this;
},
clone: function() {
return new Vector4(this.x, this.y, this.z, this.w);
},
copy: function(b) {
vec4.copy(this.array, b.array);
this._dirty = true;
return this;
},
dist: function(b) {
return vec4.dist(this.array, b.array);
},
distance: function(b) {
return vec4.distance(this.array, b.array);
},
div: function(b) {
vec4.div(this.array, this.array, b.array);
this._dirty = true;
return this;
},
divide: function(b) {
vec4.divide(this.array, this.array, b.array);
this._dirty = true;
return this;
},
dot: function(b) {
return vec4.dot(this.array, b.array);
},
len: function() {
return vec4.len(this.array);
},
length: function() {
return vec4.length(this.array);
},
lerp: function(a, b, t) {
vec4.lerp(this.array, a.array, b.array, t);
this._dirty = true;
return this;
},
min: function(b) {
vec4.min(this.array, this.array, b.array);
this._dirty = true;
return this;
},
max: function(b) {
vec4.max(this.array, this.array, b.array);
this._dirty = true;
return this;
},
mul: function(b) {
vec4.mul(this.array, this.array, b.array);
this._dirty = true;
return this;
},
multiply: function(b) {
vec4.multiply(this.array, this.array, b.array);
this._dirty = true;
return this;
},
negate: function() {
vec4.negate(this.array, this.array);
this._dirty = true;
return this;
},
normalize: function() {
vec4.normalize(this.array, this.array);
this._dirty = true;
return this;
},
random: function(scale) {
vec4.random(this.array, scale);
this._dirty = true;
return this;
},
scale: function(s) {
vec4.scale(this.array, this.array, s);
this._dirty = true;
return this;
},
scaleAndAdd: function(b, s) {
vec4.scaleAndAdd(this.array, this.array, b.array, s);
this._dirty = true;
return this;
},
sqrDist: function(b) {
return vec4.sqrDist(this.array, b.array);
},
squaredDistance: function(b) {
return vec4.squaredDistance(this.array, b.array);
},
sqrLen: function() {
return vec4.sqrLen(this.array);
},
squaredLength: function() {
return vec4.squaredLength(this.array);
},
sub: function(b) {
vec4.sub(this.array, this.array, b.array);
this._dirty = true;
return this;
},
subtract: function(b) {
vec4.subtract(this.array, this.array, b.array);
this._dirty = true;
return this;
},
transformMat4: function(m) {
vec4.transformMat4(this.array, this.array, m.array);
this._dirty = true;
return this;
},
transformQuat: function(q) {
vec4.transformQuat(this.array, this.array, q.array);
this._dirty = true;
return this;
},
toString: function() {
return "[" + Array.prototype.join.call(this.array, ",") + "]";
},
toArray: function() {
return Array.prototype.slice.call(this.array);
}
};
var defineProperty = Object.defineProperty;
if (defineProperty) {
var proto = Vector4.prototype;
defineProperty(proto, "x", {
get: function() {
return this.array[0];
},
set: function(value) {
this.array[0] = value;
this._dirty = true;
}
});
defineProperty(proto, "y", {
get: function() {
return this.array[1];
},
set: function(value) {
this.array[1] = value;
this._dirty = true;
}
});
defineProperty(proto, "z", {
get: function() {
return this.array[2];
},
set: function(value) {
this.array[2] = value;
this._dirty = true;
}
});
defineProperty(proto, "w", {
get: function() {
return this.array[3];
},
set: function(value) {
this.array[3] = value;
this._dirty = true;
}
});
}
Vector4.add = function(out, a, b) {
vec4.add(out.array, a.array, b.array);
out._dirty = true;
return out;
};
Vector4.set = function(out, x, y, z, w) {
vec4.set(out.array, x, y, z, w);
out._dirty = true;
};
Vector4.copy = function(out, b) {
vec4.copy(out.array, b.array);
out._dirty = true;
return out;
};
Vector4.dist = function(a, b) {
return vec4.distance(a.array, b.array);
};
Vector4.distance = Vector4.dist;
Vector4.div = function(out, a, b) {
vec4.divide(out.array, a.array, b.array);
out._dirty = true;
return out;
};
Vector4.divide = Vector4.div;
Vector4.dot = function(a, b) {
return vec4.dot(a.array, b.array);
};
Vector4.len = function(b) {
return vec4.length(b.array);
};
Vector4.lerp = function(out, a, b, t) {
vec4.lerp(out.array, a.array, b.array, t);
out._dirty = true;
return out;
};
Vector4.min = function(out, a, b) {
vec4.min(out.array, a.array, b.array);
out._dirty = true;
return out;
};
Vector4.max = function(out, a, b) {
vec4.max(out.array, a.array, b.array);
out._dirty = true;
return out;
};
Vector4.mul = function(out, a, b) {
vec4.multiply(out.array, a.array, b.array);
out._dirty = true;
return out;
};
Vector4.multiply = Vector4.mul;
Vector4.negate = function(out, a) {
vec4.negate(out.array, a.array);
out._dirty = true;
return out;
};
Vector4.normalize = function(out, a) {
vec4.normalize(out.array, a.array);
out._dirty = true;
return out;
};
Vector4.random = function(out, scale) {
vec4.random(out.array, scale);
out._dirty = true;
return out;
};
Vector4.scale = function(out, a, scale) {
vec4.scale(out.array, a.array, scale);
out._dirty = true;
return out;
};
Vector4.scaleAndAdd = function(out, a, b, scale) {
vec4.scaleAndAdd(out.array, a.array, b.array, scale);
out._dirty = true;
return out;
};
Vector4.sqrDist = function(a, b) {
return vec4.sqrDist(a.array, b.array);
};
Vector4.squaredDistance = Vector4.sqrDist;
Vector4.sqrLen = function(a) {
return vec4.sqrLen(a.array);
};
Vector4.squaredLength = Vector4.sqrLen;
Vector4.sub = function(out, a, b) {
vec4.subtract(out.array, a.array, b.array);
out._dirty = true;
return out;
};
Vector4.subtract = Vector4.sub;
Vector4.transformMat4 = function(out, a, m) {
vec4.transformMat4(out.array, a.array, m.array);
out._dirty = true;
return out;
};
Vector4.transformQuat = function(out, a, q) {
vec4.transformQuat(out.array, a.array, q.array);
out._dirty = true;
return out;
};
var Vector4$1 = Vector4;
export { Vector4$1 as default };