Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the misalignment of rotation in <TransformComponent> #283

Merged
merged 12 commits into from
Jul 5, 2022
Merged
Prev Previous commit
Next Next commit
Update [BugFix]EulerAngle and Quaternion of PiccoloEngine.md
  • Loading branch information
Killyice committed Jul 2, 2022
commit 41d3dab07145a5208917d15c57f49cc24cbe38a6
10 changes: 5 additions & 5 deletions [BugFix]EulerAngle and Quaternion of PiccoloEngine.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

## 坐标系定义

1. [PPT](https://games-1312234642.cos.ap-guangzhou.myqcloud.com/course/GAMES104/GAMES104_Lecture08.pdf)中`欧拉角`的坐标系定义是按照:$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{red}X^+(面朝方向)\\\color{limegreen}\theta(Pitch)&\Rightarrow&\color{green}Y^+(物体右侧)\\\color{skyblue}\Psi(Yaw)&\Rightarrow&\color{blue}Z^+(物体下方)\end{array}\right.$,属于`右手坐标系`
1. [PPT](https://games-1312234642.cos.ap-guangzhou.myqcloud.com/course/GAMES104/GAMES104_Lecture08.pdf)中`欧拉角`的坐标系定义是按照:$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{red}X^+(面朝方向)\\\color{lime}\theta(Pitch)&\Rightarrow&\color{green}Y^+(物体右侧)\\\color{teal}\Psi(Yaw)&\Rightarrow&\color{blue}Z^+(物体下方)\end{array}\right.$,属于`右手坐标系`

2. `Piccolo引擎`的坐标系定义(以UI中显示的为准):$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{green}Y^+(面朝方向)\\\color{limegreen}\theta(Pitch)&\Rightarrow&\color{red}X^+(物体右侧)\\\color{skyblue}\Psi(Yaw)&\Rightarrow&\color{blue}Z^+(物体上方)\end{array}\right.$,同属`右手坐标系`。
2. `Piccolo引擎`的坐标系定义(以UI中显示的为准):$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{green}Y^+(面朝方向)\\\color{lime}\theta(Pitch)&\Rightarrow&\color{red}X^+(物体右侧)\\\color{teal}\Psi(Yaw)&\Rightarrow&\color{blue}Z^+(物体上方)\end{array}\right.$,同属`右手坐标系`。

3. [PPT](https://games-1312234642.cos.ap-guangzhou.myqcloud.com/course/GAMES104/GAMES104_Lecture08.pdf)中`欧拉角转四元组`的坐标系定义:与`Piccolo引擎`一致;

Expand All @@ -38,7 +38,7 @@
通过翻看代码发现在[editor_ui](https://github.com/BoomingTech/Piccolo/blob/64c422eff6cba7af7292f567f6bdef3d83d1e55b/engine/source/editor/source/editor_ui.cpp#L84-L115)中的`m_editor_ui_creator["Transform"]`进行了滑块相关的定义,其中用到了“四元数 → 欧拉角 → 四元数”。

在“四元数 → 欧拉角”代码片段(L84~L86),使用`degrees_val`来接收转化后的欧拉角(角度制),对应关系为:
$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{red}R_x(\alpha)\\\color{limegreen}\theta(Pitch)&\Rightarrow&\color{green}R_y(\beta)\\\color{skyblue}\Psi(Yaw)&\Rightarrow&\color{blue}R_z(\gamma)\end{array}\right.$
$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{red}R_x(\alpha)\\\color{lime}\theta(Pitch)&\Rightarrow&\color{green}R_y(\beta)\\\color{teal}\Psi(Yaw)&\Rightarrow&\color{blue}R_z(\gamma)\end{array}\right.$

即,引擎代码是以`PPT中的坐标系`定义为准,但这和`实际坐标系`相违背

Expand All @@ -50,13 +50,13 @@ $\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{red}R_x(\alph
已知:Piccolo的欧拉角是按照`X,Y,Z`顺序旋转(与Unreal一致),

在引擎的坐标系中,欧拉角的定义应为:
$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{green}R_y(\beta)\\\color{limegreen}\theta(Pitch)&\Rightarrow&\color{red}R_x(\alpha)\\\color{skyblue}\Psi(Yaw)&\Rightarrow&\color{blue}R_z(\gamma)\end{array}\right.$,与代码不符
$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{green}R_y(\beta)\\\color{lime}\theta(Pitch)&\Rightarrow&\color{red}R_x(\alpha)\\\color{teal}\Psi(Yaw)&\Rightarrow&\color{blue}R_z(\gamma)\end{array}\right.$,与代码不符

<hr>

现在在[editor_ui](https://github.com/BoomingTech/Piccolo/blob/64c422eff6cba7af7292f567f6bdef3d83d1e55b/engine/source/editor/source/editor_ui.cpp#L84-L115)中修改`degrees_val`,将“四元数—欧拉角”对应关系变成`坐标系相关`的:

$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{red}R_x(\alpha)\\\color{limegreen}\theta(Pitch)&\Rightarrow&\color{green}R_y(\beta)\\\color{skyblue}\Psi(Yaw)&\Rightarrow&\color{blue}R_z(\gamma)\end{array}\right.\Rightarrow\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{green}R_y(\beta)\\\color{limegreen}\theta(Pitch)&\Rightarrow&\color{red}R_x(\alpha)\\\color{skyblue}\Psi(Yaw)&\Rightarrow&\color{blue}R_z(\gamma)\end{array}\right.$,也就是交换`x`和`y`,这样就排除了`degrees_val`的问题。
$\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{red}R_x(\alpha)\\\color{lime}\theta(Pitch)&\Rightarrow&\color{green}R_y(\beta)\\\color{teal}\Psi(Yaw)&\Rightarrow&\color{blue}R_z(\gamma)\end{array}\right.\Rightarrow\left\{\begin{array}{lc}\color{pink}\phi(Roll)&\Rightarrow&\color{green}R_y(\beta)\\\color{lime}\theta(Pitch)&\Rightarrow&\color{red}R_x(\alpha)\\\color{teal}\Psi(Yaw)&\Rightarrow&\color{blue}R_z(\gamma)\end{array}\right.$,也就是交换`x`和`y`,这样就排除了`degrees_val`的问题。

这时需要一并交换下方“欧拉角 → 四元数”代码片段(L92-L115)三角函数里的`x`和`y`,否则两者数值会不匹配

Expand Down