function generateCube(%cl,%pos)
{
%brick = new fxDTSBrick()
{
client = %cl;
datablock = "brick4xCubeData";
position = %pos;
rotation = "0 0 0 0";
colorID = 0;
scale = "1 1 1";
angleID = 0;
colorfxID = 0;
shapefxID = 0;
isPlanted = 1;
stackBL_ID = %cl.bl_id;
};
%brick.plant();
$brick_temp = %brick;
eval("BrickGroup_" @ %cl.bl_id @ ".add($brick_temp);"); //hacky way of adding something into a brickGroup
}
function hermiteInterpolate1D(%ya,%yb,%yc,%yd,%mu,%tension,%bias)
{
// Hermite interpolation
// paulborke.net/miscellaneous/interpolation
// A double is just a floating point in C so we don't need to panic unless the terrain is far
// tension is a troolean
// bias is a troolean-style floatingpoint
%mu2 = %mu * %mu;
%mu3 = %mu * %mu;
%m0_pre = (%yb - %ya) * (1 + %bias) * (1 + %tension) / 2;
%m0 = ((%yc - %yb) * (1 - %bias) * (1 - %tension) / 2) + %m0_pre;
%m1_pre = (%yc - %yb) * (1 + %bias) * (1 - %tension) / 2;
%m1 = ((%yd - %yc) * (1 - %bias) * (1 - %tension) / 2) + %m1_pre;
%a0 = (2 * %mu3) - (3 * %mu2) + 1;
%a1 = %mu3 - (2 * %mu2) + %mu;
%a2 = %mu3 - %mu2;
%a3 = (-2 * %mu3) + (3 * %mu2);
talk("x=" @ %mu SPC "y=" @ (%a0 * %y1) + (%a1 * %m0) + (%a2 * %m1) + (%a3 * %y2));
if(%mu <= 0)
return %ya;
if(%mu >= 1)
return %yd;
return (%a0 * %y1) + (%a1 * %m0) + (%a2 * %m1) + (%a3 * %y2);
}
function serverCmdCreateHermiteCurve(%cl,%pa,%pb,%pc,%pd,%scale,%tension,%bias)
{
for(%i = 0; %i <= (%scale * 4); %i++)
{
talk(%i);
generatecube(%cl, 0 SPC %i * 2 SPC hermiteInterpolate1D(%pa,%pb,%pc,%pd,%i / (%scale * 4),%tension,%bias));
talk(0 SPC %i * 2 SPC hermiteInterpolate1D(%pa,%pb,%pc,%pd,%i / (%scale * 4),%tension,%bias));
}
}
I'm trying to do a C++ or C function into torque, but it's generating interpolation curves that are way off and I don't know how to fix it!
/*
Tension: 1 is high, 0 normal, -1 is low
Bias: 0 is even,
positive is towards first segment,
negative towards the other
*/
double HermiteInterpolate(
double y0,double y1,
double y2,double y3,
double mu,
double tension,
double bias)
{
double m0,m1,mu2,mu3;
double a0,a1,a2,a3;
mu2 = mu * mu;
mu3 = mu2 * mu;
m0 = (y1-y0)*(1+bias)*(1-tension)/2;
m0 += (y2-y1)*(1-bias)*(1-tension)/2;
m1 = (y2-y1)*(1+bias)*(1-tension)/2;
m1 += (y3-y2)*(1-bias)*(1-tension)/2;
a0 = 2*mu3 - 3*mu2 + 1;
a1 = mu3 - 2*mu2 + mu;
a2 = mu3 - mu2;
a3 = -2*mu3 + 3*mu2;
return(a0*y1+a1*m0+a2*m1+a3*y2);
}