|
|
On Fri, 11 Aug 2000 09:19:42 -0400, "Greg M. Johnson"
<gre### [at] my-dejanewscom> wrote:
>Thanks, but I want it to work WITHIN pov. It's the angle of rotation of a knee in a
>walk cycle. This is come kind of "C" code, no?
Here are the key guts of a Tau spline implementation within pov. The
Tau spline is a Catmull-Rom spline with tension and bias parameters.
This means that:
it will pass through the control points
you can control how much it bends (and how smooth the curve is) with
tension
you can control which end of a segment the maximum bend is near with
bias.
Incidentally, the cubic interpolation (cerp) and Horner's method
(horn) macros can create many other spline types with an appropriate
control matrix. You should be able to figure out the rest from here.
If not email and I will send you a full demo as health permits.
This expects your control points to be in the array Points and Bias
and Tens to be (0 to 1) variables already declared. The other
variables are either obvious or irrelevant material from the original
project.
// begin partial code snippet
#macro Mxv(In, Mx)
<max(In.x, Mx.x), max(In.y, Mx.y), max(In.z, Mx.z)>
#end
#macro Mnv(In, Mn)
<min(In.x, Mn.x), min(In.y, Mn.y), min(In.z, Mn.z)>
#end
#declare Tau = array[4][4]
{
{ (Bias - 1) * Tens, 2 - Bias * Tens, (1 - Bias) * Tens - 2, Bias
* Tens },
{ 2 * (1 - Bias) * Tens, (3 * Bias - 1) * Tens - 3, 3 - Tens,
-Bias * Tens },
{ (Bias - 1) * Tens, (1 - 2 * Bias) * Tens, Bias * Tens, 0 },
{ 0, 1, 0, 0 }
}
#macro Horn(Row, Pt)
(T * ( T * (T * Tau[0][Row] + Tau[1][Row]) + Tau[2][Row]) +
Tau[3][Row]) * Pt
#end
#macro Cerp(Pf)
Horn(0, Points[Pf - 1]) + Horn(1, Points[Pf]) +
Horn(2, Points[Pf + 1]) + Horn(3, Points[Pf + 2])
#end
union
{
#declare Iter = 1;
#while(Iter < Dim + 2 * Close)
#declare Count = max(1, int(Fine * vlength(Points[Iter + 1] -
Points[Iter])));
#declare Incr = 1 / Count;
#declare T = 0;
#while(T < 1)
#declare Start = Mxv(Mnv(Cerp(Iter), <24 * Aspect, 24, 24>),
<-24 * Aspect, -24, 0>);
#declare T = T + Incr;
#declare End = Mxv(Mnv(Cerp(Iter), <24 * Aspect, 24, 24>),
<-24 * Aspect, -24, 0>);
#declare End = ((End.x = Start.x) ? End + <.001, 0, 0> : End);
sphere { Start, Width }
cylinder { Start, End, Width }
#end
#end
}
// end partial code snippet
Jerry Anning
clem "at" dhol "dot" org
Post a reply to this message
|
|