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
()
| 3654 | * code more readable) |
| 3655 | */ |
| 3656 | protected void curveInit() { |
| 3657 | // allocate only if/when used to save startup time |
| 3658 | if (curveDrawMatrix == null) { |
| 3659 | curveBasisMatrix = new PMatrix3D(); |
| 3660 | curveDrawMatrix = new PMatrix3D(); |
| 3661 | curveInited = true; |
| 3662 | } |
| 3663 | |
| 3664 | float s = curveTightness; |
| 3665 | curveBasisMatrix.set((s-1)/2f, (s+3)/2f, (-3-s)/2f, (1-s)/2f, |
| 3666 | (1-s), (-5-s)/2f, (s+2), (s-1)/2f, |
| 3667 | (s-1)/2f, 0, (1-s)/2f, 0, |
| 3668 | 0, 1, 0, 0); |
| 3669 | |
| 3670 | //setup_spline_forward(segments, curveForwardMatrix); |
| 3671 | splineForward(curveDetail, curveDrawMatrix); |
| 3672 | |
| 3673 | if (bezierBasisInverse == null) { |
| 3674 | bezierBasisInverse = bezierBasisMatrix.get(); |
| 3675 | bezierBasisInverse.invert(); |
| 3676 | curveToBezierMatrix = new PMatrix3D(); |
| 3677 | } |
| 3678 | |
| 3679 | // TODO only needed for PGraphicsJava2D? if so, move it there |
| 3680 | // actually, it's generally useful for other renderers, so keep it |
| 3681 | // or hide the implementation elsewhere. |
| 3682 | curveToBezierMatrix.set(curveBasisMatrix); |
| 3683 | curveToBezierMatrix.preApply(bezierBasisInverse); |
| 3684 | |
| 3685 | // multiply the basis and forward diff matrices together |
| 3686 | // saves much time since this needn't be done for each curve |
| 3687 | curveDrawMatrix.apply(curveBasisMatrix); |
| 3688 | } |
| 3689 | |
| 3690 | |
| 3691 | /** |