OpenTK.Quaternion Struct Reference

Represents a Quaternion. More...

List of all members.

Public Member Functions

 Quaternion (Vector3 v, float w)
 Construct a new Quaternion from vector and w components.
 Quaternion (float x, float y, float z, float w)
 Construct a new Quaternion.
void ToAxisAngle (out Vector3 axis, out float angle)
 Convert the current quaternion to axis angle representation.
Vector4 ToAxisAngle ()
 Convert this instance to an axis-angle representation.
void Normalize ()
 Scales the Quaternion to unit length.
void Conjugate ()
 Convert this quaternion to its conjugate.
override string ToString ()
 Returns a System.String that represents the current Quaternion.
override bool Equals (object other)
 Compares this object instance to another object for equality.
override int GetHashCode ()
 Provides the hash code for this object.
bool Equals (Quaternion other)
 Compares this Quaternion instance to another Quaternion for equality.

Static Public Member Functions

static Quaternion Add (Quaternion left, Quaternion right)
 Add two quaternions.
static void Add (ref Quaternion left, ref Quaternion right, out Quaternion result)
 Add two quaternions.
static Quaternion Sub (Quaternion left, Quaternion right)
 Subtracts two instances.
static void Sub (ref Quaternion left, ref Quaternion right, out Quaternion result)
 Subtracts two instances.
static Quaternion Mult (Quaternion left, Quaternion right)
 Multiplies two instances.
static void Mult (ref Quaternion left, ref Quaternion right, out Quaternion result)
 Multiplies two instances.
static Quaternion Multiply (Quaternion left, Quaternion right)
 Multiplies two instances.
static void Multiply (ref Quaternion left, ref Quaternion right, out Quaternion result)
 Multiplies two instances.
static void Multiply (ref Quaternion quaternion, float scale, out Quaternion result)
 Multiplies an instance by a scalar.
static Quaternion Multiply (Quaternion quaternion, float scale)
 Multiplies an instance by a scalar.
static Quaternion Conjugate (Quaternion q)
 Get the conjugate of the given quaternion.
static void Conjugate (ref Quaternion q, out Quaternion result)
 Get the conjugate of the given quaternion.
static Quaternion Invert (Quaternion q)
 Get the inverse of the given quaternion.
static void Invert (ref Quaternion q, out Quaternion result)
 Get the inverse of the given quaternion.
static Quaternion Normalize (Quaternion q)
 Scale the given quaternion to unit length.
static void Normalize (ref Quaternion q, out Quaternion result)
 Scale the given quaternion to unit length.
static Quaternion FromAxisAngle (Vector3 axis, float angle)
 Build a quaternion from the given axis and angle.
static Quaternion Slerp (Quaternion q1, Quaternion q2, float blend)
 Do Spherical linear interpolation between two quaternions.
static Quaternion operator+ (Quaternion left, Quaternion right)
 Adds two instances.
static Quaternion operator- (Quaternion left, Quaternion right)
 Subtracts two instances.
static Quaternion operator* (Quaternion left, Quaternion right)
 Multiplies two instances.
static Quaternion operator* (Quaternion quaternion, float scale)
 Multiplies an instance by a scalar.
static Quaternion operator* (float scale, Quaternion quaternion)
 Multiplies an instance by a scalar.
static bool operator== (Quaternion left, Quaternion right)
 Compares two instances for equality.
static bool operator!= (Quaternion left, Quaternion right)
 Compares two instances for inequality.

Public Attributes

Vector3 xyz
float w

Static Public Attributes

static Quaternion Identity = new Quaternion(0, 0, 0, 1)
 Defines the identity quaternion.

Properties

Vector3 XYZ [get, set]
 Gets or sets an OpenTK.Vector3 with the X, Y and Z components of this instance.
Vector3 Xyz [get, set]
 Gets or sets an OpenTK.Vector3 with the X, Y and Z components of this instance.
float X [get, set]
 Gets or sets the X component of this instance.
float Y [get, set]
 Gets or sets the Y component of this instance.
float Z [get, set]
 Gets or sets the Z component of this instance.
float W [get, set]
 Gets or sets the W component of this instance.
float Length [get]
 Gets the length (magnitude) of the quaternion.
float LengthSquared [get]
 Gets the square of the quaternion length (magnitude).

Detailed Description

Represents a Quaternion.

Definition at line 37 of file Quaternion.cs.


Constructor & Destructor Documentation

OpenTK.Quaternion.Quaternion ( Vector3  v,
float  w 
)

Construct a new Quaternion from vector and w components.

Parameters:
v The vector part
w The w part

Definition at line 53 of file Quaternion.cs.

00054         {
00055             this.xyz = v;
00056             this.w = w;
00057         }

OpenTK.Quaternion.Quaternion ( float  x,
float  y,
float  z,
float  w 
)

Construct a new Quaternion.

Parameters:
x The x component
y The y component
z The z component
w The w component

Definition at line 66 of file Quaternion.cs.

00067             : this(new Vector3(x, y, z), w)
00068         { }


Member Function Documentation

static void OpenTK.Quaternion.Add ( ref Quaternion  left,
ref Quaternion  right,
out Quaternion  result 
) [static]

Add two quaternions.

Parameters:
left The first operand
right The second operand
result The result of the addition

Definition at line 252 of file Quaternion.cs.

00253         {
00254             result = new Quaternion(
00255                 left.Xyz + right.Xyz,
00256                 left.W + right.W);
00257         }

static Quaternion OpenTK.Quaternion.Add ( Quaternion  left,
Quaternion  right 
) [static]

Add two quaternions.

Parameters:
left The first operand
right The second operand
Returns:
The result of the addition

Definition at line 239 of file Quaternion.cs.

00240         {
00241             return new Quaternion(
00242                 left.Xyz + right.Xyz,
00243                 left.W + right.W);
00244         }

static void OpenTK.Quaternion.Conjugate ( ref Quaternion  q,
out Quaternion  result 
) [static]

Get the conjugate of the given quaternion.

Parameters:
q The quaternion
result The conjugate of the given quaternion

Definition at line 388 of file Quaternion.cs.

00389         {
00390             result = new Quaternion(-q.Xyz, q.W);
00391         }

static Quaternion OpenTK.Quaternion.Conjugate ( Quaternion  q  )  [static]

Get the conjugate of the given quaternion.

Parameters:
q The quaternion
Returns:
The conjugate of the given quaternion

Definition at line 378 of file Quaternion.cs.

00379         {
00380             return new Quaternion(-q.Xyz, q.W);
00381         }

void OpenTK.Quaternion.Conjugate (  ) 

Convert this quaternion to its conjugate.

Definition at line 211 of file Quaternion.cs.

00212         {
00213             Xyz = -Xyz;
00214         }

bool OpenTK.Quaternion.Equals ( Quaternion  other  ) 

Compares this Quaternion instance to another Quaternion for equality.

Parameters:
other The other Quaternion to be used in the comparison.
Returns:
True if both instances are equal; false otherwise.

Definition at line 692 of file Quaternion.cs.

00693         {
00694             return Xyz == other.Xyz && W == other.W;
00695         }

override bool OpenTK.Quaternion.Equals ( object  other  ) 

Compares this object instance to another object for equality.

Parameters:
other The other object to be used in the comparison.
Returns:
True if both objects are Quaternions of equal value. Otherwise it returns false.

Definition at line 660 of file Quaternion.cs.

00661         {
00662             if (other is Quaternion == false) return false;
00663                return this == (Quaternion)other;
00664         }

static Quaternion OpenTK.Quaternion.FromAxisAngle ( Vector3  axis,
float  angle 
) [static]

Build a quaternion from the given axis and angle.

Parameters:
axis The axis to rotate about
angle The rotation angle in radians
Returns:

Definition at line 465 of file Quaternion.cs.

00466         {
00467             if (axis.LengthSquared == 0.0f)
00468                 return Identity;
00469 
00470             Quaternion result = Identity;
00471 
00472             angle *= 0.5f;
00473             axis.Normalize();
00474             result.Xyz = axis * (float)System.Math.Sin(angle);
00475             result.W = (float)System.Math.Cos(angle);
00476 
00477             return Normalize(result);
00478         }

override int OpenTK.Quaternion.GetHashCode (  ) 

Provides the hash code for this object.

Returns:
A hash code formed from the bitwise XOR of this objects members.

Definition at line 674 of file Quaternion.cs.

00675         {
00676             return Xyz.GetHashCode() ^ W.GetHashCode();
00677         }

static void OpenTK.Quaternion.Invert ( ref Quaternion  q,
out Quaternion  result 
) [static]

Get the inverse of the given quaternion.

Parameters:
q The quaternion to invert
result The inverse of the given quaternion

Definition at line 414 of file Quaternion.cs.

00415         {
00416             float lengthSq = q.LengthSquared;
00417             if (lengthSq != 0.0)
00418             {
00419                 float i = 1.0f / lengthSq;
00420                 result = new Quaternion(q.Xyz * -i, q.W * i);
00421             }
00422             else
00423             {
00424                 result = q;
00425             }
00426         }

static Quaternion OpenTK.Quaternion.Invert ( Quaternion  q  )  [static]

Get the inverse of the given quaternion.

Parameters:
q The quaternion to invert
Returns:
The inverse of the given quaternion

Definition at line 402 of file Quaternion.cs.

00403         {
00404             Quaternion result;
00405             Invert(ref q, out result);
00406             return result;
00407         }

static void OpenTK.Quaternion.Mult ( ref Quaternion  left,
ref Quaternion  right,
out Quaternion  result 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
result A new instance containing the result of the calculation.

Definition at line 314 of file Quaternion.cs.

00315         {
00316             result = new Quaternion(
00317                 right.W * left.Xyz + left.W * right.Xyz + Vector3.Cross(left.Xyz, right.Xyz),
00318                 left.W * right.W - Vector3.Dot(left.Xyz, right.Xyz));
00319         }

static Quaternion OpenTK.Quaternion.Mult ( Quaternion  left,
Quaternion  right 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
A new instance containing the result of the calculation.

Definition at line 300 of file Quaternion.cs.

00301         {
00302             return new Quaternion(
00303                 right.W * left.Xyz + left.W * right.Xyz + Vector3.Cross(left.Xyz, right.Xyz),
00304                 left.W * right.W - Vector3.Dot(left.Xyz, right.Xyz));
00305         }

static Quaternion OpenTK.Quaternion.Multiply ( Quaternion  quaternion,
float  scale 
) [static]

Multiplies an instance by a scalar.

Parameters:
quaternion The instance.
scale The scalar.
Returns:
A new instance containing the result of the calculation.

Definition at line 364 of file Quaternion.cs.

00365         {
00366             return new Quaternion(quaternion.X * scale, quaternion.Y * scale, quaternion.Z * scale, quaternion.W * scale);
00367         }

static void OpenTK.Quaternion.Multiply ( ref Quaternion  quaternion,
float  scale,
out Quaternion  result 
) [static]

Multiplies an instance by a scalar.

Parameters:
quaternion The instance.
scale The scalar.
result A new instance containing the result of the calculation.

Definition at line 353 of file Quaternion.cs.

00354         {
00355             result = new Quaternion(quaternion.X * scale, quaternion.Y * scale, quaternion.Z * scale, quaternion.W * scale);
00356         }

static void OpenTK.Quaternion.Multiply ( ref Quaternion  left,
ref Quaternion  right,
out Quaternion  result 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
result A new instance containing the result of the calculation.

Definition at line 340 of file Quaternion.cs.

00341         {
00342             result = new Quaternion(
00343                 right.W * left.Xyz + left.W * right.Xyz + Vector3.Cross(left.Xyz, right.Xyz),
00344                 left.W * right.W - Vector3.Dot(left.Xyz, right.Xyz));
00345         }

static Quaternion OpenTK.Quaternion.Multiply ( Quaternion  left,
Quaternion  right 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
A new instance containing the result of the calculation.

Definition at line 327 of file Quaternion.cs.

00328         {
00329             Quaternion result;
00330             Multiply(ref left, ref right, out result);
00331             return result;
00332         }

static void OpenTK.Quaternion.Normalize ( ref Quaternion  q,
out Quaternion  result 
) [static]

Scale the given quaternion to unit length.

Parameters:
q The quaternion to normalize
result The normalized quaternion

Definition at line 449 of file Quaternion.cs.

00450         {
00451             float scale = 1.0f / q.Length;
00452             result = new Quaternion(q.Xyz * scale, q.W * scale);
00453         }

static Quaternion OpenTK.Quaternion.Normalize ( Quaternion  q  )  [static]

Scale the given quaternion to unit length.

Parameters:
q The quaternion to normalize
Returns:
The normalized quaternion

Definition at line 437 of file Quaternion.cs.

00438         {
00439             Quaternion result;
00440             Normalize(ref q, out result);
00441             return result;
00442         }

void OpenTK.Quaternion.Normalize (  ) 

Scales the Quaternion to unit length.

Definition at line 197 of file Quaternion.cs.

00198         {
00199             float scale = 1.0f / this.Length;
00200             Xyz *= scale;
00201             W *= scale;
00202         }

static bool OpenTK.Quaternion.operator!= ( Quaternion  left,
Quaternion  right 
) [static]

Compares two instances for inequality.

Parameters:
left The first instance.
right The second instance.
Returns:
True, if left does not equal right; false otherwise.

Definition at line 631 of file Quaternion.cs.

00632         {
00633             return !left.Equals(right);
00634         }

static Quaternion OpenTK.Quaternion.operator* ( float  scale,
Quaternion  quaternion 
) [static]

Multiplies an instance by a scalar.

Parameters:
quaternion The instance.
scale The scalar.
Returns:
A new instance containing the result of the calculation.

Definition at line 609 of file Quaternion.cs.

00610         {
00611             return new Quaternion(quaternion.X * scale, quaternion.Y * scale, quaternion.Z * scale, quaternion.W * scale);
00612         }

static Quaternion OpenTK.Quaternion.operator* ( Quaternion  quaternion,
float  scale 
) [static]

Multiplies an instance by a scalar.

Parameters:
quaternion The instance.
scale The scalar.
Returns:
A new instance containing the result of the calculation.

Definition at line 597 of file Quaternion.cs.

00598         {
00599             Multiply(ref quaternion, scale, out quaternion);
00600             return quaternion;
00601         }

static Quaternion OpenTK.Quaternion.operator* ( Quaternion  left,
Quaternion  right 
) [static]

Multiplies two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
The result of the calculation.

Definition at line 585 of file Quaternion.cs.

00586         {
00587             Multiply(ref left, ref right, out left);
00588             return left;
00589         }

static Quaternion OpenTK.Quaternion.operator+ ( Quaternion  left,
Quaternion  right 
) [static]

Adds two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
The result of the calculation.

Definition at line 559 of file Quaternion.cs.

00560         {
00561             left.Xyz += right.Xyz;
00562             left.W += right.W;
00563             return left;
00564         }

static Quaternion OpenTK.Quaternion.operator- ( Quaternion  left,
Quaternion  right 
) [static]

Subtracts two instances.

Parameters:
left The first instance.
right The second instance.
Returns:
The result of the calculation.

Definition at line 572 of file Quaternion.cs.

00573         {
00574             left.Xyz -= right.Xyz;
00575             left.W -= right.W;
00576             return left;
00577         }

static bool OpenTK.Quaternion.operator== ( Quaternion  left,
Quaternion  right 
) [static]

Compares two instances for equality.

Parameters:
left The first instance.
right The second instance.
Returns:
True, if left equals right; false otherwise.

Definition at line 620 of file Quaternion.cs.

00621         {
00622             return left.Equals(right);
00623         }

static Quaternion OpenTK.Quaternion.Slerp ( Quaternion  q1,
Quaternion  q2,
float  blend 
) [static]

Do Spherical linear interpolation between two quaternions.

Parameters:
q1 The first quaternion
q2 The second quaternion
blend The blend factor
Returns:
A smooth blend between the given quaternions

Definition at line 491 of file Quaternion.cs.

00492         {
00493             // if either input is zero, return the other.
00494             if (q1.LengthSquared == 0.0f)
00495             {
00496                 if (q2.LengthSquared == 0.0f)
00497                 {
00498                     return Identity;
00499                 }
00500                 return q2;
00501             }
00502             else if (q2.LengthSquared == 0.0f)
00503             {
00504                 return q1;
00505             }
00506 
00507 
00508             float cosHalfAngle = q1.W * q2.W + Vector3.Dot(q1.Xyz, q2.Xyz);
00509 
00510             if (cosHalfAngle >= 1.0f || cosHalfAngle <= -1.0f)
00511             {
00512                 // angle = 0.0f, so just return one input.
00513                 return q1;
00514             }
00515             else if (cosHalfAngle < 0.0f)
00516             {
00517                 q2.Xyz = -q2.Xyz;
00518                 q2.W = -q2.W;
00519                 cosHalfAngle = -cosHalfAngle;
00520             }
00521 
00522             float blendA;
00523             float blendB;
00524             if (cosHalfAngle < 0.99f)
00525             {
00526                 // do proper slerp for big angles
00527                 float halfAngle = (float)System.Math.Acos(cosHalfAngle);
00528                 float sinHalfAngle = (float)System.Math.Sin(halfAngle);
00529                 float oneOverSinHalfAngle = 1.0f / sinHalfAngle;
00530                 blendA = (float)System.Math.Sin(halfAngle * (1.0f - blend)) * oneOverSinHalfAngle;
00531                 blendB = (float)System.Math.Sin(halfAngle * blend) * oneOverSinHalfAngle;
00532             }
00533             else
00534             {
00535                 // do lerp if angle is really small.
00536                 blendA = 1.0f - blend;
00537                 blendB = blend;
00538             }
00539 
00540             Quaternion result = new Quaternion(blendA * q1.Xyz + blendB * q2.Xyz, blendA * q1.W + blendB * q2.W);
00541             if (result.LengthSquared > 0.0f)
00542                 return Normalize(result);
00543             else
00544                 return Identity;
00545         }

static void OpenTK.Quaternion.Sub ( ref Quaternion  left,
ref Quaternion  right,
out Quaternion  result 
) [static]

Subtracts two instances.

Parameters:
left The left instance.
right The right instance.
result The result of the operation.

Definition at line 282 of file Quaternion.cs.

00283         {
00284             result = new Quaternion(
00285                 left.Xyz - right.Xyz,
00286                 left.W - right.W);
00287         }

static Quaternion OpenTK.Quaternion.Sub ( Quaternion  left,
Quaternion  right 
) [static]

Subtracts two instances.

Parameters:
left The left instance.
right The right instance.
Returns:
The result of the operation.

Definition at line 269 of file Quaternion.cs.

00270         {
00271             return  new Quaternion(
00272                 left.Xyz - right.Xyz,
00273                 left.W - right.W);
00274         }

Vector4 OpenTK.Quaternion.ToAxisAngle (  ) 

Convert this instance to an axis-angle representation.

Returns:
A Vector4 that is the axis-angle representation of this quaternion.

Definition at line 135 of file Quaternion.cs.

00136         {
00137             Quaternion q = this;
00138             if (q.W > 1.0f)
00139                 q.Normalize();
00140 
00141             Vector4 result = new Vector4();
00142 
00143             result.W = 2.0f * (float)System.Math.Acos(q.W); // angle
00144             float den = (float)System.Math.Sqrt(1.0 - q.W * q.W);
00145             if (den > 0.0001f)
00146             {
00147                 result.Xyz = q.Xyz / den;
00148             }
00149             else
00150             {
00151                 // This occurs when the angle is zero. 
00152                 // Not a problem: just set an arbitrary normalized axis.
00153                 result.Xyz = Vector3.UnitX;
00154             }
00155 
00156             return result;
00157         }

void OpenTK.Quaternion.ToAxisAngle ( out Vector3  axis,
out float  angle 
)

Convert the current quaternion to axis angle representation.

Parameters:
axis The resultant axis
angle The resultant angle

Definition at line 124 of file Quaternion.cs.

00125         {
00126             Vector4 result = ToAxisAngle();
00127             axis = result.Xyz;
00128             angle = result.W;
00129         }

override string OpenTK.Quaternion.ToString (  ) 

Returns a System.String that represents the current Quaternion.

Returns:

Definition at line 646 of file Quaternion.cs.

00647         {
00648             return String.Format("V: {0}, W: {1}", Xyz, W);
00649         }


Member Data Documentation

Quaternion OpenTK.Quaternion.Identity = new Quaternion(0, 0, 0, 1) [static]

Defines the identity quaternion.

Definition at line 227 of file Quaternion.cs.


Property Documentation

float OpenTK.Quaternion.Length [get]

Gets the length (magnitude) of the quaternion.

See also:
LengthSquared

Definition at line 168 of file Quaternion.cs.

float OpenTK.Quaternion.LengthSquared [get]

Gets the square of the quaternion length (magnitude).

Definition at line 183 of file Quaternion.cs.

float OpenTK.Quaternion.W [get, set]

Gets or sets the W component of this instance.

Definition at line 111 of file Quaternion.cs.

float OpenTK.Quaternion.X [get, set]

Gets or sets the X component of this instance.

Definition at line 94 of file Quaternion.cs.

Vector3 OpenTK.Quaternion.Xyz [get, set]

Gets or sets an OpenTK.Vector3 with the X, Y and Z components of this instance.

Definition at line 88 of file Quaternion.cs.

Vector3 OpenTK.Quaternion.XYZ [get, set]

Gets or sets an OpenTK.Vector3 with the X, Y and Z components of this instance.

Definition at line 83 of file Quaternion.cs.

float OpenTK.Quaternion.Y [get, set]

Gets or sets the Y component of this instance.

Definition at line 100 of file Quaternion.cs.

float OpenTK.Quaternion.Z [get, set]

Gets or sets the Z component of this instance.

Definition at line 106 of file Quaternion.cs.

 All Classes Functions Variables Enumerations Properties Events

Generated on Tue Mar 9 14:59:15 2010 for The Open Toolkit library by  doxygen 1.6.1