- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 247字
- 2021-06-30 14:46:02
Unit quaternions
Quaternions can be normalized just like vectors. Normalized quaternions represent only a rotation and non-normalized quaternions introduce a skew. In the context of game animation, quaternions should be normalized to avoid adding a skew to the transform.
To normalize a quaternion, divide each component of the quaternion by its length. The resulting quaternion's length will be 1. This can be implemented as follows:
- Implement the normalize function in quat.cpp and declare it in quat.h:
void normalize(quat& q) {
float lenSq = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w;
if (lenSq < QUAT_EPSILON) {
return;
}
float i_len = 1.0f / sqrtf(lenSq);
q.x *= i_len;
q.y *= i_len;
q.z *= i_len;
q.w *= i_len;
}
- Implement the normalized function in quat.cpp, and declare it in quat.h:
quat normalized(const quat& q) {
float lenSq = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w;
if (lenSq < QUAT_EPSILON) {
return quat();
}
float il = 1.0f / sqrtf(lenSq); // il: inverse length
return quat(q.x * il, q.y * il, q.z * il,q.w * il);
}
There is a fast way of inverting any unit quaternion. In the next section, you will learn how to find the conjugate and inverse of a quaternion and their relationship when it comes to unit quaternions.
- Clojure Programming Cookbook
- C語言從入門到精通(第4版)
- Flutter跨平臺開發(fā)入門與實戰(zhàn)
- Visual Basic程序設計實踐教程
- Geospatial Development By Example with Python
- JavaScript+jQuery網(wǎng)頁特效設計任務驅(qū)動教程
- 從Power BI到Analysis Services:企業(yè)級數(shù)據(jù)分析實戰(zhàn)
- Machine Learning for OpenCV
- Java EE架構(gòu)設計與開發(fā)實踐
- 程序員的成長課
- Java程序設計實用教程(第2版)
- 零基礎學SQL(升級版)
- Learn Linux Quickly
- Design Patterns and Best Practices in Java
- Swift編程實戰(zhàn):iOS應用開發(fā)實例及完整解決方案