- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 303字
- 2021-06-30 14:46:02
Conjugate and inverse
Games mostly use normalized quaternions, which comes in handy when inverting quaternions. The inverse of a normalized quaternion is its conjugate. The conjugate
of a quaternion flips its axis of rotation:
- Implement the conjugate function in quat.cpp and remember to declare the function in quat.h:
quat conjugate(const quat& q) {
return quat(
-q.x,
-q.y,
-q.z,
q.w
);
}
- The proper inverse of a quaternion is the conjugate divided by the squared length of the quaternion. Implement the quaternion inverse function in quat.cpp. Add the function declaration to quat.h:
quat inverse(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 recip = 1.0f / lenSq;
return quat(-q.x * recip,
-q.y * recip,
-q.z * recip,
q.w * recip
);
}
If you need to find out whether a quaternion is normalized or not, check the squared length. The squared length of a normalized quaternion is always 1. If a quaternion is normalized, its conjugate and inverse are the same. This means you can use the faster conjugate function, instead of the inverse function. In the next section, you will learn how to multiply two quaternions together.
- Go Web編程
- The Complete Rust Programming Reference Guide
- 造個小程序:與微信一起干件正經(jīng)事兒
- Raspberry Pi 2 Server Essentials
- QTP自動化測試進(jìn)階
- Hands-On Natural Language Processing with Python
- Mastering JBoss Enterprise Application Platform 7
- Nginx實戰(zhàn):基于Lua語言的配置、開發(fā)與架構(gòu)詳解
- WordPress 4.0 Site Blueprints(Second Edition)
- Java EE核心技術(shù)與應(yīng)用
- 基于SpringBoot實現(xiàn):Java分布式中間件開發(fā)入門與實戰(zhàn)
- C語言程序設(shè)計
- 例說FPGA:可直接用于工程項目的第一手經(jīng)驗
- HikariCP數(shù)據(jù)庫連接池實戰(zhàn)
- Learning Node.js for Mobile Application Development