Esempio n. 1
0
        /// <summary>
        ///  initializes a CCLayer with color, width and height in Points
        /// </summary>
        public virtual bool initWithColorWidthHeight(ccColor4B color, float width, float height)
        {
            // default blend function
            m_tBlendFunc.src = 1;
            m_tBlendFunc.dst = 0x0303;

            m_tColor.r = color.r;
            m_tColor.g = color.g;
            m_tColor.b = color.b;
            m_cOpacity = color.a;
            for (int i = 0; i < m_pSquareVertices.Length; i++)
            {
                m_pSquareVertices[i]   = new ccVertex2F();
                m_pSquareVertices[i].x = 0.0f;
                m_pSquareVertices[i].y = 0.0f;

                vertices[i] = new VertexPositionColor();
            }

            indexes[0] = 0;
            indexes[0] = 1;
            indexes[0] = 2;
            indexes[0] = 2;
            indexes[0] = 1;
            indexes[0] = 3;

            this.updateColor();
            this.contentSize = new CCSize(width, height);
            return(true);
        }
Esempio n. 2
0
 public ccQuad2()
 {
     this.tl = new ccVertex2F();
     this.tr = new ccVertex2F();
     this.bl = new ccVertex2F();
     this.br = new ccVertex2F();
 }
Esempio n. 3
0
        /// <summary>
        /// the vertex position from the texture coordinate
        /// </summary>
        protected ccVertex2F vertexFromTexCoord(CCPoint texCoord)
        {
            CCPoint    tmp;
            ccVertex2F ret = new ccVertex2F();

            CCTexture2D pTexture = m_pSprite.Texture;

            if (pTexture != null)
            {
                float   fXMax = Math.Max(m_pSprite.quad.br.texCoords.u, m_pSprite.quad.bl.texCoords.u);
                float   fXMin = Math.Min(m_pSprite.quad.br.texCoords.u, m_pSprite.quad.bl.texCoords.u);
                float   fYMax = Math.Max(m_pSprite.quad.tl.texCoords.v, m_pSprite.quad.bl.texCoords.v);
                float   fYMin = Math.Min(m_pSprite.quad.tl.texCoords.v, m_pSprite.quad.bl.texCoords.v);
                CCPoint tMax  = new CCPoint(fXMax, fYMax);
                CCPoint tMin  = new CCPoint(fXMin, fYMin);

                CCSize texSize = new CCSize(m_pSprite.quad.br.vertices.x - m_pSprite.quad.bl.vertices.x,
                                            m_pSprite.quad.tl.vertices.y - m_pSprite.quad.bl.vertices.y);
                tmp = new CCPoint(texSize.width * (texCoord.x - tMin.x) / (tMax.x - tMin.x),
                                  texSize.height * (1 - (texCoord.y - tMin.y) / (tMax.y - tMin.y)));
            }
            else
            {
                tmp = new CCPoint(0, 0);
            }

            ret.x = tmp.x;
            ret.y = tmp.y;
            return(ret);
        }
Esempio n. 4
0
 public ccQuad2()
 {
     tl = new ccVertex2F();
     tr = new ccVertex2F();
     bl = new ccVertex2F();
     br = new ccVertex2F();
 }
