看看人家写的博客——观察矩阵的推导,写的相当好呀呀呀呀

阅读: 评论:0

看看人家写的博客——观察矩阵的推导,写的相当好呀呀呀呀

看看人家写的博客——观察矩阵的推导,写的相当好呀呀呀呀

观察矩阵推导

矩阵的在线计算器:.py

我们同一个术语,MVP矩阵中的V矩阵叫做观察矩阵
此矩阵的目的:将世界坐标系的点,转换为视口下的相对坐标。

摄像机所在的坐标系,先经过旋转矩阵,在经过平移矩阵即可得到。
C=TR

那么视口矩阵就是C的逆变换。
首先将世界坐标的点P,经过T的逆变换,然后再经过R的逆变换,就得到了P点,在视口下的相对坐标。

有了此相对坐标,就可以进行透视投影了。

unity源码中矩阵的计算:

// Transforms a position by this matrix (generic).CSRAW public Vector3 MultiplyPoint (Vector3 v){Vector3 res;float w;res.x = this.m00 * v.x + this.m01 * v.y + this.m02 * v.z + this.m03; res.y = this.m10 * v.x + this.m11 * v.y + this.m12 * v.z + this.m13;res.z = this.m20 * v.x + this.m21 * v.y + this.m22 * v.z + this.m23;w     = this.m30 * v.x + this.m31 * v.y + this.m32 * v.z + this.m33;w = 1F / w;res.x *= w;res.y *= w;res.z *= w;return res;}// Transforms a position by this matrix (fast).CSRAW public Vector3 MultiplyPoint3x4 (Vector3 v){Vector3 res;res.x = this.m00 * v.x + this.m01 * v.y + this.m02 * v.z + this.m03;res.y = this.m10 * v.x + this.m11 * v.y + this.m12 * v.z + this.m13;res.z = this.m20 * v.x + this.m21 * v.y + this.m22 * v.z + this.m23;return res;}// Transforms a direction by this matrix.CSRAW public Vector3 MultiplyVector (Vector3 v){Vector3 res;res.x = this.m00 * v.x + this.m01 * v.y + this.m02 * v.z;res.y = this.m10 * v.x + this.m11 * v.y + this.m12 * v.z;res.z = this.m20 * v.x + this.m21 * v.y + this.m22 * v.z;return res;}

unity中的矩阵的,是行有限的。一行表示基向量。

本文发布于:2024-02-05 08:19:12,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170728038264863.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:矩阵   博客
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23