THREE.Euler()欧拉角

来源:互联网 发布:centos nat 配置 编辑:程序博客网 时间:2024/06/05 18:33

THREE.Euler

  • 用法 THREE.Euler( a , b , c , ‘xyz’ );
    表示将一个几何体绕x轴旋转a度,绕y轴旋转b度,绕z轴旋转c度;并且旋转的顺序是xyz ; 第三个参数旋转顺序可以是’XYZ’, ‘YZX’, ‘ZXY’, ‘XZY’, ‘YXZ’, ‘ZYX’
THREE.Euler = function ( x, y, z, order ) {    this._x = x || 0;    this._y = y || 0;    this._z = z || 0;    this._order = order || THREE.Euler.DefaultOrder;};

原型上的方法

set( x , y , z , order )

set: function ( x, y, z, order ) {    this._x = x;    this._y = y;    this._z = z;    this._order = order || this._order;    this.onChangeCallback();    //调用回调函数.    return this;    //返回新的Euler(欧拉角)},

setFromRotationMatrix

setFromRotationMatrix: function ( m, order ) {    var clamp = THREE.Math.clamp;   //clamp用来设置数值的取值范围    // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)    // 确保参数m是一个3x3的旋转矩阵.    var te = m.elements;    var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];    var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];    var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];    order = order || this._order;    if ( order === 'XYZ' ) {        this._y = Math.asin( clamp( m13, - 1, 1 ) );        if ( Math.abs( m13 ) < 0.99999 ) {            this._x = Math.atan2( - m23, m33 );            this._z = Math.atan2( - m12, m11 );        } else {            this._x = Math.atan2( m32, m22 );            this._z = 0;        }    } else if ( order === 'YXZ' ) {        this._x = Math.asin( - clamp( m23, - 1, 1 ) );        if ( Math.abs( m23 ) < 0.99999 ) {            this._y = Math.atan2( m13, m33 );            this._z = Math.atan2( m21, m22 );        } else {            this._y = Math.atan2( - m31, m11 );            this._z = 0;        }    } else if ( order === 'ZXY' ) {        this._x = Math.asin( clamp( m32, - 1, 1 ) );        if ( Math.abs( m32 ) < 0.99999 ) {            this._y = Math.atan2( - m31, m33 );            this._z = Math.atan2( - m12, m22 );        } else {            this._y = 0;            this._z = Math.atan2( m21, m11 );        }    } else if ( order === 'ZYX' ) {        this._y = Math.asin( - clamp( m31, - 1, 1 ) );        if ( Math.abs( m31 ) < 0.99999 ) {            this._x = Math.atan2( m32, m33 );            this._z = Math.atan2( m21, m11 );        } else {            this._x = 0;            this._z = Math.atan2( - m12, m22 );        }    } else if ( order === 'YZX' ) {        this._z = Math.asin( clamp( m21, - 1, 1 ) );        if ( Math.abs( m21 ) < 0.99999 ) {            this._x = Math.atan2( - m23, m22 );            this._y = Math.atan2( - m31, m11 );        } else {            this._x = 0;            this._y = Math.atan2( m13, m33 );        }    } else if ( order === 'XZY' ) {        this._z = Math.asin( - clamp( m12, - 1, 1 ) );        if ( Math.abs( m12 ) < 0.99999 ) {            this._x = Math.atan2( m32, m22 );            this._y = Math.atan2( m13, m11 );        } else {            this._x = Math.atan2( - m23, m33 );            this._y = 0;        }    } else {        console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )   //通过按照以上几种旋转顺序设置欧拉角对象失败报错    }    this._order = order;    //重新设置旋转顺序    this.onChangeCallback();    //调用回调函数.    return this;    //返回新的Euler(欧拉角)},
原创粉丝点击