目標是把螢幕像素中心轉成相機空間中的射線方向。假設畫面為 、寬高比 ,投影平面位於 。
- 加上 0.5 取像素中心,轉換到 :、
- 轉換到 :、
- 用寬高比修正
- 乘上 ,得到投影平面上的位置
最後射線方向為 ,正規化後即可使用。若要改變觀察方向,再把方向乘上相機旋轉矩陣;方向向量不要套用平移。
目标是把屏幕像素中心转换为相机空间中的射线方向。设画面为 、宽高比 ,投影平面位于 。
- 加上 0.5 取得像素中心,并转换到
- 转换到
- 使用宽高比修正
- 乘以 ,得到投影平面上的位置
最终射线方向为 ,归一化后即可使用。改变观察方向时,把方向乘以相机旋转矩阵;方向向量不应应用平移。
The goal is to convert a screen-pixel center into a ray direction in camera space. Let the image size be , the aspect ratio be , and the projection plane be at .
- Add 0.5 to address the pixel center and map it to
- Remap the result to
- Correct using the aspect ratio
- Multiply by to recover a point on the projection plane
The ray direction is . Normalize it before use. To change the view direction, multiply the direction by the camera rotation matrix; do not apply translation to a direction vector.
画面上のピクセル中心をカメラ空間のレイ方向へ変換します。画面サイズを 、アスペクト比を 、投影面を とします。
- 0.5 を加えてピクセル中心を取り、 へ変換します
- 結果を へ変換します
- アスペクト比で を補正します
- を掛け、投影面上の位置を求めます
レイ方向は です。使用前に正規化します。視線方向を変える場合はカメラの回転行列を掛けますが、方向ベクトルへ平行移動を適用してはいけません。
1 | Vector3f direction = Vector3f(x, y, -1).normalized(); |
參考資料
1 | Vector3f direction = Vector3f(x, y, -1).normalized(); |
参考资料
1 | Vector3f direction = Vector3f(x, y, -1).normalized(); |
References
1 | Vector3f direction = Vector3f(x, y, -1).normalized(); |