CUGL
2.0
|
#include <cugl.h>
Public Member Functions | |
Quaternion () | |
Quaternion (GLfloat s, GLfloat x, GLfloat y, GLfloat z) | |
Quaternion (const Vector &v) | |
Quaternion (GLfloat s, const Vector &v) | |
Quaternion (Vector axis, double angle) | |
Quaternion (Matrix m) | |
Quaternion (double xr, double yr, double zr) | |
Quaternion (const Point &p) | |
Quaternion (const Vector &u, const Vector &v) | |
Quaternion | operator+= (const Quaternion &q) |
Quaternion | operator-= (const Quaternion &q) |
Quaternion & | operator*= (const Quaternion &q) |
Quaternion & | operator/= (const Quaternion &q) |
Quaternion & | operator*= (GLfloat s) |
Quaternion & | operator/= (GLfloat s) |
Quaternion | operator/ (GLfloat scale) const |
void | normalize () |
Quaternion | unit () const |
Quaternion | conj () const |
Quaternion | inv () const |
Quaternion | operator~ () const |
Vector | apply (const Vector &w) const |
Vector | vector () const |
GLfloat | scalar () const |
GLfloat | norm () const |
GLfloat | magnitude () const |
void | matrix (Matrix &m) const |
void | matrix (GL_Matrix m) const |
void | apply () const |
Vector | axis () const |
double | angle () const |
void | integrate (const Vector &omega, double dt) |
void | euler (double &xr, double &yr, double &zr) const |
void | trackball (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) |
Private Attributes | |
GLfloat | s |
Vector | v |
Friends | |
class | Vector |
class | Matrix |
Quaternion | operator+ (const Quaternion &q, const Quaternion &r) |
Quaternion | operator- (const Quaternion &q, const Quaternion &r) |
Quaternion | operator* (const Quaternion &q, const Quaternion &r) |
Quaternion | operator* (const Vector &v, const Quaternion &q) |
Quaternion | operator* (const Quaternion &q, const Vector &v) |
Quaternion | operator* (const Quaternion &q, GLfloat a) |
Quaternion | operator* (GLfloat a, const Quaternion &q) |
Quaternion | log (const Quaternion &q) |
Quaternion | exp (const Quaternion &q) |
Quaternion | exp (const Vector &v) |
GLfloat | dot (const Quaternion &q, const Quaternion &r) |
bool | operator== (const Quaternion &x, const Quaternion &y) |
bool | operator!= (const Quaternion &x, const Quaternion &y) |
std::ostream & | operator<< (std::ostream &os, const Quaternion &q) |
An instance is a quaternion represented as a (scalar, vector) pair. We use the notation (s,v) for a quaternion with scalar component s and vector component v. Although arbitrary quaternions can be constructed, all of the applications of quaternions provided by the class assume that the quaternion is a unit quaternion representing a rotation.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
cugl::Quaternion::Quaternion | ( | Matrix | m | ) |
Construct the quaternion corresponding to an OpenGL rotation matrix. The result may be imprecise if the rotation angle is close to 180 degrees. This function may report BAD_ROTATION_MATRIX.
cugl::Quaternion::Quaternion | ( | double | xr, |
double | yr, | ||
double | zr | ||
) |
Construct a quaternion from Euler angles.
cugl::Quaternion::Quaternion | ( | const Point & | p | ) |
Construct a Quaternion from a Point. The quaternion consists of the vector (p[0],p[1],p[2]) and the scalar p[3].
Construct the quaternion that rotates one vector to another.
u | is a vector representing an initial orientation. |
v | is a vector representing the final orientation. The quaternion, applied to u, will yield v. |
|
inline |
void cugl::Quaternion::apply | ( | ) | const |
Apply the current quaternion to the current OpenGL matrix.
|
inline |
Return the axis of rotation of this quaternion.
Definition at line 3190 of file cugl.h.
References cugl::Vector::unit(), and v.
|
inline |
Return the conjugate of this quaternion. The conjugate of (s,v) is (s,-v). The inverse and conjugate of a unit quaternion are equal.
Definition at line 3185 of file cugl.h.
References Quaternion(), s, and v.
void cugl::Quaternion::euler | ( | double & | xr, |
double & | yr, | ||
double & | zr | ||
) | const |
Return Euler angles for this quaternion. The quaternion gives the rotation that would be obtained by calling glRotatef
three times, with arguments (xr
,1,0,0), (yr
,0,1,0), and (zr
,0,0,1).
void cugl::Quaternion::integrate | ( | const Vector & | omega, |
double | dt | ||
) |
Integrate an angular velocity vector. The rotation represented by this quaternion will be updated by applying the angular velocity omega
for a short interval of time dt
.
omega | is an angular velocity vector. |
dt | is the time increment for integration. |
Quaternion cugl::Quaternion::inv | ( | ) | const |
Return Inverse of this quaternion. q.inv() = q.conj()/q.norm(). The inverse and conjugate of a unit quaternion are equal. Report error ZERO_DIVISOR if q.norm() = 0. If q
represents a rotation then q.inv()
represents the opposite, or inverse, rotation. The prefix operator ~ has the same effect.
Referenced by operator~().
|
inline |
void cugl::Quaternion::matrix | ( | Matrix & | m | ) | const |
Compute the rotation matrix corresponding to this quaternion and store it in the Matrix m
.
Referenced by cugl::Interpolator::getMatrix().
void cugl::Quaternion::matrix | ( | GL_Matrix | m | ) | const |
Compute the rotation matrix corresponding to this quaternion and store it in the OpenGL matrix m
.
|
inline |
Return the norm of this quaternion. The norm is the sum of the squared components and is also the square of the magnitude.
Definition at line 3175 of file cugl.h.
References cugl::Vector::norm(), s, and v.
Referenced by magnitude(), and operator/=().
void cugl::Quaternion::normalize | ( | ) |
Normalize this quaternion. See also Quaternion::unit(). Report error ZERO_DIVISOR if q = (0,(0,0,0)).
|
inline |
REMOVED: ambiguous operattion - need left and right quotients. Return the quaternion ratio q/r. If q and r represent rotations, then q/r represents the rotation q followed by the rotation that is the inverse of r.
q
and return the result.
|
inline |
|
inline |
|
inline |
Quaternion cugl::Quaternion::operator/ | ( | GLfloat | scale | ) | const |
Return the quaternion q/a, where a is a scalar. a is a scalar and (s,v)/a = (s/a, v/a). Report error ZERO_DIVISOR if a = 0.
|
inline |
|
inline |
|
inline |
|
inline |
void cugl::Quaternion::trackball | ( | GLfloat | x1, |
GLfloat | y1, | ||
GLfloat | x2, | ||
GLfloat | y2 | ||
) |
Use this quaternion to simulate a trackball. To use this function in an OpenGL program, use the default constructor to construct the quaternion q = (1,(0,0,0)). In the display function, use q.rotate()
to modify the OpenGL model view matrix.
Call trackball(x1,y1,x2,y2)
to record a small mouse movement from (x1,y1) to (x2,y2). The coordinates should be normalized so that both x and y are in [-1,1].
This function will compute a rotation will apply this rotation to the current quaternion. The rotation simulates a trackball.
Quaternion cugl::Quaternion::unit | ( | ) | const |
Return a unit quaternion corresponding to this quaternion. See also Quaternion::normalize(). Report error ZERO_DIVISOR if q = (0,(0,0,0)).
|
inline |
|
friend |
The 'logarithm' of a unit quaternion is a vector. This function is defined because it appears in descriptions of quaternions. Although the name 'ln' is appropriate in some ways, this function must be used with caution because it may not have the properties you expect of a logarithm. For example, ln(q1)+ln(q2) makes sense only if q1 and q2 have the same axis.
q
and r
. The dot product of (s,u) and (t,v) is st+dot(u,v) where dot(u,v) denotes the vector dot product of u and v. q
and r
.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
Return the quaternion product q*r. If q
and r
represent rotations, then q*r represents the rotation q followed by the rotation r.
|
friend |
|
friend |
|
friend |
Return the quaternion a*q, where a is a scalar. a is a scalar and a*(s,v) = (a*s, a*v).
|
friend |
Return the quaternion a*q, where a is a scalar. a is a scalar and a*(s,v) = (a*s, a*v).
|
friend |
Return the quaternion q+r.
|
friend |
Return the quaternion q-r.
|
friend |
Write the quaternion to the output stream as s (x,y,z).
|
friend |
|
private |
Scalar component of quaternion.
Definition at line 1543 of file cugl.h.
Referenced by angle(), apply(), conj(), cugl::dot(), norm(), cugl::operator*(), operator*=(), cugl::operator+(), operator+=(), cugl::operator-(), operator-=(), operator/=(), cugl::operator==(), and scalar().
|
private |
Vector component of quaternion.
Definition at line 1546 of file cugl.h.
Referenced by apply(), axis(), conj(), cugl::dot(), norm(), cugl::operator*(), operator*=(), cugl::operator+(), operator+=(), cugl::operator-(), operator-=(), operator/=(), cugl::operator==(), cugl::Vector::Vector(), and vector().