Esempio n. 5
0
        protected ccVertex2F vertexFromTexCoord(CCPoint texCoord)
        {
            CCPoint    cCPoint;
            ccVertex2F _ccVertex2F = new ccVertex2F();

            if (this.m_pSprite.Texture == null)
            {
                cCPoint = new CCPoint(0f, 0f);
            }
            else
            {
                float   single   = Math.Max(this.m_pSprite.quad.br.texCoords.u, this.m_pSprite.quad.bl.texCoords.u);
                float   single1  = Math.Min(this.m_pSprite.quad.br.texCoords.u, this.m_pSprite.quad.bl.texCoords.u);
                float   single2  = Math.Max(this.m_pSprite.quad.tl.texCoords.v, this.m_pSprite.quad.bl.texCoords.v);
                float   single3  = Math.Min(this.m_pSprite.quad.tl.texCoords.v, this.m_pSprite.quad.bl.texCoords.v);
                CCPoint cCPoint1 = new CCPoint(single, single2);
                CCPoint cCPoint2 = new CCPoint(single1, single3);
                CCSize  cCSize   = new CCSize(this.m_pSprite.quad.br.vertices.x - this.m_pSprite.quad.bl.vertices.x, this.m_pSprite.quad.tl.vertices.y - this.m_pSprite.quad.bl.vertices.y);
                cCPoint = new CCPoint(cCSize.width * (texCoord.x - cCPoint2.x) / (cCPoint1.x - cCPoint2.x), cCSize.height * (1f - (texCoord.y - cCPoint2.y) / (cCPoint1.y - cCPoint2.y)));
            }
            _ccVertex2F.x = cCPoint.x;
            _ccVertex2F.y = cCPoint.y;
            return(_ccVertex2F);
        }
Esempio n. 6
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;
            }
        }
Esempio n. 7
0
        public static ccVertex2F vertex2(float x, float y)
        {
            ccVertex2F c = new ccVertex2F(x, y);

            return(c);
        }
Esempio n. 8
0
 public ccV2F_C4F_T2F()
 {
     vertices  = new ccVertex2F();
     colors    = new ccColor4F();
     texCoords = new ccTex2F();
 }
Esempio n. 9
0
 public ccPointSprite()
 {
     pos   = new ccVertex2F();
     color = new ccColor4B();
     size  = 0.0f;
 }
Esempio n. 10
0
 public ccV2F_C4F_T2F()
 {
     this.vertices  = new ccVertex2F();
     this.colors    = new ccColor4F();
     this.texCoords = new ccTex2F();
 }
Esempio n. 11
0
 public ccVertex2F(ccVertex2F copy)
 {
     this.x = copy.x;
     this.y = copy.y;
 }
Esempio n. 12
0
 public static ccVertex2F vertex2(float x, float y)
 {
     ccVertex2F c = new ccVertex2F(x, y);
     return c;
 }
Esempio n. 13
0
        /// <summary>
        /// the vertex position from the texture coordinate
        /// </summary>
        protected ccVertex2F vertexFromTexCoord(CCPoint texCoord)
        {
            CCPoint tmp;
            ccVertex2F ret = new ccVertex2F();

            CCTexture2D pTexture = m_pSprite.Texture;
            if (pTexture != null)
            {
                float fXMax = Math.Max(m_pSprite.quad.br.texCoords.u, m_pSprite.quad.bl.texCoords.u);
                float fXMin = Math.Min(m_pSprite.quad.br.texCoords.u, m_pSprite.quad.bl.texCoords.u);
                float fYMax = Math.Max(m_pSprite.quad.tl.texCoords.v, m_pSprite.quad.bl.texCoords.v);
                float fYMin = Math.Min(m_pSprite.quad.tl.texCoords.v, m_pSprite.quad.bl.texCoords.v);
                CCPoint tMax = new CCPoint(fXMax, fYMax);
                CCPoint tMin = new CCPoint(fXMin, fYMin);

                CCSize texSize = new CCSize(m_pSprite.quad.br.vertices.x - m_pSprite.quad.bl.vertices.x,
                                            m_pSprite.quad.tl.vertices.y - m_pSprite.quad.bl.vertices.y);
                tmp = new CCPoint(texSize.width * (texCoord.x - tMin.x) / (tMax.x - tMin.x),
                            texSize.height * (1 - (texCoord.y - tMin.y) / (tMax.y - tMin.y)));
            }
            else
            {
                tmp = new CCPoint(0, 0);
            }

            ret.x = tmp.x;
            ret.y = tmp.y;
            return ret;
        }
