• Advertisement
  • entries
    743
  • comments
    1924
  • views
    581565

Solved

Sign in to follow this  

258 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.
Sign in to follow this  


2 Comments


Recommended Comments

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

Share this comment


Link to comment
Quote:
Original post by OrangyTang
Um, 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.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement