Vec3 Class
Extends ValueType
Module: cc
Representation of 3D vectors and points.
Index
Properties
- x- Number
- y- Number
- z- Number
- ONE- Vec3return a Vec3 object with x = 1, y = 1, z = 1.
- ZERO- Vec3return a Vec3 object with x = 0, y = 0, z = 0.
- UP- Vec3return a Vec3 object with x = 0, y = 1, z = 0.
- RIGHT- Vec3return a Vec3 object with x = 1, y = 0, z = 0.
- FRONT- Vec3return a Vec3 object with x = 0, y = 0, z = 1.
Methods
- constructorConstructor
- cloneclone a Vec3 value
- setSet the current vector value with the given vector.
- equalsCheck whether the vector equals another one
- fuzzyEqualsCheck whether two vector equal with some degree of variance.
- toStringTransform to string with vector informations
- lerpCalculate linear interpolation result between this vector and another one with given ratio
- clampfClamp 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 product
- crossCross product
- magReturns 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.
- angleGet angle in radian between this and vector.
- projectCalculates the projection of the current vector over the given vector.
- signAngleGet angle in radian between this and vector with direction.
- rotaterotate.
- rotateSelfrotate self.
Details
Properties
x
| meta | description | 
|---|---|
| Type | Number | 
| Defined in | cocos2d/core/value-types/vec3.js:70 | 
y
| meta | description | 
|---|---|
| Type | Number | 
| Defined in | cocos2d/core/value-types/vec3.js:73 | 
z
| meta | description | 
|---|---|
| Type | Number | 
| Defined in | cocos2d/core/value-types/vec3.js:76 | 
ONE
return a Vec3 object with x = 1, y = 1, z = 1.
| meta | description | 
|---|---|
| Type | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:533 | 
ZERO
return a Vec3 object with x = 0, y = 0, z = 0.
| meta | description | 
|---|---|
| Type | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:544 | 
UP
return a Vec3 object with x = 0, y = 1, z = 0.
| meta | description | 
|---|---|
| Type | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:555 | 
RIGHT
return a Vec3 object with x = 1, y = 0, z = 0.
| meta | description | 
|---|---|
| Type | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:566 | 
FRONT
return a Vec3 object with x = 0, y = 0, z = 1.
| meta | description | 
|---|---|
| Type | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:577 | 
Methods
constructor
Constructor see Cc/vec3:method
| meta | description | 
|---|---|
| Defined in | cocos2d/core/value-types/vec3.js:46 | 
Parameters
clone
clone a Vec3 value
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:83 | 
set
Set the current vector value with the given vector.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:93 | 
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:108 | 
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:120 | 
Parameters
toString
Transform to string with vector informations
| meta | description | 
|---|---|
| Returns | string | 
| Defined in | cocos2d/core/value-types/vec3.js:140 | 
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:154 | 
Parameters
- toVec3
- rationumber the interpolation coefficient
- 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
clampf
Clamp the vector between from float and to float.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:169 | 
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:188 | 
Parameters
- vectorVec3
add
Adds two vectors, and returns the new result.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:203 | 
Parameters
- vectorVec3
- 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
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:219 | 
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:234 | 
Parameters
- vectorVec3
- 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
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:250 | 
Parameters
- numnumber
mul
Multiplies by a number, and returns the new result.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:265 | 
Parameters
- numnumber
- 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
scaleSelf
Multiplies two vectors.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:281 | 
Parameters
- vectorVec3
scale
Multiplies two vectors, and returns the new result.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:296 | 
Parameters
- vectorVec3
- 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
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:312 | 
Parameters
- numnumber
div
Divides by a number, and returns the new result.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:327 | 
Parameters
- numnumber
- 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
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:343 | 
neg
Negates the components, and returns the new result.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:357 | 
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:372 | 
Parameters
- vectorVec3
cross
Cross product
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:383 | 
Parameters
mag
Returns the length of this vector.
| meta | description | 
|---|---|
| Returns | number | 
| Defined in | cocos2d/core/value-types/vec3.js:397 | 
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:410 | 
normalizeSelf
Make the length of this vector to 1.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:420 | 
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:432 | 
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:451 | 
Parameters
- mMat4 matrix to transform with
- outVec3 the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
angle
Get angle in radian between this and vector.
| meta | description | 
|---|---|
| Returns | number | 
| Defined in | cocos2d/core/value-types/vec3.js:463 | 
Parameters
- vectorVec3
project
Calculates the projection of the current vector over the given vector.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:472 | 
Parameters
- vectorVec3
Examples
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
Get angle in radian between this and vector with direction. 
In order to compatible with the vec2 API.
| meta | description | 
|---|---|
| Returns | number | 
| Defined in | cocos2d/core/value-types/vec3.js:487 | 
Parameters
rotate
rotate. In order to compatible with the vec2 API.
| meta | description | 
|---|---|
| Returns | Vec2 | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:503 | 
Parameters
- radiansnumber
- outVec3 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
rotate self. In order to compatible with the vec2 API.
| meta | description | 
|---|---|
| Returns | Vec3 | 
| Defined in | cocos2d/core/value-types/vec3.js:516 | 
Parameters
- radiansnumber
