MCPcopy Index your code
hub / github.com/stemkoski/stemkoski.github.com / clipLine

Function clipLine

Three.js/js/Three62dev.js:8224–8292  ·  view source on GitHub ↗
( s1, s2 )

Source from the content-addressed store, hash-verified

8222 }
8223
8224 function clipLine( s1, s2 ) {
8225
8226 var alpha1 = 0, alpha2 = 1,
8227
8228 // Calculate the boundary coordinate of each vertex for the near and far clip planes,
8229 // Z = -1 and Z = +1, respectively.
8230 bc1near = s1.z + s1.w,
8231 bc2near = s2.z + s2.w,
8232 bc1far = - s1.z + s1.w,
8233 bc2far = - s2.z + s2.w;
8234
8235 if ( bc1near >= 0 && bc2near >= 0 && bc1far >= 0 && bc2far >= 0 ) {
8236
8237 // Both vertices lie entirely within all clip planes.
8238 return true;
8239
8240 } else if ( ( bc1near < 0 && bc2near < 0) || (bc1far < 0 && bc2far < 0 ) ) {
8241
8242 // Both vertices lie entirely outside one of the clip planes.
8243 return false;
8244
8245 } else {
8246
8247 // The line segment spans at least one clip plane.
8248
8249 if ( bc1near < 0 ) {
8250
8251 // v1 lies outside the near plane, v2 inside
8252 alpha1 = Math.max( alpha1, bc1near / ( bc1near - bc2near ) );
8253
8254 } else if ( bc2near < 0 ) {
8255
8256 // v2 lies outside the near plane, v1 inside
8257 alpha2 = Math.min( alpha2, bc1near / ( bc1near - bc2near ) );
8258
8259 }
8260
8261 if ( bc1far < 0 ) {
8262
8263 // v1 lies outside the far plane, v2 inside
8264 alpha1 = Math.max( alpha1, bc1far / ( bc1far - bc2far ) );
8265
8266 } else if ( bc2far < 0 ) {
8267
8268 // v2 lies outside the far plane, v2 inside
8269 alpha2 = Math.min( alpha2, bc1far / ( bc1far - bc2far ) );
8270
8271 }
8272
8273 if ( alpha2 < alpha1 ) {
8274
8275 // The line segment spans two boundaries, but is outside both of them.
8276 // (This can't happen when we're only clipping against just near/far but good
8277 // to leave the check here for future usage if other clip planes are added.)
8278 return false;
8279
8280 } else {
8281

Callers 1

Three62dev.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected