Set the number of segments to use when drawing a Catmull-Rom curve, and setting the s parameter, which defines how tightly the curve fits to each vertex. Catmull-Rom curves are actually a subset of this curve type where the s is set to zero. (This function is not optimized, since it's not expect
()
| 3557 | * code more readable) |
| 3558 | */ |
| 3559 | protected void curveInit() { |
| 3560 | // allocate only if/when used to save startup time |
| 3561 | if (curveDrawMatrix == null) { |
| 3562 | curveBasisMatrix = new PMatrix3D(); |
| 3563 | curveDrawMatrix = new PMatrix3D(); |
| 3564 | curveInited = true; |
| 3565 | } |
| 3566 | |
| 3567 | float s = curveTightness; |
| 3568 | curveBasisMatrix.set((s-1)/2f, (s+3)/2f, (-3-s)/2f, (1-s)/2f, |
| 3569 | (1-s), (-5-s)/2f, (s+2), (s-1)/2f, |
| 3570 | (s-1)/2f, 0, (1-s)/2f, 0, |
| 3571 | 0, 1, 0, 0); |
| 3572 | |
| 3573 | //setup_spline_forward(segments, curveForwardMatrix); |
| 3574 | splineForward(curveDetail, curveDrawMatrix); |
| 3575 | |
| 3576 | if (bezierBasisInverse == null) { |
| 3577 | bezierBasisInverse = bezierBasisMatrix.get(); |
| 3578 | bezierBasisInverse.invert(); |
| 3579 | curveToBezierMatrix = new PMatrix3D(); |
| 3580 | } |
| 3581 | |
| 3582 | // TODO only needed for PGraphicsJava2D? if so, move it there |
| 3583 | // actually, it's generally useful for other renderers, so keep it |
| 3584 | // or hide the implementation elsewhere. |
| 3585 | curveToBezierMatrix.set(curveBasisMatrix); |
| 3586 | curveToBezierMatrix.preApply(bezierBasisInverse); |
| 3587 | |
| 3588 | // multiply the basis and forward diff matrices together |
| 3589 | // saves much time since this needn't be done for each curve |
| 3590 | curveDrawMatrix.apply(curveBasisMatrix); |
| 3591 | } |
| 3592 | |
| 3593 | |
| 3594 | /** |