- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 259字
- 2021-06-30 14:46:01
Angle axis
Quaternions are often created using an axis of rotation and an angle. A rotation about an axis by θ can be represented on a sphere as any directed arc whose length is on the plane perpendicular to the rotation axis. Positive angles yield a counterclockwise rotation around the axis.
Create a new file, quat.cpp. Implement the angleAxis function in quat.cpp. Don't forget to add the function declaration to quat.h:
#include "quat.h"
#include <cmath>
quat angleAxis(float angle, const vec3& axis) {
vec3 norm = normalized(axis);
float s = sinf(angle * 0.5f);
return quat(norm.x * s,
norm.y * s,
norm.z * s,
cosf(angle * 0.5f)
);
}
Why ? A quaternion can track two full rotations, which is 720 degrees. This makes the period of a quaternion 720 degrees. The period of sin/cos is 360 degrees. Dividing θ by 2 maps the range of a quaternion to the range of sin/cos.
In this section, you learned how the angle and axis of a rotation are encoded in
a quaternion. In the next section, you will learn how to build an angle and an axis
for the rotation between two vectors and encode that into a quaternion.
- Getting started with Google Guava
- DevOps for Networking
- 三維圖形化C++趣味編程
- Blockly創意趣味編程
- Learning Laravel 4 Application Development
- Hands-On Microservices with Kotlin
- 深入淺出RxJS
- R大數據分析實用指南
- The DevOps 2.5 Toolkit
- 響應式架構:消息模式Actor實現與Scala、Akka應用集成
- Android開發三劍客:UML、模式與測試
- 移動增值應用開發技術導論
- Oracle數據庫編程經典300例
- Mastering Embedded Linux Programming
- Thymeleaf 3完全手冊