Vec3 类型
继承于 ValueType
模块: cc
表示 3D 向量和坐标
索引
属性(properties)
xNumberyNumberzNumberONEVec3新 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 对象。FRONTVec3返回 x = 0,y = 0,z = 1 的 Vec3 对象。
方法
constructor构造函数,可查看 Cc/vec3:methodclone克隆一个 Vec3 值set用另一个向量设置当前的向量对象值。equals当前的向量是否与指定的向量相等。fuzzyEquals近似判断两个点是否相等。toString转换为方便阅读的字符串。lerp线性插值。clampf返回指定限制区域后的向量。addSelf向量加法。add向量加法,并返回新结果。subSelf向量减法。sub向量减法,并返回新结果。mulSelf缩放当前向量。mul缩放向量,并返回新结果。scaleSelf分量相乘。scale分量相乘,并返回新的结果。divSelf向量除法。div向量除法,并返回新的结果。negSelf向量取反。neg返回取反后的新向量。dot当前向量与指定向量进行点乘。cross当前向量与指定向量进行叉乘。mag返回该向量的长度。magSqr返回该向量的长度平方。normalizeSelf向量归一化,让这个向量的长度为 1。normalize返回归一化后的向量。transformMat4Transforms the vec3 with a mat4. 4th vector component is implicitly '1'angle夹角的弧度。project返回当前向量在指定 vector 向量上的投影向量。signAngle带方向的夹角的弧度。rotate返回旋转给定弧度后的新向量。rotateSelf按指定弧度旋转向量。
Details
属性(properties)
x
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec3.js:70 |
y
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec3.js:73 |
z
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/vec3.js:76 |
ONE
新 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:528 |
ZERO
返回 x = 0,y = 0,z = 0 的 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:539 |
UP
返回 x = 0, y = 1, z = 0 的 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:550 |
RIGHT
返回 x = 1,y = 0,z = 0 的 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:561 |
FRONT
返回 x = 0,y = 0,z = 1 的 Vec3 对象。
| meta | description |
|---|---|
| 类型 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:572 |
方法
constructor
构造函数,可查看 Cc/vec3:method
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/vec3.js:46 |
参数列表
clone
克隆一个 Vec3 值
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:83 |
set
用另一个向量设置当前的向量对象值。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:93 |
参数列表
newValueVec3 !#en new value to set. !#zh 要设置的新值
equals
当前的向量是否与指定的向量相等。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/vec3.js:108 |
参数列表
otherVec3
fuzzyEquals
近似判断两个点是否相等。
判断 2 个向量是否在指定数值的范围之内,如果在则返回 true,反之则返回 false。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/vec3.js:120 |
参数列表
toString
转换为方便阅读的字符串。
| meta | description |
|---|---|
| 返回 | string |
| 定义于 | cocos2d/core/value-types/vec3.js:140 |
lerp
线性插值。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:154 |
参数列表
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.js:169 |
参数列表
addSelf
向量加法。如果你想保存结果到另一个向量,使用 add() 代替。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:188 |
参数列表
vectorVec3
add
向量加法,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:203 |
参数列表
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
subSelf
向量减法。如果你想保存结果到另一个向量,可使用 sub() 代替。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:219 |
参数列表
vectorVec3
sub
向量减法,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:234 |
参数列表
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.js:250 |
参数列表
numnumber
mul
缩放向量,并返回新结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:265 |
参数列表
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.js:281 |
参数列表
vectorVec3
scale
分量相乘,并返回新的结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:296 |
参数列表
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
divSelf
向量除法。如果你想结果保存到另一个向量,可使用 div() 代替。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:312 |
参数列表
numnumber
div
向量除法,并返回新的结果。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:327 |
参数列表
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
negSelf
向量取反。如果你想结果保存到另一个向量,可使用 neg() 代替。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:343 |
neg
返回取反后的新向量。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:357 |
参数列表
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
dot
当前向量与指定向量进行点乘。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.js:372 |
参数列表
vectorVec3
cross
当前向量与指定向量进行叉乘。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:383 |
参数列表
mag
返回该向量的长度。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.js:397 |
示例
var v = cc.v2(10, 10);
v.mag(); // return 14.142135623730951;
magSqr
返回该向量的长度平方。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.js:410 |
normalizeSelf
向量归一化,让这个向量的长度为 1。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:420 |
normalize
返回归一化后的向量。
注意,当前向量不变,并返回一个新的归一化向量。如果你想来归一化当前向量,可使用 normalizeSelf 函数。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:432 |
参数列表
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.js:451 |
参数列表
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
angle
夹角的弧度。
| meta | description |
|---|---|
| 返回 | number |
| 定义于 | cocos2d/core/value-types/vec3.js:463 |
参数列表
vectorVec3
project
返回当前向量在指定 vector 向量上的投影向量。
| meta | description |
|---|---|
| 返回 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:472 |
参数列表
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.js:487 |
参数列表
rotate
返回旋转给定弧度后的新向量。该方法仅用做兼容 2D 计算。
| meta | description |
|---|---|
| 返回 | Vec2 | Vec3 |
| 定义于 | cocos2d/core/value-types/vec3.js:502 |
参数列表
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.js:515 |
参数列表
radiansnumber