Example #1
0
        public static void LineToPolygon(CCPoint[] points, float stroke, ccVertex2F[] vertices, int offset, int nuPoints)
        {
            int     num;
            CCPoint cCPoint;

            nuPoints = nuPoints + offset;
            if (nuPoints <= 1)
            {
                return;
            }
            stroke = stroke * 0.5f;
            int num1 = nuPoints - 1;

            for (int i = offset; i < nuPoints; i++)
            {
                num = i * 2;
                CCPoint cCPoint1 = points[i];
                if (i == 0)
                {
                    cCPoint = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(cCPoint1, points[i + 1])));
                }
                else if (i != num1)
                {
                    CCPoint cCPoint2 = points[i + 1];
                    CCPoint cCPoint3 = points[i - 1];
                    CCPoint cCPoint4 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(cCPoint2, cCPoint1));
                    CCPoint cCPoint5 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(cCPoint3, cCPoint1));
                    float   single   = (float)Math.Acos((double)CCPointExtension.ccpDot(cCPoint4, cCPoint5));
                    if (single >= ccMacros.CC_DEGREES_TO_RADIANS(70f))
                    {
                        cCPoint = (single >= ccMacros.CC_DEGREES_TO_RADIANS(170f) ? CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(cCPoint2, cCPoint3))) : CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(cCPoint4, cCPoint5)));
                    }
                    else
                    {
                        cCPoint = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(cCPoint4, cCPoint5)));
                    }
                }
                else
                {
                    cCPoint = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(points[i - 1], cCPoint1)));
                }
                cCPoint           = CCPointExtension.ccpMult(cCPoint, stroke);
                vertices[num]     = new ccVertex2F(cCPoint1.x + cCPoint.x, cCPoint1.y + cCPoint.y);
                vertices[num + 1] = new ccVertex2F(cCPoint1.x - cCPoint.x, cCPoint1.y - cCPoint.y);
            }
            offset = (offset == 0 ? 0 : offset - 1);
            for (int j = offset; j < num1; j++)
            {
                num = j * 2;
                int        num2         = num + 2;
                ccVertex2F _ccVertex2F  = vertices[num];
                ccVertex2F _ccVertex2F1 = vertices[num + 1];
                ccVertex2F _ccVertex2F2 = vertices[num2];
                ccVertex2F _ccVertex2F3 = vertices[num2 + 1];
                float      single1      = 0f;
                bool       flag         = !CCVertex.LineIntersect(_ccVertex2F.x, _ccVertex2F.y, _ccVertex2F3.x, _ccVertex2F3.y, _ccVertex2F1.x, _ccVertex2F1.y, _ccVertex2F2.x, _ccVertex2F2.y, out single1);
                if (!flag && (single1 < 0f || single1 > 1f))
                {
                    flag = true;
                }
                if (flag)
                {
                    vertices[num2]     = _ccVertex2F3;
                    vertices[num2 + 1] = _ccVertex2F2;
                }
            }
        }
