Vector 表示向量、矢量的意思,含有大小和方向;Vector3 由名可得表示三维向量(描述三维空间中的一个[vector]
(矢量)。),包含想 x, y, z 三个分量,相对应的vector2就是2d的 简单理解Vector3就是相当于一个类,可直接new. 其中xyz三维坐标系可参考左手坐标系 注意:构造之后只读,对于实例中的 x/y/z 进行修改是无意义的
local v1 = Vector3.New(100,100,100)
local v2 = Vector3.New(50,50,50)
local v3 = v1 + v2
local v4 = v1 - v2
local v5 = v1*v2
local v6 = v1/v2
local v7 = -v1
print("v1 x:"..tostring(v1.x).." y:"..tostring(v1.y).." z:"..tostring(v1.z))
print("v2 x:"..tostring(v2.x).." y:"..tostring(v2.y).." z:"..tostring(v2.z))
print("v3 x:"..tostring(v3.x).." y:"..tostring(v3.y).." z:"..tostring(v3.z))
print("v4 x:"..tostring(v4.x).." y:"..tostring(v4.y).." z:"..tostring(v4.z))
print("v5 x:"..tostring(v5.x).." y:"..tostring(v5.y).." z:"..tostring(v5.z))
print("v6 x:"..tostring(v6.x).." y:"..tostring(v6.y).." z:"..tostring(v6.z))
print("v7 x:"..tostring(v7.x).." y:"..tostring(v7.y).." z:"..tostring(v7.z))
Vector3.Normalize(v1)
print("v1 x:"..tostring(v1.x).." y:"..tostring(v1.y).." z:"..tostring(v1.z))
v2:Normalize()
print("v2 x:"..tostring(v2.x).." y:"..tostring(v2.y).." z:"..tostring(v2.z))
local quat = Quaternion.New(0,0,2,1)
Vector3.FromQuaternion(quat)