Esempio n. 14
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;
            }
        }
Esempio n. 15
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;
                }
            }
        }
Esempio n. 16
0
        public static void LineToPolygon(CCPoint[] points, float stroke, ccVertex2F[] vertices, int offset, int nuPoints)
        {
            nuPoints += offset;
            if (nuPoints <= 1)
            {
                return;
            }

            stroke *= 0.5f;

            int idx;
            int nuPointsMinus = nuPoints - 1;

            for (int i = offset; i < nuPoints; i++)
            {
                idx = i * 2;
                CCPoint p1 = points[i];
                CCPoint perpVector;

                if (i == 0)
                {
                    perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p1, points[i + 1])));
                }
                else if (i == nuPointsMinus)
                {
                    perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(points[i - 1], p1)));
                }
                else
                {
                    CCPoint p2 = points[i + 1];
                    CCPoint p0 = points[i - 1];

                    CCPoint p2p1 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p2, p1));
                    CCPoint p0p1 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p0, p1));

                    // Calculate angle between vectors
                    float angle = (float)Math.Acos(CCPointExtension.ccpDot(p2p1, p0p1));

                    if (angle < ccMacros.CC_DEGREES_TO_RADIANS(70))
                    {
                        perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(p2p1, p0p1)));
                    }
                    else if (angle < ccMacros.CC_DEGREES_TO_RADIANS(170))
                    {
                        perpVector = CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(p2p1, p0p1));
                    }
                    else
                    {
                        perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p2, p0)));
                    }
                }
                perpVector = CCPointExtension.ccpMult(perpVector, stroke);

                vertices[idx]     = new ccVertex2F(p1.x + perpVector.x, p1.y + perpVector.y);
                vertices[idx + 1] = new ccVertex2F(p1.x - perpVector.x, p1.y - perpVector.y);
            }

            // Validate vertexes
            offset = (offset == 0) ? 0 : (offset - 1);
            for (int i = offset; i < nuPointsMinus; i++)
            {
                idx = i * 2;
                int idx1 = idx + 2;

                ccVertex2F p1 = vertices[idx];
                ccVertex2F p2 = vertices[idx + 1];
                ccVertex2F p3 = vertices[idx1];
                ccVertex2F p4 = vertices[idx1 + 1];

                float s = 0f;
                //BOOL fixVertex = !ccpLineIntersect(ccp(p1.x, p1.y), ccp(p4.x, p4.y), ccp(p2.x, p2.y), ccp(p3.x, p3.y), &s, &t);
                bool fixVertex = !LineIntersect(p1.x, p1.y, p4.x, p4.y, p2.x, p2.y, p3.x, p3.y, out s);
                if (!fixVertex)
                {
                    if (s < 0.0f || s > 1.0f)
                    {
                        fixVertex = true;
                    }
                }

                if (fixVertex)
                {
                    vertices[idx1]     = p4;
                    vertices[idx1 + 1] = p3;
                }
            }
        }
Esempio n. 17
0
        public float size; // 4 bytes

        #endregion Fields

        #region Constructors

        public ccPointSprite()
        {
            pos = new ccVertex2F();
            color = new ccColor4B();
            size = 0.0f;
        }
Esempio n. 18
0
 public ccVertex2F(ccVertex2F copy)
 {
     x = copy.x;
     y = copy.y;
 }
Esempio n. 19
0
 public ccQuad2()
 {
     tl = new ccVertex2F();
     tr = new ccVertex2F();
     bl = new ccVertex2F();
     br = new ccVertex2F();
 }
Esempio n. 20
0
 public ccPointSprite()
 {
     this.pos   = new ccVertex2F();
     this.color = new ccColor4B();
     this.size  = 0f;
 }
Esempio n. 21
0
 public ccV2F_C4F_T2F()
 {
     vertices = new ccVertex2F();
     colors = new ccColor4F();
     texCoords = new ccTex2F();
 }
