Advertisement

D3DXVec2CatmullRom Question

Started by November 09, 2010 04:37 AM
0 comments, last by lucky6969b 14 years ago
        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, &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]
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);			catmull.push_back(m_finalArray);			 		     		} 		else	if (i == m_finalArray.size())		{			catmull.push_back(m_finalArray);			catmull.push_back(m_finalArray);		 		} else		{			catmull.push_back(m_finalArray);		 		 		}			}	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]

This topic is closed to new replies.

Advertisement