getWorldSpaceHalfWidth function

double getWorldSpaceHalfWidth(
  1. Camera camera,
  2. double distance,
  3. Vector2 resolution
)

Implementation

double getWorldSpaceHalfWidth(Camera camera, double distance, Vector2 resolution ) {
	// transform into clip space, adjust the x and y values by the pixel width offset, then
	// transform back into world space to get world offset. Note clip space is [-1, 1] so full
	// width does not need to be halved.
	_clipToWorldVector.setValues( 0, 0, - distance, 1.0 ).applyMatrix4( camera.projectionMatrix );
	_clipToWorldVector.scale( 1.0 / _clipToWorldVector.w );
	_clipToWorldVector.x = _lineWidth / resolution.x;
	_clipToWorldVector.y = _lineWidth / resolution.y;
	_clipToWorldVector.applyMatrix4( camera.projectionMatrixInverse );
	_clipToWorldVector.scale( 1.0 / _clipToWorldVector.w );

	return ( math.max( _clipToWorldVector.x, _clipToWorldVector.y ) ).abs();
}