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

equals(sphere) 方法用于判断当前的 BoundingSphere 对象是否等同于传入的 sphere 对象。

语法

equals(sphere: BoundingSphere): boolean

参数

  • sphere: BoundingSphere:必需,表示要比较的 BoundingSphere 对象。

返回值

  • boolean:表示比较结果,若两个 BoundingSphere 对象等同,则返回 true,否则返回 false

示例

const sphereA = new Yuka.BoundingSphere(new Yuka.Vector3(10, 0, 0), 5);
const sphereB = new Yuka.BoundingSphere(new Yuka.Vector3(10, 0, 0), 5);

console.log(sphereA.equals(sphereB)); // 输出 true

实现原理

equals() 方法实质上是通过比较当前 BoundingSphere 对象中心点和半径与传入的 BoundingSphere 对象是否一致来判断两者是否等同。

具体实现过程如下:

  1. 比较两个 BoundingSphere 对象中心点的 x、y、z 坐标分别是否相等,若坐标均相等,则继续执行;否则返回 false
  2. 比较两个 BoundingSphere 对象的半径是否相等,若半径相等,则返回 true;否则返回 false

注意事项

  • 由于比较的是浮点数,可能会存在精度误差的问题,因此在比较两个 BoundingSphere 对象中心点坐标时,应该使用一定的容差值,例如 0.0001

参考链接