Example #2
0
        public override void update(float delta)
        {
            if (!m_bStartingPositionInitialized)
            {
                return;
            }

            if (m_pVerticesPCT == null)
            {
                m_pVerticesPCT = new VertexPositionColorTexture[((m_uNuPoints + 1) * 2)];
            }
            if (m_uNuPoints * 2 > m_pVerticesPCT.Length)
            {
                VertexPositionColorTexture[] tmp = new VertexPositionColorTexture[((m_uNuPoints + 1) * 2)];
                m_pVerticesPCT.CopyTo(tmp, 0);
                m_pVerticesPCT = tmp;
            }
            delta *= m_fFadeDelta;

            int newIdx, newIdx2, i, i2;
            int mov = 0;

            // Update current points
            for (i = 0; i < m_uNuPoints; i++)
            {
                if (m_pVerticesPCT[i] == null)
                {
                    m_pVerticesPCT[i] = new VertexPositionColorTexture(m_pVertices[i].ToVector3(), m_pColor[i].XNAColor, m_pTexCoords[i].ToVector2());
                }
                if (m_pVerticesPCT[i * 2] == null)
                {
                    m_pVerticesPCT[i * 2] = new VertexPositionColorTexture(m_pVerticesPCT[i].Position, m_pVerticesPCT[i].Color, m_pVerticesPCT[i].TextureCoordinate);
                }
                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] = new CCPoint(m_pPointVertexes[i]);

                        // Move vertices
                        i2      = i * 2;
                        newIdx2 = newIdx * 2;
                        m_pVertices[newIdx2]     = new ccVertex2F(m_pVertices[i2]);
                        m_pVertices[newIdx2 + 1] = new ccVertex2F(m_pVertices[i2 + 1]);
                        // Move color
                        m_pColor[newIdx2]     = new ccColor4B(m_pColor[i2]);
                        m_pColor[newIdx2 + 1] = new ccColor4B(m_pColor[i2 + 1]);
                        // Move the GL vertex data
                        m_pVerticesPCT[newIdx2]     = m_pVerticesPCT[i2];
                        m_pVerticesPCT[newIdx2 + 1] = m_pVerticesPCT[i2 + 1];
                    }
                    else
                    {
                        newIdx2 = newIdx * 2;
                    }
                    byte op = (byte)(m_pPointState[newIdx] * 255.0f);
                    m_pColor[newIdx2].a     = op;
                    m_pColor[newIdx2 + 1].a = op;
                    VertexPositionColorTexture vpc;
                    if (m_pVertices[newIdx2] != null)
                    {
                        vpc = new VertexPositionColorTexture(m_pVertices[newIdx2].ToVector3(), m_pColor[newIdx2].XNAColor, m_pTexCoords[newIdx2].ToVector2());
                        m_pVerticesPCT[newIdx2] = vpc;
                    }
                    if (m_pVertices[newIdx2 + 1] != null)
                    {
                        vpc = new VertexPositionColorTexture(m_pVertices[newIdx2 + 1].ToVector3(), m_pColor[newIdx2 + 1].XNAColor, m_pTexCoords[newIdx2 + 1].ToVector2());
                        m_pVerticesPCT[newIdx2 + 1] = vpc;
                    }
                }
            }
            m_uNuPoints -= mov;

            // Append new point
            bool appendNewPoint = true;

            if (m_uNuPoints >= m_uMaxPoints)
            {
                appendNewPoint = false;
            }

            else if (m_uNuPoints > 0)
            {
                bool a1 = (m_pPointVertexes[m_uNuPoints - 1].DistanceSQ(m_tPositionR) < m_fMinSeg);
                bool a2 = (m_uNuPoints == 1) ? false : (m_pPointVertexes[m_uNuPoints - 2].DistanceSQ(m_tPositionR) < (m_fMinSeg * 2.0f));
                if (a1 || a2)
                {
                    appendNewPoint = false;
                }
            }

            if (appendNewPoint)
            {
                m_pPointVertexes[m_uNuPoints] = new CCPoint(m_tPositionR);
                m_pPointState[m_uNuPoints]    = 1.0f;

                // Color asignment
                int offset = m_uNuPoints * 2;
                m_pColor[offset]     = new ccColor4B(m_tColor);
                m_pColor[offset + 1] = new ccColor4B(m_tColor);

                // Opacity
                m_pColor[offset].a     = 255;
                m_pColor[offset + 1].a = 255;

                // Generate polygon
                if (m_uNuPoints > 0 && m_bFastMode)
                {
                    if (m_uNuPoints > 1)
                    {
                        CCVertex.LineToPolygon(m_pPointVertexes, m_fStroke, m_pVertices, m_uNuPoints, 1);
                    }
                    else
                    {
                        CCVertex.LineToPolygon(m_pPointVertexes, m_fStroke, m_pVertices, 0, 2);
                    }
                }

                m_uNuPoints++;
            }

            if (!m_bFastMode)
            {
                CCVertex.LineToPolygon(m_pPointVertexes, m_fStroke, m_pVertices, 0, m_uNuPoints);
            }

            // Updated Tex Coords only if they are different than previous step
            if (m_uPreviousNuPoints != m_uNuPoints)
            {
                if (m_uNuPoints > m_uPreviousNuPoints)
                {
                    int count = (m_uNuPoints + 1) * 2;
                    if (count < m_pVerticesPCT.Length)
                    {
                        count = m_pVerticesPCT.Length;
                    }
                    VertexPositionColorTexture[] tmp = new VertexPositionColorTexture[count];
                    m_pVerticesPCT.CopyTo(tmp, 0);
                    m_pVerticesPCT = tmp;
                }
                float texDelta = 1.0f / m_uNuPoints;
                for (i = 0; i < m_uNuPoints; i++)
                {
                    m_pTexCoords[i * 2]     = new ccTex2F(0, texDelta * i);
                    m_pTexCoords[i * 2 + 1] = new ccTex2F(1, texDelta * i);
                    VertexPositionColorTexture vpc;
                    if (m_pVertices[i * 2] != null)
                    {
                        vpc = new VertexPositionColorTexture(m_pVertices[i * 2].ToVector3(), m_pColor[i * 2].XNAColor, m_pTexCoords[i * 2].ToVector2());
                        m_pVerticesPCT[i * 2] = vpc;
                    }
                    if (m_pVertices[i * 2 + 1] != null)
                    {
                        vpc = new VertexPositionColorTexture(m_pVertices[i * 2 + 1].ToVector3(), m_pColor[i * 2 + 1].XNAColor, m_pTexCoords[i * 2 + 1].ToVector2());
                        m_pVerticesPCT[i * 2 + 1] = vpc;
                    }
                }

                m_uPreviousNuPoints = m_uNuPoints;
            }
        }
