code
stringlengths 10
343k
| docstring
stringlengths 36
21.9k
| func_name
stringlengths 1
3.35k
| language
stringclasses 1
value | repo
stringlengths 7
58
| path
stringlengths 4
131
| url
stringlengths 44
195
| license
stringclasses 5
values |
---|---|---|---|---|---|---|---|
Mat33.prototype.get = function get() {
return this.values;
}; | Return the values in the Mat33 as an array.
@method
@return {Array} matrix values as array of rows. | get ( ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.prototype.set = function set(values) {
this.values = values;
return this;
}; | Set the values of the current Mat33.
@method
@param {Array} values Array of nine numbers to set in the Mat33.
@return {Mat33} this | set ( values ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.prototype.copy = function copy(matrix) {
var A = this.values;
var B = matrix.values;
A[0] = B[0];
A[1] = B[1];
A[2] = B[2];
A[3] = B[3];
A[4] = B[4];
A[5] = B[5];
A[6] = B[6];
A[7] = B[7];
A[8] = B[8];
return this;
}; | Copy the values of the input Mat33.
@method
@param {Mat33} matrix The Mat33 to copy.
@return {Mat33} this | copy ( matrix ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.prototype.vectorMultiply = function vectorMultiply(v, output) {
var M = this.values;
var v0 = v.x;
var v1 = v.y;
var v2 = v.z;
output.x = M[0]*v0 + M[1]*v1 + M[2]*v2;
output.y = M[3]*v0 + M[4]*v1 + M[5]*v2;
output.z = M[6]*v0 + M[7]*v1 + M[8]*v2;
return output;
}; | Take this Mat33 as A, input vector V as a column vector, and return Mat33 product (A)(V).
@method
@param {Vec3} v Vector to rotate.
@param {Vec3} output Vec3 in which to place the result.
@return {Vec3} The input vector after multiplication. | vectorMultiply ( v , output ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.prototype.multiply = function multiply(matrix) {
var A = this.values;
var B = matrix.values;
var A0 = A[0];
var A1 = A[1];
var A2 = A[2];
var A3 = A[3];
var A4 = A[4];
var A5 = A[5];
var A6 = A[6];
var A7 = A[7];
var A8 = A[8];
var B0 = B[0];
var B1 = B[1];
var B2 = B[2];
var B3 = B[3];
var B4 = B[4];
var B5 = B[5];
var B6 = B[6];
var B7 = B[7];
var B8 = B[8];
A[0] = A0*B0 + A1*B3 + A2*B6;
A[1] = A0*B1 + A1*B4 + A2*B7;
A[2] = A0*B2 + A1*B5 + A2*B8;
A[3] = A3*B0 + A4*B3 + A5*B6;
A[4] = A3*B1 + A4*B4 + A5*B7;
A[5] = A3*B2 + A4*B5 + A5*B8;
A[6] = A6*B0 + A7*B3 + A8*B6;
A[7] = A6*B1 + A7*B4 + A8*B7;
A[8] = A6*B2 + A7*B5 + A8*B8;
return this;
}; | Multiply the provided Mat33 with the current Mat33. Result is (this) * (matrix).
@method
@param {Mat33} matrix Input Mat33 to multiply on the right.
@return {Mat33} this | multiply ( matrix ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.prototype.transpose = function transpose() {
var M = this.values;
var M1 = M[1];
var M2 = M[2];
var M3 = M[3];
var M5 = M[5];
var M6 = M[6];
var M7 = M[7];
M[1] = M3;
M[2] = M6;
M[3] = M1;
M[5] = M7;
M[6] = M2;
M[7] = M5;
return this;
}; | Transposes the Mat33.
@method
@return {Mat33} this | transpose ( ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.prototype.getDeterminant = function getDeterminant() {
var M = this.values;
var M3 = M[3];
var M4 = M[4];
var M5 = M[5];
var M6 = M[6];
var M7 = M[7];
var M8 = M[8];
var det = M[0]*(M4*M8 - M5*M7) -
M[1]*(M3*M8 - M5*M6) +
M[2]*(M3*M7 - M4*M6);
return det;
}; | The determinant of the Mat33.
@method
@return {Number} The determinant. | getDeterminant ( ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.prototype.inverse = function inverse() {
var M = this.values;
var M0 = M[0];
var M1 = M[1];
var M2 = M[2];
var M3 = M[3];
var M4 = M[4];
var M5 = M[5];
var M6 = M[6];
var M7 = M[7];
var M8 = M[8];
var det = M0*(M4*M8 - M5*M7) -
M1*(M3*M8 - M5*M6) +
M2*(M3*M7 - M4*M6);
if (Math.abs(det) < 1e-40) return null;
det = 1 / det;
M[0] = (M4*M8 - M5*M7) * det;
M[3] = (-M3*M8 + M5*M6) * det;
M[6] = (M3*M7 - M4*M6) * det;
M[1] = (-M1*M8 + M2*M7) * det;
M[4] = (M0*M8 - M2*M6) * det;
M[7] = (-M0*M7 + M1*M6) * det;
M[2] = (M1*M5 - M2*M4) * det;
M[5] = (-M0*M5 + M2*M3) * det;
M[8] = (M0*M4 - M1*M3) * det;
return this;
}; | The inverse of the Mat33.
@method
@return {Mat33} this | inverse ( ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.clone = function clone(m) {
return new Mat33(m.values.slice());
}; | Clones the input Mat33.
@method
@param {Mat33} m Mat33 to clone.
@return {Mat33} New copy of the original Mat33. | clone ( m ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.inverse = function inverse(matrix, output) {
var M = matrix.values;
var result = output.values;
var M0 = M[0];
var M1 = M[1];
var M2 = M[2];
var M3 = M[3];
var M4 = M[4];
var M5 = M[5];
var M6 = M[6];
var M7 = M[7];
var M8 = M[8];
var det = M0*(M4*M8 - M5*M7) -
M1*(M3*M8 - M5*M6) +
M2*(M3*M7 - M4*M6);
if (Math.abs(det) < 1e-40) return null;
det = 1 / det;
result[0] = (M4*M8 - M5*M7) * det;
result[3] = (-M3*M8 + M5*M6) * det;
result[6] = (M3*M7 - M4*M6) * det;
result[1] = (-M1*M8 + M2*M7) * det;
result[4] = (M0*M8 - M2*M6) * det;
result[7] = (-M0*M7 + M1*M6) * det;
result[2] = (M1*M5 - M2*M4) * det;
result[5] = (-M0*M5 + M2*M3) * det;
result[8] = (M0*M4 - M1*M3) * det;
return output;
}; | The inverse of the Mat33.
@method
@param {Mat33} matrix Mat33 to invert.
@param {Mat33} output Mat33 in which to place the result.
@return {Mat33} The Mat33 after the invert. | inverse ( matrix , output ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.transpose = function transpose(matrix, output) {
var M = matrix.values;
var result = output.values;
var M0 = M[0];
var M1 = M[1];
var M2 = M[2];
var M3 = M[3];
var M4 = M[4];
var M5 = M[5];
var M6 = M[6];
var M7 = M[7];
var M8 = M[8];
result[0] = M0;
result[1] = M3;
result[2] = M6;
result[3] = M1;
result[4] = M4;
result[5] = M7;
result[6] = M2;
result[7] = M5;
result[8] = M8;
return output;
}; | Transposes the Mat33.
@method
@param {Mat33} matrix Mat33 to transpose.
@param {Mat33} output Mat33 in which to place the result.
@return {Mat33} The Mat33 after the transpose. | transpose ( matrix , output ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.add = function add(matrix1, matrix2, output) {
var A = matrix1.values;
var B = matrix2.values;
var result = output.values;
var A0 = A[0];
var A1 = A[1];
var A2 = A[2];
var A3 = A[3];
var A4 = A[4];
var A5 = A[5];
var A6 = A[6];
var A7 = A[7];
var A8 = A[8];
var B0 = B[0];
var B1 = B[1];
var B2 = B[2];
var B3 = B[3];
var B4 = B[4];
var B5 = B[5];
var B6 = B[6];
var B7 = B[7];
var B8 = B[8];
result[0] = A0 + B0;
result[1] = A1 + B1;
result[2] = A2 + B2;
result[3] = A3 + B3;
result[4] = A4 + B4;
result[5] = A5 + B5;
result[6] = A6 + B6;
result[7] = A7 + B7;
result[8] = A8 + B8;
return output;
}; | Add the provided Mat33's.
@method
@param {Mat33} matrix1 The left Mat33.
@param {Mat33} matrix2 The right Mat33.
@param {Mat33} output Mat33 in which to place the result.
@return {Mat33} The result of the addition. | add ( matrix1 , matrix2 , output ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.subtract = function subtract(matrix1, matrix2, output) {
var A = matrix1.values;
var B = matrix2.values;
var result = output.values;
var A0 = A[0];
var A1 = A[1];
var A2 = A[2];
var A3 = A[3];
var A4 = A[4];
var A5 = A[5];
var A6 = A[6];
var A7 = A[7];
var A8 = A[8];
var B0 = B[0];
var B1 = B[1];
var B2 = B[2];
var B3 = B[3];
var B4 = B[4];
var B5 = B[5];
var B6 = B[6];
var B7 = B[7];
var B8 = B[8];
result[0] = A0 - B0;
result[1] = A1 - B1;
result[2] = A2 - B2;
result[3] = A3 - B3;
result[4] = A4 - B4;
result[5] = A5 - B5;
result[6] = A6 - B6;
result[7] = A7 - B7;
result[8] = A8 - B8;
return output;
}; | Subtract the provided Mat33's.
@method
@param {Mat33} matrix1 The left Mat33.
@param {Mat33} matrix2 The right Mat33.
@param {Mat33} output Mat33 in which to place the result.
@return {Mat33} The result of the subtraction. | subtract ( matrix1 , matrix2 , output ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
Mat33.multiply = function multiply(matrix1, matrix2, output) {
var A = matrix1.values;
var B = matrix2.values;
var result = output.values;
var A0 = A[0];
var A1 = A[1];
var A2 = A[2];
var A3 = A[3];
var A4 = A[4];
var A5 = A[5];
var A6 = A[6];
var A7 = A[7];
var A8 = A[8];
var B0 = B[0];
var B1 = B[1];
var B2 = B[2];
var B3 = B[3];
var B4 = B[4];
var B5 = B[5];
var B6 = B[6];
var B7 = B[7];
var B8 = B[8];
result[0] = A0*B0 + A1*B3 + A2*B6;
result[1] = A0*B1 + A1*B4 + A2*B7;
result[2] = A0*B2 + A1*B5 + A2*B8;
result[3] = A3*B0 + A4*B3 + A5*B6;
result[4] = A3*B1 + A4*B4 + A5*B7;
result[5] = A3*B2 + A4*B5 + A5*B8;
result[6] = A6*B0 + A7*B3 + A8*B6;
result[7] = A6*B1 + A7*B4 + A8*B7;
result[8] = A6*B2 + A7*B5 + A8*B8;
return output;
}; | Multiply the provided Mat33 M2 with this Mat33. Result is (this) * (M2).
@method
@param {Mat33} matrix1 The left Mat33.
@param {Mat33} matrix2 The right Mat33.
@param {Mat33} output Mat33 in which to place the result.
@return {Mat33} the result of the multiplication. | multiply ( matrix1 , matrix2 , output ) | javascript | Famous/engine | math/Mat33.js | https://github.com/Famous/engine/blob/master/math/Mat33.js | MIT |
var Vec2 = function(x, y) {
if (x instanceof Array || x instanceof Float32Array) {
this.x = x[0] || 0;
this.y = x[1] || 0;
}
else {
this.x = x || 0;
this.y = y || 0;
}
}; | A two-dimensional vector.
@class Vec2
@param {Number} x The x component.
@param {Number} y The y component. | Vec2 ( x , y ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.set = function set(x, y) {
if (x != null) this.x = x;
if (y != null) this.y = y;
return this;
}; | Set the components of the current Vec2.
@method
@param {Number} x The x component.
@param {Number} y The y component.
@return {Vec2} this | set ( x , y ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.add = function add(v) {
this.x += v.x;
this.y += v.y;
return this;
}; | Add the input v to the current Vec2.
@method
@param {Vec2} v The Vec2 to add.
@return {Vec2} this | add ( v ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.subtract = function subtract(v) {
this.x -= v.x;
this.y -= v.y;
return this;
}; | Subtract the input v from the current Vec2.
@method
@param {Vec2} v The Vec2 to subtract.
@return {Vec2} this | subtract ( v ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.scale = function scale(s) {
if (s instanceof Vec2) {
this.x *= s.x;
this.y *= s.y;
}
else {
this.x *= s;
this.y *= s;
}
return this;
}; | Scale the current Vec2 by a scalar or Vec2.
@method
@param {Number|Vec2} s The Number or vec2 by which to scale.
@return {Vec2} this | scale ( s ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.rotate = function(theta) {
var x = this.x;
var y = this.y;
var cosTheta = Math.cos(theta);
var sinTheta = Math.sin(theta);
this.x = x * cosTheta - y * sinTheta;
this.y = x * sinTheta + y * cosTheta;
return this;
}; | Rotate the Vec2 counter-clockwise by theta about the z-axis.
@method
@param {Number} theta Angle by which to rotate.
@return {Vec2} this | Vec2.prototype.rotate ( theta ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.dot = function(v) {
return this.x * v.x + this.y * v.y;
}; | The dot product of of the current Vec2 with the input Vec2.
@method
@param {Number} v The other Vec2.
@return {Vec2} this | Vec2.prototype.dot ( v ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.cross = function(v) {
return this.x * v.y - this.y * v.x;
}; | The cross product of of the current Vec2 with the input Vec2.
@method
@param {Number} v The other Vec2.
@return {Vec2} this | Vec2.prototype.cross ( v ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.invert = function invert() {
this.x *= -1;
this.y *= -1;
return this;
}; | Preserve the magnitude but invert the orientation of the current Vec2.
@method
@return {Vec2} this | invert ( ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.map = function map(fn) {
this.x = fn(this.x);
this.y = fn(this.y);
return this;
}; | Apply a function component-wise to the current Vec2.
@method
@param {Function} fn Function to apply.
@return {Vec2} this | map ( fn ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.length = function length() {
var x = this.x;
var y = this.y;
return Math.sqrt(x * x + y * y);
}; | Get the magnitude of the current Vec2.
@method
@return {Number} the length of the vector | length ( ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.copy = function copy(v) {
this.x = v.x;
this.y = v.y;
return this;
}; | Copy the input onto the current Vec2.
@method
@param {Vec2} v Vec2 to copy
@return {Vec2} this | copy ( v ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.clear = function clear() {
this.x = 0;
this.y = 0;
return this;
}; | Reset the current Vec2.
@method
@return {Vec2} this | clear ( ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.isZero = function isZero() {
if (this.x !== 0 || this.y !== 0) return false;
else return true;
}; | Check whether the magnitude of the current Vec2 is exactly 0.
@method
@return {Boolean} whether or not the length is 0 | isZero ( ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.prototype.toArray = function toArray() {
return [this.x, this.y];
}; | The array form of the current Vec2.
@method
@return {Array} the Vec to as an array | toArray ( ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.normalize = function normalize(v, output) {
var x = v.x;
var y = v.y;
var length = Math.sqrt(x * x + y * y) || 1;
length = 1 / length;
output.x = v.x * length;
output.y = v.y * length;
return output;
}; | Normalize the input Vec2.
@method
@param {Vec2} v The reference Vec2.
@param {Vec2} output Vec2 in which to place the result.
@return {Vec2} The normalized Vec2. | normalize ( v , output ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.clone = function clone(v) {
return new Vec2(v.x, v.y);
}; | Clone the input Vec2.
@method
@param {Vec2} v The Vec2 to clone.
@return {Vec2} The cloned Vec2. | clone ( v ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.add = function add(v1, v2, output) {
output.x = v1.x + v2.x;
output.y = v1.y + v2.y;
return output;
}; | Add the input Vec2's.
@method
@param {Vec2} v1 The left Vec2.
@param {Vec2} v2 The right Vec2.
@param {Vec2} output Vec2 in which to place the result.
@return {Vec2} The result of the addition. | add ( v1 , v2 , output ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.subtract = function subtract(v1, v2, output) {
output.x = v1.x - v2.x;
output.y = v1.y - v2.y;
return output;
}; | Subtract the second Vec2 from the first.
@method
@param {Vec2} v1 The left Vec2.
@param {Vec2} v2 The right Vec2.
@param {Vec2} output Vec2 in which to place the result.
@return {Vec2} The result of the subtraction. | subtract ( v1 , v2 , output ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.scale = function scale(v, s, output) {
output.x = v.x * s;
output.y = v.y * s;
return output;
}; | Scale the input Vec2.
@method
@param {Vec2} v The reference Vec2.
@param {Number} s Number to scale by.
@param {Vec2} output Vec2 in which to place the result.
@return {Vec2} The result of the scaling. | scale ( v , s , output ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.dot = function dot(v1, v2) {
return v1.x * v2.x + v1.y * v2.y;
}; | The dot product of the input Vec2's.
@method
@param {Vec2} v1 The left Vec2.
@param {Vec2} v2 The right Vec2.
@return {Number} The dot product. | dot ( v1 , v2 ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
Vec2.cross = function(v1,v2) {
return v1.x * v2.y - v1.y * v2.x;
}; | The cross product of the input Vec2's.
@method
@param {Number} v1 The left Vec2.
@param {Number} v2 The right Vec2.
@return {Number} The z-component of the cross product. | Vec2.cross ( v1 , v2 ) | javascript | Famous/engine | math/Vec2.js | https://github.com/Famous/engine/blob/master/math/Vec2.js | MIT |
var Vec3 = function(x ,y, z){
this.x = x || 0;
this.y = y || 0;
this.z = z || 0;
}; | A three-dimensional vector.
@class Vec3
@param {Number} x The x component.
@param {Number} y The y component.
@param {Number} z The z component. | Vec3 ( x , y , z ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.set = function set(x, y, z) {
if (x != null) this.x = x;
if (y != null) this.y = y;
if (z != null) this.z = z;
return this;
}; | Set the components of the current Vec3.
@method
@param {Number} x The x component.
@param {Number} y The y component.
@param {Number} z The z component.
@return {Vec3} this | set ( x , y , z ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.add = function add(v) {
this.x += v.x;
this.y += v.y;
this.z += v.z;
return this;
}; | Add the input v to the current Vec3.
@method
@param {Vec3} v The Vec3 to add.
@return {Vec3} this | add ( v ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.subtract = function subtract(v) {
this.x -= v.x;
this.y -= v.y;
this.z -= v.z;
return this;
}; | Subtract the input v from the current Vec3.
@method
@param {Vec3} v The Vec3 to subtract.
@return {Vec3} this | subtract ( v ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.rotateX = function rotateX(theta) {
var y = this.y;
var z = this.z;
var cosTheta = Math.cos(theta);
var sinTheta = Math.sin(theta);
this.y = y * cosTheta - z * sinTheta;
this.z = y * sinTheta + z * cosTheta;
return this;
}; | Rotate the current Vec3 by theta clockwise about the x axis.
@method
@param {Number} theta Angle by which to rotate.
@return {Vec3} this | rotateX ( theta ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.rotateY = function rotateY(theta) {
var x = this.x;
var z = this.z;
var cosTheta = Math.cos(theta);
var sinTheta = Math.sin(theta);
this.x = z * sinTheta + x * cosTheta;
this.z = z * cosTheta - x * sinTheta;
return this;
}; | Rotate the current Vec3 by theta clockwise about the y axis.
@method
@param {Number} theta Angle by which to rotate.
@return {Vec3} this | rotateY ( theta ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.rotateZ = function rotateZ(theta) {
var x = this.x;
var y = this.y;
var cosTheta = Math.cos(theta);
var sinTheta = Math.sin(theta);
this.x = x * cosTheta - y * sinTheta;
this.y = x * sinTheta + y * cosTheta;
return this;
}; | Rotate the current Vec3 by theta clockwise about the z axis.
@method
@param {Number} theta Angle by which to rotate.
@return {Vec3} this | rotateZ ( theta ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.dot = function dot(v) {
return this.x*v.x + this.y*v.y + this.z*v.z;
}; | The dot product of the current Vec3 with input Vec3 v.
@method
@param {Vec3} v The other Vec3.
@return {Vec3} this | dot ( v ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.cross = function cross(v) {
var x = this.x;
var y = this.y;
var z = this.z;
var vx = v.x;
var vy = v.y;
var vz = v.z;
this.x = y * vz - z * vy;
this.y = z * vx - x * vz;
this.z = x * vy - y * vx;
return this;
}; | The dot product of the current Vec3 with input Vec3 v.
Stores the result in the current Vec3.
@method cross
@param {Vec3} v The other Vec3
@return {Vec3} this | cross ( v ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.scale = function scale(s) {
this.x *= s;
this.y *= s;
this.z *= s;
return this;
}; | Scale the current Vec3 by a scalar.
@method
@param {Number} s The Number by which to scale
@return {Vec3} this | scale ( s ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.invert = function invert() {
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
return this;
}; | Preserve the magnitude but invert the orientation of the current Vec3.
@method
@return {Vec3} this | invert ( ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.map = function map(fn) {
this.x = fn(this.x);
this.y = fn(this.y);
this.z = fn(this.z);
return this;
}; | Apply a function component-wise to the current Vec3.
@method
@param {Function} fn Function to apply.
@return {Vec3} this | map ( fn ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.length = function length() {
var x = this.x;
var y = this.y;
var z = this.z;
return Math.sqrt(x * x + y * y + z * z);
}; | The magnitude of the current Vec3.
@method
@return {Number} the magnitude of the Vec3 | length ( ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.lengthSq = function lengthSq() {
var x = this.x;
var y = this.y;
var z = this.z;
return x * x + y * y + z * z;
}; | The magnitude squared of the current Vec3.
@method
@return {Number} magnitude of the Vec3 squared | lengthSq ( ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.copy = function copy(v) {
this.x = v.x;
this.y = v.y;
this.z = v.z;
return this;
}; | Copy the input onto the current Vec3.
@method
@param {Vec3} v Vec3 to copy
@return {Vec3} this | copy ( v ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.clear = function clear() {
this.x = 0;
this.y = 0;
this.z = 0;
return this;
}; | Reset the current Vec3.
@method
@return {Vec3} this | clear ( ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.isZero = function isZero() {
return this.x === 0 && this.y === 0 && this.z === 0;
}; | Check whether the magnitude of the current Vec3 is exactly 0.
@method
@return {Boolean} whether or not the magnitude is zero | isZero ( ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.toArray = function toArray() {
return [this.x, this.y, this.z];
}; | The array form of the current Vec3.
@method
@return {Array} a three element array representing the components of the Vec3 | toArray ( ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.normalize = function normalize() {
var x = this.x;
var y = this.y;
var z = this.z;
var len = Math.sqrt(x * x + y * y + z * z) || 1;
len = 1 / len;
this.x *= len;
this.y *= len;
this.z *= len;
return this;
}; | Preserve the orientation but change the length of the current Vec3 to 1.
@method
@return {Vec3} this | normalize ( ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.applyRotation = function applyRotation(q) {
var cw = q.w;
var cx = -q.x;
var cy = -q.y;
var cz = -q.z;
var vx = this.x;
var vy = this.y;
var vz = this.z;
var tw = -cx * vx - cy * vy - cz * vz;
var tx = vx * cw + vy * cz - cy * vz;
var ty = vy * cw + cx * vz - vx * cz;
var tz = vz * cw + vx * cy - cx * vy;
var w = cw;
var x = -cx;
var y = -cy;
var z = -cz;
this.x = tx * w + x * tw + y * tz - ty * z;
this.y = ty * w + y * tw + tx * z - x * tz;
this.z = tz * w + z * tw + x * ty - tx * y;
return this;
}; | Apply the rotation corresponding to the input (unit) Quaternion
to the current Vec3.
@method
@param {Quaternion} q Unit Quaternion representing the rotation to apply
@return {Vec3} this | applyRotation ( q ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.prototype.applyMatrix = function applyMatrix(matrix) {
var M = matrix.get();
var x = this.x;
var y = this.y;
var z = this.z;
this.x = M[0]*x + M[1]*y + M[2]*z;
this.y = M[3]*x + M[4]*y + M[5]*z;
this.z = M[6]*x + M[7]*y + M[8]*z;
return this;
}; | Apply the input Mat33 the the current Vec3.
@method
@param {Mat33} matrix Mat33 to apply
@return {Vec3} this | applyMatrix ( matrix ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.normalize = function normalize(v, output) {
var x = v.x;
var y = v.y;
var z = v.z;
var length = Math.sqrt(x * x + y * y + z * z) || 1;
length = 1 / length;
output.x = x * length;
output.y = y * length;
output.z = z * length;
return output;
}; | Normalize the input Vec3.
@method
@param {Vec3} v The reference Vec3.
@param {Vec3} output Vec3 in which to place the result.
@return {Vec3} The normalize Vec3. | normalize ( v , output ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.applyRotation = function applyRotation(v, q, output) {
var cw = q.w;
var cx = -q.x;
var cy = -q.y;
var cz = -q.z;
var vx = v.x;
var vy = v.y;
var vz = v.z;
var tw = -cx * vx - cy * vy - cz * vz;
var tx = vx * cw + vy * cz - cy * vz;
var ty = vy * cw + cx * vz - vx * cz;
var tz = vz * cw + vx * cy - cx * vy;
var w = cw;
var x = -cx;
var y = -cy;
var z = -cz;
output.x = tx * w + x * tw + y * tz - ty * z;
output.y = ty * w + y * tw + tx * z - x * tz;
output.z = tz * w + z * tw + x * ty - tx * y;
return output;
}; | Apply a rotation to the input Vec3.
@method
@param {Vec3} v The reference Vec3.
@param {Quaternion} q Unit Quaternion representing the rotation to apply.
@param {Vec3} output Vec3 in which to place the result.
@return {Vec3} The rotated version of the input Vec3. | applyRotation ( v , q , output ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.clone = function clone(v) {
return new Vec3(v.x, v.y, v.z);
}; | Clone the input Vec3.
@method
@param {Vec3} v The Vec3 to clone.
@return {Vec3} The cloned Vec3. | clone ( v ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.add = function add(v1, v2, output) {
output.x = v1.x + v2.x;
output.y = v1.y + v2.y;
output.z = v1.z + v2.z;
return output;
}; | Add the input Vec3's.
@method
@param {Vec3} v1 The left Vec3.
@param {Vec3} v2 The right Vec3.
@param {Vec3} output Vec3 in which to place the result.
@return {Vec3} The result of the addition. | add ( v1 , v2 , output ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.subtract = function subtract(v1, v2, output) {
output.x = v1.x - v2.x;
output.y = v1.y - v2.y;
output.z = v1.z - v2.z;
return output;
}; | Subtract the second Vec3 from the first.
@method
@param {Vec3} v1 The left Vec3.
@param {Vec3} v2 The right Vec3.
@param {Vec3} output Vec3 in which to place the result.
@return {Vec3} The result of the subtraction. | subtract ( v1 , v2 , output ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.scale = function scale(v, s, output) {
output.x = v.x * s;
output.y = v.y * s;
output.z = v.z * s;
return output;
}; | Scale the input Vec3.
@method
@param {Vec3} v The reference Vec3.
@param {Number} s Number to scale by.
@param {Vec3} output Vec3 in which to place the result.
@return {Vec3} The result of the scaling. | scale ( v , s , output ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.dot = function dot(v1, v2) {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}; | The dot product of the input Vec3's.
@method
@param {Vec3} v1 The left Vec3.
@param {Vec3} v2 The right Vec3.
@return {Number} The dot product. | dot ( v1 , v2 ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.cross = function cross(v1, v2, output) {
var x1 = v1.x;
var y1 = v1.y;
var z1 = v1.z;
var x2 = v2.x;
var y2 = v2.y;
var z2 = v2.z;
output.x = y1 * z2 - z1 * y2;
output.y = z1 * x2 - x1 * z2;
output.z = x1 * y2 - y1 * x2;
return output;
}; | The (right-handed) cross product of the input Vec3's.
v1 x v2.
@method
@param {Vec3} v1 The left Vec3.
@param {Vec3} v2 The right Vec3.
@param {Vec3} output Vec3 in which to place the result.
@return {Object} the object the result of the cross product was placed into | cross ( v1 , v2 , output ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
Vec3.project = function project(v1, v2, output) {
var x1 = v1.x;
var y1 = v1.y;
var z1 = v1.z;
var x2 = v2.x;
var y2 = v2.y;
var z2 = v2.z;
var scale = x1 * x2 + y1 * y2 + z1 * z2;
scale /= x2 * x2 + y2 * y2 + z2 * z2;
output.x = x2 * scale;
output.y = y2 * scale;
output.z = z2 * scale;
return output;
}; | The projection of v1 onto v2.
@method
@param {Vec3} v1 The left Vec3.
@param {Vec3} v2 The right Vec3.
@param {Vec3} output Vec3 in which to place the result.
@return {Object} the object the result of the cross product was placed into | project ( v1 , v2 , output ) | javascript | Famous/engine | math/Vec3.js | https://github.com/Famous/engine/blob/master/math/Vec3.js | MIT |
GeometryHelper.computeNormals = function computeNormals(vertices, indices, out) {
var normals = out || [];
var indexOne;
var indexTwo;
var indexThree;
var normal;
var j;
var len = indices.length / 3;
var i;
var x;
var y;
var z;
var length;
for (i = 0; i < len; i++) {
indexTwo = indices[i*3 + 0] * 3;
indexOne = indices[i*3 + 1] * 3;
indexThree = indices[i*3 + 2] * 3;
outputs[0].set(vertices[indexOne], vertices[indexOne + 1], vertices[indexOne + 2]);
outputs[1].set(vertices[indexTwo], vertices[indexTwo + 1], vertices[indexTwo + 2]);
outputs[2].set(vertices[indexThree], vertices[indexThree + 1], vertices[indexThree + 2]);
normal = outputs[2].subtract(outputs[0]).cross(outputs[1].subtract(outputs[0])).normalize();
normals[indexOne + 0] = (normals[indexOne + 0] || 0) + normal.x;
normals[indexOne + 1] = (normals[indexOne + 1] || 0) + normal.y;
normals[indexOne + 2] = (normals[indexOne + 2] || 0) + normal.z;
normals[indexTwo + 0] = (normals[indexTwo + 0] || 0) + normal.x;
normals[indexTwo + 1] = (normals[indexTwo + 1] || 0) + normal.y;
normals[indexTwo + 2] = (normals[indexTwo + 2] || 0) + normal.z;
normals[indexThree + 0] = (normals[indexThree + 0] || 0) + normal.x;
normals[indexThree + 1] = (normals[indexThree + 1] || 0) + normal.y;
normals[indexThree + 2] = (normals[indexThree + 2] || 0) + normal.z;
}
for (i = 0; i < normals.length; i += 3) {
x = normals[i];
y = normals[i+1];
z = normals[i+2];
length = Math.sqrt(x * x + y * y + z * z);
for(j = 0; j< 3; j++) {
normals[i+j] /= length;
}
}
return normals;
}; | Calculates normals belonging to each face of a geometry.
Assumes clockwise declaration of vertices.
@static
@method
@param {Array} vertices Vertices of all points on the geometry.
@param {Array} indices Indices declaring faces of geometry.
@param {Array} out Array to be filled and returned.
@return {Array} Calculated face normals. | computeNormals ( vertices , indices , out ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.subdivide = function subdivide(indices, vertices, textureCoords) {
var triangleIndex = indices.length / 3;
var face;
var i;
var j;
var k;
var pos;
var tex;
while (triangleIndex--) {
face = indices.slice(triangleIndex * 3, triangleIndex * 3 + 3);
pos = face.map(function(vertIndex) {
return new Vec3(vertices[vertIndex * 3], vertices[vertIndex * 3 + 1], vertices[vertIndex * 3 + 2]);
});
vertices.push.apply(vertices, Vec3.scale(Vec3.add(pos[0], pos[1], outputs[0]), 0.5, outputs[1]).toArray());
vertices.push.apply(vertices, Vec3.scale(Vec3.add(pos[1], pos[2], outputs[0]), 0.5, outputs[1]).toArray());
vertices.push.apply(vertices, Vec3.scale(Vec3.add(pos[0], pos[2], outputs[0]), 0.5, outputs[1]).toArray());
if (textureCoords) {
tex = face.map(function(vertIndex) {
return new Vec2(textureCoords[vertIndex * 2], textureCoords[vertIndex * 2 + 1]);
});
textureCoords.push.apply(textureCoords, Vec2.scale(Vec2.add(tex[0], tex[1], outputs[3]), 0.5, outputs[4]).toArray());
textureCoords.push.apply(textureCoords, Vec2.scale(Vec2.add(tex[1], tex[2], outputs[3]), 0.5, outputs[4]).toArray());
textureCoords.push.apply(textureCoords, Vec2.scale(Vec2.add(tex[0], tex[2], outputs[3]), 0.5, outputs[4]).toArray());
}
i = vertices.length - 3;
j = i + 1;
k = i + 2;
indices.push(i, j, k);
indices.push(face[0], i, k);
indices.push(i, face[1], j);
indices[triangleIndex] = k;
indices[triangleIndex + 1] = j;
indices[triangleIndex + 2] = face[2];
}
}; | Divides all inserted triangles into four sub-triangles. Alters the
passed in arrays.
@static
@method
@param {Array} indices Indices declaring faces of geometry
@param {Array} vertices Vertices of all points on the geometry
@param {Array} textureCoords Texture coordinates of all points on the geometry
@return {undefined} undefined | subdivide ( indices , vertices , textureCoords ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.getUniqueFaces = function getUniqueFaces(vertices, indices) {
var triangleIndex = indices.length / 3,
registered = [],
index;
while (triangleIndex--) {
for (var i = 0; i < 3; i++) {
index = indices[triangleIndex * 3 + i];
if (registered[index]) {
vertices.push(vertices[index * 3], vertices[index * 3 + 1], vertices[index * 3 + 2]);
indices[triangleIndex * 3 + i] = vertices.length / 3 - 1;
}
else {
registered[index] = true;
}
}
}
}; | Creates duplicate of vertices that are shared between faces.
Alters the input vertex and index arrays.
@static
@method
@param {Array} vertices Vertices of all points on the geometry
@param {Array} indices Indices declaring faces of geometry
@return {undefined} undefined | getUniqueFaces ( vertices , indices ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.subdivideSpheroid = function subdivideSpheroid(vertices, indices) {
var triangleIndex = indices.length / 3,
abc,
face,
i, j, k;
while (triangleIndex--) {
face = indices.slice(triangleIndex * 3, triangleIndex * 3 + 3);
abc = face.map(function(vertIndex) {
return new Vec3(vertices[vertIndex * 3], vertices[vertIndex * 3 + 1], vertices[vertIndex * 3 + 2]);
});
vertices.push.apply(vertices, Vec3.normalize(Vec3.add(abc[0], abc[1], outputs[0]), outputs[1]).toArray());
vertices.push.apply(vertices, Vec3.normalize(Vec3.add(abc[1], abc[2], outputs[0]), outputs[1]).toArray());
vertices.push.apply(vertices, Vec3.normalize(Vec3.add(abc[0], abc[2], outputs[0]), outputs[1]).toArray());
i = vertices.length / 3 - 3;
j = i + 1;
k = i + 2;
indices.push(i, j, k);
indices.push(face[0], i, k);
indices.push(i, face[1], j);
indices[triangleIndex * 3] = k;
indices[triangleIndex * 3 + 1] = j;
indices[triangleIndex * 3 + 2] = face[2];
}
}; | Divides all inserted triangles into four sub-triangles while maintaining
a radius of one. Alters the passed in arrays.
@static
@method
@param {Array} vertices Vertices of all points on the geometry
@param {Array} indices Indices declaring faces of geometry
@return {undefined} undefined | subdivideSpheroid ( vertices , indices ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.getSpheroidNormals = function getSpheroidNormals(vertices, out) {
out = out || [];
var length = vertices.length / 3;
var normalized;
for (var i = 0; i < length; i++) {
normalized = new Vec3(
vertices[i * 3 + 0],
vertices[i * 3 + 1],
vertices[i * 3 + 2]
).normalize().toArray();
out[i * 3 + 0] = normalized[0];
out[i * 3 + 1] = normalized[1];
out[i * 3 + 2] = normalized[2];
}
return out;
}; | Divides all inserted triangles into four sub-triangles while maintaining
a radius of one. Alters the passed in arrays.
@static
@method
@param {Array} vertices Vertices of all points on the geometry
@param {Array} out Optional array to be filled with resulting normals.
@return {Array} New list of calculated normals. | getSpheroidNormals ( vertices , out ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.getSpheroidUV = function getSpheroidUV(vertices, out) {
out = out || [];
var length = vertices.length / 3;
var vertex;
var uv = [];
for(var i = 0; i < length; i++) {
vertex = outputs[0].set(
vertices[i * 3],
vertices[i * 3 + 1],
vertices[i * 3 + 2]
)
.normalize()
.toArray();
var azimuth = this.getAzimuth(vertex);
var altitude = this.getAltitude(vertex);
uv[0] = azimuth * 0.5 / Math.PI + 0.5;
uv[1] = altitude / Math.PI + 0.5;
out.push.apply(out, uv);
}
return out;
}; | Calculates texture coordinates for spheroid primitives based on
input vertices.
@static
@method
@param {Array} vertices Vertices of all points on the geometry
@param {Array} out Optional array to be filled with resulting texture coordinates.
@return {Array} New list of calculated texture coordinates | getSpheroidUV ( vertices , out ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.normalizeAll = function normalizeAll(vertices, out) {
out = out || [];
var len = vertices.length / 3;
for (var i = 0; i < len; i++) {
Array.prototype.push.apply(out, new Vec3(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]).normalize().toArray());
}
return out;
}; | Iterates through and normalizes a list of vertices.
@static
@method
@param {Array} vertices Vertices of all points on the geometry
@param {Array} out Optional array to be filled with resulting normalized vectors.
@return {Array} New list of normalized vertices | normalizeAll ( vertices , out ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.normalizeVertices = function normalizeVertices(vertices, out) {
out = out || [];
var len = vertices.length / 3;
var vectors = [];
var minX;
var maxX;
var minY;
var maxY;
var minZ;
var maxZ;
var v;
var i;
for (i = 0; i < len; i++) {
v = vectors[i] = new Vec3(
vertices[i * 3],
vertices[i * 3 + 1],
vertices[i * 3 + 2]
);
if (minX == null || v.x < minX) minX = v.x;
if (maxX == null || v.x > maxX) maxX = v.x;
if (minY == null || v.y < minY) minY = v.y;
if (maxY == null || v.y > maxY) maxY = v.y;
if (minZ == null || v.z < minZ) minZ = v.z;
if (maxZ == null || v.z > maxZ) maxZ = v.z;
}
var translation = new Vec3(
getTranslationFactor(maxX, minX),
getTranslationFactor(maxY, minY),
getTranslationFactor(maxZ, minZ)
);
var scale = Math.min(
getScaleFactor(maxX + translation.x, minX + translation.x),
getScaleFactor(maxY + translation.y, minY + translation.y),
getScaleFactor(maxZ + translation.z, minZ + translation.z)
);
for (i = 0; i < vectors.length; i++) {
out.push.apply(out, vectors[i].add(translation).scale(scale).toArray());
}
return out;
}; | Normalizes a set of vertices to model space.
@static
@method
@param {Array} vertices Vertices of all points on the geometry
@param {Array} out Optional array to be filled with model space position vectors.
@return {Array} Output vertices. | normalizeVertices ( vertices , out ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
function getTranslationFactor(max, min) {
return -(min + (max - min) / 2);
} | Determines translation amount for a given axis to normalize model coordinates.
@method
@private
@param {Number} max Maximum position value of given axis on the model.
@param {Number} min Minimum position value of given axis on the model.
@return {Number} Number by which the given axis should be translated for all vertices. | getTranslationFactor ( max , min ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
function getScaleFactor(max, min) {
return 1 / ((max - min) / 2);
} | Determines scale amount for a given axis to normalize model coordinates.
@method
@private
@param {Number} max Maximum scale value of given axis on the model.
@param {Number} min Minimum scale value of given axis on the model.
@return {Number} Number by which the given axis should be scaled for all vertices. | getScaleFactor ( max , min ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.getAzimuth = function azimuth(v) {
return Math.atan2(v[2], -v[0]);
}; | Finds the azimuth, or angle above the XY plane, of a given vector.
@static
@method
@param {Array} v Vertex to retreive azimuth from.
@return {Number} Azimuth value in radians. | azimuth ( v ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.getAltitude = function altitude(v) {
return Math.atan2(-v[1], Math.sqrt((v[0] * v[0]) + (v[2] * v[2])));
}; | Finds the altitude, or angle above the XZ plane, of a given vector.
@static
@method
@param {Array} v Vertex to retreive altitude from.
@return {Number} Altitude value in radians. | altitude ( v ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.trianglesToLines = function triangleToLines(indices, out) {
var numVectors = indices.length / 3;
out = out || [];
var i;
for (i = 0; i < numVectors; i++) {
out.push(indices[i * 3 + 0], indices[i * 3 + 1]);
out.push(indices[i * 3 + 1], indices[i * 3 + 2]);
out.push(indices[i * 3 + 2], indices[i * 3 + 0]);
}
return out;
}; | Converts a list of indices from 'triangle' to 'line' format.
@static
@method
@param {Array} indices Indices of all faces on the geometry
@param {Array} out Indices of all faces on the geometry
@return {Array} New list of line-formatted indices | triangleToLines ( indices , out ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.addBackfaceTriangles = function addBackfaceTriangles(vertices, indices) {
var nFaces = indices.length / 3;
var maxIndex = 0;
var i = indices.length;
while (i--) if (indices[i] > maxIndex) maxIndex = indices[i];
maxIndex++;
for (i = 0; i < nFaces; i++) {
var indexOne = indices[i * 3],
indexTwo = indices[i * 3 + 1],
indexThree = indices[i * 3 + 2];
indices.push(indexOne + maxIndex, indexThree + maxIndex, indexTwo + maxIndex);
}
// Iterating instead of .slice() here to avoid max call stack issue.
var nVerts = vertices.length;
for (i = 0; i < nVerts; i++) {
vertices.push(vertices[i]);
}
}; | Adds a reverse order triangle for every triangle in the mesh. Adds extra vertices
and indices to input arrays.
@static
@method
@param {Array} vertices X, Y, Z positions of all vertices in the geometry
@param {Array} indices Indices of all faces on the geometry
@return {undefined} undefined | addBackfaceTriangles ( vertices , indices ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
GeometryHelper.generateParametric = function generateParametric(detailX, detailY, func, wrap) {
var vertices = [];
var i;
var theta;
var phi;
var j;
// We can wrap around slightly more than once for uv coordinates to look correct.
var offset = (Math.PI / (detailX - 1));
var Xrange = wrap ? Math.PI + offset : Math.PI;
var out = [];
for (i = 0; i < detailX + 1; i++) {
theta = (i === 0 ? 0.0001 : i) * Math.PI / detailX;
for (j = 0; j < detailY; j++) {
phi = j * 2.0 * Xrange / detailY;
func(theta, phi, out);
vertices.push(out[0], out[1], out[2]);
}
}
var indices = [],
v = 0,
next;
for (i = 0; i < detailX; i++) {
for (j = 0; j < detailY; j++) {
next = (j + 1) % detailY;
indices.push(v + j, v + j + detailY, v + next);
indices.push(v + next, v + j + detailY, v + next + detailY);
}
v += detailY;
}
return {
vertices: vertices,
indices: indices
};
};
/**
* Calculates normals belonging to each face of a geometry.
* Assumes clockwise declaration of vertices.
*
* @static
* @method
*
* @param {Array} vertices Vertices of all points on the geometry.
* @param {Array} indices Indices declaring faces of geometry.
* @param {Array} out Array to be filled and returned.
*
* @return {Array} Calculated face normals.
*/
GeometryHelper.computeNormals = function computeNormals(vertices, indices, out) {
var normals = out || [];
var indexOne;
var indexTwo;
var indexThree;
var normal;
var j;
var len = indices.length / 3;
var i;
var x;
var y;
var z;
var length;
for (i = 0; i < len; i++) {
indexTwo = indices[i*3 + 0] * 3;
indexOne = indices[i*3 + 1] * 3;
indexThree = indices[i*3 + 2] * 3;
outputs[0].set(vertices[indexOne], vertices[indexOne + 1], vertices[indexOne + 2]);
outputs[1].set(vertices[indexTwo], vertices[indexTwo + 1], vertices[indexTwo + 2]);
outputs[2].set(vertices[indexThree], vertices[indexThree + 1], vertices[indexThree + 2]);
normal = outputs[2].subtract(outputs[0]).cross(outputs[1].subtract(outputs[0])).normalize();
normals[indexOne + 0] = (normals[indexOne + 0] || 0) + normal.x;
normals[indexOne + 1] = (normals[indexOne + 1] || 0) + normal.y;
normals[indexOne + 2] = (normals[indexOne + 2] || 0) + normal.z;
normals[indexTwo + 0] = (normals[indexTwo + 0] || 0) + normal.x;
normals[indexTwo + 1] = (normals[indexTwo + 1] || 0) + normal.y;
normals[indexTwo + 2] = (normals[indexTwo + 2] || 0) + normal.z;
normals[indexThree + 0] = (normals[indexThree + 0] || 0) + normal.x;
normals[indexThree + 1] = (normals[indexThree + 1] || 0) + normal.y;
normals[indexThree + 2] = (normals[indexThree + 2] || 0) + normal.z;
}
for (i = 0; i < normals.length; i += 3) {
x = normals[i];
y = normals[i+1];
z = normals[i+2];
length = Math.sqrt(x * x + y * y + z * z);
for(j = 0; j< 3; j++) {
normals[i+j] /= length;
}
}
return normals;
};
/**
* Divides all inserted triangles into four sub-triangles. Alters the
* passed in arrays.
*
* @static
* @method
*
* @param {Array} indices Indices declaring faces of geometry
* @param {Array} vertices Vertices of all points on the geometry
* @param {Array} textureCoords Texture coordinates of all points on the geometry
* @return {undefined} undefined
*/
GeometryHelper.subdivide = function subdivide(indices, vertices, textureCoords) {
var triangleIndex = indices.length / 3;
var face;
var i;
var j;
var k;
var pos;
var tex;
while (triangleIndex--) {
face = indices.slice(triangleIndex * 3, triangleIndex * 3 + 3);
pos = face.map(function(vertIndex) {
return new Vec3(vertices[vertIndex * 3], vertices[vertIndex * 3 + 1], vertices[vertIndex * 3 + 2]);
});
vertices.push.apply(vertices, Vec3.scale(Vec3.add(pos[0], pos[1], outputs[0]), 0.5, outputs[1]).toArray());
vertices.push.apply(vertices, Vec3.scale(Vec3.add(pos[1], pos[2], outputs[0]), 0.5, outputs[1]).toArray());
vertices.push.apply(vertices, Vec3.scale(Vec3.add(pos[0], pos[2], outputs[0]), 0.5, outputs[1]).toArray());
if (textureCoords) {
tex = face.map(function(vertIndex) {
return new Vec2(textureCoords[vertIndex * 2], textureCoords[vertIndex * 2 + 1]);
});
textureCoords.push.apply(textureCoords, Vec2.scale(Vec2.add(tex[0], tex[1], outputs[3]), 0.5, outputs[4]).toArray());
textureCoords.push.apply(textureCoords, Vec2.scale(Vec2.add(tex[1], tex[2], outputs[3]), 0.5, outputs[4]).toArray());
textureCoords.push.apply(textureCoords, Vec2.scale(Vec2.add(tex[0], tex[2], outputs[3]), 0.5, outputs[4]).toArray());
}
i = vertices.length - 3;
j = i + 1;
k = i + 2;
indices.push(i, j, k);
indices.push(face[0], i, k);
indices.push(i, face[1], j);
indices[triangleIndex] = k;
indices[triangleIndex + 1] = j;
indices[triangleIndex + 2] = face[2];
}
};
/**
* Creates duplicate of vertices that are shared between faces.
* Alters the input vertex and index arrays.
*
* @static
* @method
*
* @param {Array} vertices Vertices of all points on the geometry
* @param {Array} indices Indices declaring faces of geometry
* @return {undefined} undefined
*/
GeometryHelper.getUniqueFaces = function getUniqueFaces(vertices, indices) {
var triangleIndex = indices.length / 3,
registered = [],
index;
while (triangleIndex--) {
for (var i = 0; i < 3; i++) {
index = indices[triangleIndex * 3 + i];
if (registered[index]) {
vertices.push(vertices[index * 3], vertices[index * 3 + 1], vertices[index * 3 + 2]);
indices[triangleIndex * 3 + i] = vertices.length / 3 - 1;
}
else {
registered[index] = true;
}
}
}
};
/**
* Divides all inserted triangles into four sub-triangles while maintaining
* a radius of one. Alters the passed in arrays.
*
* @static
* @method
*
* @param {Array} vertices Vertices of all points on the geometry
* @param {Array} indices Indices declaring faces of geometry
* @return {undefined} undefined
*/
GeometryHelper.subdivideSpheroid = function subdivideSpheroid(vertices, indices) {
var triangleIndex = indices.length / 3,
abc,
face,
i, j, k;
while (triangleIndex--) {
face = indices.slice(triangleIndex * 3, triangleIndex * 3 + 3);
abc = face.map(function(vertIndex) {
return new Vec3(vertices[vertIndex * 3], vertices[vertIndex * 3 + 1], vertices[vertIndex * 3 + 2]);
});
vertices.push.apply(vertices, Vec3.normalize(Vec3.add(abc[0], abc[1], outputs[0]), outputs[1]).toArray());
vertices.push.apply(vertices, Vec3.normalize(Vec3.add(abc[1], abc[2], outputs[0]), outputs[1]).toArray());
vertices.push.apply(vertices, Vec3.normalize(Vec3.add(abc[0], abc[2], outputs[0]), outputs[1]).toArray());
i = vertices.length / 3 - 3;
j = i + 1;
k = i + 2;
indices.push(i, j, k);
indices.push(face[0], i, k);
indices.push(i, face[1], j);
indices[triangleIndex * 3] = k;
indices[triangleIndex * 3 + 1] = j;
indices[triangleIndex * 3 + 2] = face[2];
}
};
/**
* Divides all inserted triangles into four sub-triangles while maintaining
* a radius of one. Alters the passed in arrays.
*
* @static
* @method
*
* @param {Array} vertices Vertices of all points on the geometry
* @param {Array} out Optional array to be filled with resulting normals.
*
* @return {Array} New list of calculated normals.
*/
GeometryHelper.getSpheroidNormals = function getSpheroidNormals(vertices, out) {
out = out || [];
var length = vertices.length / 3;
var normalized;
for (var i = 0; i < length; i++) {
normalized = new Vec3(
vertices[i * 3 + 0],
vertices[i * 3 + 1],
vertices[i * 3 + 2]
).normalize().toArray();
out[i * 3 + 0] = normalized[0];
out[i * 3 + 1] = normalized[1];
out[i * 3 + 2] = normalized[2];
}
return out;
};
/**
* Calculates texture coordinates for spheroid primitives based on
* input vertices.
*
* @static
* @method
*
* @param {Array} vertices Vertices of all points on the geometry
* @param {Array} out Optional array to be filled with resulting texture coordinates.
*
* @return {Array} New list of calculated texture coordinates
*/
GeometryHelper.getSpheroidUV = function getSpheroidUV(vertices, out) {
out = out || [];
var length = vertices.length / 3;
var vertex;
var uv = [];
for(var i = 0; i < length; i++) {
vertex = outputs[0].set(
vertices[i * 3],
vertices[i * 3 + 1],
vertices[i * 3 + 2]
)
.normalize()
.toArray();
var azimuth = this.getAzimuth(vertex);
var altitude = this.getAltitude(vertex);
uv[0] = azimuth * 0.5 / Math.PI + 0.5;
uv[1] = altitude / Math.PI + 0.5;
out.push.apply(out, uv);
}
return out;
};
/**
* Iterates through and normalizes a list of vertices.
*
* @static
* @method
*
* @param {Array} vertices Vertices of all points on the geometry
* @param {Array} out Optional array to be filled with resulting normalized vectors.
*
* @return {Array} New list of normalized vertices
*/
GeometryHelper.normalizeAll = function normalizeAll(vertices, out) {
out = out || [];
var len = vertices.length / 3;
for (var i = 0; i < len; i++) {
Array.prototype.push.apply(out, new Vec3(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]).normalize().toArray());
}
return out;
};
/**
* Normalizes a set of vertices to model space.
*
* @static
* @method
*
* @param {Array} vertices Vertices of all points on the geometry
* @param {Array} out Optional array to be filled with model space position vectors.
*
* @return {Array} Output vertices.
*/
GeometryHelper.normalizeVertices = function normalizeVertices(vertices, out) {
out = out || [];
var len = vertices.length / 3;
var vectors = [];
var minX;
var maxX;
var minY;
var maxY;
var minZ;
var maxZ;
var v;
var i;
for (i = 0; i < len; i++) {
v = vectors[i] = new Vec3(
vertices[i * 3],
vertices[i * 3 + 1],
vertices[i * 3 + 2]
);
if (minX == null || v.x < minX) minX = v.x;
if (maxX == null || v.x > maxX) maxX = v.x;
if (minY == null || v.y < minY) minY = v.y;
if (maxY == null || v.y > maxY) maxY = v.y;
if (minZ == null || v.z < minZ) minZ = v.z;
if (maxZ == null || v.z > maxZ) maxZ = v.z;
}
var translation = new Vec3(
getTranslationFactor(maxX, minX),
getTranslationFactor(maxY, minY),
getTranslationFactor(maxZ, minZ)
);
var scale = Math.min(
getScaleFactor(maxX + translation.x, minX + translation.x),
getScaleFactor(maxY + translation.y, minY + translation.y),
getScaleFactor(maxZ + translation.z, minZ + translation.z)
);
for (i = 0; i < vectors.length; i++) {
out.push.apply(out, vectors[i].add(translation).scale(scale).toArray());
}
return out;
};
/**
* Determines translation amount for a given axis to normalize model coordinates.
*
* @method
* @private
*
* @param {Number} max Maximum position value of given axis on the model.
* @param {Number} min Minimum position value of given axis on the model.
*
* @return {Number} Number by which the given axis should be translated for all vertices.
*/
function getTranslationFactor(max, min) {
return -(min + (max - min) / 2);
}
/**
* Determines scale amount for a given axis to normalize model coordinates.
*
* @method
* @private
*
* @param {Number} max Maximum scale value of given axis on the model.
* @param {Number} min Minimum scale value of given axis on the model.
*
* @return {Number} Number by which the given axis should be scaled for all vertices.
*/
function getScaleFactor(max, min) {
return 1 / ((max - min) / 2);
}
/**
* Finds the azimuth, or angle above the XY plane, of a given vector.
*
* @static
* @method
*
* @param {Array} v Vertex to retreive azimuth from.
*
* @return {Number} Azimuth value in radians.
*/
GeometryHelper.getAzimuth = function azimuth(v) {
return Math.atan2(v[2], -v[0]);
};
/**
* Finds the altitude, or angle above the XZ plane, of a given vector.
*
* @static
* @method
*
* @param {Array} v Vertex to retreive altitude from.
*
* @return {Number} Altitude value in radians.
*/
GeometryHelper.getAltitude = function altitude(v) {
return Math.atan2(-v[1], Math.sqrt((v[0] * v[0]) + (v[2] * v[2])));
};
/**
* Converts a list of indices from 'triangle' to 'line' format.
*
* @static
* @method
*
* @param {Array} indices Indices of all faces on the geometry
* @param {Array} out Indices of all faces on the geometry
*
* @return {Array} New list of line-formatted indices
*/
GeometryHelper.trianglesToLines = function triangleToLines(indices, out) {
var numVectors = indices.length / 3;
out = out || [];
var i;
for (i = 0; i < numVectors; i++) {
out.push(indices[i * 3 + 0], indices[i * 3 + 1]);
out.push(indices[i * 3 + 1], indices[i * 3 + 2]);
out.push(indices[i * 3 + 2], indices[i * 3 + 0]);
}
return out;
};
/**
* Adds a reverse order triangle for every triangle in the mesh. Adds extra vertices
* and indices to input arrays.
*
* @static
* @method
*
* @param {Array} vertices X, Y, Z positions of all vertices in the geometry
* @param {Array} indices Indices of all faces on the geometry
* @return {undefined} undefined
*/
GeometryHelper.addBackfaceTriangles = function addBackfaceTriangles(vertices, indices) {
var nFaces = indices.length / 3;
var maxIndex = 0;
var i = indices.length;
while (i--) if (indices[i] > maxIndex) maxIndex = indices[i];
maxIndex++;
for (i = 0; i < nFaces; i++) {
var indexOne = indices[i * 3],
indexTwo = indices[i * 3 + 1],
indexThree = indices[i * 3 + 2];
indices.push(indexOne + maxIndex, indexThree + maxIndex, indexTwo + maxIndex);
}
// Iterating instead of .slice() here to avoid max call stack issue.
var nVerts = vertices.length;
for (i = 0; i < nVerts; i++) {
vertices.push(vertices[i]);
}
};
module.exports = GeometryHelper; | A function that iterates through vertical and horizontal slices
based on input detail, and generates vertices and indices for each
subdivision.
@static
@method
@param {Number} detailX Amount of slices to iterate through.
@param {Number} detailY Amount of stacks to iterate through.
@param {Function} func Function used to generate vertex positions at each point.
@param {Boolean} wrap Optional parameter (default: Pi) for setting a custom wrap range
@return {Object} Object containing generated vertices and indices. | generateParametric ( detailX , detailY , func , wrap ) | javascript | Famous/engine | webgl-geometries/GeometryHelper.js | https://github.com/Famous/engine/blob/master/webgl-geometries/GeometryHelper.js | MIT |
function DynamicGeometry(options) {
Geometry.call(this, options);
this.spec.dynamic = true;
} | DynamicGeometry is a component that defines and manages data
(vertex data and attributes) that is used to draw to WebGL.
@class DynamicGeometry
@constructor
@param {Object} options instantiation options
@return {undefined} undefined | DynamicGeometry ( options ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.getLength = function getLength() {
return this.getVertexPositions().length;
}; | Returns the number of attribute values used to draw the DynamicGeometry.
@class DynamicGeometry
@constructor
@return {Object} flattened length of the vertex positions attribute in the geometry. | getLength ( ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.getVertexBuffer = function getVertexBuffer(bufferName) {
if (! bufferName) throw 'getVertexBuffer requires a name';
var idx = this.spec.bufferNames.indexOf(bufferName);
if (~idx) return this.spec.bufferValues[idx];
else throw 'buffer does not exist';
}; | Gets the buffer object based on buffer name. Throws error
if bufferName is not provided.
@method
@param {String} bufferName name of vertexBuffer to be retrieved.
@return {Object} value of buffer with corresponding bufferName. | getVertexBuffer ( bufferName ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.setVertexBuffer = function setVertexBuffer(bufferName, value, size) {
var idx = this.spec.bufferNames.indexOf(bufferName);
if (idx === -1) {
idx = this.spec.bufferNames.push(bufferName) - 1;
}
this.spec.bufferValues[idx] = value || [];
this.spec.bufferSpacings[idx] = size || this.DEFAULT_BUFFER_SIZE;
if (this.spec.invalidations.indexOf(idx) === -1) {
this.spec.invalidations.push(idx);
}
return this;
}; | Sets a vertex buffer with given name to input value. Registers a new
buffer if one does not exist with given name.
@method
@param {String} bufferName Name of vertexBuffer to be set.
@param {Array} value Input data to fill target buffer.
@param {Number} size Vector size of input buffer data.
@return {Object} current geometry. | setVertexBuffer ( bufferName , value , size ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.fromGeometry = function fromGeometry(geometry) {
var len = geometry.spec.bufferNames.length;
for (var i = 0; i < len; i++) {
this.setVertexBuffer(
geometry.spec.bufferNames[i],
geometry.spec.bufferValues[i],
geometry.spec.bufferSpacings[i]
);
}
return this;
}; | Copies and sets all buffers from another geometry instance.
@method
@param {Object} geometry Geometry instance to copy buffers from.
@return {Object} current geometry. | fromGeometry ( geometry ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.setVertexPositions = function (value) {
return this.setVertexBuffer('a_pos', value, 3);
}; | Set the positions of the vertices in this geometry.
@method
@param {Array} value New value for vertex position buffer
@return {Object} current geometry. | DynamicGeometry.prototype.setVertexPositions ( value ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.setNormals = function (value) {
return this.setVertexBuffer('a_normals', value, 3);
}; | Set the normals on this geometry.
@method
@param {Array} value Value to set normal buffer to.
@return {Object} current geometry. | DynamicGeometry.prototype.setNormals ( value ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.setTextureCoords = function (value) {
return this.setVertexBuffer('a_texCoord', value, 2);
}; | Set the texture coordinates on this geometry.
@method
@param {Array} value New value for texture coordinates buffer.
@return {Object} current geometry. | DynamicGeometry.prototype.setTextureCoords ( value ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.setIndices = function (value) {
return this.setVertexBuffer('indices', value, 1);
}; | Set the texture coordinates on this geometry.
@method
@param {Array} value New value for index buffer
@return {Object} current geometry. | DynamicGeometry.prototype.setIndices ( value ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.setDrawType = function (value) {
this.spec.type = value.toUpperCase();
return this;
}; | Set the WebGL drawing primitive for this geometry.
@method
@param {String} value New drawing primitive for geometry
@return {Object} current geometry. | DynamicGeometry.prototype.setDrawType ( value ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.getVertexPositions = function () {
return this.getVertexBuffer('a_pos');
}; | Returns the 'pos' vertex buffer of the geometry.
@method
@return {Array} Vertex buffer. | DynamicGeometry.prototype.getVertexPositions ( ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.getNormals = function () {
return this.getVertexBuffer('a_normals');
}; | Returns the 'normal' vertex buffer of the geometry.
@method
@return {Array} Vertex Buffer. | DynamicGeometry.prototype.getNormals ( ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
DynamicGeometry.prototype.getTextureCoords = function () {
return this.getVertexBuffer('a_texCoord');
}; | Returns the 'textureCoord' vertex buffer of the geometry.
@method
@return {Array} Vertex Buffer. | DynamicGeometry.prototype.getTextureCoords ( ) | javascript | Famous/engine | webgl-geometries/DynamicGeometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/DynamicGeometry.js | MIT |
function Geometry(options) {
this.options = options || {};
this.DEFAULT_BUFFER_SIZE = 3;
this.spec = {
id: GeometryIds++,
dynamic: false,
type: this.options.type || 'TRIANGLES',
bufferNames: [],
bufferValues: [],
bufferSpacings: [],
invalidations: []
};
if (this.options.buffers) {
var len = this.options.buffers.length;
for (var i = 0; i < len;) {
this.spec.bufferNames.push(this.options.buffers[i].name);
this.spec.bufferValues.push(this.options.buffers[i].data);
this.spec.bufferSpacings.push(this.options.buffers[i].size || this.DEFAULT_BUFFER_SIZE);
this.spec.invalidations.push(i++);
}
}
} | Geometry is a component that defines and manages data
(vertex data and attributes) that is used to draw to WebGL.
@class Geometry
@constructor
@param {Object} options instantiation options
@return {undefined} undefined | Geometry ( options ) | javascript | Famous/engine | webgl-geometries/Geometry.js | https://github.com/Famous/engine/blob/master/webgl-geometries/Geometry.js | MIT |
ParametricSphere.generator = function generator(u, v, pos) {
var x = Math.sin(u) * Math.cos(v);
var y = Math.cos(u);
var z = -Math.sin(u) * Math.sin(v);
pos[0] = x;
pos[1] = y;
pos[2] = z;
}; | Function used in iterative construction of parametric primitive.
@static
@method
@param {Number} u Longitudal progress from 0 to PI.
@param {Number} v Latitudal progress from 0 to PI.
@param {Array} pos X, Y, Z position of vertex at given slice and stack.
@return {undefined} undefined | generator ( u , v , pos ) | javascript | Famous/engine | webgl-geometries/primitives/Sphere.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Sphere.js | MIT |
function Plane(options) {
options = options || {};
var detailX = options.detailX || options.detail || 1;
var detailY = options.detailY || options.detail || 1;
var vertices = [];
var textureCoords = [];
var normals = [];
var indices = [];
var i;
for (var y = 0; y <= detailY; y++) {
var t = y / detailY;
for (var x = 0; x <= detailX; x++) {
var s = x / detailX;
vertices.push(2. * (s - .5), 2 * (t - .5), 0);
textureCoords.push(s, 1 - t);
if (x < detailX && y < detailY) {
i = x + y * (detailX + 1);
indices.push(i, i + 1, i + detailX + 1);
indices.push(i + detailX + 1, i + 1, i + detailX + 2);
}
}
}
if (options.backface !== false) {
GeometryHelper.addBackfaceTriangles(vertices, indices);
// duplicate texture coordinates as well
var len = textureCoords.length;
for (i = 0; i < len; i++) textureCoords.push(textureCoords[i]);
}
normals = GeometryHelper.computeNormals(vertices, indices);
options.buffers = [
{ name: 'a_pos', data: vertices },
{ name: 'a_texCoord', data: textureCoords, size: 2 },
{ name: 'a_normals', data: normals },
{ name: 'indices', data: indices, size: 1 }
];
return new Geometry(options);
} | This function returns a new static geometry, which is passed
custom buffer data.
@class Plane
@constructor
@param {Object} options Parameters that alter the
vertex buffers of the generated geometry.
@return {Object} constructed geometry | Plane ( options ) | javascript | Famous/engine | webgl-geometries/primitives/Plane.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Plane.js | MIT |
function GeodesicSphere (options) {
var t = (1 + Math.sqrt(5)) * 0.5;
var vertices = [
- 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
0, - 1, -t, 0, 1, -t, 0, - 1, t, 0, 1, t,
t, 0, 1, t, 0, -1, - t, 0, 1, - t, 0, -1
];
var indices = [
0, 5, 11, 0, 1, 5, 0, 7, 1, 0, 10, 7, 0, 11, 10,
1, 9, 5, 5, 4, 11, 11, 2, 10, 10, 6, 7, 7, 8, 1,
3, 4, 9, 3, 2, 4, 3, 6, 2, 3, 8, 6, 3, 9, 8,
4, 5, 9, 2, 11, 4, 6, 10, 2, 8, 7, 6, 9, 1, 8
];
vertices = GeometryHelper.normalizeAll(vertices);
options = options || {};
var detail = options.detail || 3;
while(--detail) GeometryHelper.subdivideSpheroid(vertices, indices);
GeometryHelper.getUniqueFaces(vertices, indices);
var normals = GeometryHelper.computeNormals(vertices, indices);
var textureCoords = GeometryHelper.getSpheroidUV(vertices);
options.buffers = [
{ name: 'a_pos', data: vertices },
{ name: 'a_texCoord', data: textureCoords, size: 2 },
{ name: 'a_normals', data: normals },
{ name: 'indices', data: indices, size: 1 }
];
return new Geometry(options);
} | This function returns a new static geometry, which is passed
custom buffer data.
@class GeodesicSphere
@constructor
@param {Object} options Parameters that alter the
vertex buffers of the generated geometry.
@return {Object} constructed geometry | GeodesicSphere ( options ) | javascript | Famous/engine | webgl-geometries/primitives/GeodesicSphere.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/GeodesicSphere.js | MIT |
ParametricCone.generator = function generator(r, u, v, pos) {
pos[0] = -r * u * Math.cos(v);
pos[1] = r * u * Math.sin(v);
pos[2] = -u / (Math.PI / 2) + 1;
}; | function used in iterative construction of parametric primitive.
@static
@method
@param {Number} r Cone Radius.
@param {Number} u Longitudal progress from 0 to PI.
@param {Number} v Latitudal progress from 0 to PI.
@return {Array} x, y and z coordinate of geometry. | generator ( r , u , v , pos ) | javascript | Famous/engine | webgl-geometries/primitives/ParametricCone.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/ParametricCone.js | MIT |
Torus.generator = function generator(c, a, u, v, pos) {
pos[0] = (c + a * Math.cos(2 * v)) * Math.sin(2 * u);
pos[1] = -(c + a * Math.cos(2 * v)) * Math.cos(2 * u);
pos[2] = a * Math.sin(2 * v);
}; | function used in iterative construction of parametric primitive.
@static
@method
@param {Number} c Radius of inner hole.
@param {Number} a Radius of tube.
@param {Number} u Longitudal progress from 0 to PI.
@param {Number} v Latitudal progress from 0 to PI.
@param {Array} pos X, Y, Z position of vertex at given slice and stack.
@return {undefined} undefined | generator ( c , a , u , v , pos ) | javascript | Famous/engine | webgl-geometries/primitives/Torus.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Torus.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.