@ue-too/board / clampRotateByHandler
Function: clampRotateByHandler()
clampRotateByHandler(
delta,camera,config):number
Defined in: packages/board/src/camera/camera-rig/rotation-handler.ts:242
Handler pipeline step that clamps "rotate by" deltas to prevent angular boundary violations.
Parameters
delta
number
Rotation angle change in radians
camera
Current camera instance (provides current rotation and boundaries)
config
Clamping configuration
Returns
number
Adjusted delta that respects rotation boundaries
Remarks
This handler ensures that applying the delta won't exceed rotation boundaries.
Algorithm:
- Calculate potential new rotation (current + delta)
- Normalize angle to [0, 2π) range
- Clamp to rotation boundaries
- Calculate shortest angular distance from current to clamped angle
- Return that distance as the new delta
Behavior:
- If
clampRotationis false: Returns delta unchanged - If
clampRotationis true: Adjusts delta to stay within boundaries
The resulting delta may be zero if already at a boundary and trying to rotate further.
Example
typescript
camera.rotation = Math.PI * 0.4; // 72 degrees
camera.rotationBoundaries = { max: Math.PI / 2 }; // Max 90 degrees
const config: RotationHandlerClampConfig = {
clampRotation: true
};
const delta = Math.PI * 0.2; // Try to rotate 36 degrees (would exceed max)
const clamped = clampRotateByHandler(delta, camera, config);
// clamped ≈ 0.314 radians (18 degrees - only rotate to boundary)See
- normalizeAngleZero2TwoPI for angle normalization
- clampRotation for boundary clamping
- angleSpan for calculating angular distance