clampPoint method
dynamic
clampPoint(
- dynamic point,
- dynamic result
Reference: Closest Point on OBB to Point in Real-Time Collision Detection by Christer Ericson (chapter 5.1.4)
Implementation
clampPoint(point, result) {
var halfSize = this.halfSize;
v1.subVectors(point, center);
rotation.extractBasis(xAxis, yAxis, zAxis);
// start at the center position of the OBB
result.copy(center);
// project the target onto the OBB axes and walk towards that point
var x = MathUtils.clamp(v1.dot(xAxis), -halfSize.x, halfSize.x);
result.add(xAxis.multiplyScalar(x));
var y = MathUtils.clamp(v1.dot(yAxis), -halfSize.y, halfSize.y);
result.add(yAxis.multiplyScalar(y));
var z = MathUtils.clamp(v1.dot(zAxis), -halfSize.z, halfSize.z);
result.add(zAxis.multiplyScalar(z));
return result;
}