Vec3 类型
继承于 ValueType
表示 3D 向量和坐标
索引
属性(properties)
ONEVec3新 Vec3 对象。ZEROVec3返回 x = 0,y = 0,z = 0 的 Vec3 对象。UPVec3返回 x = 0, y = 1, z = 0 的 Vec3 对象。RIGHTVec3返回 x = 1,y = 0,z = 0 的 Vec3 对象。FORWARDVec3返回 x = 0,y = 0,z = 1 的 Vec3 对象。xNumberyNumberzNumber
方法
mag返回该向量的长度。magSqr返回该向量的长度平方。subSelf向量减法。sub向量减法,并返回新结果。mulSelf缩放当前向量。mul缩放向量,并返回新结果。divSelf向量除法。div向量除法,并返回新的结果。scaleSelf分量相乘。scale分量相乘,并返回新的结果。negSelf向量取反。neg返回取反后的新向量。zero将目标赋值为零向量clone获得指定向量的拷贝copy复制目标向量set设置向量值add逐元素向量加法subtract逐元素向量减法multiply逐元素向量乘法 (分量积)divide逐元素向量除法ceil逐元素向量向上取整floor逐元素向量向下取整min逐元素向量最小值max逐元素向量最大值round逐元素向量四舍五入取整multiplyScalar向量标量乘法scaleAndAdd逐元素向量乘加: A + B * scaledistance求两向量的欧氏距离squaredDistance求两向量的欧氏距离平方len求向量长度lengthSqr求向量长度平方negate逐元素向量取负inverse逐元素向量取倒数,接近 0 时返回 InfinityinverseSafe逐元素向量取倒数,接近 0 时返回 0normalize归一化向量dot向量点积(数量积)cross向量叉积(向量积)lerp逐元素向量线性插值: A + t * (B - A)random生成一个在单位球体上均匀分布的随机向量transformMat4向量与四维矩阵乘法,默认向量第四位为 1。transformMat4Normal向量与四维矩阵乘法,默认向量第四位为 0。transformMat3向量与三维矩阵乘法transformAffine向量仿射变换transformQuat向量四元数乘法transformQuat以缩放 -> 旋转 -> 平移顺序变换向量transformInverseRTS以平移 -> 旋转 -> 缩放顺序逆变换向量rotateX绕 X 轴旋转向量指定弧度rotateY绕 Y 轴旋转向量指定弧度rotateZ绕 Z 轴旋转向量指定弧度strictEquals向量等价判断equals排除浮点数误差的向量近似等价判断angle求两向量夹角弧度projectOnPlane计算向量在指定平面上的投影project计算向量在指定向量上的投影toArray向量转数组fromArray数组转向量constructor构造函数,可查看 Cc/vec3:methodclone克隆一个 Vec3 值set用另一个向量设置当前的向量对象值。equals当前的向量是否与指定的向量相等。fuzzyEquals近似判断两个点是否相等。toString转换为方便阅读的字符串。lerp线性插值。clampf返回指定限制区域后的向量。addSelf向量加法。add向量加法,并返回新结果。subtract向量减法。multiplyScalar缩放当前向量。multiply分量相乘。divide向量除法。negate向量取反。dot当前向量与指定向量进行点乘。cross当前向量与指定向量进行叉乘。len返回该向量的长度。lengthSqr返回该向量的长度平方。normalizeSelf向量归一化,让这个向量的长度为 1。normalize返回归一化后的向量。transformMat4Transforms the vec3 with a mat4. 4th vector component is implicitly '1'maxAxisReturns the maximum value in x, y, and zangle夹角的弧度。project返回当前向量在指定 vector 向量上的投影向量。signAngle带方向的夹角的弧度。rotate返回旋转给定弧度后的新向量。rotateSelf按指定弧度旋转向量。
Details
属性(properties)
ONE
新 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:174 |
ZERO
返回 x = 0,y = 0,z = 0 的 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:184 |
UP
返回 x = 0, y = 1, z = 0 的 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:194 |
RIGHT
返回 x = 1,y = 0,z = 0 的 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:204 |
FORWARD
返回 x = 0,y = 0,z = 1 的 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:214 |
x
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec3.ts:1028 |
y
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec3.ts:1032 |
z
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec3.ts:1036 |
方法
mag
返回该向量的长度。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.ts:58 |
示例
var v = cc.v3(10, 10, 10);
v.mag(); // return 17.320508075688775;
magSqr
返回该向量的长度平方。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.ts:68 |
subSelf
向量减法。如果你想保存结果到另一个向量,可使用 sub() 代替。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:75 |
参数列表
vectorVec3
sub
向量减法,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:84 |
参数列表
vectorVec3outVec3 optional, the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
mulSelf
缩放当前向量。如果你想结果保存到另一个向量,可使用 mul() 代替。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:95 |
参数列表
numnumber
mul
缩放向量,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:104 |
参数列表
numnumberoutVec3 optional, the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
divSelf
向量除法。如果你想结果保存到另一个向量,可使用 div() 代替。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:115 |
参数列表
numnumber
div
向量除法,并返回新的结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:124 |
参数列表
numnumberoutVec3 optional, the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
scaleSelf
分量相乘。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:135 |
参数列表
vectorVec3
scale
分量相乘,并返回新的结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:144 |
参数列表
vectorVec3outVec3 optional, the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
negSelf
向量取反。如果你想结果保存到另一个向量,可使用 neg() 代替。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:155 |
neg
返回取反后的新向量。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:163 |
参数列表
outVec3 optional, the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
zero
将目标赋值为零向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:225 |
clone
获得指定向量的拷贝
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:240 |
copy
复制目标向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:252 |
set
设置向量值
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:267 |
add
逐元素向量加法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:282 |
subtract
逐元素向量减法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:297 |
multiply
逐元素向量乘法 (分量积)
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:312 |
divide
逐元素向量除法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:327 |
ceil
逐元素向量向上取整
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:342 |
floor
逐元素向量向下取整
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:357 |
min
逐元素向量最小值
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:372 |
max
逐元素向量最大值
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:387 |
round
逐元素向量四舍五入取整
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:402 |
multiplyScalar
向量标量乘法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:417 |
scaleAndAdd
逐元素向量乘加: A + B * scale
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:432 |
distance
求两向量的欧氏距离
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:447 |
squaredDistance
求两向量的欧氏距离平方
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:462 |
len
求向量长度
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:477 |
lengthSqr
求向量长度平方
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:492 |
negate
逐元素向量取负
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:507 |
inverse
逐元素向量取倒数,接近 0 时返回 Infinity
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:522 |
inverseSafe
逐元素向量取倒数,接近 0 时返回 0
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:537 |
normalize
归一化向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:571 |
dot
向量点积(数量积)
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:594 |
cross
向量叉积(向量积)
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:606 |
lerp
逐元素向量线性插值: A + t * (B - A)
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:623 |
random
生成一个在单位球体上均匀分布的随机向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:638 |
参数列表
scaleUnknown 生成的向量长度
transformMat4
向量与四维矩阵乘法,默认向量第四位为 1。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:660 |
transformMat4Normal
向量与四维矩阵乘法,默认向量第四位为 0。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:681 |
transformMat3
向量与三维矩阵乘法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:702 |
transformAffine
向量仿射变换
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:721 |
transformQuat
向量四元数乘法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:741 |
transformQuat
以缩放 -> 旋转 -> 平移顺序变换向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:765 |
transformInverseRTS
以平移 -> 旋转 -> 缩放顺序逆变换向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:788 |
rotateX
绕 X 轴旋转向量指定弧度
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:811 |
参数列表
vUnknown 待旋转向量oUnknown 旋转中心aUnknown 旋转弧度
rotateY
绕 Y 轴旋转向量指定弧度
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:843 |
参数列表
vUnknown 待旋转向量oUnknown 旋转中心aUnknown 旋转弧度
rotateZ
绕 Z 轴旋转向量指定弧度
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:875 |
参数列表
vUnknown 待旋转向量oUnknown 旋转中心aUnknown 旋转弧度
strictEquals
向量等价判断
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:907 |
equals
排除浮点数误差的向量近似等价判断
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:919 |
angle
求两向量夹角弧度
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:940 |
projectOnPlane
计算向量在指定平面上的投影
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:961 |
参数列表
aUnknown 待投影向量nUnknown 指定平面的法线
project
计算向量在指定向量上的投影
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:975 |
参数列表
aUnknown 待投影向量nUnknown 目标向量
toArray
向量转数组
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:994 |
参数列表
ofsUnknown 数组起始偏移量
fromArray
数组转向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:1011 |
参数列表
ofsUnknown 数组起始偏移量
constructor
构造函数,可查看 Cc/vec3:method
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.ts:1042 |
参数列表
clone
克隆一个 Vec3 值
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1067 |
set
用另一个向量设置当前的向量对象值。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1077 |
参数列表
newValueVec3 !#en new value to set. !#zh 要设置的新值
equals
当前的向量是否与指定的向量相等。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/vec3.ts:1092 |
参数列表
otherVec3
fuzzyEquals
近似判断两个点是否相等。
判断 2 个向量是否在指定数值的范围之内,如果在则返回 true,反之则返回 false。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/vec3.ts:1104 |
参数列表
toString
转换为方便阅读的字符串。
| meta | description |
|---|---|
| 返回 | string |
| 定义于 | cocos2d/core/value-types/vec3.ts:1124 |
lerp
线性插值。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1138 |
参数列表
toVec3rationumber the interpolation coefficientoutVec3 optional, the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
clampf
返回指定限制区域后的向量。
向量大于 max_inclusive 则返回 max_inclusive。
向量小于 min_inclusive 则返回 min_inclusive。
否则返回自身。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1153 |
参数列表
addSelf
向量加法。如果你想保存结果到另一个向量,使用 add() 代替。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1172 |
参数列表
vectorVec3
add
向量加法,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1187 |
参数列表
vectorVec3outVec3 optional, the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
subtract
向量减法。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1203 |
参数列表
vectorVec3
multiplyScalar
缩放当前向量。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1218 |
参数列表
numnumber
multiply
分量相乘。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1233 |
参数列表
vectorVec3
divide
向量除法。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1248 |
参数列表
numnumber
negate
向量取反。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1263 |
dot
当前向量与指定向量进行点乘。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.ts:1277 |
参数列表
vectorVec3
cross
当前向量与指定向量进行叉乘。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1288 |
参数列表
len
返回该向量的长度。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.ts:1302 |
示例
var v = cc.v3(10, 10, 10);
v.len(); // return 17.320508075688775;
lengthSqr
返回该向量的长度平方。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.ts:1315 |
normalizeSelf
向量归一化,让这个向量的长度为 1。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1325 |
normalize
返回归一化后的向量。
注意,当前向量不变,并返回一个新的归一化向量。如果你想来归一化当前向量,可使用 normalizeSelf 函数。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1337 |
参数列表
outVec3 optional, the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
transformMat4
Transforms the vec3 with a mat4. 4th vector component is implicitly '1'
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1356 |
参数列表
mMat4 matrix to transform withoutVec3 the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
maxAxis
Returns the maximum value in x, y, and z
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.ts:1369 |
angle
夹角的弧度。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.ts:1378 |
参数列表
vectorVec3
project
返回当前向量在指定 vector 向量上的投影向量。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1386 |
参数列表
vectorVec3
示例
var v1 = cc.v3(20, 20, 20);
var v2 = cc.v3(5, 5, 5);
v1.project(v2); // Vec3 {x: 20, y: 20, z: 20};
signAngle
带方向的夹角的弧度。该方法仅用做兼容 2D 计算。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.ts:1400 |
参数列表
rotate
返回旋转给定弧度后的新向量。该方法仅用做兼容 2D 计算。
| meta | description |
|---|---|
| 返回 | Vec2 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1416 |
参数列表
radiansnumberoutVec3 optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
rotateSelf
按指定弧度旋转向量。该方法仅用做兼容 2D 计算。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.ts:1430 |
参数列表
radiansnumber