void _XWindLine::addAPoint(const _XVector2 & p) //插入一个点 { if(!m_isInited) return; if(m_points.size() == 0) {//第一个点,不需要插值 _XSmoothPoint *ip = createMem<_XSmoothPoint>(); if(ip == NULL) return; ip->m_length = 0.0f; ip->m_percentage = 0.0f; ip->m_position = p; m_points.push_back(ip); m_pointsLife.push_back(m_maxLife); }else { //方案1:线性插值 _XSmoothPoint * last = m_points[m_points.size() - 1]; //获取最后一个点 float lastLife = m_pointsLife[m_points.size() - 1]; float len = p.getLength(last->m_position); if(len <= 0.0f) return; //与最后一个点重合不需要加入新的点 int sum = len / m_insertLength; sum = XEE_Min(m_insertSum,sum); //尚未完成 float d = 1.0f / (sum + 1.0f); float per = d; for(int i = 1;i < sum + 1; ++ i) {//下面插入点 pushAPoint(lineSlerp<_XVector2>(last->m_position,p,per), lineSlerp<float>(lastLife,m_maxLife,per)); per += d; } //方案2:贝塞尔插值 (尚未实现) //更新内部数据 updateData(); } }
void XWindLine::addAPoint(const XVec2& p) //插入一个点 { if(!m_isInited) return; if(m_points.size() == 0) {//第一个点,不需要插值 XSmoothPoint *ip = XMem::createMem<XSmoothPoint>(); if(ip == NULL) return; ip->m_length = 0.0f; ip->m_percentage = 0.0f; ip->m_position = p; m_points.push_back(ip); m_pointsLife.push_back(m_maxLife); }else { //方案1:线性插值 XSmoothPoint * last = *(m_points.end() - 1); //获取最后一个点 assert(m_points.size() == m_pointsLife.size()); //float lastLife = m_pointsLife[(int)(m_points.size()) - 1]; float lastLife = *(m_pointsLife.end() - 1); float len = p.getLength(last->m_position); if(len <= 0.0f) return; //与最后一个点重合不需要加入新的点 int sum = len / m_insertLength; sum = (std::min)(m_insertSum,sum); //尚未完成 float d = 1.0f / (sum + 1.0f); float per = d; for(int i = 1;i < sum + 1; ++ i) {//下面插入点 pushAPoint(XMath::lineSlerp<XVec2>(last->m_position,p,per), XMath::lineSlerp<float>(lastLife,m_maxLife,per)); per += d; } //方案2:贝塞尔插值 (尚未实现) //更新内部数据 updateData(); } }