Quat (struct)

The Quat represents a 3D rotation as a quaternion. Quaternions are used within the Xfo type. A Quat can be converted to and from Mat33 as well as Euler types.

参考

Xfo, Euler, Mat33

/*
** Example: Quat
*/

// create several quaternions
Quat q0, q1, q2, q3, q4;
q0 = Quat(Vec3(1.0, 0.0, 0.0), 0.0);
q1.setFromEuler(Euler(PI, 0.0, 0.0));
q2.setFromDirectionAndUpvector(Vec3(1.0, 0.0, 0.0), Vec3(0.0, 1.0, 0.0));
q3.setFrom2Vectors(Vec3(1.0, 0.0, 0.0), Vec3(1.0, 1.0, 0.0));
q4.setFromAxisAndAngle(Vec3(0.0, 1.0, 0.0), HALF_PI);

Quat Quat Quat

Members

Vec3 v  
Scalar w  

Methods

  Quat ( in Euler e )
  Quat ( in Mat33 mat )
  Quat ( in Quat other )
  Quat ( in Scalar w, in Vec3 v )
  Quat ( in Scalar x, in Scalar y, in Scalar z, in Scalar w )
  Quat ( in Vec3 v, in Scalar w )
  Quat ()
Quat add ? ( in Quat other )
  alignWith ! ( in Quat other )
Boolean almostEqual ? ( in Quat other )
Boolean almostEqual ? ( in Quat other, in Scalar precision )
Quat clone ? ()
Quat conjugate ? ()
Quat divide ? ( in Quat other )
Quat divideScalar ? ( in Scalar other )
Scalar dot ? ( in Quat other )
Boolean equal ? ( in Quat other )
  get ? ( io Float32 v<> )
  get ? ( io Float32 v<>, in UInt32 o )
  get ? ( io Float32 v[] )
  get ? ( io Float32 v[], in UInt32 o )
  get ? ( io Float64 v<> )
  get ? ( io Float64 v<>, in UInt32 o )
  get ? ( io Float64 v[] )
  get ? ( io Float64 v[], in UInt32 o )
Scalar getAngle ? ()
Vec3 getXaxis ? ()
Vec3 getYaxis ? ()
Vec3 getZaxis ? ()
UInt32 hash ? ()
Quat inverse ? ()
Scalar length ? ()
Scalar lengthSquared ? ()
Quat linearInterpolate ? ( in Quat other, in Scalar t )
  mirror ! ( in Integer axisIndex )
Quat multiply ? ( in Quat other )
Quat multiplyScalar ? ( in Scalar other )
Vec3 rotateVector ? ( in Vec3 v )
  set ! ( in Float32 v<> )
  set ! ( in Float32 v<>, in UInt32 o )
  set ! ( in Float64 v<> )
  set ! ( in Float64 v<>, in UInt32 o )
  set ! ( in Scalar w, in Vec3 v )
  set ! ( in Scalar x, in Scalar y, in Scalar z, in Scalar w )
  set ! ( in Vec3 v, in Scalar w )
Quat setFrom2Vectors ! ( in Vec3 sourceDirVec, in Vec3 destDirVec )
Quat setFrom2Vectors ! ( in Vec3 sourceDirVec, in Vec3 destDirVec, in Boolean arbitraryIfAmbiguous )
Quat setFromAxisAndAngle ! ( in Vec3 axis, in Scalar angle )
Quat setFromDirectionAndUpvector ! ( in Vec3 direction, in Vec3 upvector )
Quat setFromEuler ! ( in Euler e )
Quat setFromEulerAngles ! ( in Scalar eulerX, in Scalar eulerY, in Scalar eulerZ )
Quat setFromEulerAngles ! ( in Scalar eulerX, in Scalar eulerY, in Scalar eulerZ, in RotationOrder ro )
Quat setFromEulerAngles ! ( in Vec3 angles )
Quat setFromEulerAngles ! ( in Vec3 angles, in RotationOrder ro )
Quat setFromMat33 ! ( in Mat33 mat )
  setIdentity ! ()
