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

compose

功能

在Yuka js库的Matrix4类中,compose方法用于计算传入的平移、旋转和缩放矩阵的乘积,并将结果赋值给调用该方法的Matrix4实例。

语法

compose( translationMatrix, rotationMatrix, scaleMatrix )

参数

  • translationMatrix:表示平移变换的Matrix4实例。
  • rotationMatrix:表示旋转变换的Matrix4实例。
  • scaleMatrix:表示缩放变换的Matrix4实例。

返回值

该方法没有返回值,但会修改调用该方法的Matrix4实例的值。

描述

将平移、旋转和缩放变换矩阵组合成一个矩阵。顺序为:先进行平移变换、再进行旋转变换、最后进行缩放变换。将三个变换矩阵按照上述顺序计算其乘积,得到一个新的矩阵,并将该矩阵的值赋值给调用该方法的Matrix4实例。

示例

const matrix = new Matrix4();

const translationMatrix = new Matrix4().setPosition( 2, 3, 4 );
const rotationMatrix = new Matrix4().setRotationFromAxis( new Vector3( 0, 1, 0 ), Math.PI / 2 );
const scaleMatrix = new Matrix4().setScale( 2, 2, 2 );

matrix.compose( translationMatrix, rotationMatrix, scaleMatrix );

console.log( matrix.toArray() ); // [2, 0, 0, 0, 0, 0, -2, 0, 0, 2, 0, 0, 2, 3, 4, 1]

上例中,首先创建了一个Matrix4实例matrix。接着,分别创建了平移变换矩阵translationMatrix、旋转变换矩阵rotationMatrix和缩放变换矩阵scaleMatrix。随后,调用matrix的compose方法,并将平移变换矩阵、旋转变换矩阵和缩放变换矩阵作为参数传入。最后,将新矩阵的值打印出来。