# Class: Vector3
# Table of contents
# Constructors
# Properties
# Accessors
# Methods
- abs
- add
- angleTo
- applyMatrix4
- applyMatrix4Raw
- applyQuaternion
- clone
- cross
- distanceTo
- dot
- equal
- fromArray
- fromPhysics
- get
- isZero
- length
- lerp
- negate
- normalize
- scale
- scaleXYZ
- set
- setArray
- setFromArray
- setFromMatrixColumn
- setFromMatrixPosition
- setFromMatrixScale
- setValue
- sub
- toArray
- toPhysics
- transformDirection
- transformDirectionRaw
- clearPhysicsPool
- createFromArray
- createFromNumber
- createFromTypedArray
- fromPhysics
- transformCoordinate
- transformQuat
# Constructors
# constructor
• new Vector3(raw?
, offset?
)
# Parameters
Name | Type |
---|---|
raw? | Float32Array |
offset? | number |
# Properties
# ForwardLH
▪ Static
Readonly
ForwardLH: Vector3
前方向,基于左手坐标系,不要对该对象进行修改
static
memberof
Vector3
# ONE
▪ Static
Readonly
ONE: Vector3
一向量,不要对该对象进行修改
readonly
static
memberof
Vector3
# Phys3D
▪ Static
Optional
Phys3D: typeof phys3D
# Up
▪ Static
Readonly
Up: Vector3
上方向,不要对该对象进行修改
static
memberof
Vector3
# ZERO
▪ Static
Readonly
ZERO: Vector3
零向量,不要对该对象进行修改
readonly
static
memberof
Vector3
# Accessors
# x
• get
x(): number
x值
memberof
Vector3
# Returns
number
• set
x(val
): void
x值
# Parameters
Name | Type |
---|---|
val | number |
# Returns
void
# y
• get
y(): number
y值
memberof
Vector3
# Returns
number
• set
y(val
): void
y值
# Parameters
Name | Type |
---|---|
val | number |
# Returns
void
# z
• get
z(): number
z值
memberof
Vector3
# Returns
number
• set
z(val
): void
z值
# Parameters
Name | Type |
---|---|
val | number |
# Returns
void
# Methods
# abs
▸ abs(): Vector3
# Returns
# add
▸ add(v
, dst?
): Vector3
向量加法
memberof
Vector3
# Parameters
# Returns
计算结果
# angleTo
▸ angleTo(location
, dst?
): Vector3
获取到目标点的角度
memberof
Vector3
# Parameters
# Returns
计算结果
# applyMatrix4
▸ applyMatrix4(m
): Vector3
create by janzen Multiplies this vector (with an implicit 1 in the 4th dimension) and m, and divides by perspective.
# Parameters
Name | Type |
---|---|
m | Matrix4 |
# Returns
# applyMatrix4Raw
▸ applyMatrix4Raw(m
): Vector3
create by roamye Multiplies this vector (with an implicit 1 in the 4th dimension) and m, and divides by perspective.
# Parameters
Name | Type |
---|---|
m | Float32Array |
# Returns
# applyQuaternion
▸ applyQuaternion(q
): Vector3
# Parameters
Name | Type |
---|---|
q | Quaternion |
# Returns
# clone
▸ clone(): Vector3
拷贝该向量
memberof
Vector3
# Returns
拷贝出来的对象
# cross
▸ cross(v
, dst?
): Vector3
向量叉乘
memberof
Vector3
# Parameters
# Returns
计算结果
# distanceTo
▸ distanceTo(p
): number
获取到目标点的距离
memberof
Vector3
# Parameters
Name | Type | Description |
---|---|---|
p | Vector3 | 目标点 |
# Returns
number
计算结果
# dot
▸ dot(v
): number
向量点乘
memberof
Vector3
# Parameters
Name | Type | Description |
---|---|---|
v | Vector3 | 目标向量 |
# Returns
number
计算结果
# equal
▸ equal(v
): boolean
判断与目标向量的值是否相等
memberof
Vector3
# Parameters
Name | Type | Description |
---|---|---|
v | Vector3 | 目标向量 |
# Returns
boolean
是否相等,这里误差小于10^-6视为相等
# fromArray
▸ fromArray(array
, offset
): Vector3
# Parameters
Name | Type |
---|---|
array | Float32Array |
offset | number |
# Returns
# fromPhysics
▸ fromPhysics(v
): Vector3
# Parameters
Name | Type |
---|---|
v | any |
# Returns
# get
▸ get(i
): number
# Parameters
Name | Type |
---|---|
i | number |
# Returns
number
# isZero
▸ isZero(): boolean
是否为零向量
memberof
Vector3
# Returns
boolean
# length
▸ length(): number
向量的模
memberof
Vector3
# Returns
number
计算结果
# lerp
▸ lerp(v
, f
, dst?
): Vector3
在该向量与目标向量之间计算插值
memberof
Vector3
# Parameters
# Returns
计算结果
# negate
▸ negate(): Vector3
取反
# Returns
# normalize
▸ normalize(dst?
): Vector3
向量归一化
memberof
Vector3
# Parameters
Name | Type |
---|---|
dst? | Vector3 |
# Returns
计算结果
▸ print(): void
# Returns
void
# scale
▸ scale(f
, dst?
): Vector3
向量缩放
memberof
Vector3
# Parameters
Name | Type | Description |
---|---|---|
f | number | 缩放比 |
dst? | Vector3 | - |
# Returns
计算结果
# scaleXYZ
▸ scaleXYZ(x
, y
, z
, dst?
): Vector3
向量缩放
memberof
Vector3
# Parameters
Name | Type | Description |
---|---|---|
x | number | x缩放比 |
y | number | y缩放比 |
z | number | z缩放比 |
dst? | Vector3 | - |
# Returns
计算结果
# set
▸ set(v
): Vector3
拷贝目标向量的值到该向量
memberof
Vector3
# Parameters
Name | Type |
---|---|
v | Vector3 |
# Returns
自身
# setArray
▸ setArray(value
, offset?
): Vector3
# Parameters
Name | Type |
---|---|
value | ArrayLike <number > |
offset? | number |
# Returns
# setFromArray
▸ setFromArray(xyz
): Vector3
# Parameters
Name | Type |
---|---|
xyz | number [] |
# Returns
# setFromMatrixColumn
▸ setFromMatrixColumn(m
, index
): Vector3
# Parameters
Name | Type |
---|---|
m | Matrix4 |
index | number |
# Returns
# setFromMatrixPosition
▸ setFromMatrixPosition(worldMatrix
): Vector3
create by janzen Sets this vector to the position elements of the transformation matrix
# Parameters
Name | Type |
---|---|
worldMatrix | Matrix4 |
# Returns
# setFromMatrixScale
▸ setFromMatrixScale(m
): Vector3
# Parameters
Name | Type |
---|---|
m | Matrix4 |
# Returns
# setValue
▸ setValue(x
, y
, z
): Vector3
设置向量的值
memberof
Vector3
# Parameters
Name | Type | Description |
---|---|---|
x | number | x |
y | number | y |
z | number | z |
# Returns
自身
# sub
▸ sub(v
, dst?
): Vector3
向量减法
memberof
Vector3
# Parameters
# Returns
计算结果
# toArray
▸ toArray(): [number
, number
, number
]
返回向量数据
memberof
Vector3
# Returns
[number
, number
, number
]
矩阵数据,以JSArray返回
# toPhysics
▸ toPhysics(): any
created by shanexyzhou 生成物理引擎内的RawVec3f
# Returns
any
# transformDirection
▸ transformDirection(m
): Vector3
create by janzen Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a m) and then normalizes the result.
# Parameters
Name | Type |
---|---|
m | Matrix4 |
# Returns
# transformDirectionRaw
▸ transformDirectionRaw(raw
): Vector3
create by roamye Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a m) and then normalizes the result.
# Parameters
Name | Type |
---|---|
raw | Float32Array |
# Returns
# clearPhysicsPool
▸ Static
clearPhysicsPool(): void
# Returns
void
# createFromArray
▸ Static
createFromArray(array
): Vector3
使用一个数组创建 此操作会拷贝一份数组
static
memberof
Vector3
# Parameters
Name | Type | Description |
---|---|---|
array | number [] | 数据源,长度必须为3,否则会抛出异常 |
# Returns
创建出来的向量
# createFromNumber
▸ Static
createFromNumber(x
, y
, z
): Vector3
使用数值创建 推荐使用这种方式代替new Vector3
static
memberof
Vector3
# Parameters
Name | Type | Description |
---|---|---|
x | number | x |
y | number | y |
z | number | z |
# Returns
创建出来的向量
# createFromTypedArray
▸ Static
createFromTypedArray(array
, offset?
): Vector3
使用某个已有的typedArray创建 此操作不会拷贝数据,而是在原来的内存区域上操作
static
memberof
Vector3
# Parameters
Name | Type | Default value | Description |
---|---|---|---|
array | Float32Array | undefined | 数据源 |
offset | number | 0 | - |
# Returns
# fromPhysics
▸ Static
fromPhysics(v
): Vector3
created by shanexyzhou 从物理引擎内的RawVec3f生成Vector3
# Parameters
Name | Type |
---|---|
v | any |
# Returns
# transformCoordinate
▸ Static
transformCoordinate(coordinate
, transform
, dst?
): Vector3
# Parameters
# Returns
# transformQuat
▸ Static
transformQuat(source
, rotation
, dst?
): Vector3
使用四元数进行向量旋转
static
memberof
Vector3
# Parameters
Name | Type | Description |
---|---|---|
source | Vector3 | 源向量 |
rotation | Quaternion | 用于旋转的四元数 |
dst? | Vector3 | - |
# Returns
计算结果