29 lines
641 B
JavaScript
29 lines
641 B
JavaScript
|
|
module.exports = rotateX;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Rotate a 3D vector around the x-axis
|
||
|
|
* @param {vec3} out The receiving vec3
|
||
|
|
* @param {vec3} a The vec3 point to rotate
|
||
|
|
* @param {vec3} b The origin of the rotation
|
||
|
|
* @param {Number} c The angle of rotation
|
||
|
|
* @returns {vec3} out
|
||
|
|
*/
|
||
|
|
function rotateX(out, a, b, c){
|
||
|
|
var by = b[1]
|
||
|
|
var bz = b[2]
|
||
|
|
|
||
|
|
// Translate point to the origin
|
||
|
|
var py = a[1] - by
|
||
|
|
var pz = a[2] - bz
|
||
|
|
|
||
|
|
var sc = Math.sin(c)
|
||
|
|
var cc = Math.cos(c)
|
||
|
|
|
||
|
|
// perform rotation and translate to correct position
|
||
|
|
out[0] = a[0]
|
||
|
|
out[1] = by + py * cc - pz * sc
|
||
|
|
out[2] = bz + py * sc + pz * cc
|
||
|
|
|
||
|
|
return out
|
||
|
|
}
|