- 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.
- JavaScript從入門到精通(微視頻精編版)
- TypeScript入門與實(shí)戰(zhàn)
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)踐教程
- AWS Serverless架構(gòu):使用AWS從傳統(tǒng)部署方式向Serverless架構(gòu)遷移
- C#程序設(shè)計(jì)(慕課版)
- TestNG Beginner's Guide
- C語(yǔ)言程序設(shè)計(jì)案例精粹
- 大學(xué)計(jì)算機(jī)基礎(chǔ)(第2版)(微課版)
- Apache Mesos Essentials
- Python面向?qū)ο缶幊蹋簶?gòu)建游戲和GUI
- C語(yǔ)言程序設(shè)計(jì)
- Mastering JavaScript Design Patterns(Second Edition)
- 劍指Java:核心原理與應(yīng)用實(shí)踐
- Java程序設(shè)計(jì)入門
- 微課學(xué)人工智能Python編程