Camera.worldToCameraMatrix 世界转相机矩阵

var worldToCameraMatrix : Matrix4x4

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的约定相匹配,相机的前面为Z轴负方向,这不同于Unity的约定,向前为Z轴正向。

If you change this matrix, the camera no longer updates its rendering based on its Transform. This lasts until you call ResetWorldToCameraMatrix.

如果你改变这个矩阵,相机的渲染不再基于它的Transform更新,知道调用ResetWorldToCameraMatrix.

using UnityEngine;

using System.Collections;



public class example : MonoBehaviour {

	public Vector3(0, 1, 0);

		void LateUpdate() {

		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 (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 (-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;

}
Page last updated: 2013-7-30