Vec4 类型
继承于 ValueType
表示 3D 向量和坐标
索引
属性(properties)
方法
subSelf向量减法。sub向量减法,并返回新结果。mulSelf缩放当前向量。mul缩放向量,并返回新结果。divSelf向量除法。div向量除法,并返回新的结果。scaleSelf分量相乘。scale分量相乘,并返回新的结果。negSelf向量取反。neg返回取反后的新向量。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向量点积(数量积)lerp逐元素向量线性插值: A + t * (B - A)random生成一个在单位球体上均匀分布的随机向量transformMat4向量矩阵乘法transformAffine向量仿射变换transformQuat向量四元数乘法strictEquals向量等价判断equals排除浮点数误差的向量近似等价判断toArray向量转数组fromArray数组转向量constructor构造函数,可查看 Cc/vec4:methodclone克隆一个 Vec4 值set用另一个向量设置当前的向量对象值。equals当前的向量是否与指定的向量相等。equals4f判断当前向量是否在误差范围内与指定分量的向量相等。strictEquals判断当前向量是否与指定向量相等。strictEquals4f判断当前向量是否与指定分量的向量相等。lerp根据指定的插值比率,从当前向量到目标向量之间做插值。toString返回当前向量的字符串表示。clampf设置当前向量的值,使其各个分量都处于指定的范围内。addSelf向量加法。add向量加法,并返回新结果。subtract向量减法,并返回新结果。multiplyScalar缩放当前向量。multiply分量相乘。divide向量除法。negate向量取反dot当前向量与指定向量进行点乘。cross当前向量与指定向量进行叉乘。len返回该向量的长度。lengthSqr返回该向量的长度平方。normalizeSelf向量归一化,让这个向量的长度为 1。normalize返回归一化后的向量。transformMat4Transforms the vec4 with a mat4. 4th vector component is implicitly '1'maxAxisReturns the maximum value in x, y, z, w.
Details
属性(properties)
x
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec4.ts:731 |
y
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec4.ts:736 |
z
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec4.ts:741 |
w
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec4.ts:746 |
方法
subSelf
向量减法。如果你想保存结果到另一个向量,可使用 sub() 代替。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:57 |
参数列表
vectorVec4
sub
向量减法,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:66 |
参数列表
vectorVec4outVec4 optional, the receiving vector, you can pass the same vec4 to save result to itself, if not provided, a new vec4 will be created
mulSelf
缩放当前向量。如果你想结果保存到另一个向量,可使用 mul() 代替。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:77 |
参数列表
numnumber
mul
缩放向量,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:86 |
参数列表
numnumberoutVec4 optional, the receiving vector, you can pass the same vec4 to save result to itself, if not provided, a new vec4 will be created
divSelf
向量除法。如果你想结果保存到另一个向量,可使用 div() 代替。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:97 |
参数列表
numnumber
div
向量除法,并返回新的结果。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:106 |
参数列表
numnumberoutVec4 optional, the receiving vector, you can pass the same vec4 to save result to itself, if not provided, a new vec4 will be created
scaleSelf
分量相乘。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:117 |
参数列表
vectorVec4
scale
分量相乘,并返回新的结果。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:126 |
参数列表
vectorVec4outVec4 optional, the receiving vector, you can pass the same vec4 to save result to itself, if not provided, a new vec4 will be created
negSelf
向量取反。如果你想结果保存到另一个向量,可使用 neg() 代替。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:137 |
neg
返回取反后的新向量。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:145 |
参数列表
outVec4 optional, the receiving vector, you can pass the same vec4 to save result to itself, if not provided, a new vec4 will be created
clone
获得指定向量的拷贝
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:165 |
copy
复制目标向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:177 |
set
设置向量值
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:193 |
add
逐元素向量加法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:209 |
subtract
逐元素向量减法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:225 |
multiply
逐元素向量乘法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:241 |
divide
逐元素向量除法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:257 |
ceil
逐元素向量向上取整
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:273 |
floor
逐元素向量向下取整
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:289 |
min
逐元素向量最小值
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:305 |
max
逐元素向量最大值
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:321 |
round
逐元素向量四舍五入取整
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:337 |
multiplyScalar
向量标量乘法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:353 |
scaleAndAdd
逐元素向量乘加: A + B * scale
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:369 |
distance
求两向量的欧氏距离
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:385 |
squaredDistance
求两向量的欧氏距离平方
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:401 |
len
求向量长度
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:417 |
lengthSqr
求向量长度平方
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:433 |
negate
逐元素向量取负
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:449 |
inverse
逐元素向量取倒数,接近 0 时返回 Infinity
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:465 |
inverseSafe
逐元素向量取倒数,接近 0 时返回 0
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:481 |
normalize
归一化向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:522 |
dot
向量点积(数量积)
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:546 |
lerp
逐元素向量线性插值: A + t * (B - A)
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:558 |
random
生成一个在单位球体上均匀分布的随机向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:574 |
参数列表
scaleUnknown 生成的向量长度
transformMat4
向量矩阵乘法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:597 |
transformAffine
向量仿射变换
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:618 |
transformQuat
向量四元数乘法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:640 |
strictEquals
向量等价判断
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:670 |
equals
排除浮点数误差的向量近似等价判断
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:682 |
toArray
向量转数组
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:697 |
参数列表
ofsUnknown 数组起始偏移量
fromArray
数组转向量
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:714 |
参数列表
ofsUnknown 数组起始偏移量
constructor
构造函数,可查看 Cc/vec4:method
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec4.ts:751 |
参数列表
clone
克隆一个 Vec4 值
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:778 |
set
用另一个向量设置当前的向量对象值。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:788 |
参数列表
newValueVec4 !#en new value to set. !#zh 要设置的新值
equals
当前的向量是否与指定的向量相等。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/vec4.ts:814 |
参数列表
equals4f
判断当前向量是否在误差范围内与指定分量的向量相等。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/vec4.ts:829 |
参数列表
xnumber 相比较的向量的 x 分量。ynumber 相比较的向量的 y 分量。znumber 相比较的向量的 z 分量。wnumber 相比较的向量的 w 分量。epsilonnumber 允许的误差,应为非负数。
strictEquals
判断当前向量是否与指定向量相等。两向量的各分量都分别相等时返回 true;否则返回 false。
| meta | description |
|---|---|
| 返回 | boolean |
| 定义于 | cocos2d/core/value-types/vec4.ts:847 |
参数列表
otherVec4 相比较的向量。
strictEquals4f
判断当前向量是否与指定分量的向量相等。两向量的各分量都分别相等时返回 true;否则返回 false。
| meta | description |
|---|---|
| 返回 | boolean |
| 定义于 | cocos2d/core/value-types/vec4.ts:858 |
参数列表
lerp
根据指定的插值比率,从当前向量到目标向量之间做插值。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:872 |
参数列表
toString
返回当前向量的字符串表示。
| meta | description |
|---|---|
| 返回 | string |
| 定义于 | cocos2d/core/value-types/vec4.ts:892 |
clampf
设置当前向量的值,使其各个分量都处于指定的范围内。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:902 |
参数列表
addSelf
向量加法。如果你想保存结果到另一个向量,使用 add() 代替。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:918 |
参数列表
vectorVec4
add
向量加法,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:934 |
参数列表
vectorVec4outVec4 optional, the receiving vector, you can pass the same vec4 to save result to itself, if not provided, a new vec4 will be created
subtract
向量减法,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:951 |
参数列表
vectorVec4outVec4 optional, the receiving vector, you can pass the same vec4 to save result to itself, if not provided, a new vec4 will be created
multiplyScalar
缩放当前向量。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:968 |
参数列表
numnumber
multiply
分量相乘。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:984 |
参数列表
vectorVec4
divide
向量除法。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:1000 |
参数列表
numnumber
negate
向量取反
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:1016 |
dot
当前向量与指定向量进行点乘。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec4.ts:1031 |
参数列表
vectorVec4
cross
当前向量与指定向量进行叉乘。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:1042 |
参数列表
len
返回该向量的长度。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec4.ts:1061 |
示例
var v = cc.v4(10, 10);
v.len(); // return 14.142135623730951;
lengthSqr
返回该向量的长度平方。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec4.ts:1078 |
normalizeSelf
向量归一化,让这个向量的长度为 1。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:1092 |
normalize
返回归一化后的向量。
注意,当前向量不变,并返回一个新的归一化向量。如果你想来归一化当前向量,可使用 normalizeSelf 函数。
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:1104 |
参数列表
outVec4 optional, the receiving vector, you can pass the same vec4 to save result to itself, if not provided, a new vec4 will be created
transformMat4
Transforms the vec4 with a mat4. 4th vector component is implicitly '1'
| meta | description |
|---|---|
| 返回 | Vec4 |
| 定义于 | cocos2d/core/value-types/vec4.ts:1134 |
参数列表
mMat4 matrix to transform withoutVec4 the receiving vector, you can pass the same vec4 to save result to itself, if not provided, a new vec4 will be created
maxAxis
Returns the maximum value in x, y, z, w.
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec4.ts:1155 |