Quaternion

Implementation of a quaternion. This is used for rotating things without encountering the dreaded gimbal lock issue, amongst other advantages.

Example

var quaternion = new THREE.Quaternion(); quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.PI / 2 ); var vector = new THREE.Vector3( 1, 0, 0 ); vector.applyQuaternion( quaternion );

Constructor

Quaternion( xyzw )

x - x coordinate
y - y coordinate
z - z coordinate
w - w coordinate

Properties

#.x

Changing this property will result in onChangeCallback being called.

#.y

Changing this property will result in onChangeCallback being called.

#.z

Changing this property will result in onChangeCallback being called.

#.w

Changing this property will result in onChangeCallback being called.

Methods

#.clone ()

Creates a new Quaternion with identical xyz and w properties to this one.

#.conjugate ()

Returns the rotational conjugate of this quaternion. The conjugate of a quaternion represents the same rotation in the opposite direction about the rotational axis.

#.copy ( q )

Copies the xy, z and w properties of q into this quaternion.

#.equals ( v )

v - Quaternion that this quaternion will be compared to.

Compares the xy, z and w properties of v to the equivalent properties of this quaternion to determine if they represent the same rotation.

#.dot ( v )

Calculates the dot product of quaternions v and this one.

#.fromArray ( arrayoffset )

array - array of format (x, y, z, w) used to construct the quaternion.
offset - (optional) an offset into the array.

Sets this quaternion's xy, z and w properties from an array.

#.inverse ()

Inverts this quaternion - calculate the conjugate and then normalizes the result.

#.length ()

Computes the Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector.

#.lengthSq ()

Computes the Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector. This can be useful if you are comparing the lengths of two quaternions, as this is a slightly more efficient calculation than length().

#.normalize ()

Normalizes this quaternion - that is, calculated the quaternion that performs the same rotation as this one, but has length equal to 1.

#.multiply ( q )

Multiplies this quaternion by q.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

#.multiplyQuaternions ( ab )

Sets this quaternion to a x b.
Adapted from the method outlined here.

#.onChange ( onChangeCallback )

Sets the onChangeCallback() method.

#.onChangeCallback ( )

This function is called whenever any of the following occurs:

By default it is the empty function, however you can change it if needed using onChangeonChangeCallback ).

#.premultiply ( q )

Pre-multiplies this quaternion by q.

#.slerp ( qbt )

qb - The other quaternion rotation
t - interpolation factor in the closed interval [0, 1].

Handles the spherical linear interpolation between quaternions. t represents the amount of rotation between this quaternion (where t is 0) and qb (where t is 1). This quaternion is set to the result. Also see the static version of the slerp below.// rotate a mesh towards a target quaternion mesh.quaternion.slerp( endQuaternion, 0.01 );

#.set ( xyzw )

Sets xyzw properties of this quaternion.

#.setFromAxisAngle ( axisangle )

Sets this quaternion from rotation specified by axis and angle.
Adapted from the method here.
Axis is assumed to be normalized, angle is in radians.

#.setFromEuler ( euler )

Sets this quaternion from the rotation specified by Euler angle.

#.setFromRotationMatrix ( m )

Sets this quaternion from rotation component of m.
Adapted from the method here.

#.setFromUnitVectors ( vFromvTo )

Sets this quaternion to the rotation required to rotate direction vector vFrom to direction vector vTo.
Adapted from the method here.
vFrom and vTo are assumed to be normalized.

#.toArray ( arrayoffset )

array - An optional array to store the quaternion. If not specified, a new array will be created.
offset - (optional) if specified, the result will be copied into this Array.

Returns the numerical elements of this quaternion in an array of format [x, y, z, w].

Static Methods

Static methods (as opposed to instance methods) are designed to be called directly from the class, rather than from a specific instance. So to use the static version of, call it like so:THREE.Quaternion.slerp( qStart, qEnd, qTarget, t );By contrast, to call the 'normal' or instanced slerp method, you would do the following://instantiate a quaternion with default values var q = new THREE.Quaternion(); //call the instanced slerp method q.slerp( qb, t )

#.slerp ( qStartqEndqTargett )

qStart - The starting quaternion (where t is 0)
qEnd - The ending quaternion (where t is 1)
qTarget - The target quaternion that gets set with the result
t - interpolation factor in the closed interval [0, 1].

Unlike the normal method, the static version of slerp sets a target quaternion to the result of the slerp operation.// Code setup var startQuaternion = new THREE.Quaternion().set( 0, 0, 0, 1 ).normalize(); var endQuaternion = new THREE.Quaternion().set( 1, 1, 1, 1 ).normalize(); var t = 0; // Update a mesh's rotation in the loop t = ( t + 0.01 ) % 1; // constant angular momentum THREE.Quaternion.slerp( startQuaternion, endQuaternion, mesh.quaternion, t );

#.slerpFlat ( dstdstOffsetsrc0srcOffset0src1srcOffset1t )

dst - The output array.
dstOffset - An offset into the output array.
src0 - The source array of the starting quaternion.
srcOffset0 - An offset into the array src0.
src1 - The source array of the target quatnerion.
srcOffset1 - An offset into the array src1.
t - Normalized interpolation factor (between 0 and 1).
 

Like the static slerp method above, but operates directly on flat arrays of numbers.

 

[출처] https://threejs.org/docs/#api/math/Quaternion

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED