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

Cells

Cells(单元格)是Yuka js库中CellSpacePartitioning(空间划分)算法的基本单元。

概述

Cells将空间划分为若干个单元格,每个单元格的大小是固定的,当一个实体(Entity)被添加到空间中时,它所处的位置将被计算,并将其添加到对应的单元格中。这样,在进行空间查询时,可以仅对实体所处的单元格进行查询,从而大大减少了查询的时间复杂度。

属性

  • position:单元格的位置,由一个2D向量表示。
  • size:单元格的大小,由一个2D向量表示。
  • entities:一个数组,用于存储该单元格中包含的所有实体。

方法

  • addEntity:将一个实体添加到单元格中。
  • removeEntity:将一个实体从单元格中移除。
  • clear:移除该单元格中的所有实体。

示例

const cell = new Cells(new Vector2(0, 0), new Vector2(100, 100));
cell.addEntity(entity);
cell.removeEntity(entity);
cell.clear();

应用

Cells常用于游戏开发中的碰撞检测,通过将实体所处的空间划分为若干单元格,可以快速地确定一个实体是否与其他实体发生碰撞。它也可以用于优化空间查询,例如查找地图上在一定范围内的所有点,通过将空间划分为单元格,并仅查询该实体所处的单元格及其周围的单元格,可以提高查询效率。