Class: Quaternion

Quaternion

new Quaternion(x, y, z, w)

Name Type Default Description
x Number 0 optional

X component

y Number 0 optional

Y component

z Number 0 optional

Z component

w Number 1 optional

W component

Fires:
  • event:update 数据更新事件

Mixes In

Members Show Inherited

Name Type Default Description
className String Quaternion

类名

isQuaternion Boolean true
x Number

X component

y Number

Y component

z Number

Z component

w Number

W component

Methods Show Inherited

copy(q, dontFireEvent){Quaternion}

Copy the values from one quat to this

Name Type Default Description
q Quaternion
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

Creates a new quat initialized with values from an existing quaternion

Returns:
Type Description
Quaternion a new quaternion

toArray(array, offset){Array}

转换到数组

Name Type Default Description
array Array [] optional

数组

offset Number 0 optional

数组偏移值

Returns:
Type Description
Array

fromArray(array, offset, dontFireEvent){Quaternion}

从数组赋值

Name Type Default Description
array Array

数组

offset Number 0 optional

数组偏移值

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

set(x, y, z, w, dontFireEvent){Quaternion}

Set the components of a quat to the given values

Name Type Default Description
x Number

X component

y Number

Y component

z Number

Z component

w Number

W component

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

identity(dontFireEvent){Quaternion}

Set this to the identity quaternion

Name Type Default Description
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

rotationTo(a, b, dontFireEvent){Quaternion}

Sets a quaternion to represent the shortest rotation from one vector to another.

Name Type Default Description
a Vector3

the initial vector

b Vector3

the destination vector

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

setAxes(view, right, up, dontFireEvent){Quaternion}

Sets the specified quaternion with values corresponding to the given axes. Each axis is a vec3 and is expected to be unit length and perpendicular to all other specified axes.

Name Type Default Description
view Vector3

the vector representing the viewing direction

right Vector3

the vector representing the local "right" direction

up Vector3

the vector representing the local "up" direction

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

setAxisAngle(axis, rad, dontFireEvent){Quaternion}

Sets a quat from the given angle and rotation axis, then returns it.

Name Type Default Description
axis Vector3

the axis around which to rotate

rad Number

the angle in radians

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

getAxisAngle(out_axis){Number}

Gets the rotation axis and angle for a given quaternion. If a quaternion is created with setAxisAngle, this method will return the same values as providied in the original parameter list OR functionally equivalent values. Example: The quaternion formed by axis [0, 0, 1] and angle -90 is the same as the quaternion formed by [0, 0, 1] and 270. This method favors the latter.

Name Type Description
out_axis Vector3

Vector receiving the axis of rotation

Returns:
Type Description
Number Angle, in radians, of the rotation

add(q, dontFireEvent){Quaternion}

Adds two quat's

Name Type Default Description
q Quaternion
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

multiply(q, dontFireEvent){Quaternion}

Multiplies two quat's

Name Type Default Description
q Quaternion
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

premultiply(q, dontFireEvent){Quaternion}

premultiply the quat

Name Type Default Description
q Quaternion
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

scale(scale, dontFireEvent){Quaternion}

Scales a quat by a scalar number

Name Type Default Description
scale Vector3

the vector to scale

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

rotateX(rad, dontFireEvent){Quaternion}

Rotates a quaternion by the given angle about the X axis

Name Type Default Description
rad Number

angle (in radians) to rotate

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

rotateY(rad, dontFireEvent){Quaternion}

Rotates a quaternion by the given angle about the Y axis

Name Type Default Description
rad Number

angle (in radians) to rotate

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

rotateZ(rad, dontFireEvent){Quaternion}

Rotates a quaternion by the given angle about the Z axis

Name Type Default Description
rad Number

angle (in radians) to rotate

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

calculateW(dontFireEvent){Quaternion}

Calculates the W component of a quat from the X, Y, and Z components. Assumes that quaternion is 1 unit in length. Any existing W component will be ignored.

Name Type Default Description
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

dot(q){Number}

Calculates the dot product of two quat's

Name Type Description
q Quaternion
Returns:
Type Description
Number dot product of two quat's

lerp(q, t, dontFireEvent){Quaternion}

Performs a linear interpolation between two quat's

Name Type Default Description
q Quaternion
t Number

interpolation amount between the two inputs

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

slerp(q, t, dontFireEvent){Quaternion}

Performs a spherical linear interpolation between two quat

Name Type Default Description
q Quaternion
t Number

interpolation amount between the two inputs

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

sqlerp(qa, qb, qc, qd, t, dontFireEvent){Quaternion}

Performs a spherical linear interpolation with two control points

Name Type Default Description
qa Quaternion
qb Quaternion
qc Quaternion
qd Quaternion
t Number

interpolation amount

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

invert(dontFireEvent){Quaternion}

Calculates the inverse of a quat

Name Type Default Description
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

conjugate(dontFireEvent){Quaternion}

Calculates the conjugate of a quat If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.

Name Type Default Description
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

length(){Number}

Calculates the length of a quat

Returns:
Type Description
Number length of this

squaredLength(){Number}

Calculates the squared length of a quat

Returns:
Type Description
Number squared length of this

normalize(dontFireEvent){Quaternion}

Normalize this

Name Type Default Description
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

fromMat3(m, dontFireEvent){Quaternion}

Creates a quaternion from the given 3x3 rotation matrix.

NOTE: The resultant quaternion is not normalized, so you should be sure to renormalize the quaternion yourself where necessary.

Name Type Default Description
m Matrix3

rotation matrix

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

fromMat4(m, dontFireEvent){Quaternion}

Creates a quaternion from the given 3x3 rotation matrix.

NOTE: The resultant quaternion is not normalized, so you should be sure to renormalize the quaternion yourself where necessary.

Name Type Default Description
m Matrix4

rotation matrix

dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

exactEquals(q){Boolean}

Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)

Name Type Description
q Quaternion
Returns:
Type Description
Boolean

equals(q){Boolean}

Returns whether or not the quaternions have approximately the same elements in the same position.

Name Type Description
q Quaternion
Returns:
Type Description
Boolean

fromEuler(euler, dontFireEvent){Quaternion}

Creates a quaternion from the given euler.

Name Type Default Description
euler Euler
dontFireEvent Boolean false optional

wether or not don`t fire change event.

Returns:
Type Description
Quaternion this

Alias for Quaternion#length