Esempio n. 22
0
        /// <summary>
        ///  initializes a CCLayer with color, width and height in Points
        /// </summary>
        public virtual bool initWithColorWidthHeight(ccColor4B color, float width, float height)
        {
            // default blend function
            m_tBlendFunc.src = 1;
            m_tBlendFunc.dst = 0x0303;

            m_tColor.r = color.r;
            m_tColor.g = color.g;
            m_tColor.b = color.b;
            m_cOpacity = color.a;
            for (int i = 0; i < m_pSquareVertices.Length; i++)
            {
                m_pSquareVertices[i] = new ccVertex2F();
                m_pSquareVertices[i].x = 0.0f;
                m_pSquareVertices[i].y = 0.0f;

                vertices[i] = new VertexPositionColor();
            }

            indexes[0] = 0;
            indexes[0] = 1;
            indexes[0] = 2;
            indexes[0] = 2;
            indexes[0] = 1;
            indexes[0] = 3;

            this.updateColor();
            this.contentSize = new CCSize(width, height);
            return true;
        }
Esempio n. 23
0
        public static void LineToPolygon(CCPoint[] points, float stroke, ccVertex2F[] vertices, int offset, int nuPoints)
        {
            nuPoints += offset;
            if (nuPoints <= 1) return;

            stroke *= 0.5f;

            int idx;
            int nuPointsMinus = nuPoints - 1;

            for (int i = offset; i < nuPoints; i++)
            {
                idx = i * 2;
                CCPoint p1 = points[i];
                CCPoint perpVector;

                if (i == 0)
                    perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p1, points[i + 1])));
                else if (i == nuPointsMinus)
                    perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(points[i - 1], p1)));
                else
                {
                    CCPoint p2 = points[i + 1];
                    CCPoint p0 = points[i - 1];

                    CCPoint p2p1 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p2, p1));
                    CCPoint p0p1 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p0, p1));

                    // Calculate angle between vectors
                    float angle = (float)Math.Acos(CCPointExtension.ccpDot(p2p1, p0p1));

                    if (angle < ccMacros.CC_DEGREES_TO_RADIANS(70))
                        perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(p2p1, p0p1)));
                    else if (angle < ccMacros.CC_DEGREES_TO_RADIANS(170))
                        perpVector = CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(p2p1, p0p1));
                    else
                        perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p2, p0)));
                }
                perpVector = CCPointExtension.ccpMult(perpVector, stroke);

                vertices[idx] = new ccVertex2F(p1.x + perpVector.x, p1.y + perpVector.y);
                vertices[idx + 1] = new ccVertex2F(p1.x - perpVector.x, p1.y - perpVector.y);

            }

            // Validate vertexes
            offset = (offset == 0) ? 0 : (offset - 1);
            for (int i = offset; i < nuPointsMinus; i++)
            {
                idx = i * 2;
                int idx1 = idx + 2;

                ccVertex2F p1 = vertices[idx];
                ccVertex2F p2 = vertices[idx + 1];
                ccVertex2F p3 = vertices[idx1];
                ccVertex2F p4 = vertices[idx1 + 1];

                float s = 0f;
                //BOOL fixVertex = !ccpLineIntersect(ccp(p1.x, p1.y), ccp(p4.x, p4.y), ccp(p2.x, p2.y), ccp(p3.x, p3.y), &s, &t);
                bool fixVertex = !LineIntersect(p1.x, p1.y, p4.x, p4.y, p2.x, p2.y, p3.x, p3.y, out s);
                if (!fixVertex)
                    if (s < 0.0f || s > 1.0f)
                        fixVertex = true;

                if (fixVertex)
                {
                    vertices[idx1] = p4;
                    vertices[idx1 + 1] = p3;
                }
            }
        }
Esempio n. 24
0
 public ccVertex2F(ccVertex2F copy)
 {
     x = copy.x;
     y = copy.y;
 }