Vec3 Class
Extends ValueType
Module: cc
Representation of 3D vectors and points.
Index
Properties
Methods
constructorConstructorcloneclone a Vec3 valuesetSet the current vector value with the given vector.equalsCheck whether the vector equals another onefuzzyEqualsCheck whether two vector equal with some degree of variance.toStringTransform to string with vector informationslerpCalculate linear interpolation result between this vector and another one with given ratioclampfClamp the vector between from float and to float.addSelfAdds this vector.addAdds two vectors, and returns the new result.subSelfSubtracts one vector from this.subSubtracts one vector from this, and returns the new result.mulSelfMultiplies this by a number.mulMultiplies by a number, and returns the new result.scaleSelfMultiplies two vectors.scaleMultiplies two vectors, and returns the new result.divSelfDivides by a number.divDivides by a number, and returns the new result.negSelfNegates the components.negNegates the components, and returns the new result.dotDot productcrossCross productmagReturns the length of this vector.magSqrReturns the squared length of this vector.normalizeSelfMake the length of this vector to 1.normalizeNote that the current vector is unchanged and a new normalized vector is returned.transformMat4Transforms the vec3 with a mat4.v3The convenience method to create a new cc.Vec3.
Details
Properties
x
| meta | description |
|---|---|
| Type | Number |
| Defined in | cocos2d/core/value-types/vec3.js:68 |
y
| meta | description |
|---|---|
| Type | Number |
| Defined in | cocos2d/core/value-types/vec3.js:71 |
z
| meta | description |
|---|---|
| Type | Number |
| Defined in | cocos2d/core/value-types/vec3.js:74 |
Methods
constructor
Constructor see Cc/vec3:method
| meta | description |
|---|---|
| Defined in | cocos2d/core/value-types/vec3.js:44 |
Parameters
clone
clone a Vec3 value
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:81 |
set
Set the current vector value with the given vector.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:91 |
Parameters
newValueVec3 !#en new value to set. !#zh 要设置的新值
equals
Check whether the vector equals another one
| meta | description |
|---|---|
| Returns | Boolean |
| Defined in | cocos2d/core/value-types/vec3.js:106 |
Parameters
otherVec3
fuzzyEquals
Check whether two vector equal with some degree of variance.
| meta | description |
|---|---|
| Returns | Boolean |
| Defined in | cocos2d/core/value-types/vec3.js:118 |
Parameters
toString
Transform to string with vector informations
| meta | description |
|---|---|
| Returns | string |
| Defined in | cocos2d/core/value-types/vec3.js:138 |
lerp
Calculate linear interpolation result between this vector and another one with given ratio
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:152 |
Parameters
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
Clamp the vector between from float and to float.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:167 |
Parameters
addSelf
Adds this vector. If you want to save result to another vector, use add() instead.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:186 |
Parameters
vectorVec3
add
Adds two vectors, and returns the new result.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:201 |
Parameters
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
Subtracts one vector from this. If you want to save result to another vector, use sub() instead.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:217 |
Parameters
vectorVec3
sub
Subtracts one vector from this, and returns the new result.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:232 |
Parameters
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
Multiplies this by a number. If you want to save result to another vector, use mul() instead.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:248 |
Parameters
numnumber
mul
Multiplies by a number, and returns the new result.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:263 |
Parameters
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
Multiplies two vectors.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:279 |
Parameters
vectorVec3
scale
Multiplies two vectors, and returns the new result.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:294 |
Parameters
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
Divides by a number. If you want to save result to another vector, use div() instead.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:310 |
Parameters
divisornumber
div
Divides by a number, and returns the new result.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:325 |
Parameters
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
Negates the components. If you want to save result to another vector, use neg() instead.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:341 |
neg
Negates the components, and returns the new result.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:355 |
Parameters
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
Dot product
| meta | description |
|---|---|
| Returns | number |
| Defined in | cocos2d/core/value-types/vec3.js:370 |
Parameters
vectorVec3
cross
Cross product
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:381 |
Parameters
mag
Returns the length of this vector.
| meta | description |
|---|---|
| Returns | number |
| Defined in | cocos2d/core/value-types/vec3.js:395 |
Examples
var v = cc.v2(10, 10);
v.mag(); // return 14.142135623730951;
magSqr
Returns the squared length of this vector.
| meta | description |
|---|---|
| Returns | number |
| Defined in | cocos2d/core/value-types/vec3.js:408 |
normalizeSelf
Make the length of this vector to 1.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:418 |
normalize
Returns this vector with a magnitude of 1.
Note that the current vector is unchanged and a new normalized vector is returned. If you want to normalize the current vector, use normalizeSelf function.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:430 |
Parameters
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 |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:449 |
Parameters
mMat4 matrix to transform withm00Number Component in column 0, row 0 position (index 0)m01Number Component in column 0, row 1 position (index 1)m02Number Component in column 0, row 2 position (index 2)m03Number Component in column 0, row 3 position (index 3)m10Number Component in column 1, row 0 position (index 4)m11Number Component in column 1, row 1 position (index 5)m12Number Component in column 1, row 2 position (index 6)m13Number Component in column 1, row 3 position (index 7)m20Number Component in column 2, row 0 position (index 8)m21Number Component in column 2, row 1 position (index 9)m22Number Component in column 2, row 2 position (index 10)m23Number Component in column 2, row 3 position (index 11)m30Number Component in column 3, row 0 position (index 12)m31Number Component in column 3, row 1 position (index 13)m32Number Component in column 3, row 2 position (index 14)m33Number Component in column 3, row 3 position (index 15)
outVec3 the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
v3
The convenience method to create a new cc.Vec3.
| meta | description |
|---|---|
| Returns | Vec3 |
| Defined in | cocos2d/core/value-types/vec3.js:461 |
Parameters
Examples
var v1 = cc.v3();
var v2 = cc.v3(0, 0, 0);
var v3 = cc.v3(v2);
var v4 = cc.v3({x: 100, y: 100, z: 0});