Bingo, Computer Graphics & Game Developer

Atmos坐标变换

坐标变换

通常摄像机动画,模型动画中会使用旋转平移变换来完成坐标变换。这里使用基变换来完成通用的坐标系转换。

现要求得世界坐标PworldP_{world}对应的代求坐标系Ω\Omega下坐标PΩP_{\Omega},已知Ω\Omega坐标轴向量分别为X,Y,Z\overset{\rightharpoonup}{X}, \overset{\rightharpoonup}{Y}, \overset{\rightharpoonup}{Z},坐标原点为OO

worldToObject[X.xY.xZ.xO.xX.xY.yZ.yO.yX.zY.zZ.zO.z0001]worldToObject
\left[
\begin{matrix}
\overset{\rightharpoonup}{X}.x & \overset{\rightharpoonup}{Y}.x & \overset{\rightharpoonup}{Z}.x & O.x \
\overset{\rightharpoonup}{X}.x & \overset{\rightharpoonup}{Y}.y & \overset{\rightharpoonup}{Z}.y & O.y \\
\overset{\rightharpoonup}{X}.z & \overset{\rightharpoonup}{Y}.z & \overset{\rightharpoonup}{Z}.z & O.z \\
0 & 0 & 0 & 1
\end{matrix}
\right]

即有PΩ=worldToObjectPworldP_{\Omega}=worldToObject * P_{world}.(该矩阵含义可展开其含义自明)

PBRT以及Atmos中关于相机各类坐标系的转换

PBRT中的NDC坐标系在Atmos中未使用,因为其本身在PBRT中并不直接体现

具体的转换管线流程如下,实现公式可由下图各自推导出来,不做赘述。

rasterPosition(imageX, imageY);

// raster to screen
screenPosition(rasterPosition.x - image->width / 2.0f, -rasterPosition.y + image->height / 2.0f);

// screen to camera
// 这里pbrt中使用投影矩阵的逆变换得到cameraPos,不过由于透视的特殊性,其方向向量是一致的。
cameraPosition.x = 2 * canvasSize.x * screenPosition.x / image->width;
cameraPosition.y = 2 * canvasSize.y * screenPosition.y / image->height;
cameraPosition.z = canvasDistance;

// camera to world
ray->direction = (cameraToWorld * cameraPosition).getNormalized();
ray->origin = cameraToWorld * zeroVector3;

之后可以用worldToCamera矩阵进行转换。

worldToCamera[right.xup.xdirection.xorigin.xright.xup.ydirection.yorigin.yright.zup.zdirection.zorigin.z0001]worldToCamera
\left[
\begin{matrix}
right.x & up.x & direction.x & origin.x \
right.x & up.y & direction.y & origin.y \\
right.z & up.z & direction.z & origin.z \\
0 & 0 & 0 & 1
\end{matrix}
\right]