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

getIndexForPosition函数

功能

该函数用于获取给定位置所在的partion索引。

参数

  1. position:一个包含x和y属性的对象,表示想要获取索引的位置。

返回值

函数返回一个整数,表示给定位置所在的partion索引。

实现方法

  1. 该函数首先会通过将position的x和y值分别除以partitionSize,来获取该位置位于第几个column和第几个row。
  2. 然后,函数通过将row * numCellsX + column,来计算出该位置所对应的partion的索引。

示例代码

function getIndexForPosition(position) {
  const column = Math.floor(position.x / partitionSize);
  const row = Math.floor(position.y / partitionSize);
  return row * numCellsX + column;
}

注意事项

  1. 在使用该函数之前,必须先进行合适的初始化,以设置partitionSize和numCellsX等参数。
  2. partitionSize和numCellsX的值必须具有实际意义,否则将无法正确使用该函数获取partion索引。