Saturday, December 19, 2015

Kochanek Bartels Spline Class for Objective-C + OpenGL

A Kochanek Bartels spline is a lovely, flexible means for casting a curve through multiple points, and providing artistically useful control over the character of the curve. It is also known as a TCB spline, because the controls are Tension, Continuity, and Bias. It was originally developed for providing smooth keyframed animation control curves, but it is also useful for general graphics purposes. For one of my Apple Motion FxPlug projects, I developed a Objective C class to render a Kochanek Bartels spline in OpenGL. It includes an additional feature of interpolating colors between the target points.


I have placed the code on GitHub. Corrections/improvements welcomed.

And here's a taste of what happens if one sets the parameters outside of the standard -1 to 1 range. Here T = -4.38, C = -1.31, and B = 0.37:


  1. Would be nice to see a port to OpenGL ES :-)

  2. Hi Ron, is that a volunteer I hear? ;-) [Actually, I know almost nothing about ES, but I would think the code is generic enough to transfer easily.]


  3. I knew you'd say that, Bret :-) I actually don't know ES (or OpenGL) that well myself, but I do know that it doesn't use glBegin(), glEnd() or glVertex():

    For the moment I've opted to continue to work with openFrameworks - perhaps at some point I'll have the time (though I wouldn't bet on it!) either to actually learn OpenGL, so that I can more easily integrate things such as you've offered here, or figure out how I might fold the Kochanek Bartels equations into the OF context. With Apple moving away from OpenGL and towards their own Metal framework, it's hard to say where I'll end up!