Ray


描述

射线 注意:构造之后只读,对于实例中的 origin/Direction/Unit 进行修改是无意义的


属性

Ray
构造
射线起点
射线方向
Ray
单位射线
获取碰撞位置
float
射线距离

函数

Vector3 (Ray ray, Vector3 point)
射线某个方向投影的
point = origin + cos(theta) *(unit)
(也表示点到射线的最先距离)
参数名称类别默认描述
rayRay
pointVector3
返回类型概要
Vector3
int (Ray ray, Vector3 point)
射线到某个位置的距离
参数名称类别默认描述
rayRay
pointVector3
返回类型概要
int距离

示例代码

local origin = Vector3.New(0,0,0)
local direct = Vector3.New(0,1,0)
local ray = Ray.New(origin, direct)
local unitRay = ray.Unit
local pos = Vector3.New(50,10,10)
local d = ray:Distance(pos)
local v3 = ray:ClosestPoint(pos)
print("Unit Ray:"..tostring(unitRay))
--Unit Ray:userdata: 42B65808
print("Ray Origin x:"..tostring(ray.Origin.x).." y:"..tostring(ray.Origin.y).." z:"..tostring(ray.Origin.z))
--Ray Origin x:0 y:0 z:0
print("Ray Direction x:"..tostring(ray.Direction.x).." y:"..tostring(ray.Direction.y).." z:"..tostring(ray.Direction.z))
--Ray Direction x:0 y:1 z:0
print("d:"..tostring(d))
--d:50.990196228027
print("v3:x:"..tostring(v3.x).." y:"..tostring(v3.y).." z:"..tostring(v3.z))
--v3:x:0 y:10 z:0
Last Updated: