eye | 指定要设置的立体视图矩阵。 |
matrix | 要设置的矩阵。 |
为特定立体眼睛设置自定义视图矩阵。
在大多数情况下,您应该使用 VR SDK 提供的投影矩阵,以确保准确的立体渲染。但是,在某些情况下,重写视图矩阵以实现特定效果可能比较有用。例如,要在 VR 中实现双筒望远镜效果,就需要使用自定义视图矩阵。
如果已设置自定义视图矩阵,摄像机将分析该视图矩阵,以确定能否安全地使用单通道剔除处理,还是必须为每只眼睛进行单独的剔除操作。使用 Camera.areVRStereoViewMatricesWithinSingleCullTolerance 可以确定将使用的剔除方法。
调用 Camera.ResetStereoViewMatrices 会将摄像机还原为使用 VR SDK 提供的视图矩阵。注意,在您调用 Camera.ResetStereoViewMatrices 之前,不会应用 Camera.stereoSeparation。
另请参阅:Camera.ResetStereoViewMatrices、Camera.stereoSeparation、Camera.areVRStereoViewMatricesWithinSingleCullTolerance
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { // Use this for initialization void Start() { }
// Update is called once per frame void Update() { Camera cam = GetComponent<Camera>();
Matrix4x4 viewL = cam.worldToCameraMatrix; Matrix4x4 viewR = cam.worldToCameraMatrix;
viewL[12] += 0.011f; viewR[12] -= 0.011f; cam.SetStereoViewMatrix(Camera.StereoscopicEye.Left, viewL); cam.SetStereoViewMatrix(Camera.StereoscopicEye.Right, viewR); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.