Vec3
Class
Extends ValueType
Module: cc
Representation of 3D vectors and points.
Index
Properties
x
Number
y
Number
z
Number
ONE
Vec3
return a Vec3 object with x = 1, y = 1, z = 1.ZERO
Vec3
return a Vec3 object with x = 0, y = 0, z = 0.UP
Vec3
return a Vec3 object with x = 0, y = 1, z = 0.RIGHT
Vec3
return a Vec3 object with x = 1, y = 0, z = 0.FRONT
Vec3
return a Vec3 object with x = 0, y = 0, z = 1.
Methods
constructor
Constructorclone
clone a Vec3 valueset
Set the current vector value with the given vector.equals
Check whether the vector equals another onefuzzyEquals
Check whether two vector equal with some degree of variance.toString
Transform to string with vector informationslerp
Calculate linear interpolation result between this vector and another one with given ratioclampf
Clamp the vector between from float and to float.addSelf
Adds this vector.add
Adds two vectors, and returns the new result.subSelf
Subtracts one vector from this.sub
Subtracts one vector from this, and returns the new result.mulSelf
Multiplies this by a number.mul
Multiplies by a number, and returns the new result.scaleSelf
Multiplies two vectors.scale
Multiplies two vectors, and returns the new result.divSelf
Divides by a number.div
Divides by a number, and returns the new result.negSelf
Negates the components.neg
Negates the components, and returns the new result.dot
Dot productcross
Cross productmag
Returns the length of this vector.magSqr
Returns the squared length of this vector.normalizeSelf
Make the length of this vector to 1.normalize
Note that the current vector is unchanged and a new normalized vector is returned.transformMat4
Transforms the vec3 with a mat4.angle
Get angle in radian between this and vector.project
Calculates the projection of the current vector over the given vector.signAngle
Get angle in radian between this and vector with direction.rotate
rotate.rotateSelf
rotate 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
newValue
Vec3 !#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
other
Vec3
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
to
Vec3ratio
number the interpolation coefficientout
Vec3 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
vector
Vec3
add
Adds two vectors, and returns the new result.
meta | description |
---|---|
Returns | Vec3 |
Defined in | cocos2d/core/value-types/vec3.js:203 |
Parameters
vector
Vec3out
Vec3 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
vector
Vec3
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
vector
Vec3out
Vec3 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
num
number
mul
Multiplies by a number, and returns the new result.
meta | description |
---|---|
Returns | Vec3 |
Defined in | cocos2d/core/value-types/vec3.js:265 |
Parameters
num
numberout
Vec3 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
vector
Vec3
scale
Multiplies two vectors, and returns the new result.
meta | description |
---|---|
Returns | Vec3 |
Defined in | cocos2d/core/value-types/vec3.js:296 |
Parameters
vector
Vec3out
Vec3 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
num
number
div
Divides by a number, and returns the new result.
meta | description |
---|---|
Returns | Vec3 |
Defined in | cocos2d/core/value-types/vec3.js:327 |
Parameters
num
numberout
Vec3 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
out
Vec3 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
vector
Vec3
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
out
Vec3 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
m
Mat4 matrix to transform without
Vec3 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
vector
Vec3
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
vector
Vec3
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
radians
numberout
Vec3 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
radians
number