- 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.
推薦閱讀
- 零基礎(chǔ)搭建量化投資系統(tǒng):以Python為工具
- ASP.NET MVC4框架揭秘
- 編程卓越之道(卷3):軟件工程化
- Visual C++數(shù)字圖像模式識(shí)別技術(shù)詳解
- Clojure for Domain:specific Languages
- Mastering Kotlin
- INSTANT Weka How-to
- Learn React with TypeScript 3
- 小學(xué)生C++創(chuàng)意編程(視頻教學(xué)版)
- 深入淺出React和Redux
- Visual Basic 6.0程序設(shè)計(jì)實(shí)驗(yàn)教程
- OpenCV with Python Blueprints
- Hacking Android
- Application Development with Parse using iOS SDK
- Java多線程并發(fā)體系實(shí)戰(zhàn)(微課視頻版)