视角坐标系变换公式与其变体

来源:互联网 发布:淘宝类目数量表 编辑:程序博客网 时间:2024/06/01 20:41

前提条件:讨论范围为右手坐标系,矩阵计算机存储为行主序。

内容:

第一步:依据eye,center,up三个参数构造出视角坐标系的3个轴向

  vec3 f( vec3(center-eye))  f=-z轴(即z的反方向)

  vec3 s(f^up) s=x轴 (这里up不等于y轴,只是来辅助求出x轴)

 vec3 u(s^f)  u=y轴 

第二步:根据坐标系的3个坐标轴构建出坐标系变换矩阵的旋转分量

Matrix rotation( s[0], u[0], -f[0], 0.0f,
                                  s[1], u[1], -f[1], 0.0f,
                                s[2], u[2], -f[2], 0.0f,
                               0.0f, 0.0f,  0.0f, 1.0f );

inverse(rotation)即rotation的逆矩阵才是坐标系变换矩阵的旋转分量

第三步 :变换矩阵的平移分量

Matrix translate(eye)即平移分量

最终变换矩阵等式:

Matrix transform=inverse(rotation)*translate(eye),即先将坐标系在原点旋转,后平移到eye点

变体:

Matrix transform=translate(vec3(0,0,distance))*inverse(rotation)*translate(center),distance(非负数)为eye到center的距离,即将坐标系先沿着z轴平移distance单位,然后进行旋转,最后在以center向量平移。这里translate(center)和translate(distance)顺序不能颠倒,该变体多应用于三维引擎的视角操控器实现,通过改center,distance参数容易实现zoom in ,zoom out的效果。

transform即为视角坐标系变换矩阵,point*inverse(transform)用来将点point由世界坐标系转化为视角坐标系。

0 0