Scalar setUnit ! ()
Quat sphericalLinearInterpolate ? ( in Quat q2, in Scalar t )
Quat subtract ? ( in Quat other )
Euler toEuler ? ( in RotationOrder rotationOrder )
Vec3 toEulerAngles ? ( in RotationOrder order )
Vec3 toEulerAngles ? ()
Mat33 toMat33 ? ()
Quat unit ? ()
Quat unit_safe ? ()

Operators

Quat = ( Param other )

Methods in detail

Quat ( in Euler e )

Construct from euler angles


Quat ( in Mat33 mat )

Construct from Mat33


Quat ( in Quat other )

copy constructor


Quat ( in Scalar w, in Vec3 v )

Construct from scalar and vector


Quat ( in Scalar x, in Scalar y, in Scalar z, in Scalar w )

Construct from scalars


Quat ( in Vec3 v, in Scalar w )

Construct from vector and scalar


Quat ()

Default constructor - set to identity


Quat Quat.add? ( in Quat other )

Overload method for the add operator


Quat.alignWith! ( in Quat other )

Aligns this quaternion with another one ensuring that the delta between the Quaternion values is the shortest path over the hypersphere.


Boolean Quat.almostEqual? ( in Quat other )

Returns true if this quaternion is almost equal to another one (using a default precision)


Boolean Quat.almostEqual? ( in Quat other, in Scalar precision )

Returns true if this quaternion is almost equal to another one (given a precision)


Quat Quat.clone? ()

clone method


Quat Quat.conjugate? ()

Returns the conjugate of this quaternion


Quat Quat.divide? ( in Quat other )

Overload method for the divide operator


Quat Quat.divideScalar? ( in Scalar other )

Returns the division of this quaternion and a scalar


Scalar Quat.dot? ( in Quat other )

Returns the dot product of this quaternion and another one


Boolean Quat.equal? ( in Quat other )

Returns true if this quaternion is equal to another one


Quat.get? ( io Float32 v<> )

Getter as external float32 array


Quat.get? ( io Float32 v<>, in UInt32 o )

Getter as external float32 array and an offset


Quat.get? ( io Float32 v[] )

Getter as float32 array


Quat.get? ( io Float32 v[], in UInt32 o )

Getter as float32 array and an offset


Quat.get? ( io Float64 v<> )

Getter as external float64 array


Quat.get? ( io Float64 v<>, in UInt32 o )

Getter as external float64 array and an offset


Quat.get? ( io Float64 v[] )

Getter as float64 array


Quat.get? ( io Float64 v[], in UInt32 o )

Getter as float64 array and an offset


Scalar Quat.getAngle? ()

Returns the angle of this quaternion (in radians)


Vec3 Quat.getXaxis? ()

Returns the X axis of this quaternion


Vec3 Quat.getYaxis? ()

Returns the Y axis of this quaternion


Vec3 Quat.getZaxis? ()

Returns the Z axis of this quaternion


UInt32 Quat.hash? ()

Hash for this value


Quat Quat.inverse? ()

Returns a inverse quaternion of this one


Scalar Quat.length? ()

Returns the length of this quaternion


Scalar Quat.lengthSquared? ()

Returns the squared length of this quaternion


Quat Quat.linearInterpolate? ( in Quat other, in Scalar t )

Interpolates two quaternions lineally (lerp) with a given blend value (0.0 to 1.0).

注釈

The interpolation of the 2 quaternions will result acceleration and deceleration. Use Quat.sphericalLinearInterpolate for an interpolation that does not introduce acceleration.


Quat.mirror! ( in Integer axisIndex )

Reflects this Quaternion according to the axis provided.

axisIndex An integer with value of 0 for the X axis, 1 for the Y axis, and 2 for the Z axis.


Quat Quat.multiply? ( in Quat other )

Overload method for the multiply operator


Quat Quat.multiplyScalar? ( in Scalar other )

