- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 154字
- 2021-06-30 14:46:02
Length and squared length
Like vectors, the squared length of a quaternion is the same as the dot product of the quaternion with itself. The length of a quaternion is the square root of the square length:
- Implement the lenSq function in quat.cpp and declare the function in quat.h:
float lenSq(const quat& q) {
return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
}
- Implement the len function in quat.cpp. Don't forget to add the function declaration to quat.h:
float len(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 0.0f;
}
return sqrtf(lenSq);
}
Quaternions that represent a rotation should always have a length of 1. In the next section, you will learn about unit quaternions, which always have a length of 1.
推薦閱讀
- Mastering Objectoriented Python
- Learning ArcGIS Pro 2
- INSTANT Passbook App Development for iOS How-to
- 機器學習與R語言實戰
- 執劍而舞:用代碼創作藝術
- C#開發案例精粹
- Swift語言實戰晉級
- Nagios Core Administration Cookbook(Second Edition)
- Learning JavaScript Data Structures and Algorithms(Second Edition)
- FPGA嵌入式項目開發實戰
- Python應用與實戰
- 虛擬現實建模與編程(SketchUp+OSG開發技術)
- Java Web入門很輕松(微課超值版)
- 少年小魚的魔法之旅:神奇的Python
- Learning Scrapy