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

equals

该方法用于比较两个 Matrix4 对象是否相等。

语法

matrix.equals(matrix2)

参数

  • matrix:一个 Matrix4 对象,需要与当前对象进行比较。

返回值

  • Boolean:如果两个 Matrix4 对象的所有元素都相等,则返回 true,否则返回 false

示例

const matrix1 = new Matrix4().set(
  1, 2, 3, 4,
  5, 6, 7, 8,
  9, 10, 11, 12,
  13, 14, 15, 16
);
const matrix2 = new Matrix4().set(
  1, 2, 3, 4,
  5, 6, 7, 8,
  9, 10, 11, 12,
  13, 14, 15, 16
);
const matrix3 = new Matrix4().set(
  1, 2, 3, 4,
  5, 6, 7, 8,
  9, 10, 11, 12,
  13, 14, 15, 17
);

console.log(matrix1.equals(matrix2)); // true
console.log(matrix1.equals(matrix3)); // false

在上面的示例中,我们首先创建了两个 Matrix4 对象,分别为 matrix1matrix2,它们的所有元素都相等。然后我们使用 equals 方法比较这两个对象,返回了 true

接着,我们又创建了一个 Matrix4 对象 matrix3,它的最后一个元素不同于 matrix1matrix2,所以使用 equals 方法比较 matrix1matrix3,返回了 false

注意事项

  • 该方法比较的是对象的元素值,不能比较两个对象的引用地址。如果需要判断两个 Matrix4 对象是否是同一个对象,应该使用 === 运算符。
  • 该方法会修改当前对象的状态,但不会修改参数对象的状态。
  • 如果两个 Matrix4 对象之间存在精度问题,两个对象的元素虽然很接近但不相等,返回的结果也会是 false。在实际比较中,应该使用精度范围内的相等判断。