AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

fromArray

简介

fromArray 方法可以将一个数组转换为 3x3 的矩阵,矩阵的第一列为数组的前三个元素,第二列为数组的第四到第六个元素,第三列为数组的第七到第九个元素,并返回转换后的矩阵。

语法

Matrix3.fromArray(array)

参数

  • array :需要转换为矩阵的数组,必须包含 9 个元素,否则会抛出错误。

示例

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const m = new Yuka.Matrix3();

m.fromArray(arr);

console.log(m.elements); // [1, 4, 7, 2, 5, 8, 3, 6, 9]

说明

在上面的示例中,我们创建了一个包含 9 个元素的数组,并使用 fromArray 将其转换为矩阵。转换后的矩阵可以通过 elements 获取。

异常

  • 如果输入的数组不包含 9 个元素,则会抛出错误。

参考