Vec3
Class
Extends ValueType
Module: cc
Parent Module: cc
Representation of 3D vectors and points.
Index
Properties
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.
FORWARD
Vec3
return a Vec3 object with x = 0, y = 0, z = 1.
x
Number
y
Number
z
Number
Methods
mag
Returns the length of this vector.
magSqr
Returns the squared length of this vector.
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.
divSelf
Divides by a number.
div
Divides by a number, and returns the new result.
scaleSelf
Multiplies two vectors.
scale
Multiplies two vectors, and returns the new result.
negSelf
Negates the components.
neg
Negates the components, and returns the new result.
zero
The target of an assignment zero vector
clone
Obtaining copy vectors designated
copy
Copy the target vector
set
Set to value
add
Element-wise vector addition
subtract
Element-wise vector subtraction
multiply
Element-wise vector multiplication (product component)
divide
Element-wise vector division
ceil
Rounding up by elements of the vector
floor
Element vector by rounding down
min
The minimum by-element vector
max
The maximum value of the element-wise vector
round
Element-wise vector of rounding to whole
multiplyScalar
Vector scalar multiplication
scaleAndAdd
Element-wise vector multiply add: A + B * scale
distance
Seeking two vectors Euclidean distance
squaredDistance
Euclidean distance squared seeking two vectors
len
Seeking vector length
lengthSqr
Seeking squared vector length
negate
By taking the negative elements of the vector
inverse
Element vector by taking the inverse, return near 0 Infinity
inverseSafe
Element vector by taking the inverse, return near 0 0
normalize
Normalized vector
dot
Vector dot product (scalar product)
cross
Vector cross product (vector product)
lerp
Vector element by element linear interpolation: A + t * (B - A)
random
Generates a uniformly distributed random vectors on the unit sphere
transformMat4
Four-dimensional vector and matrix multiplication, the default vectors fourth one.
transformMat4Normal
Four-dimensional vector and matrix multiplication, vector fourth default is 0.
transformMat3
Dimensional vector matrix multiplication
transformQuat
Vector quaternion multiplication
rotateX
Rotation vector specified angle about the X axis
rotateY
Rotation vector specified angle around the Y axis
rotateZ
Around the Z axis specified angle vector
strictEquals
Equivalent vectors Analyzing
equals
Negative error vector floating point approximately equivalent Analyzing
angle
Radian angle between two vectors seek
projectOnPlane
Calculating a projection vector in the specified plane
project
Projection vector calculated in the vector designated
toArray
Vector transfer array
fromArray
Array steering amount
constructor
Constructor
clone
clone a Vec3 value
set
Set the current vector value with the given vector.
equals
Check whether the vector equals another one
fuzzyEquals
Check whether two vector equal with some degree of variance.
toString
Transform to string with vector informations
lerp
Calculate linear interpolation result between this vector and another one with given ratio
clampf
Clamp the vector between from float and to float.
addSelf
Adds this vector.
add
Adds two vectors, and returns the new result.
subtract
Subtracts one vector from this.
multiplyScalar
Multiplies this by a number.
multiply
Multiplies two vectors.
divide
Divides by a number.
negate
Negates the components.
dot
Dot product
cross
Cross product
len
Returns the length of this vector.
lengthSqr
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.
maxAxis
Returns the maximum value in x, y, and z
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
ONE
return a Vec3 object with x = 1, y = 1, z = 1.
ZERO
return a Vec3 object with x = 0, y = 0, z = 0.
UP
return a Vec3 object with x = 0, y = 1, z = 0.
RIGHT
return a Vec3 object with x = 1, y = 0, z = 0.
FORWARD
return a Vec3 object with x = 0, y = 0, z = 1.
x
y
z
Methods
mag
Returns the length of this vector.
Examples
var v = cc.v3(10, 10, 10);
v.mag();
magSqr
Returns the squared length of this vector.
subSelf
Subtracts one vector from this. If you want to save result to another vector, use sub() instead.
Parameters
sub
Subtracts one vector from this, and returns the new result.
Parameters
vector
Vec3
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
mulSelf
Multiplies this by a number. If you want to save result to another vector, use mul() instead.
Parameters
mul
Multiplies by a number, and returns the new result.
Parameters
num
number
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
divSelf
Divides by a number. If you want to save result to another vector, use div() instead.
Parameters
div
Divides by a number, and returns the new result.
Parameters
num
number
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
scaleSelf
Multiplies two vectors.
Parameters
scale
Multiplies two vectors, and returns the new result.
Parameters
vector
Vec3
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
negSelf
Negates the components. If you want to save result to another vector, use neg() instead.
neg
Negates the components, and returns the new result.
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
zero
The target of an assignment zero vector
clone
Obtaining copy vectors designated
copy
Copy the target vector
set
Set to value
add
Element-wise vector addition
subtract
Element-wise vector subtraction
multiply
Element-wise vector multiplication (product component)
divide
Element-wise vector division
ceil
Rounding up by elements of the vector
floor
Element vector by rounding down
min
The minimum by-element vector
max
The maximum value of the element-wise vector
round
Element-wise vector of rounding to whole
multiplyScalar
Vector scalar multiplication
scaleAndAdd
Element-wise vector multiply add: A + B * scale
distance
Seeking two vectors Euclidean distance
squaredDistance
Euclidean distance squared seeking two vectors
len
Seeking vector length
lengthSqr
Seeking squared vector length
negate
By taking the negative elements of the vector
inverse
Element vector by taking the inverse, return near 0 Infinity
inverseSafe
Element vector by taking the inverse, return near 0 0
normalize
Normalized vector
dot
Vector dot product (scalar product)
cross
Vector cross product (vector product)
lerp
Vector element by element linear interpolation: A + t * (B - A)
random
Generates a uniformly distributed random vectors on the unit sphere
Parameters
Four-dimensional vector and matrix multiplication, the default vectors fourth one.
Four-dimensional vector and matrix multiplication, vector fourth default is 0.
Dimensional vector matrix multiplication
Vector quaternion multiplication
rotateX
Rotation vector specified angle about the X axis
Parameters
v
Unknown 待旋转向量
o
Unknown 旋转中心
a
Unknown 旋转弧度
rotateY
Rotation vector specified angle around the Y axis
Parameters
v
Unknown 待旋转向量
o
Unknown 旋转中心
a
Unknown 旋转弧度
rotateZ
Around the Z axis specified angle vector
Parameters
v
Unknown 待旋转向量
o
Unknown 旋转中心
a
Unknown 旋转弧度
strictEquals
Equivalent vectors Analyzing
equals
Negative error vector floating point approximately equivalent Analyzing
angle
Radian angle between two vectors seek
projectOnPlane
Calculating a projection vector in the specified plane
Parameters
a
Unknown 待投影向量
n
Unknown 指定平面的法线
project
Projection vector calculated in the vector designated
Parameters
a
Unknown 待投影向量
n
Unknown 目标向量
toArray
Vector transfer array
Parameters
fromArray
Array steering amount
Parameters
constructor
Constructor
see Cc/vec3:method
Parameters
clone
clone a Vec3 value
set
Set the current vector value with the given vector.
Parameters
newValue
Vec3 !#en new value to set. !#zh 要设置的新值
equals
Check whether the vector equals another one
Parameters
fuzzyEquals
Check whether two vector equal with some degree of variance.
Parameters
toString
Transform to string with vector informations
lerp
Calculate linear interpolation result between this vector and another one with given ratio
Parameters
to
Vec3
ratio
number the interpolation coefficient
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
clampf
Clamp the vector between from float and to float.
Parameters
addSelf
Adds this vector. If you want to save result to another vector, use add() instead.
Parameters
add
Adds two vectors, and returns the new result.
Parameters
vector
Vec3
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
subtract
Subtracts one vector from this.
Parameters
multiplyScalar
Multiplies this by a number.
Parameters
multiply
Multiplies two vectors.
Parameters
divide
Divides by a number.
Parameters
negate
Negates the components.
dot
Dot product
Parameters
cross
Cross product
Parameters
len
Returns the length of this vector.
Examples
var v = cc.v3(10, 10, 10);
v.len();
lengthSqr
Returns the squared length of this vector.
normalizeSelf
Make the length of this vector to 1.
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.
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
Transforms the vec3 with a mat4. 4th vector component is implicitly '1'
Parameters
m
Mat4 matrix to transform with
out
Vec3 the receiving vector, you can pass the same vec3 to save result to itself, if not provided, a new vec3 will be created
maxAxis
Returns the maximum value in x, y, and z
angle
Get angle in radian between this and vector.
Parameters
project
Calculates the projection of the current vector over the given vector.
Parameters
Examples
var v1 = cc.v3(20, 20, 20);
var v2 = cc.v3(5, 5, 5);
v1.project(v2);
signAngle
Get angle in radian between this and vector with direction.
In order to compatible with the vec2 API.
Parameters
rotate
rotate. In order to compatible with the vec2 API.
Parameters
radians
number
out
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.
Parameters