예제 #1
0
 public ccQuad2()
 {
     tl = new ccVertex2F();
     tr = new ccVertex2F();
     bl = new ccVertex2F();
     br = new ccVertex2F();
 }
예제 #2
0
 public static ccVertex2F vertex2(float x, float y)
 {
     ccVertex2F c = new ccVertex2F(x, y);
     return c;
 }
예제 #3
0
 public ccV2F_C4F_T2F()
 {
     vertices = new ccVertex2F();
     colors = new ccColor4F();
     texCoords = new ccTex2F();
 }
예제 #4
0
 public ccPointSprite()
 {
     pos = new ccVertex2F();
     color = new ccColor4B();
     size = 0.0f;
 }
예제 #5
0
 public ccVertex2F(ccVertex2F copy)
 {
     x = copy.x;
     y = copy.y;
 }
예제 #6
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;
                }
            }
        }