Returns the product of this quaternion and a scalar


Vec3 Quat.rotateVector? ( in Vec3 v )

Rotates a vector by this quaterion. Don’t forget to normalize the quaternion unless you want axial translation as well as rotation.


Quat.set! ( in Float32 v<> )

Setter from (standard/external) float32 array


Quat.set! ( in Float32 v<>, in UInt32 o )

Setter from (standard/external) float32 array and an offset


Quat.set! ( in Float64 v<> )

Setter from (standard/external) float64 array


Quat.set! ( in Float64 v<>, in UInt32 o )

Setter from (standard/external) float64 array and an offset


Quat.set! ( in Scalar w, in Vec3 v )

Setter from scalar and vector


Quat.set! ( in Scalar x, in Scalar y, in Scalar z, in Scalar w )

Sets each component with a single scalar value.


Quat.set! ( in Vec3 v, in Scalar w )

Setter from vector and scalar


Quat Quat.setFrom2Vectors! ( in Vec3 sourceDirVec, in Vec3 destDirVec )

Overload for previous setFrom2Vectors method, avoid arbitrary rotations.


Quat Quat.setFrom2Vectors! ( in Vec3 sourceDirVec, in Vec3 destDirVec, in Boolean arbitraryIfAmbiguous )

Set the quaternion to the rotation required to rotate the source vector to the destination vector Function taken from the ‘Game Programming Gems’ article ‘The Shortest Arc Quaternion’ by Stan Melax Both vectors must be units.


Quat Quat.setFromAxisAndAngle! ( in Vec3 axis, in Scalar angle )

Set this quat to a rotation defined by an axis and an angle (in radians)


Quat Quat.setFromDirectionAndUpvector! ( in Vec3 direction, in Vec3 upvector )

Set the quat to represent the direction as the Z axis and the upvector pointing along the XY plane.


Quat Quat.setFromEuler! ( in Euler e )

Set this quat from a euler rotation


Quat Quat.setFromEulerAngles! ( in Scalar eulerX, in Scalar eulerY, in Scalar eulerZ )

Set this quat to a given angles vector (in radians) using the default XYZ rotation order


Quat Quat.setFromEulerAngles! ( in Scalar eulerX, in Scalar eulerY, in Scalar eulerZ, in RotationOrder ro )

Set this quat to a given angles vector (in radians) and a rotation order


Quat Quat.setFromEulerAngles! ( in Vec3 angles )

Set this quat to a given angles vector (in radians) using the default XYZ rotation order


Quat Quat.setFromEulerAngles! ( in Vec3 angles, in RotationOrder ro )

Set this quat to a given angles vector (in radians) and a rotation order


Quat Quat.setFromMat33! ( in Mat33 mat )

Set this quat to the rotation described by a 3x3 rotation matrix


Quat.setIdentity! ()

Set this quat to the identity


Scalar Quat.setUnit! ()

Sets this quaternion to a unit quaternion and returns the previous length


Quat Quat.sphericalLinearInterpolate? ( in Quat q2, in Scalar t )

interpolates two quaternions spherically (slerp) given a scalar blend value (0.0 to 1.0).

注釈

this and q2 should be unit Quaternions


Quat Quat.subtract? ( in Quat other )

Overload method for the subtract operator


Euler Quat.toEuler? ( in RotationOrder rotationOrder )

Returns this quaternion as a Euler rotation giving a rotation order


Vec3 Quat.toEulerAngles? ( in RotationOrder order )

Returns this quaternion as a Euler angles using the rotationorder XYZ


Vec3 Quat.toEulerAngles? ()

Returns this quaternion as a Euler angles using the rotationorder XYZ


Mat33 Quat.toMat33? ()

Returns this quaternion as a 3x3 rotation matrix


Quat Quat.unit? ()

Returns a unit quaternion of this one


Quat Quat.unit_safe? ()

Returns a unit quaternion of this one, no error reported if cannot be made unit

Operators in detail

Quat = ( Param other )

Adds another quaternion to this one