找回密碼
 注冊帳號

掃一掃,訪問微社區

camera.worldtocameramatrix 世界轉相機矩陣

2015-1-4 08:47| 發布者: 楊炎| 查看: 2397| 評論: 0|原作者: 蠻牛|來自: unity3d腳本manual

摘要: camera.worldtocameramatrix 世界轉相機矩陣varworldtocameramatrix:matrix4x4description描述matrix that transforms from world to camera space.從世界到相機空間的變換矩陣。use this to calculate the camera s ...

camera.worldtocameramatrix 世界轉相機矩陣

varworldtocameramatrix: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 itstransform. this lasts until you callresetworldtocameramatrix.

如果你改變這個矩陣,相機的渲染不再基于它的transform更新,知道調用resetworldtocameramatrix.

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

publicvector3(0, 1, 0);

void lateupdate() {

vector3(-offset.x, -offset.y, offset.z);

matrix4x4m =matrix4x4.trs(camoffset,quaternion.identity, newvector3(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;

}

相關閱讀

文章點評
相關文章
女校游泳队彩金