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

clampPoint

方法描述

clampPoint 方法的作用是将给定的点约束到此AABB中。

方法语法

AABB.clampPoint(point: Vector3, target: Vector3): Vector3

参数说明

  • point:Vector3类型,表示需要被约束的点。
  • target:Vector3类型,表示一个可选的向量用于存放约束后的点。如果未指定此参数,则会返回一个新的Vector3对象。

返回值

Vector3类型,表示约束后的点。如果存在 target 参数,则返回该参数;否则,返回一个新的 Vector3 对象。

方法实现

clampPoint: function ( point, target ) {

    var min = this.min;
    var max = this.max;

    if ( target === undefined ) {

        console.warn( 'Yuka: AABB - No result vector given.' );
        target = new Vector3();

    }

    target.copy( point );

    target.x = Math.max( min.x, Math.min( max.x, target.x ) );
    target.y = Math.max( min.y, Math.min( max.y, target.y ) );
    target.z = Math.max( min.z, Math.min( max.z, target.z ) );

    return target;

}

使用示例

const aabb = new AABB( new Vector3( -1, -1, -1 ), new Vector3( 1, 1, 1 ) );
const point = new Vector3( 4, 4, 4 );

const result = aabb.clampPoint( point ); // result equals (1, 1, 1)