Example #3
0
        public override void update(float delta)
        {
            int num;
            int i;
            VertexPositionColorTexture vertexPositionColorTexture;
            VertexPositionColorTexture vertexPositionColorTexture1;

            if (!this.m_bStartingPositionInitialized)
            {
                return;
            }
            if (this.m_pVerticesPCT == null)
            {
                this.m_pVerticesPCT = new VertexPositionColorTexture[(this.m_uNuPoints + 1) * 2];
            }
            if (this.m_uNuPoints * 2 > (int)this.m_pVerticesPCT.Length)
            {
                VertexPositionColorTexture[] vertexPositionColorTextureArray = new VertexPositionColorTexture[(this.m_uNuPoints + 1) * 2];
                this.m_pVerticesPCT.CopyTo(vertexPositionColorTextureArray, 0);
                this.m_pVerticesPCT = vertexPositionColorTextureArray;
            }
            delta = delta * this.m_fFadeDelta;
            int num1 = 0;

            for (i = 0; i < this.m_uNuPoints; i++)
            {
                VertexPositionColorTexture mPVerticesPCT  = this.m_pVerticesPCT[i];
                VertexPositionColorTexture mPVerticesPCT1 = this.m_pVerticesPCT[i * 2];
                this.m_pPointState[i] = this.m_pPointState[i] - delta;
                if (this.m_pPointState[i] > 0f)
                {
                    int num2 = i - num1;
                    if (num1 <= 0)
                    {
                        num = num2 * 2;
                    }
                    else
                    {
                        this.m_pPointState[num2]    = this.m_pPointState[i];
                        this.m_pPointVertexes[num2] = new CCPoint(this.m_pPointVertexes[i]);
                        int num3 = i * 2;
                        num = num2 * 2;
                        this.m_pVertices[num]        = new ccVertex2F(this.m_pVertices[num3]);
                        this.m_pVertices[num + 1]    = new ccVertex2F(this.m_pVertices[num3 + 1]);
                        this.m_pColor[num]           = new ccColor4B(this.m_pColor[num3]);
                        this.m_pColor[num + 1]       = new ccColor4B(this.m_pColor[num3 + 1]);
                        this.m_pVerticesPCT[num]     = this.m_pVerticesPCT[num3];
                        this.m_pVerticesPCT[num + 1] = this.m_pVerticesPCT[num3 + 1];
                    }
                    byte mPPointState = (byte)(this.m_pPointState[num2] * 255f);
                    this.m_pColor[num].a     = mPPointState;
                    this.m_pColor[num + 1].a = mPPointState;
                    if (this.m_pVertices[num] != null)
                    {
                        vertexPositionColorTexture = new VertexPositionColorTexture(this.m_pVertices[num].ToVector3(), this.m_pColor[num].XNAColor, this.m_pTexCoords[num].ToVector2());
                        this.m_pVerticesPCT[num]   = vertexPositionColorTexture;
                    }
                    if (this.m_pVertices[num + 1] != null)
                    {
                        vertexPositionColorTexture   = new VertexPositionColorTexture(this.m_pVertices[num + 1].ToVector3(), this.m_pColor[num + 1].XNAColor, this.m_pTexCoords[num + 1].ToVector2());
                        this.m_pVerticesPCT[num + 1] = vertexPositionColorTexture;
                    }
                }
                else
                {
                    num1++;
                }
            }
            CCMotionStreak mUNuPoints = this;

            mUNuPoints.m_uNuPoints = mUNuPoints.m_uNuPoints - num1;
            bool flag = true;

            if (this.m_uNuPoints >= this.m_uMaxPoints)
            {
                flag = false;
            }
            else if (this.m_uNuPoints > 0)
            {
                bool flag1 = this.m_pPointVertexes[this.m_uNuPoints - 1].DistanceSQ(this.m_tPositionR) < this.m_fMinSeg;
                if (flag1 || (this.m_uNuPoints == 1 ? false : this.m_pPointVertexes[this.m_uNuPoints - 2].DistanceSQ(this.m_tPositionR) < this.m_fMinSeg * 2f))
                {
                    flag = false;
                }
            }
            if (flag)
            {
                this.m_pPointVertexes[this.m_uNuPoints] = new CCPoint(this.m_tPositionR);
                this.m_pPointState[this.m_uNuPoints]    = 1f;
                int mUNuPoints1 = this.m_uNuPoints * 2;
                this.m_pColor[mUNuPoints1]       = new ccColor4B(this.m_tColor);
                this.m_pColor[mUNuPoints1 + 1]   = new ccColor4B(this.m_tColor);
                this.m_pColor[mUNuPoints1].a     = 255;
                this.m_pColor[mUNuPoints1 + 1].a = 255;
                if (this.m_uNuPoints > 0 && this.m_bFastMode)
                {
                    if (this.m_uNuPoints <= 1)
                    {
                        CCVertex.LineToPolygon(this.m_pPointVertexes, this.m_fStroke, this.m_pVertices, 0, 2);
                    }
                    else
                    {
                        CCVertex.LineToPolygon(this.m_pPointVertexes, this.m_fStroke, this.m_pVertices, this.m_uNuPoints, 1);
                    }
                }
                CCMotionStreak cCMotionStreak = this;
                cCMotionStreak.m_uNuPoints = cCMotionStreak.m_uNuPoints + 1;
            }
            if (!this.m_bFastMode)
            {
                CCVertex.LineToPolygon(this.m_pPointVertexes, this.m_fStroke, this.m_pVertices, 0, this.m_uNuPoints);
            }
            if (this.m_uPreviousNuPoints != this.m_uNuPoints)
            {
                if (this.m_uNuPoints > this.m_uPreviousNuPoints)
                {
                    int length = (this.m_uNuPoints + 1) * 2;
                    if (length < (int)this.m_pVerticesPCT.Length)
                    {
                        length = (int)this.m_pVerticesPCT.Length;
                    }
                    VertexPositionColorTexture[] vertexPositionColorTextureArray1 = new VertexPositionColorTexture[length];
                    this.m_pVerticesPCT.CopyTo(vertexPositionColorTextureArray1, 0);
                    this.m_pVerticesPCT = vertexPositionColorTextureArray1;
                }
                float single = 1f / (float)this.m_uNuPoints;
                for (i = 0; i < this.m_uNuPoints; i++)
                {
                    this.m_pTexCoords[i * 2]     = new ccTex2F(0f, single * (float)i);
                    this.m_pTexCoords[i * 2 + 1] = new ccTex2F(1f, single * (float)i);
                    if (this.m_pVertices[i * 2] != null)
                    {
                        vertexPositionColorTexture1 = new VertexPositionColorTexture(this.m_pVertices[i * 2].ToVector3(), this.m_pColor[i * 2].XNAColor, this.m_pTexCoords[i * 2].ToVector2());
                        this.m_pVerticesPCT[i * 2]  = vertexPositionColorTexture1;
                    }
                    if (this.m_pVertices[i * 2 + 1] != null)
                    {
                        vertexPositionColorTexture1    = new VertexPositionColorTexture(this.m_pVertices[i * 2 + 1].ToVector3(), this.m_pColor[i * 2 + 1].XNAColor, this.m_pTexCoords[i * 2 + 1].ToVector2());
                        this.m_pVerticesPCT[i * 2 + 1] = vertexPositionColorTexture1;
                    }
                }
                this.m_uPreviousNuPoints = this.m_uNuPoints;
            }
        }