- 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.
- 數(shù)據(jù)庫(kù)程序員面試筆試真題與解析
- Python數(shù)據(jù)分析入門與實(shí)戰(zhàn)
- 簡(jiǎn)單高效LATEX
- Cocos2d-x游戲開發(fā):手把手教你Lua語(yǔ)言的編程方法
- 程序員面試筆試寶典
- Designing Hyper-V Solutions
- 精通Python設(shè)計(jì)模式(第2版)
- The HTML and CSS Workshop
- 速學(xué)Python:程序設(shè)計(jì)從入門到進(jìn)階
- Java EE 7 with GlassFish 4 Application Server
- IBM RUP參考與認(rèn)證指南
- R語(yǔ)言:邁向大數(shù)據(jù)之路
- Swift iOS Programming for Kids
- 大學(xué)計(jì)算機(jī)基礎(chǔ)
- VB語(yǔ)言程序設(shè)計(jì)實(shí)驗(yàn)教程