Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Camera.worldToCameraMatrix 世界转相机矩阵
# [Camera](Camera.html).worldToCameraMatrix 世界转相机矩阵 var *worldToCameraMatrix* : [Matrix4x4](../Matrix4x4/Matrix4x4.html) *Description* 描述 Matrix that transforms from world to camera space. 从世界到相机空间的变换矩阵。 Use this to calculate the camera space position of objects or to provide custom camera's location that is not based on the transform. 用这个计算物体的相机空间位置或提供自定义的位置,这个位置不是基于变换的。 Note that camera space matches OpenGL convention: camera's forward is the negative Z axis. This is different from Unity's convention, where forward is the positive Z axis. 注意相机空间与 OpenGL 的 u 额定相同,相机的前面为 Z 轴负方向,这不同于 Unity 的约定,向前为 Z 轴正向。 If you change this matrix, the camera no longer updates its rendering based on its [Transform](../Transform/Transform.html). This lasts until you call [ResetWorldToCameraMatrix](Camera.ResetWorldToCameraMatrix.html). 如果你改变这个矩阵,相机的渲染不再基于它的 Transform 更新,知道调用 [ResetWorldToCameraMatrix](Camera.ResetWorldToCameraMatrix.html). * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { public Vector3 offset = new Vector3(0, 1, 0); void LateUpdate() { Vector3 camoffset = new Vector3(-offset.x, -offset.y, offset.z); Matrix4x4 m = Matrix4x4.TRS(camoffset, Quaternion.identity, new Vector3(1, 1, -1)); camera.worldToCameraMatrix = m * transform.worldToLocalMatrix; } } ``` ``` // Offsets camera's rendering from the transform's position. //从Offsets位置偏移相机的渲染 var offset : Vector3 = Vector3 (0,1,0); function LateUpdate () { // Construct a matrix that offsets and mirrors along // Z axis. Because camera space has mirrored Z with respect // to the rest of Unity. //构建一个沿着Z轴偏移和镜像的矩阵,因为相机已经为Z轴镜像,并用于其余部分 var camoffset : Vector3 = Vector3 (-offset.x, -offset.y, offset.z); var m : Matrix4x4 = Matrix4x4.TRS (camoffset, Quaternion.identity, Vector3 (1,1,-1)); // Override worldToCameraMatrix to be offset/mirrored // transform's matrix. //重载worldToCameraMatrix为偏移/镜像的变换矩阵 camera.worldToCameraMatrix = m * transform.worldToLocalMatrix; } ```
da
2022年5月17日 13:35
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码