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

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
26 자바스크립트 문자열 비교 예제; 대소 문자 구분/구분 없이 졸리운_곰 2017.07.22 1285
25 [javascript] hashtable 같은 key=value 예제 졸리운_곰 2017.07.22 484
24 Javascript [자바스크립트] 변수 선언과 유효범위 졸리운_곰 2017.07.08 582
23 Javascript 문자열을 실수(부동소수점) 변수로 변환 가을의곰 2017.06.10 518
22 JavaScript 강좌 | 배열(Array) > 선언하기 file 졸리운_곰 2017.05.31 294
21 JSON javascript 읽기 졸리운_곰 2017.05.31 525
20 자바스크립트와 Node.js를 이용한 웹 크롤링 테크닉 file 졸리운_곰 2017.05.27 570
19 JSON - 자바스크립트 강좌 JS / CSE file 졸리운_곰 2017.05.06 499
18 Javascript JSON.parse(), JSON.stringify() 사용하는법 졸리운_곰 2017.05.06 492
17 JSON Text를 JSON Object로 변환하기 졸리운_곰 2017.05.06 475
16 Three.js로 AutoCad DXF 모델 출력 : Three-Dxf file 졸리운_곰 2017.04.27 912
15 three.js r84 다운로드 file 졸리운_곰 2017.04.15 393
14 jqPlot으로 그래프 그리기! file 졸리운_곰 2017.03.20 682
13 basic plot graph by javascript, 자바스크립트로 그래프그리기 초간단 졸리운_곰 2015.11.13 572
12 A Survey of the JavaScript Programming Language file 졸리운_곰 2015.11.12 665
11 JavaScript Canvas examples 졸리운_곰 2015.11.10 360
10 [MEAN Stack] MEAN Stack 소개 file 졸리운_곰 2015.10.11 564
9 자바스크립트 패킹(packing), 자바스크립트 난독화, file 졸리운_곰 2015.05.31 920
8 •웹 소켓(Web Socket)이 있기까지 file 졸리운_곰 2015.05.22 762
7 자바스크립트의 한계 / 자바스크립트란 무엇인가? 졸리운_곰 2015.04.28 634
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED