|
inlib
1.2.0
|
Public Member Functions | |
| qrot () | |
| qrot (const a3::vec< T > &a_axis, T a_radians) | |
| virtual | ~qrot () |
| qrot (const qrot &a_from) | |
| qrot & | operator= (const qrot &a_from) |
| qrot & | operator*= (const qrot &a_q) |
| bool | operator== (const qrot &a_r) const |
| bool | operator!= (const qrot &a_r) const |
| qrot | operator* (const qrot &a_r) const |
| bool | invert () |
| bool | inverse (qrot &a_r) const |
| bool | set_value (const a3::vec< T > &a_axis, T a_radians) |
| bool | value (a3::vec< T > &a_axis, T &a_radians) const |
| void | value (a4::sqm< T > &matrix) const |
| void | mult_vec (const a3::vec< T > &a_in, a3::vec< T > &a_out) const |
| const a4::vec< T > & | quat () const |
| a4::vec< T > & | quat () |
Protected Member Functions | |
| qrot (T a_q0, T a_q1, T a_q2, T a_q3) | |
Static Protected Member Functions | |
| static T | one () |
| static T | minus_one () |
Protected Attributes | |
| a4::vec< T > | m_quat |
| inlib::qrot< T >::qrot | ( | ) | [inline] |
| inlib::qrot< T >::qrot | ( | const a3::vec< T > & | a_axis, |
| T | a_radians | ||
| ) | [inline] |
| virtual inlib::qrot< T >::~qrot | ( | ) | [inline, virtual] |
| inlib::qrot< T >::qrot | ( | const qrot< T > & | a_from | ) | [inline] |
| inlib::qrot< T >::qrot | ( | T | a_q0, |
| T | a_q1, | ||
| T | a_q2, | ||
| T | a_q3 | ||
| ) | [inline, protected] |
| bool inlib::qrot< T >::inverse | ( | qrot< T > & | a_r | ) | const [inline] |
Definition at line 94 of file qrot.
{
//Non-destructively inverses the rotation and returns the result.
T length = m_quat.length();
if(length==T()) return false;
// Optimize by doing 1 div and 4 muls instead of 4 divs.
T inv = one() / length;
a_r.m_quat.set_value(-m_quat.v0() * inv,
-m_quat.v1() * inv,
-m_quat.v2() * inv,
m_quat.v3() * inv);
return true;
}
| bool inlib::qrot< T >::invert | ( | ) | [inline] |
| static T inlib::qrot< T >::minus_one | ( | ) | [inline, static, protected] |
| void inlib::qrot< T >::mult_vec | ( | const a3::vec< T > & | a_in, |
| a3::vec< T > & | a_out | ||
| ) | const [inline] |
Definition at line 217 of file qrot.
{
const T x = m_quat.v0();
const T y = m_quat.v1();
const T z = m_quat.v2();
const T w = m_quat.v3();
// first row :
T v0 = (w*w + x*x - y*y - z*z) * a_in.v0()
+ (2*x*y - 2*w*z) * a_in.v1()
+ (2*x*z + 2*w*y) * a_in.v2();
T v1 = (2*x*y + 2*w*z) * a_in.v0()
+(w*w - x*x + y*y - z*z) * a_in.v1()
+ (2*y*z - 2*w*x) * a_in.v2();
T v2 = (2*x*z - 2*w*y) * a_in.v0()
+ (2*y*z + 2*w*x) * a_in.v1()
+(w*w - x*x - y*y + z*z) * a_in.v2();
a_out.set_value(v0,v1,v2);
}
| static T inlib::qrot< T >::one | ( | ) | [inline, static, protected] |
| bool inlib::qrot< T >::operator!= | ( | const qrot< T > & | a_r | ) | const [inline] |
Definition at line 70 of file qrot.
{
return !operator==(a_r);
}
| qrot inlib::qrot< T >::operator* | ( | const qrot< T > & | a_r | ) | const [inline] |
| qrot& inlib::qrot< T >::operator*= | ( | const qrot< T > & | a_q | ) | [inline] |
Definition at line 43 of file qrot.
{
//Multiplies the quaternions.
//Note that order is important when combining quaternions with the
//multiplication operator.
// Formula from <http://www.lboro.ac.uk/departments/ma/gallery/quat/>
T tx = m_quat.v0();
T ty = m_quat.v1();
T tz = m_quat.v2();
T tw = m_quat.v3();
T qx = a_q.m_quat.v0();
T qy = a_q.m_quat.v1();
T qz = a_q.m_quat.v2();
T qw = a_q.m_quat.v3();
m_quat.set_value(qw*tx + qx*tw + qy*tz - qz*ty,
qw*ty - qx*tz + qy*tw + qz*tx,
qw*tz + qx*ty - qy*tx + qz*tw,
qw*tw - qx*tx - qy*ty - qz*tz);
m_quat.normalize();
return *this;
}
| qrot& inlib::qrot< T >::operator= | ( | const qrot< T > & | a_from | ) | [inline] |
| bool inlib::qrot< T >::operator== | ( | const qrot< T > & | a_r | ) | const [inline] |
| const a4::vec<T>& inlib::qrot< T >::quat | ( | ) | const [inline] |
| a4::vec<T>& inlib::qrot< T >::quat | ( | ) | [inline] |
| bool inlib::qrot< T >::set_value | ( | const a3::vec< T > & | a_axis, |
| T | a_radians | ||
| ) | [inline] |
Definition at line 111 of file qrot.
{
// Reset rotation with the given axis-of-rotation and rotation angle.
// Make sure axis is not the null vector when calling this method.
// From <http://www.automation.hut.fi/~jaro/thesis/hyper/node9.html>.
if(a_axis.length()==T()) return false;
m_quat.v3(::cos(a_radians/2));
T sineval = ::sin(a_radians/2);
a3::vec<T> a = a_axis;
a.normalize();
m_quat.v0(a.v0() * sineval);
m_quat.v1(a.v1() * sineval);
m_quat.v2(a.v2() * sineval);
return true;
}
| bool inlib::qrot< T >::value | ( | a3::vec< T > & | a_axis, |
| T & | a_radians | ||
| ) | const [inline] |
Definition at line 126 of file qrot.
{
//WARNING : can fail.
if( (m_quat.v3()<minus_one()) || (m_quat.v3()> one()) ){
a_axis.set_value(0,0,1);
a_radians = 0;
return false;
}
a_radians = ::acos(m_quat.v3()) * 2;
T sineval = ::sin(a_radians/2);
if(sineval==T()) { //???
a_axis.set_value(0,0,1);
a_radians = 0;
return false;
}
a_axis.set_value(m_quat.v0()/sineval,
m_quat.v1()/sineval,
m_quat.v2()/sineval);
return true;
}
| void inlib::qrot< T >::value | ( | a4::sqm< T > & | matrix | ) | const [inline] |
Definition at line 184 of file qrot.
{
//Return this rotation in the form of a matrix.
const T x = m_quat.v0();
const T y = m_quat.v1();
const T z = m_quat.v2();
const T w = m_quat.v3();
// z = w + x * i + y * j + z * k
// first row :
matrix.set_value(0,0,w*w + x*x - y*y - z*z);
matrix.set_value(0,1,2*x*y - 2*w*z);
matrix.set_value(0,2,2*x*z + 2*w*y);
matrix.set_value(0,3,0);
// second row :
matrix.set_value(1,0,2*x*y + 2*w*z);
matrix.set_value(1,1,w*w - x*x + y*y - z*z);
matrix.set_value(1,2,2*y*z - 2*w*x);
matrix.set_value(1,3,0);
// third row :
matrix.set_value(2,0,2*x*z - 2*w*y);
matrix.set_value(2,1,2*y*z + 2*w*x);
matrix.set_value(2,2,w*w - x*x - y*y + z*z);
matrix.set_value(2,3,0);
// fourth row :
matrix.set_value(3,0,0);
matrix.set_value(3,1,0);
matrix.set_value(3,2,0);
matrix.set_value(3,3,w*w + x*x + y*y + z*z);
}
a4::vec<T> inlib::qrot< T >::m_quat [protected] |
1.7.5.1