void MotionStreak::update(float delta) { if (!_startingPositionInitialized) { return; } delta *= _fadeDelta; unsigned int newIdx, newIdx2, i, i2; unsigned int mov = 0; // Update current points for(i = 0; i<_nuPoints; i++) { _pointState[i]-=delta; if(_pointState[i] <= 0) mov++; else { newIdx = i-mov; if(mov>0) { // Move data _pointState[newIdx] = _pointState[i]; // Move point _pointVertexes[newIdx] = _pointVertexes[i]; // Move vertices i2 = i*2; newIdx2 = newIdx*2; _vertices[newIdx2] = _vertices[i2]; _vertices[newIdx2+1] = _vertices[i2+1]; // Move color i2 *= 4; newIdx2 *= 4; _colorPointer[newIdx2+0] = _colorPointer[i2+0]; _colorPointer[newIdx2+1] = _colorPointer[i2+1]; _colorPointer[newIdx2+2] = _colorPointer[i2+2]; _colorPointer[newIdx2+4] = _colorPointer[i2+4]; _colorPointer[newIdx2+5] = _colorPointer[i2+5]; _colorPointer[newIdx2+6] = _colorPointer[i2+6]; } else newIdx2 = newIdx*8; const GLubyte op = (GLubyte)(_pointState[newIdx] * 255.0f); _colorPointer[newIdx2+3] = op; _colorPointer[newIdx2+7] = op; } } _nuPoints-=mov; // Append new point bool appendNewPoint = true; if(_nuPoints >= _maxPoints) { appendNewPoint = false; } else if(_nuPoints>0) { bool a1 = _pointVertexes[_nuPoints-1].getDistanceSq(_positionR) < _minSeg; bool a2 = (_nuPoints == 1) ? false : (_pointVertexes[_nuPoints-2].getDistanceSq(_positionR)< (_minSeg * 2.0f)); if(a1 || a2) { appendNewPoint = false; } } if(appendNewPoint) { _pointVertexes[_nuPoints] = _positionR; _pointState[_nuPoints] = 1.0f; // Color assignment const unsigned int offset = _nuPoints*8; *((Color3B*)(_colorPointer + offset)) = _displayedColor; *((Color3B*)(_colorPointer + offset+4)) = _displayedColor; // Opacity _colorPointer[offset+3] = 255; _colorPointer[offset+7] = 255; // Generate polygon if(_nuPoints > 0 && _fastMode ) { if(_nuPoints > 1) { ccVertexLineToPolygon(_pointVertexes, _stroke, _vertices, _nuPoints, 1); } else { ccVertexLineToPolygon(_pointVertexes, _stroke, _vertices, 0, 2); } } _nuPoints ++; } if( ! _fastMode ) { ccVertexLineToPolygon(_pointVertexes, _stroke, _vertices, 0, _nuPoints); } // Updated Tex Coords only if they are different than previous step if( _nuPoints && _previousNuPoints != _nuPoints ) { float texDelta = 1.0f / _nuPoints; for( i=0; i < _nuPoints; i++ ) { _texCoords[i*2] = Tex2F(0, texDelta*i); _texCoords[i*2+1] = Tex2F(1, texDelta*i); } _previousNuPoints = _nuPoints; } }
void CCMotionStreak::update(float delta) { if (!m_bStartingPositionInitialized) { return; } delta *= m_fFadeDelta; unsigned int newIdx, newIdx2, i, i2; unsigned int mov = 0; // Update current points for(i = 0; i<m_uNuPoints; i++) { m_pPointState[i]-=delta; if(m_pPointState[i] <= 0) mov++; else { newIdx = i-mov; if(mov>0) { // Move data m_pPointState[newIdx] = m_pPointState[i]; // Move point m_pPointVertexes[newIdx] = m_pPointVertexes[i]; // Move vertices i2 = i*2; newIdx2 = newIdx*2; m_pVertices[newIdx2] = m_pVertices[i2]; m_pVertices[newIdx2+1] = m_pVertices[i2+1]; // Move color i2 *= 4; newIdx2 *= 4; m_pColorPointer[newIdx2+0] = m_pColorPointer[i2+0]; m_pColorPointer[newIdx2+1] = m_pColorPointer[i2+1]; m_pColorPointer[newIdx2+2] = m_pColorPointer[i2+2]; m_pColorPointer[newIdx2+4] = m_pColorPointer[i2+4]; m_pColorPointer[newIdx2+5] = m_pColorPointer[i2+5]; m_pColorPointer[newIdx2+6] = m_pColorPointer[i2+6]; }else newIdx2 = newIdx*8; const GLubyte op = (GLubyte)(m_pPointState[newIdx] * 255.0f); m_pColorPointer[newIdx2+3] = op; m_pColorPointer[newIdx2+7] = op; } } m_uNuPoints-=mov; // Append new point bool appendNewPoint = true; if(m_uNuPoints >= m_uMaxPoints) { appendNewPoint = false; } else if(m_uNuPoints>0) { bool a1 = ccpDistanceSQ(m_pPointVertexes[m_uNuPoints-1], m_tPositionR) < m_fMinSeg; bool a2 = (m_uNuPoints == 1) ? false : (ccpDistanceSQ(m_pPointVertexes[m_uNuPoints-2], m_tPositionR) < (m_fMinSeg * 2.0f)); if(a1 || a2) { appendNewPoint = false; } } if(appendNewPoint) { m_pPointVertexes[m_uNuPoints] = m_tPositionR; m_pPointState[m_uNuPoints] = 1.0f; // Color assignment const unsigned int offset = m_uNuPoints*8; *((ccColor3B*)(m_pColorPointer + offset)) = _displayedColor; *((ccColor3B*)(m_pColorPointer + offset+4)) = _displayedColor; // Opacity m_pColorPointer[offset+3] = 255; m_pColorPointer[offset+7] = 255; // Generate polygon if(m_uNuPoints > 0 && m_bFastMode ) { if(m_uNuPoints > 1) { ccVertexLineToPolygon(m_pPointVertexes, m_fStroke, m_pVertices, m_uNuPoints, 1); } else { ccVertexLineToPolygon(m_pPointVertexes, m_fStroke, m_pVertices, 0, 2); } } m_uNuPoints ++; } if( ! m_bFastMode ) { ccVertexLineToPolygon(m_pPointVertexes, m_fStroke, m_pVertices, 0, m_uNuPoints); } // Updated Tex Coords only if they are different than previous step if( m_uNuPoints && m_uPreviousNuPoints != m_uNuPoints ) { float texDelta = 1.0f / m_uNuPoints; for( i=0; i < m_uNuPoints; i++ ) { m_pTexCoords[i*2] = tex2(0, texDelta*i); m_pTexCoords[i*2+1] = tex2(1, texDelta*i); } m_uPreviousNuPoints = m_uNuPoints; } }