• entries
743
1924
• views
584152

# Solved

302 views

The curve issue is solved based on some inspiration from JTippetts in the comments to my last post.

bool PathSequence::GetPosition(float Distance,D3DXVECTOR3 &Pos){    if(Distance<=0)        {        Pos=Segs[0].Pos;        return true;        }    if(Distance>=Len)        {        Pos=Segs.back().Pos;        return false;        }    float Remainder=Distance;    size_t N=0;    while(N1)        {        if(Remainder>Segs[N].Len)            {            Remainder-=Segs[N].Len;            ++N;            }		        else break;        }    if(N==Segs.size()-1)        {        Pos=Segs.back().Pos;        return false;        }    const float Inc=0.001f;    float Fac=Inc;    D3DXVECTOR3 A=Segs[N].Pos;    D3DXVECTOR3 B=Bezier(Segs[N].Pos,Segs[N].Ctrl,Segs[N+1].Pos,Fac);    float Dist=D3DXVec3Length(&(B-A));    Remainder-=Dist;	    while(Remainder>Inc)        {        Fac+=Inc;        A=B;        B=Bezier(Segs[N].Pos,Segs[N].Ctrl,Segs[N+1].Pos,Fac);        Dist=D3DXVec3Length(&(B-A));        Remainder-=Dist;	        }    Pos=B;    return true;}

Basically, identify the correct segment, step along it in very small increments and keep subtracting the linear distance between this point and the last one from the remainder until we get within a small tolerance, then return.

The results are quite acceptable even though it is potentially a bit slow. It's only probably performed once a frame so it doesn't matter.

Um, did you check out the code I posted? It should be much, much faster than the brute force stepping approach.

Quote:
 Original post by OrangyTangUm, did you check out the code I posted? It should be much, much faster than the brute force stepping approach.

I did and appreciate you posting it but it seems to use cubic splines and I can't justify the time to adapt it.

## Create an account

Register a new account