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

Function clipLine

7DFPS/js/Three.js:8163–8231  ·  view source on GitHub ↗
( s1, s2 )

Source from the content-addressed store, hash-verified

8161 }
8162
8163 function clipLine( s1, s2 ) {
8164
8165 var alpha1 = 0, alpha2 = 1,
8166
8167 // Calculate the boundary coordinate of each vertex for the near and far clip planes,
8168 // Z = -1 and Z = +1, respectively.
8169 bc1near = s1.z + s1.w,
8170 bc2near = s2.z + s2.w,
8171 bc1far = - s1.z + s1.w,
8172 bc2far = - s2.z + s2.w;
8173
8174 if ( bc1near >= 0 && bc2near >= 0 && bc1far >= 0 && bc2far >= 0 ) {
8175
8176 // Both vertices lie entirely within all clip planes.
8177 return true;
8178
8179 } else if ( ( bc1near < 0 && bc2near < 0) || (bc1far < 0 && bc2far < 0 ) ) {
8180
8181 // Both vertices lie entirely outside one of the clip planes.
8182 return false;
8183
8184 } else {
8185
8186 // The line segment spans at least one clip plane.
8187
8188 if ( bc1near < 0 ) {
8189
8190 // v1 lies outside the near plane, v2 inside
8191 alpha1 = Math.max( alpha1, bc1near / ( bc1near - bc2near ) );
8192
8193 } else if ( bc2near < 0 ) {
8194
8195 // v2 lies outside the near plane, v1 inside
8196 alpha2 = Math.min( alpha2, bc1near / ( bc1near - bc2near ) );
8197
8198 }
8199
8200 if ( bc1far < 0 ) {
8201
8202 // v1 lies outside the far plane, v2 inside
8203 alpha1 = Math.max( alpha1, bc1far / ( bc1far - bc2far ) );
8204
8205 } else if ( bc2far < 0 ) {
8206
8207 // v2 lies outside the far plane, v2 inside
8208 alpha2 = Math.min( alpha2, bc1far / ( bc1far - bc2far ) );
8209
8210 }
8211
8212 if ( alpha2 < alpha1 ) {
8213
8214 // The line segment spans two boundaries, but is outside both of them.
8215 // (This can't happen when we're only clipping against just near/far but good
8216 // to leave the check here for future usage if other clip planes are added.)
8217 return false;
8218
8219 } else {
8220

Callers 1

Three.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected