找回密碼
 注冊帳號

掃一掃,訪問微社區

camera.viewportpointtoray 視窗位置轉射線

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

摘要: camera.viewportpointtoray 視窗位置轉射線functionviewportpointtoray(position:raydescription描述returns a ray going from camera through a viewport point.返回從相機出發穿過視點的一個射線。resulting ray i ...

camera.viewportpointtoray 視窗位置轉射線

functionviewportpointtoray(position:ray

description描述

returns a ray going from camera through a viewport point.

返回從相機出發穿過視點的一個射線。

resulting ray is in world space, starting on the near plane of the camera and going through position's (x,y) coordinates on the viewport (position.z is ignored).

產生的射線是在世界空間中,從相機的近裁剪面開始并穿過視口position(x,y)坐標(position.z被忽略)

viewport coordinates are normalized and relative to the camera. the bottom-left of the camera is (0,0); the top-right is (1,1).

視窗坐標被規范化,并相對于相機。相機的左下為(0,0);右上是(1,1)。

c#

javascript

using unityengine;

using system.collections;

public class example : monobehaviour {

void update() {

ray ray = camera.viewportpointtoray(new vector3(0.5f, 0.5f, 0));

raycasthit hit;

if (physics.raycast(ray, out hit))

print("i'm looking at " + hit.transform.name);

else

print("i'm looking at nothing!");

}

}

// prints the name of the object camera is directly looking at

//打印相機直接看到物體名稱

function update () {

// get the ray going through the center of the screen

//獲取穿過屏幕中心的射線

var ray :ray= camera.viewportpointtoray (vector3(0.5,0.5,0));

// do a raycast

//投射

var hit :raycasthit;

if (physics.raycast(ray, hit))

print ("i'm looking at " + hit.transform.name);

else

print ("i'm looking at nothing!");

}

相關閱讀

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