- 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.
- Getting Started with Citrix XenApp? 7.6
- Getting started with Google Guava
- SpringMVC+MyBatis快速開發(fā)與項(xiàng)目實(shí)戰(zhàn)
- Rust編程從入門到實(shí)戰(zhàn)
- Web Application Development with R Using Shiny(Second Edition)
- Android 7編程入門經(jīng)典:使用Android Studio 2(第4版)
- Java加密與解密的藝術(shù)
- JavaScript by Example
- Yii Project Blueprints
- Bootstrap 4 Cookbook
- PHP編程基礎(chǔ)與實(shí)例教程
- Processing創(chuàng)意編程指南
- MySQL 8從零開始學(xué)(視頻教學(xué)版)
- Python+Office:輕松實(shí)現(xiàn)Python辦公自動(dòng)化
- Python Automation Cookbook