I have a bezier curve class. Each point on the curve is defined thus:
struct bpoint
{
vector3D position;
vector3D controlpoint_in;
vector3d controlpoint_out;
};
To retrieve a point on the curve's spline (the curve can have infinite points), I use this function:
vector3d GetSplinePoint(float thePos)
{
float aPos=thePos-floorf(thePos);
int aIPos=(int)floorf(thePos);
bpoint& aP1=pointList[aIPos];
bpoint& aP2=pointList[min(aIPos+1,pointList.size())];
vector3D aResult;
vector3D aAB, aBC, aCD, aABBC, aBCCD;
Lerp(aAB,aP1.mPos,aP1.mOut,aPos);
Lerp(aBC,aP1.mOut,aP2.mIn,aPos);
Lerp(aCD,aP2.mIn,aP2.mPos,aPos);
Lerp(aABBC,aAB,aBC,aPos);
Lerp(aBCCD,aBC,aCD,aPos);
Lerp(aResult,aABBC,aBCCD,aPos);
return aResult;
}
Works great, but now I'm in a situation where I want to add normals to each point, so that I can do some fancier stuff (rotations, etc). Like so:
struct bpoint
{
vector3D position;
vector3D controlpoint_in;
vector3d controlpoint_out;
vector3d normal;
};
I've been utterly unsuccessful in trying to write a GetSplineNormal(float thePos) function. I'm not even sure where to begin-- I thought I could just interpolate between the points, but I don't know how to factor in the control points.
How could I accomplish this?