Sign in to follow this  
lucky6969b

D3DXVec2CatmullRom Question

Recommended Posts

lucky6969b    1330

std::vector<D3DXVECTOR2>::iterator it;
std::vector<D3DXVECTOR2> newList;
int count = 0;
for (it = lstPoints.begin(); it != lstPoints.end();)
{
if (count == 0 || count == 1)
{
// double up
newList.push_back(*it);
count++;
continue;
} else if (count == lstPoints.size() || count == lstPoints.size()-1)
{
// double up
newList.push_back(*it);
count++;
continue;

} else
{
newList.push_back(*it);
count++;
it++;
}


}
// now we have a full list that include the double ups
float s = 0.0f;
for (int i = 0; i < count-3; i+=3)
{
D3DXVECTOR2 vecPos;
s += 0.25;
if (s >= 1.0f)
s = 0.0f;
D3DXVec2CatmullRom(&vecPos, &newList[i], &newList[i+1], &newList[i+2], &newList[i+3], s);
char buff[256];
sprintf (buff, "X:%f Y:%f\n", vecPos.x, vecPos.y);
OutputDebugString(buff);
m_finalArray.push_back(vecPos);
}






lstPoints is worked-out path in pixels.
This result is a bee-like path, not a smoothed solid line. Does the line s+=0.25 make the difference? Any fix for me?
Thanks
Jack

[Edited by - lucky6969b on November 9, 2010 5:01:32 AM]

Share this post


Link to post
Share on other sites
lucky6969b    1330

void CAStar::SmoothPath()
{
std::vector<D3DXVECTOR2> catmull;

if (m_finalArray.size() < 3)
return;


for (int i = 0; i < m_finalArray.size(); i++)
{
if (i == 0) {
catmull.push_back(m_finalArray[i]);
catmull.push_back(m_finalArray[i]);


}
else if (i == m_finalArray.size())
{
catmull.push_back(m_finalArray[i]);
catmull.push_back(m_finalArray[i]);

} else
{
catmull.push_back(m_finalArray[i]);


}

}
m_finalArray.clear();
//assert (m_finalArray.size() != catmull.size());

for (int j = 0; j < catmull.size()-3;j++) {
D3DXVECTOR2 v;
for (double s = 0; s <= 1.0f; s+=0.1){
D3DXVec2CatmullRom(&v, &catmull[j], &catmull[j+1], &catmull[j+2], &catmull[j+3],s);
m_finalArray.push_back(v);
}
}




Looks better yet? still the same outcome
Thanks
Jack

[Edited by - lucky6969b on November 10, 2010 2:45:30 AM]

Share this post


Link to post
Share on other sites

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

Sign in to follow this