BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Box2.clampPoint()

描述

Box2.clampPoint() 方法用于将一个点的位置限制在一个包围盒(矩形)内。

语法

Box2.clampPoint(point: Vector2, target: Vector2): Vector2

参数

  • point:一个二维向量,表示要被限制的点的位置。
  • target:可选参数,一个二维向量,表示输出位置的目标向量。

返回值

返回一个二维向量,表示被限制后的点的位置。如果提供了 target 参数,则返回该参数。

示例

// 创建一个矩形包围盒
const box = new THREE.Box2(new THREE.Vector2(0, 0), new THREE.Vector2(5, 5));

// 要被限制的点
const point = new THREE.Vector2(2, 6);

// 将点限制在包围盒内
const clampedPoint = box.clampPoint(point);

console.log(clampedPoint); // 输出:(2, 5)

参考链接