我正在使用WebCamTexture从相机(iOS和Android)获取输入。但是,由于这是原始输入,因此在渲染到纹理时旋转是错误的。我读了很多,发现了这个(看看底部):WebCamTexture rotated and flipped on iPhone
他的代码(但有测试值):
Quaternion rotation = Quaternion.Euler(45f, 30f, 90f);
Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, rotation, new Vector3(1, 1, 1));
material.SetMatrix("_Rotation", rotationMatrix);
但无论我使用什么价值,都没有任何事情发生(无论是在编辑器中还是在设备上)......
谢谢!
修改 经过一些激烈的测试,我发现material.SetMatrix,SetFloat,SetWhatever没有效果(没有设置值),除非它在“Properties”块中声明。看看团结:自己的例子,这不应该(也不能)为矩阵完成(不能在属性内部声明,只能在CGProgram中)。那么......你如何设置矩阵呢?或者我还有什么其他的错误?
答案 0 :(得分:0)
将相机沿z轴旋转90度(相机正在渲染webcamtexture
游戏对象)。
答案 1 :(得分:-1)
您应该使用: WebCamTexture.videoRotationAngle
它旨在解决这个问题,请阅读有关此here的更多信息。
示例代码:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public WebCamTexture webcamTexture;
public Quaternion baseRotation;
void Start() {
webcamTexture = new WebCamTexture();
renderer.material.mainTexture = webcamTexture;
baseRotation = transform.rotation;
webcamTexture.Play();
}
void Update() {
transform.rotation = baseRotation * Quaternion.AngleAxis(webcamTexture.videoRotationAngle, Vector3.up);
}
}