diff options
author | Valerio Virgillito | 2012-07-09 14:35:44 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-07-09 14:35:44 -0700 |
commit | 84b3327bd92faafab7954b5eb64c7abe24a3fe13 (patch) | |
tree | 3f56cbed2f08c5a81ea79eaf0bcb9bd031d8a627 /js/helper-classes/3D/StageLine.js | |
parent | c0a42c56f768a873ba637f5b86d5f6a84d4a3312 (diff) | |
parent | 40c6eb2c06b34f65a74d59ef9687251952858bab (diff) | |
download | ninja-84b3327bd92faafab7954b5eb64c7abe24a3fe13.tar.gz |
Merge branch 'normalize' of https://github.com/kriskowal/ninja-internal
Conflicts:
js/components/gradientpicker.reel/gradientpicker.js
js/components/tools-properties/text-properties.reel/text-properties.js
js/document/views/base.js
js/document/views/design.js
js/helper-classes/3D/StageLine.js
js/helper-classes/3D/draw-utils.js
js/lib/drawing/world.js
js/lib/geom/circle.js
js/lib/geom/line.js
js/lib/geom/rectangle.js
js/lib/geom/shape-primitive.js
js/lib/rdge/materials/bump-metal-material.js
js/lib/rdge/materials/flag-material.js
js/lib/rdge/materials/fly-material.js
js/lib/rdge/materials/julia-material.js
js/lib/rdge/materials/keleidoscope-material.js
js/lib/rdge/materials/mandel-material.js
js/lib/rdge/materials/material.js
js/lib/rdge/materials/plasma-material.js
js/lib/rdge/materials/pulse-material.js
js/lib/rdge/materials/radial-gradient-material.js
js/lib/rdge/materials/taper-material.js
js/lib/rdge/materials/twist-vert-material.js
js/lib/rdge/materials/water-material.js
js/panels/Materials/materials-library-panel.reel/materials-library-panel.html
js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
js/panels/Materials/materials-popup.reel/materials-popup.html
js/panels/Materials/materials-popup.reel/materials-popup.js
js/tools/LineTool.js
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/helper-classes/3D/StageLine.js')
-rwxr-xr-x | js/helper-classes/3D/StageLine.js | 370 |
1 files changed, 185 insertions, 185 deletions
diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js index aaa9f95d..b869fb17 100755 --- a/js/helper-classes/3D/StageLine.js +++ b/js/helper-classes/3D/StageLine.js | |||
@@ -120,7 +120,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { | |||
120 | // add the intersection | 120 | // add the intersection |
121 | var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3]; | 121 | var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3]; |
122 | var deltaVis = (dot > 0) ? 1 : -1; | 122 | var deltaVis = (dot > 0) ? 1 : -1; |
123 | // if (plane.isBackFacing()) | 123 | // if (plane.isBackFacing()) |
124 | // deltaVis = (dot < 0) ? 1 : -1; | 124 | // deltaVis = (dot < 0) ? 1 : -1; |
125 | 125 | ||
126 | this.addIntersection( plane, t, deltaVis ); | 126 | this.addIntersection( plane, t, deltaVis ); |
@@ -175,14 +175,14 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { | |||
175 | MathUtils.negate( vec ); | 175 | MathUtils.negate( vec ); |
176 | planeEq = [-vec[1], vec[0], 0]; | 176 | planeEq = [-vec[1], vec[0], 0]; |
177 | var normal = [planeEq[0], planeEq[1], planeEq[2]]; | 177 | var normal = [planeEq[0], planeEq[1], planeEq[2]]; |
178 | // var d = -planeEq.dot(bPt0); | 178 | // var d = -planeEq.dot(bPt0); |
179 | var d = -vecUtils.vecDot(3, planeEq, bPt0); | 179 | var d = -vecUtils.vecDot(3, planeEq, bPt0); |
180 | planeEq[3] = d; | 180 | planeEq[3] = d; |
181 | 181 | ||
182 | t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); | 182 | t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); |
183 | if (t) | 183 | if (t) |
184 | { | 184 | { |
185 | if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! | 185 | if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! |
186 | { | 186 | { |
187 | // get the intersection point | 187 | // get the intersection point |
188 | var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); | 188 | var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); |
@@ -207,47 +207,47 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { | |||
207 | } | 207 | } |
208 | }, | 208 | }, |
209 | 209 | ||
210 | doCoplanarIntersection: { | 210 | doCoplanarIntersection: { |
211 | value: function( plane ) | 211 | value: function( plane ) |
212 | { | 212 | { |
213 | // get the boundary points for the plane | 213 | // get the boundary points for the plane |
214 | var boundaryPts = plane.getBoundaryPoints(); | 214 | var boundaryPts = plane.getBoundaryPoints(); |
215 | var planeEq = plane.getPlaneEq(); | 215 | var planeEq = plane.getPlaneEq(); |
216 | 216 | ||
217 | if (plane.isBackFacing()) | 217 | if (plane.isBackFacing()) |
218 | { | 218 | { |
219 | var tmp; | 219 | var tmp; |
220 | tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; | 220 | tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; |
221 | tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; | 221 | tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; |
222 | } | 222 | } |
223 | 223 | ||
224 | var pt0 = this.getPoint0(), | 224 | var pt0 = this.getPoint0(), |
225 | pt1 = this.getPoint1(); | 225 | pt1 = this.getPoint1(); |
226 | 226 | ||
227 | // keep a couple flags to prevent counting crossings twice in edge cases | 227 | // keep a couple flags to prevent counting crossings twice in edge cases |
228 | var gotEnter = false, | 228 | var gotEnter = false, |
229 | gotExit = false; | 229 | gotExit = false; |
230 | 230 | ||
231 | var bp1 = boundaryPts[3]; | 231 | var bp1 = boundaryPts[3]; |
232 | for (var i=0; i<4; i++) | 232 | for (var i=0; i<4; i++) |
233 | { | 233 | { |
234 | var bp0 = bp1; | 234 | var bp0 = bp1; |
235 | bp1 = boundaryPts[i]; | 235 | bp1 = boundaryPts[i]; |
236 | var vec = vecUtils.vecSubtract(3, bp1, bp0); | 236 | var vec = vecUtils.vecSubtract(3, bp1, bp0); |
237 | var nrm = vecUtils.vecCross(3, vec, planeEq); | 237 | var nrm = vecUtils.vecCross(3, vec, planeEq); |
238 | nrm[3] = -vecUtils.vecDot(3, bp0, nrm); | 238 | nrm[3] = -vecUtils.vecDot(3, bp0, nrm); |
239 | 239 | ||
240 | var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], | 240 | var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], |
241 | d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; | 241 | d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; |
242 | 242 | ||
243 | var s0 = MathUtils.fpSign(d0), | 243 | var s0 = MathUtils.fpSign(d0), |
244 | s1 = MathUtils.fpSign(d1); | 244 | s1 = MathUtils.fpSign(d1); |
245 | 245 | ||
246 | if (s0 != s1) | 246 | if (s0 != s1) |
247 | { | 247 | { |
248 | var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); | 248 | var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); |
249 | if (MathUtils.fpSign(t) === 0) | 249 | if (MathUtils.fpSign(t) === 0) |
250 | { | 250 | { |
251 | // the first point of the line is on the (infinite) extension of a side of the boundary. | 251 | // the first point of the line is on the (infinite) extension of a side of the boundary. |
252 | // Make sure the point (pt0) is within the range of the polygon edge | 252 | // Make sure the point (pt0) is within the range of the polygon edge |
253 | var vt0 = vecUtils.vecSubtract(3, pt0, bp0), | 253 | var vt0 = vecUtils.vecSubtract(3, pt0, bp0), |
@@ -257,144 +257,144 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { | |||
257 | var st0 = MathUtils.fpSign(dt0), st1 = MathUtils.fpSign(dt1); | 257 | var st0 = MathUtils.fpSign(dt0), st1 = MathUtils.fpSign(dt1); |
258 | if ((st0 >= 0) && (st1 >= 0)) | 258 | if ((st0 >= 0) && (st1 >= 0)) |
259 | { | 259 | { |
260 | if (s1 > 0) // entering the material from the beginning of the line that is to be drawn | 260 | if (s1 > 0) // entering the material from the beginning of the line that is to be drawn |
261 | { | 261 | { |
262 | // see if the start point of the line is at a corner of the bounded plane | 262 | // see if the start point of the line is at a corner of the bounded plane |
263 | var lineDir = vecUtils.vecSubtract(3, pt1, pt0); | 263 | var lineDir = vecUtils.vecSubtract(3, pt1, pt0); |
264 | vecUtils.vecNormalize(3, lineDir); | 264 | vecUtils.vecNormalize(3, lineDir); |
265 | var dist = vecUtils.vecDist( 3, pt0, bp1 ); | 265 | var dist = vecUtils.vecDist( 3, pt0, bp1 ); |
266 | var bp2, bv0, bv1, cross1, cross2, cross3; | 266 | var bp2, bv0, bv1, cross1, cross2, cross3; |
267 | if ( MathUtils.fpSign(dist) == 0) | 267 | if ( MathUtils.fpSign(dist) == 0) |
268 | { | 268 | { |
269 | bp2 = boundaryPts[(i+1) % 4]; | 269 | bp2 = boundaryPts[(i+1) % 4]; |
270 | bv0 = vecUtils.vecSubtract(3, bp2, bp1); | 270 | bv0 = vecUtils.vecSubtract(3, bp2, bp1); |
271 | bv1 = vecUtils.vecSubtract(3, bp0, bp1); | 271 | bv1 = vecUtils.vecSubtract(3, bp0, bp1); |
272 | cross1 = vecUtils.vecCross(3, bv0, lineDir); | 272 | cross1 = vecUtils.vecCross(3, bv0, lineDir); |
273 | cross2 = vecUtils.vecCross(3, lineDir, bv1); | 273 | cross2 = vecUtils.vecCross(3, lineDir, bv1); |
274 | cross3 = vecUtils.vecCross(3, bv0, bv1); | 274 | cross3 = vecUtils.vecCross(3, bv0, bv1); |
275 | if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) | 275 | if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) |
276 | { | 276 | { |
277 | gotEnter = true; | 277 | gotEnter = true; |
278 | this.addIntersection( plane, t, 1 ); | 278 | this.addIntersection( plane, t, 1 ); |
279 | } | 279 | } |
280 | } | 280 | } |
281 | else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) | 281 | else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) |
282 | { | 282 | { |
283 | bp2 = boundaryPts[(i+2) % 4]; | 283 | bp2 = boundaryPts[(i+2) % 4]; |
284 | bv0 = vecUtils.vecSubtract(3, bp2, bp0); | 284 | bv0 = vecUtils.vecSubtract(3, bp2, bp0); |
285 | bv1 = vecUtils.vecSubtract(3, bp1, bp0); | 285 | bv1 = vecUtils.vecSubtract(3, bp1, bp0); |
286 | cross1 = vecUtils.vecCross(3, bv0, lineDir); | 286 | cross1 = vecUtils.vecCross(3, bv0, lineDir); |
287 | cross2 = vecUtils.vecCross(3, lineDir, bv1); | 287 | cross2 = vecUtils.vecCross(3, lineDir, bv1); |
288 | cross3 = vecUtils.vecCross(3, bv0, bv1); | 288 | cross3 = vecUtils.vecCross(3, bv0, bv1); |
289 | if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) | 289 | if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) |
290 | { | 290 | { |
291 | gotEnter = true; | 291 | gotEnter = true; |
292 | this.addIntersection( plane, t, 1 ); | 292 | this.addIntersection( plane, t, 1 ); |
293 | } | 293 | } |
294 | } | 294 | } |
295 | else | 295 | else |
296 | { | 296 | { |
297 | // check if the line is on the edge of the boundary or goes to the interior | 297 | // check if the line is on the edge of the boundary or goes to the interior |
298 | gotEnter = true; | 298 | gotEnter = true; |
299 | this.addIntersection( plane, t, 1 ); | 299 | this.addIntersection( plane, t, 1 ); |
300 | } | 300 | } |
301 | } | 301 | } |
302 | } | 302 | } |
303 | } | ||
304 | else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) | ||
305 | { | ||
306 | // get the point where the line crosses the edge of the element plane | ||
307 | var pt = MathUtils.interpolateLine3D(pt0, pt1, t ); | ||
308 | |||
309 | // we know that the line crosses the infinite extension of the edge. Determine | ||
310 | // if that crossing is within the bounds of the edge | ||
311 | var dot0 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp0), vec), | ||
312 | dot1 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp1), vec); | ||
313 | if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0)) |