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

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
143 [Three.js] 마우스 커서를 이용한 객체 선택하기 file 가을의곰 2017.06.10 659
142 [three.js] Quaternion 적용 가을의곰 2017.06.10 459
» [three.js] Quaternion 가을의곰 2017.06.10 311
140 Three.js Lights and Cameras file 가을의곰 2017.06.10 670
139 How to Build a First Person Shooter in the Browser with Three.js and WebGL/HTML5 Canvas file 가을의곰 2017.06.10 197
138 HTML div 왼쪽, 오른쪽 배치 가을의곰 2017.06.10 493
137 getting-started-with-three-js 가을의곰 2017.06.10 605
136 HTML DIV tag: 테두리 너비 지정하는 방법 - WIDTH : 픽셀(px) 또는 퍼센트(%) file 가을의곰 2017.06.10 827
135 Three.js object rotation with quaternion file 졸리운_곰 2017.06.09 358
134 [Three.js] PerspectiveCamera 가을의곰 2017.06.04 591
133 JavaScript 강좌 | 배열(Array) > 선언하기 file 졸리운_곰 2017.05.31 294
132 JSON javascript 읽기 졸리운_곰 2017.05.31 525
131 Three.js Examples file 졸리운_곰 2017.05.31 731
130 THREE.JS EXPERIMENT 2 – SELECTION/HIGHLIGHTING file 졸리운_곰 2017.05.31 482
129 threejs-cookbook/03-camera/03.10-select-an-object-in-the-scene.html 졸리운_곰 2017.05.31 312
128 learning-threejs/chapter-09/02-selecting-objects.html 졸리운_곰 2017.05.31 383
127 [three.js] OBJECT PICKING : select object by mouse 졸리운_곰 2017.05.31 504
126 웹지엘 좌표계 file 졸리운_곰 2017.05.30 557
125 HOW TO PUT TEXT BOXES IN AN HTML5 FORM file 졸리운_곰 2017.05.30 449
124 HTML div 왼쪽, 오른쪽 분할 졸리운_곰 2017.05.30 438
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED