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

getCenter

功能

本函数用于获取AABB(轴对齐边界框)的中心点坐标。

参数

本函数不接受参数。

返回值

本函数返回一个由两个浮点数组成的数组,表示AABB的中心点坐标。第一个浮点数表示X轴坐标,第二个浮点数表示Y轴坐标。

示例

var myAABB = new Yuka.AABB(-5, -5, 5, 5);
var center = myAABB.getCenter();
console.log(center); // 输出 [0, 0]

myAABB.translate(new Yuka.Vector2(2, 2));
center = myAABB.getCenter();
console.log(center); // 输出 [2, 2]

实现

本函数的实现代码如下:

AABB.prototype.getCenter = function() {
  return [(this.min.x + this.max.x) * 0.5, (this.min.y + this.max.y) * 0.5];
};

异常情况

本函数不会发生异常。