コード例 #1
0
        public CCSprite()
        {
            // do not remove this
            // This sets up the atlas index correctly.  If not set correctly lot of weird sprite artifacts start showing up.
            BatchNode = null;

            IsTextureRectRotated = false;

            opacityModifyRGB = true;
            BlendFunc        = CCBlendFunc.AlphaBlend;

            //AnchorPoint = CCPoint.AnchorMiddle;

            quad = new CCV3F_C4B_T2F_Quad();
            quad.BottomLeft.Colors  = CCColor4B.White;
            quad.BottomRight.Colors = CCColor4B.White;
            quad.TopLeft.Colors     = CCColor4B.White;
            quad.TopRight.Colors    = CCColor4B.White;

            UpdateSpriteTextureQuads();
        }
コード例 #2
0
        public CCQuadCommand(float globalZOrder, CCTexture2D texture, CCBlendFunc blendType, 
            CCV3F_C4B_T2F_Quad[] quads, int quadCount, CCAffineTransform modelViewTransform, int flags = 0) 
            : base(globalZOrder, modelViewTransform, flags)
        {
            CommandType = CommandType.QUAD_COMMAND;
            Quads = quads;
            QuadCount = quadCount;
            Texture = texture;
            BlendType = blendType;

            var textureId = texture == null ? 0 : texture.TextureId;

            // +=========================================================+
            // | Material Id 24 bits                                     |
            // +============================+============================+
            // | Texture ID                 | BlendFunc (Src ^ Dest)     |
            // | 12 bits                    | 12 bits                    |
            // +============================+============================+
            MaterialId = textureId << 12 | BlendType.GetHashCode();

            System.Diagnostics.Debug.Assert(MaterialId != 0, "Material Id not set");
                
        }
コード例 #3
0
        CCTex2F TextureCoordFromAlphaPoint(CCPoint alpha)
        {
            CCTex2F ret = new CCTex2F(0.0f, 0.0f);

            if (Sprite != null)
            {
                CCV3F_C4B_T2F_Quad quad = Sprite.Quad;

                CCPoint min = new CCPoint(quad.BottomLeft.TexCoords.U, quad.BottomLeft.TexCoords.V);
                CCPoint max = new CCPoint(quad.TopRight.TexCoords.U, quad.TopRight.TexCoords.V);

                //  Fix bug #1303 so that progress timer handles sprite frame texture rotation
                if (Sprite.IsTextureRectRotated)
                {
                    float tmp = alpha.X;
                    alpha.X = alpha.Y;
                    alpha.Y = tmp;
                }

                ret = new CCTex2F(min.X * (1f - alpha.X) + max.X * alpha.X, min.Y * (1f - alpha.Y) + max.Y * alpha.Y);
            }

            return(ret);
        }
コード例 #4
0
ファイル: CCLabel.cs プロジェクト: haithemaraissia/CocosSharp
        void UpdateColorCallback(ref CCV3F_C4B_T2F_Quad[] quads)
        {

            if (TextureAtlas == null)
            {
                return;
            }

            var color4 = new CCColor4B( DisplayedColor.R, DisplayedColor.G, DisplayedColor.B, DisplayedOpacity );

            // special opacity for premultiplied textures
            if (IsColorModifiedByOpacity)
            {
                color4.R = (byte)(color4.R * DisplayedOpacity / 255.0f);
                color4.G = (byte)(color4.G * DisplayedOpacity / 255.0f);
                color4.B = (byte)(color4.B * DisplayedOpacity / 255.0f);
            }

            if (quads != null)
            {
                
                var totalQuads = quads.Length;
                CCV3F_C4B_T2F_Quad quad;

                for (int index = 0; index < totalQuads; ++index)
                {
                    quad = quads[index];
                    quad.BottomLeft.Colors = color4;
                    quad.BottomRight.Colors = color4;
                    quad.TopLeft.Colors = color4;
                    quad.TopRight.Colors = color4;
                    TextureAtlas.UpdateQuad(ref quad, index);
                }

            }
        }
コード例 #5
0
ファイル: CCSprite.cs プロジェクト: h7ing/CocosSharp
        void InitWithSpriteFrame(CCSpriteFrame spriteFrame)
        {
            opacityModifyRGB = true;
            BlendFunc = CCBlendFunc.AlphaBlend;

            AnchorPoint = new CCPoint(0.5f, 0.5f);

            quad = new CCV3F_C4B_T2F_Quad();
            quad.BottomLeft.Colors = CCColor4B.White;
            quad.BottomRight.Colors = CCColor4B.White;
            quad.TopLeft.Colors = CCColor4B.White;
            quad.TopRight.Colors = CCColor4B.White;

            SpriteFrame = spriteFrame;
        }
コード例 #6
0
ファイル: CCSprite.cs プロジェクト: h7ing/CocosSharp
        public CCSprite()
        {  
            // do not remove this
            // This sets up the atlas index correctly.  If not set correctly lot of weird sprite artifacts start showing up.
            BatchNode = null;

            IsTextureRectRotated = false;

            opacityModifyRGB = true;
            BlendFunc = CCBlendFunc.AlphaBlend;

            //AnchorPoint = CCPoint.AnchorMiddle;

            quad = new CCV3F_C4B_T2F_Quad();
            quad.BottomLeft.Colors = CCColor4B.White;
            quad.BottomRight.Colors = CCColor4B.White;
            quad.TopLeft.Colors = CCColor4B.White;
            quad.TopRight.Colors = CCColor4B.White;

            UpdateSpriteTextureQuads();        
        }
コード例 #7
0
        void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, ref CCParticleBase particle)
        {
            CCPoint newPosition;

            if(PositionType == CCPositionType.Free || PositionType == CCPositionType.Relative)
            {
                newPosition.X = particle.Position.X - (currentPosition.X - particle.StartPosition.X);
                newPosition.Y = particle.Position.Y - (currentPosition.Y - particle.StartPosition.Y);
            }
            else
            {
                newPosition = particle.Position;
            }

            // translate newPos to correct position, since matrix transform isn't performed in batchnode
            // don't update the particle with the new position information, it will interfere with the radius and tangential calculations
            if(BatchNode != null)
            {
                newPosition.X += Position.X;
                newPosition.Y += Position.Y;
            }

            CCColor4B color = new CCColor4B();

            if(OpacityModifyRGB)
            {
                color.R = (byte) (particle.Color.R * particle.Color.A * 255);
                color.G = (byte) (particle.Color.G * particle.Color.A * 255);
                color.B = (byte) (particle.Color.B * particle.Color.A * 255);
                color.A = (byte)(particle.Color.A * 255);
            }
            else
            {
                color.R = (byte)(particle.Color.R * 255);
                color.G = (byte)(particle.Color.G * 255);
                color.B = (byte)(particle.Color.B * 255);
                color.A = (byte)(particle.Color.A * 255);
            }

            quad.BottomLeft.Colors = color;
            quad.BottomRight.Colors = color;
            quad.TopLeft.Colors = color;
            quad.TopRight.Colors = color;

            // vertices
            float size_2 = particle.Size / 2;
            if (particle.Rotation != 0.0)
            {
                float x1 = -size_2;
                float y1 = -size_2;

                float x2 = size_2;
                float y2 = size_2;
                float x = newPosition.X;
                float y = newPosition.Y;

                float r = -CCMathHelper.ToRadians(particle.Rotation);
                float cr = CCMathHelper.Cos(r);
                float sr = CCMathHelper.Sin(r);
                float ax = x1 * cr - y1 * sr + x;
                float ay = x1 * sr + y1 * cr + y;
                float bx = x2 * cr - y1 * sr + x;
                float by = x2 * sr + y1 * cr + y;
                float cx = x2 * cr - y2 * sr + x;
                float cy = x2 * sr + y2 * cr + y;
                float dx = x1 * cr - y2 * sr + x;
                float dy = x1 * sr + y2 * cr + y;

                // bottom-left
                quad.BottomLeft.Vertices.X = ax;
                quad.BottomLeft.Vertices.Y = ay;

                // bottom-right vertex:
                quad.BottomRight.Vertices.X = bx;
                quad.BottomRight.Vertices.Y = by;

                // top-left vertex:
                quad.TopLeft.Vertices.X = dx;
                quad.TopLeft.Vertices.Y = dy;

                // top-right vertex:
                quad.TopRight.Vertices.X = cx;
                quad.TopRight.Vertices.Y = cy;
            }
            else
            {
                // bottom-left vertex:
                quad.BottomLeft.Vertices.X = newPosition.X - size_2;
                quad.BottomLeft.Vertices.Y = newPosition.Y - size_2;

                // bottom-right vertex:
                quad.BottomRight.Vertices.X = newPosition.X + size_2;
                quad.BottomRight.Vertices.Y = newPosition.Y - size_2;

                // top-left vertex:
                quad.TopLeft.Vertices.X = newPosition.X - size_2;
                quad.TopLeft.Vertices.Y = newPosition.Y + size_2;

                // top-right vertex:
                quad.TopRight.Vertices.X = newPosition.X + size_2;
                quad.TopRight.Vertices.Y = newPosition.Y + size_2;
            }
        }
コード例 #8
0
ファイル: CCTextureAtlas.cs プロジェクト: Kingwl/CocosSharp
        public void FillWithEmptyQuadsFromIndex(int index, int amount)
        {
            int to = index + amount;
            CCV3F_C4B_T2F_Quad[] elements = Quads.Elements;
            var empty = new CCV3F_C4B_T2F_Quad();

            for (int i = index; i < to; i++)
            {
                elements[i] = empty;
            }

            Dirty = true;
        }
コード例 #9
0
        public CCV3F_C4B_T2F_Quad Transform(CCV3F_C4B_T2F_Quad quad)
        {
            Transform(ref quad.TopLeft);
            Transform(ref quad.TopRight);
            Transform(ref quad.BottomLeft);
            Transform(ref quad.BottomRight);

            return quad;
        }
コード例 #10
0
        void UpdateColorCallback(ref CCV3F_C4B_T2F_Quad[] quads)
        {
            var color4 = new CCColor4B(DisplayedColor.R, DisplayedColor.G, DisplayedColor.B, DisplayedOpacity);

            if(opacityModifyRGB)
            {
                color4.R = (byte)(color4.R * DisplayedOpacity / 255.0f);
                color4.G = (byte)(color4.G * DisplayedOpacity / 255.0f);
                color4.B = (byte)(color4.B * DisplayedOpacity / 255.0f);
            }

            quads[0].BottomLeft.Colors = color4;
            quads[0].BottomRight.Colors = color4;
            quads[0].TopLeft.Colors = color4;
            quads[0].TopRight.Colors = color4;
        }
コード例 #11
0
 public CCQuadCommand(float globalZOrder, CCTexture2D texture, CCBlendFunc blendType, 
     CCV3F_C4B_T2F_Quad[] quads) 
     : this(globalZOrder, texture, blendType, quads, quads.Length, CCAffineTransform.Identity, 0)
 {}
コード例 #12
0
        public CCV3F_C4B_T2F_Quad Transform(CCV3F_C4B_T2F_Quad quad)
        {
            Transform(ref quad);

            return quad;
        }
コード例 #13
0
            public void UpdateQuad(int flattenedTileIndex, ref CCTileGidAndFlags tileGID, bool updateBuffer = false)
            {
                int adjustedTileIndex = flattenedTileIndex - TileStartIndex;
                int adjustedStartVertexIndex = adjustedTileIndex * NumOfCornersPerQuad;

                if (tileGID.Gid == 0)
                {
                    for (int i = 0; i < NumOfCornersPerQuad; i++)
                        QuadsVertexBuffer.Data[adjustedStartVertexIndex + i] = new CCV3F_C4B_T2F();

                    if (updateBuffer)
                        QuadsVertexBuffer.UpdateBuffer(adjustedStartVertexIndex, NumOfCornersPerQuad);

                    return;
                }
                else if (tileGID.Gid < TileSetInfo.FirstGid || tileGID.Gid > TileSetInfo.LastGid)
                {
                    return;
                }

                float left, right, top, bottom, vertexZ;
                vertexZ = TileMapLayer.TileVertexZ(flattenedTileIndex);


                CCSize tileSize = TileSetInfo.TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;
                CCSize texSize = TileSetInfo.TilesheetSize;
                CCPoint tilePos = TileMapLayer.TilePosition(flattenedTileIndex);

                var quadVertexData = QuadsVertexBuffer.Data;
                var quad = new CCV3F_C4B_T2F_Quad();

                // vertices
                if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0)
                {
                    left = tilePos.X;
                    right = tilePos.X + tileSize.Height;
                    bottom = tilePos.Y + tileSize.Width;
                    top = tilePos.Y;
                }
                else
                {
                    left = tilePos.X;
                    right = tilePos.X + tileSize.Width;
                    bottom = tilePos.Y + tileSize.Height;
                    top = tilePos.Y;
                }

                float temp;
                if ((tileGID.Flags & CCTileFlags.Vertical) != 0)
                {
                    temp = top;
                    top = bottom;
                    bottom = temp;
                }

                if ((tileGID.Flags & CCTileFlags.Horizontal) != 0)
                {
                    temp = left;
                    left = right;
                    right = temp;
                }

                if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0)
                {
                    // FIXME: not working correcly
                    quad.BottomLeft.Vertices = new CCVertex3F(left, bottom, vertexZ);
                    quad.BottomRight.Vertices = new CCVertex3F(left, top, vertexZ);
                    quad.TopLeft.Vertices = new CCVertex3F(right, bottom, vertexZ);
                    quad.TopRight.Vertices = new CCVertex3F(right, top, vertexZ);
                }
                else
                {
                    quad.BottomLeft.Vertices = new CCVertex3F(left, bottom, vertexZ);
                    quad.BottomRight.Vertices = new CCVertex3F(right, bottom, vertexZ);
                    quad.TopLeft.Vertices = new CCVertex3F(left, top, vertexZ);
                    quad.TopRight.Vertices = new CCVertex3F(right, top, vertexZ);
                }

                // texcoords
                CCRect tileTexture = TileSetInfo.TextureRectForGID(tileGID.Gid);
                left = ((tileTexture.Origin.X) / texSize.Width) + 0.5f / texSize.Width;
                right = left + ((tileTexture.Size.Width) / texSize.Width) - 1.0f / texSize.Width;
                bottom = ((tileTexture.Origin.Y) / texSize.Height) + 0.5f / texSize.Height;
                top = bottom + ((tileTexture.Size.Height) / texSize.Height) - 1.0f / texSize.Height;

                quad.BottomLeft.TexCoords = new CCTex2F(left, bottom);
                quad.BottomRight.TexCoords = new CCTex2F(right, bottom);
                quad.TopLeft.TexCoords = new CCTex2F(left, top);
                quad.TopRight.TexCoords = new CCTex2F(right, top);

                quad.BottomLeft.Colors = CCColor4B.White;
                quad.BottomRight.Colors = CCColor4B.White;
                quad.TopLeft.Colors = CCColor4B.White;
                quad.TopRight.Colors = CCColor4B.White;

                QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex] = quad.TopLeft;
                QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 1] = quad.BottomLeft;
                QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 2] = quad.TopRight;
                QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 3] = quad.BottomRight;

                if (updateBuffer)
                    QuadsVertexBuffer.UpdateBuffer(adjustedStartVertexIndex, NumOfCornersPerQuad);
            }
コード例 #14
0
 public void Transform(ref CCV3F_C4B_T2F_Quad quad)
 {
     Transform(ref quad.TopLeft);
     Transform(ref quad.TopRight);
     Transform(ref quad.BottomLeft);
     Transform(ref quad.BottomRight);
 }
コード例 #15
0
ファイル: CCTextureAtlas.cs プロジェクト: Kingwl/CocosSharp
 public void InsertQuad(ref CCV3F_C4B_T2F_Quad quad, int index)
 {
     Debug.Assert(index < Quads.Capacity, "insertQuadWithTexture: Invalid index");
     Quads.Insert(index, quad);
     Dirty = true;
 }
コード例 #16
0
ファイル: CCTextureAtlas.cs プロジェクト: Kingwl/CocosSharp
 public void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, int index)
 {
     Debug.Assert(index >= 0 && index <= Quads.Capacity, "updateQuadWithTexture: Invalid index");
     Quads.Count = Math.Max(index + 1, Quads.Count);
     Quads.Elements[index] = quad;
     Dirty = true;
 }
コード例 #17
0
ファイル: CCTileMapAtlas.cs プロジェクト: KerwinMa/CocosSharp
        void UpdateAtlasValueAt(int x, int y, Color value, int index)
        {
            float row = (float)(value.R % ItemsPerRow);
            float col = (float)(value.R / ItemsPerRow);

            float textureWide = (TextureAtlas.Texture.PixelsWide);
            float textureHigh = (TextureAtlas.Texture.PixelsHigh);

            float itemWidthInPixels = ItemWidth;
            float itemHeightInPixels = ItemHeight;

            #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
            float left        = (2 * row * itemWidthInPixels + 1) / (2 * textureWide);
            float right       = left + (itemWidthInPixels * 2 - 2) / (2 * textureWide);
            float top         = (2 * col * itemHeightInPixels + 1) / (2 * textureHigh);
            float bottom      = top + (itemHeightInPixels * 2 - 2) / (2 * textureHigh);
            #else
            float left = (row * itemWidthInPixels) / textureWide;
            float right = left + itemWidthInPixels / textureWide;
            float top = (col * itemHeightInPixels) / textureHigh;
            float bottom = top + itemHeightInPixels / textureHigh;
            #endif

            CCV3F_C4B_T2F_Quad quad = new CCV3F_C4B_T2F_Quad();

            quad.TopLeft.TexCoords.U = left;
            quad.TopLeft.TexCoords.V = top;
            quad.TopRight.TexCoords.U = right;
            quad.TopRight.TexCoords.V = top;
            quad.BottomLeft.TexCoords.U = left;
            quad.BottomLeft.TexCoords.V = bottom;
            quad.BottomRight.TexCoords.U = right;
            quad.BottomRight.TexCoords.V = bottom;

            quad.BottomLeft.Vertices.X = (x * ItemWidth);
            quad.BottomLeft.Vertices.Y = (y * ItemHeight);
            quad.BottomLeft.Vertices.Z = 0.0f;
            quad.BottomRight.Vertices.X = (x * ItemWidth + ItemWidth);
            quad.BottomRight.Vertices.Y = (y * ItemHeight);
            quad.BottomRight.Vertices.Z = 0.0f;
            quad.TopLeft.Vertices.X = (x * ItemWidth);
            quad.TopLeft.Vertices.Y = (y * ItemHeight + ItemHeight);
            quad.TopLeft.Vertices.Z = 0.0f;
            quad.TopRight.Vertices.X = (x * ItemWidth + ItemWidth);
            quad.TopRight.Vertices.Y = (y * ItemHeight + ItemHeight);
            quad.TopRight.Vertices.Z = 0.0f;

            var color = new CCColor4B(DisplayedColor.R, DisplayedColor.G, DisplayedColor.B, DisplayedOpacity);
            quad.TopRight.Colors = color;
            quad.TopLeft.Colors = color;
            quad.BottomRight.Colors = color;
            quad.BottomLeft.Colors = color;

            TextureAtlas.UpdateQuad(ref quad, index);
        }
コード例 #18
0
 public CCQuadCommand(float globalZOrder, CCTexture2D texture, CCBlendFunc blendType, 
     CCV3F_C4B_T2F_Quad quad) 
     : this(globalZOrder, texture, blendType, new CCV3F_C4B_T2F_Quad[] { quad }, 1,
         CCAffineTransform.Identity, 0)
 { }
コード例 #19
0
        void UpdateSpriteTextureQuadsCallback(ref CCV3F_C4B_T2F_Quad[] quads)
        {
            if (!Visible)
            {
                quads[0].BottomRight.Vertices = quads[0].TopLeft.Vertices 
                    = quads[0].TopRight.Vertices = quads[0].BottomLeft.Vertices = CCVertex3F.Zero;
            }
            else
            {
                CCPoint relativeOffset = unflippedOffsetPositionFromCenter;

                if (flipX)
                {
                    relativeOffset.X = -relativeOffset.X;
                }
                if (flipY)
                {
                    relativeOffset.Y = -relativeOffset.Y;
                }

                CCPoint centerPoint = UntrimmedSizeInPixels.Center + relativeOffset;
                CCPoint subRectOrigin;
                subRectOrigin.X = centerPoint.X - textureRectInPixels.Size.Width / 2.0f;
                subRectOrigin.Y = centerPoint.Y - textureRectInPixels.Size.Height / 2.0f;

                CCRect subRectRatio = CCRect.Zero;

                if (UntrimmedSizeInPixels.Width > 0 && UntrimmedSizeInPixels.Height > 0)
                {
                    subRectRatio = new CCRect(
                        subRectOrigin.X / UntrimmedSizeInPixels.Width, 
                        subRectOrigin.Y / UntrimmedSizeInPixels.Height,
                        textureRectInPixels.Size.Width / UntrimmedSizeInPixels.Width,
                        textureRectInPixels.Size.Height / UntrimmedSizeInPixels.Height);
                }

                // Atlas: Vertex
                float x1 = subRectRatio.Origin.X * ContentSize.Width;
                float y1 = subRectRatio.Origin.Y * ContentSize.Height;
                float x2 = x1 + (subRectRatio.Size.Width * ContentSize.Width);
                float y2 = y1 + (subRectRatio.Size.Height * ContentSize.Height);

                // Don't set z-value: The node's transform will be set to include z offset
                quads[0].BottomLeft.Vertices = new CCVertex3F(x1, y1, 0);
                quads[0].BottomRight.Vertices = new CCVertex3F(x2, y1, 0);
                quads[0].TopLeft.Vertices = new CCVertex3F(x1, y2, 0);
                quads[0].TopRight.Vertices = new CCVertex3F(x2, y2, 0);

                if (Texture == null)
                {
                    return;
                }

                float atlasWidth = Texture.PixelsWide;
                float atlasHeight = Texture.PixelsHigh;

                float left, right, top, bottom;

                if (IsTextureRectRotated)
                {
                    #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
                    left = (2 * textureRectInPixels.Origin.X + 1) / (2 * atlasWidth);
                    right = left + (textureRectInPixels.Size.Height * 2 - 2) / (2 * atlasWidth);
                    top = (2 * textureRectInPixels.Origin.Y + 1) / (2 * atlasHeight);
                    bottom = top + (textureRectInPixels.Size.Width * 2 - 2) / (2 * atlasHeight);
                    #else
                    left = textureRectInPixels.Origin.X / atlasWidth;
                    right = (textureRectInPixels.Origin.X + textureRectInPixels.Size.Height) / atlasWidth;
                    top = textureRectInPixels.Origin.Y / atlasHeight;
                    bottom = (textureRectInPixels.Origin.Y + textureRectInPixels.Size.Width) / atlasHeight;
                    #endif

                    if (flipX)
                    {
                        CCMacros.CCSwap(ref top, ref bottom);
                    }

                    if (flipY)
                    {
                        CCMacros.CCSwap(ref left, ref right);
                    }

                    quads[0].BottomLeft.TexCoords.U = left;
                    quads[0].BottomLeft.TexCoords.V = top;
                    quads[0].BottomRight.TexCoords.U = left;
                    quads[0].BottomRight.TexCoords.V = bottom;
                    quads[0].TopLeft.TexCoords.U = right;
                    quads[0].TopLeft.TexCoords.V = top;
                    quads[0].TopRight.TexCoords.U = right;
                    quads[0].TopRight.TexCoords.V = bottom;
                }
                else
                {
                    #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
                    left = (2 * textureRectInPixels.Origin.X + 1) / (2 * atlasWidth);
                    right = left + (textureRectInPixels.Size.Width * 2 - 2) / (2 * atlasWidth);
                    top = (2 * textureRectInPixels.Origin.Y + 1) / (2 * atlasHeight);
                    bottom = top + (textureRectInPixels.Size.Height * 2 - 2) / (2 * atlasHeight);
                    #else
                    left = textureRectInPixels.Origin.X / atlasWidth;
                    right = (textureRectInPixels.Origin.X + textureRectInPixels.Size.Width) / atlasWidth;
                    top = textureRectInPixels.Origin.Y / atlasHeight;
                    bottom = (textureRectInPixels.Origin.Y + textureRectInPixels.Size.Height) / atlasHeight;
                    #endif

                    if (flipX)
                    {
                        CCMacros.CCSwap(ref left, ref right);
                    }

                    if (flipY)
                    {
                        CCMacros.CCSwap(ref top, ref bottom);
                    }

                    quads[0].BottomLeft.TexCoords.U = left;
                    quads[0].BottomLeft.TexCoords.V = bottom;
                    quads[0].BottomRight.TexCoords.U = right;
                    quads[0].BottomRight.TexCoords.V = bottom;
                    quads[0].TopLeft.TexCoords.U = left;
                    quads[0].TopLeft.TexCoords.V = top;
                    quads[0].TopRight.TexCoords.U = right;
                    quads[0].TopRight.TexCoords.V = top;
                }
            }
        }
コード例 #20
0
ファイル: CCTextureAtlas.cs プロジェクト: Kingwl/CocosSharp
        public void MoveQuadsFromIndex(int oldIndex, int amount, int newIndex)
        {
            Debug.Assert(newIndex + amount <= Quads.Count, "insertQuadFromIndex:atIndex: Invalid index");
            Debug.Assert(oldIndex < Quads.Count, "insertQuadFromIndex:atIndex: Invalid index");

            if (oldIndex == newIndex)
            {
                return;
            }

            var tmp = new CCV3F_C4B_T2F_Quad[amount];
            Array.Copy(Quads.Elements, oldIndex, tmp, 0, amount);

            if (newIndex < oldIndex)
            {
                // move quads from newIndex to newIndex + amount to make room for buffer
                Array.Copy(Quads.Elements, newIndex + amount, Quads.Elements, newIndex, oldIndex - newIndex);
            }
            else
            {
                // move quads above back
                Array.Copy(Quads.Elements, oldIndex + amount, Quads.Elements, oldIndex, newIndex - oldIndex);
            }
            Array.Copy(tmp, 0, Quads.Elements, newIndex, amount);

            Dirty = true;
        }
コード例 #21
0
 public CCQuadCommand(float globalZOrder, CCTexture2D texture, CCBlendFunc blendType, 
     CCV3F_C4B_T2F_Quad quad, CCAffineTransform modelViewTransform, int flags = 0) 
     : this(globalZOrder, texture, blendType, new CCV3F_C4B_T2F_Quad[] { quad }, 1,
         modelViewTransform, flags)
 { }
コード例 #22
0
        void UpdateLocalTransformedSpriteTextureQuadsCallback(ref CCV3F_C4B_T2F_Quad[] quads)
        {
            if(AtlasIndex == CCMacros.CCSpriteIndexNotInitialized)
                return;

            CCV3F_C4B_T2F_Quad transformedQuad = quads[0];

            AffineLocalTransform.Transform(ref transformedQuad);

            if(TextureAtlas != null && TextureAtlas.TotalQuads > AtlasIndex)
                TextureAtlas.UpdateQuad(ref transformedQuad, AtlasIndex);
        }
コード例 #23
0
        //virtual cocos2d::CCTextureAtlas* getTextureAtlas (RegionAttachment regionAttachment);
        #region SpinesCocos2d

        void UpdateRegionAttachmentQuad(RegionAttachment self, Slot slot, ref CCV3F_C4B_T2F_Quad quad, bool premultipliedAlpha = false)
        {

            float[] vertices = new float[8];

            self.ComputeWorldVertices(slot.Skeleton.X, slot.Skeleton.Y, slot.Bone, vertices);

            float r = slot.Skeleton.R * slot.R * 255;
            float g = slot.Skeleton.G * slot.G * 255;
            float b = slot.Skeleton.B * slot.B * 255;

            float normalizedAlpha = slot.Skeleton.A * slot.A;
            if (premultipliedAlpha)
            {
                r *= normalizedAlpha;
                g *= normalizedAlpha;
                b *= normalizedAlpha;
            }

            float a = normalizedAlpha * 255;
            quad.BottomLeft.Colors.R = (byte)r;
            quad.BottomLeft.Colors.G = (byte)g;
            quad.BottomLeft.Colors.B = (byte)b;
            quad.BottomLeft.Colors.A = (byte)a;
            quad.TopLeft.Colors.R = (byte)r;
            quad.TopLeft.Colors.G = (byte)g;
            quad.TopLeft.Colors.B = (byte)b;
            quad.TopLeft.Colors.A = (byte)a;
            quad.TopRight.Colors.R = (byte)r;
            quad.TopRight.Colors.G = (byte)g;
            quad.TopRight.Colors.B = (byte)b;
            quad.TopRight.Colors.A = (byte)a;
            quad.BottomRight.Colors.R = (byte)r;
            quad.BottomRight.Colors.G = (byte)g;
            quad.BottomRight.Colors.B = (byte)b;
            quad.BottomRight.Colors.A = (byte)a;

            quad.BottomLeft.Vertices.X = vertices[RegionAttachment.X1];
            quad.BottomLeft.Vertices.Y = vertices[RegionAttachment.Y1];
            quad.TopLeft.Vertices.X = vertices[RegionAttachment.X2];
            quad.TopLeft.Vertices.Y = vertices[RegionAttachment.Y2];
            quad.TopRight.Vertices.X = vertices[RegionAttachment.X3];
            quad.TopRight.Vertices.Y = vertices[RegionAttachment.Y3];
            quad.BottomRight.Vertices.X = vertices[RegionAttachment.X4];
            quad.BottomRight.Vertices.Y = vertices[RegionAttachment.Y4];

            quad.BottomLeft.TexCoords.U = self.UVs[RegionAttachment.X1];
            quad.BottomLeft.TexCoords.V = self.UVs[RegionAttachment.Y1];
            quad.TopLeft.TexCoords.U = self.UVs[RegionAttachment.X2];
            quad.TopLeft.TexCoords.V = self.UVs[RegionAttachment.Y2];
            quad.TopRight.TexCoords.U = self.UVs[RegionAttachment.X3];
            quad.TopRight.TexCoords.V = self.UVs[RegionAttachment.Y3];
            quad.BottomRight.TexCoords.U = self.UVs[RegionAttachment.X4];
            quad.BottomRight.TexCoords.V = self.UVs[RegionAttachment.Y4];

        }
コード例 #24
0
        void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, ref CCParticleBase particle)
        {
            CCPoint newPosition;

            if (PositionType == CCPositionType.Free || PositionType == CCPositionType.Relative)
            {
                newPosition.X = particle.Position.X - (currentPosition.X - particle.StartPosition.X);
                newPosition.Y = particle.Position.Y - (currentPosition.Y - particle.StartPosition.Y);
            }
            else
            {
                newPosition = particle.Position;
            }

            // translate newPos to correct position, since matrix transform isn't performed in batchnode
            // don't update the particle with the new position information, it will interfere with the radius and tangential calculations
            if (BatchNode != null)
            {
                newPosition.X += Position.X;
                newPosition.Y += Position.Y;
            }

            CCColor4B color = new CCColor4B();

            if (OpacityModifyRGB)
            {
                color.R = (byte)(particle.Color.R * particle.Color.A * 255);
                color.G = (byte)(particle.Color.G * particle.Color.A * 255);
                color.B = (byte)(particle.Color.B * particle.Color.A * 255);
                color.A = (byte)(particle.Color.A * 255);
            }
            else
            {
                color.R = (byte)(particle.Color.R * 255);
                color.G = (byte)(particle.Color.G * 255);
                color.B = (byte)(particle.Color.B * 255);
                color.A = (byte)(particle.Color.A * 255);
            }

            quad.BottomLeft.Colors  = color;
            quad.BottomRight.Colors = color;
            quad.TopLeft.Colors     = color;
            quad.TopRight.Colors    = color;

            // vertices
            float size_2 = particle.Size / 2;

            if (particle.Rotation != 0.0)
            {
                float x1 = -size_2;
                float y1 = -size_2;

                float x2 = size_2;
                float y2 = size_2;
                float x  = newPosition.X;
                float y  = newPosition.Y;

                float r  = -CCMathHelper.ToRadians(particle.Rotation);
                float cr = CCMathHelper.Cos(r);
                float sr = CCMathHelper.Sin(r);
                float ax = x1 * cr - y1 * sr + x;
                float ay = x1 * sr + y1 * cr + y;
                float bx = x2 * cr - y1 * sr + x;
                float by = x2 * sr + y1 * cr + y;
                float cx = x2 * cr - y2 * sr + x;
                float cy = x2 * sr + y2 * cr + y;
                float dx = x1 * cr - y2 * sr + x;
                float dy = x1 * sr + y2 * cr + y;

                // bottom-left
                quad.BottomLeft.Vertices.X = ax;
                quad.BottomLeft.Vertices.Y = ay;

                // bottom-right vertex:
                quad.BottomRight.Vertices.X = bx;
                quad.BottomRight.Vertices.Y = by;

                // top-left vertex:
                quad.TopLeft.Vertices.X = dx;
                quad.TopLeft.Vertices.Y = dy;

                // top-right vertex:
                quad.TopRight.Vertices.X = cx;
                quad.TopRight.Vertices.Y = cy;
            }
            else
            {
                // bottom-left vertex:
                quad.BottomLeft.Vertices.X = newPosition.X - size_2;
                quad.BottomLeft.Vertices.Y = newPosition.Y - size_2;

                // bottom-right vertex:
                quad.BottomRight.Vertices.X = newPosition.X + size_2;
                quad.BottomRight.Vertices.Y = newPosition.Y - size_2;

                // top-left vertex:
                quad.TopLeft.Vertices.X = newPosition.X - size_2;
                quad.TopLeft.Vertices.Y = newPosition.Y + size_2;

                // top-right vertex:
                quad.TopRight.Vertices.X = newPosition.X + size_2;
                quad.TopRight.Vertices.Y = newPosition.Y + size_2;
            }
        }
コード例 #25
0
        void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, ref CCParticleBase particle)
        {
            CCPoint newPosition;

            if (PositionType == CCPositionType.Free)
            {
                newPosition.X = particle.Position.X - (currentPosition.X - particle.StartPosition.X);
                newPosition.Y = particle.Position.Y - (currentPosition.Y - particle.StartPosition.Y);
            }
            else
            {
                newPosition = particle.Position;
            }

            CCColor4B color = new CCColor4B();

            if (OpacityModifyRGB)
            {
                color.R = (byte)(particle.Color.R * particle.Color.A * 255);
                color.G = (byte)(particle.Color.G * particle.Color.A * 255);
                color.B = (byte)(particle.Color.B * particle.Color.A * 255);
                color.A = (byte)(particle.Color.A * 255);
            }
            else
            {
                color.R = (byte)(particle.Color.R * 255);
                color.G = (byte)(particle.Color.G * 255);
                color.B = (byte)(particle.Color.B * 255);
                color.A = (byte)(particle.Color.A * 255);
            }

            quad.BottomLeft.Colors  = color;
            quad.BottomRight.Colors = color;
            quad.TopLeft.Colors     = color;
            quad.TopRight.Colors    = color;

            // vertices
            float size_2 = particle.Size / 2;

            if (particle.Rotation != 0.0)
            {
                float x1 = -size_2;
                float y1 = -size_2;

                float x2 = size_2;
                float y2 = size_2;
                float x  = newPosition.X;
                float y  = newPosition.Y;

                float r  = -CCMathHelper.ToRadians(particle.Rotation);
                float cr = CCMathHelper.Cos(r);
                float sr = CCMathHelper.Sin(r);
                float ax = x1 * cr - y1 * sr + x;
                float ay = x1 * sr + y1 * cr + y;
                float bx = x2 * cr - y1 * sr + x;
                float by = x2 * sr + y1 * cr + y;
                float cx = x2 * cr - y2 * sr + x;
                float cy = x2 * sr + y2 * cr + y;
                float dx = x1 * cr - y2 * sr + x;
                float dy = x1 * sr + y2 * cr + y;

                // bottom-left
                quad.BottomLeft.Vertices.X = ax;
                quad.BottomLeft.Vertices.Y = ay;

                // bottom-right vertex:
                quad.BottomRight.Vertices.X = bx;
                quad.BottomRight.Vertices.Y = by;

                // top-left vertex:
                quad.TopLeft.Vertices.X = dx;
                quad.TopLeft.Vertices.Y = dy;

                // top-right vertex:
                quad.TopRight.Vertices.X = cx;
                quad.TopRight.Vertices.Y = cy;
            }
            else
            {
                // bottom-left vertex:
                quad.BottomLeft.Vertices.X = newPosition.X - size_2;
                quad.BottomLeft.Vertices.Y = newPosition.Y - size_2;

                // bottom-right vertex:
                quad.BottomRight.Vertices.X = newPosition.X + size_2;
                quad.BottomRight.Vertices.Y = newPosition.Y - size_2;

                // top-left vertex:
                quad.TopLeft.Vertices.X = newPosition.X - size_2;
                quad.TopLeft.Vertices.Y = newPosition.Y + size_2;

                // top-right vertex:
                quad.TopRight.Vertices.X = newPosition.X + size_2;
                quad.TopRight.Vertices.Y = newPosition.Y + size_2;
            }
        }
コード例 #26
0
ファイル: CCTextureAtlas.cs プロジェクト: zhuruvl/CocosSharp
 public void InsertQuad(ref CCV3F_C4B_T2F_Quad quad, int index)
 {
     Debug.Assert(index < Quads.Capacity, "insertQuadWithTexture: Invalid index");
     Quads.Insert(index, quad);
     Dirty = true;
 }
コード例 #27
0
 void UpdateRadialParticleQuads(CCV3F_C4B_T2F_Quad[] rawQuads)
 {
     var count = ParticleCount;
     if (BatchNode != null)
     {
         for (int i = 0; i < count; i++)
         {
             UpdateQuad(ref rawQuads[AtlasIndex + RadialParticles[i].AtlasIndex], ref RadialParticles[i].ParticleBase);
         }
     }
     else
     {
         for (int i = 0; i < count; i++)
         {
             UpdateQuad(ref rawQuads[i], ref RadialParticles[i].ParticleBase);
         }
     }
 }
コード例 #28
0
ファイル: CCLabelAtlas.cs プロジェクト: h7ing/CocosSharp
        public override void UpdateAtlasValues()
        {
            if(Scene == null)
                return;

            int n = m_sString.Length;

            CCTexture2D texture = TextureAtlas.Texture;

            float textureWide = texture.PixelsWide;
            float textureHigh = texture.PixelsHigh;
            float scaleFactor = 1.0f;

            float itemWidthInPixels = ItemWidth * scaleFactor;
            float itemHeightInPixels = ItemHeight * scaleFactor;

            for (int i = 0; i < n; i++)
            {
                var a = (char) (m_sString[i] - m_cMapStartChar);
                float row = (a % ItemsPerRow);
                float col = (a / ItemsPerRow);

                #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
                // Issue #938. Don't use texStepX & texStepY
                float left          = (2 * row * itemWidthInPixels + 1) / (2 * textureWide);
                float right         = left + (itemWidthInPixels * 2 - 2) / (2 * textureWide);
                float top           = (2 * col * itemHeightInPixels + 1) / (2 * textureHigh);
                float bottom        = top + (itemHeightInPixels * 2 - 2) / (2 * textureHigh);
                #else
                float left = row * itemWidthInPixels / textureWide;
                float right = left + itemWidthInPixels / textureWide;
                float top = col * itemHeightInPixels / textureHigh;
                float bottom = top + itemHeightInPixels / textureHigh;
                #endif
                // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL

                CCV3F_C4B_T2F_Quad quad = new CCV3F_C4B_T2F_Quad();

                quad.TopLeft.TexCoords.U = left;
                quad.TopLeft.TexCoords.V = top;
                quad.TopRight.TexCoords.U = right;
                quad.TopRight.TexCoords.V = top;
                quad.BottomLeft.TexCoords.U = left;
                quad.BottomLeft.TexCoords.V = bottom;
                quad.BottomRight.TexCoords.U = right;
                quad.BottomRight.TexCoords.V = bottom;

                quad.BottomLeft.Vertices.X = i * ItemWidth;
                quad.BottomLeft.Vertices.Y = 0.0f;
                quad.BottomLeft.Vertices.Z = 0.0f;
                quad.BottomRight.Vertices.X = i * ItemWidth + ItemWidth;
                quad.BottomRight.Vertices.Y = 0.0f;
                quad.BottomRight.Vertices.Z = 0.0f;
                quad.TopLeft.Vertices.X = i * ItemWidth;
                quad.TopLeft.Vertices.Y = ItemHeight;
                quad.TopLeft.Vertices.Z = 0.0f;
                quad.TopRight.Vertices.X = i * ItemWidth + ItemWidth;
                quad.TopRight.Vertices.Y = ItemHeight;
                quad.TopRight.Vertices.Z = 0.0f;


                quad.TopLeft.Colors = quad.TopRight.Colors = quad.BottomLeft.Colors = quad.BottomRight.Colors =
                    new CCColor4B(DisplayedColor.R, DisplayedColor.G, DisplayedColor.B, DisplayedOpacity);

                TextureAtlas.UpdateQuad(ref quad, i);
            }
        }
コード例 #29
0
            public void UpdateQuad(int flattenedTileIndex, ref CCTileGidAndFlags tileGID, bool updateBuffer = false)
            {
                int adjustedTileIndex        = flattenedTileIndex - TileStartIndex;
                int adjustedStartVertexIndex = adjustedTileIndex * NumOfCornersPerQuad;

                if (tileGID.Gid == 0)
                {
                    for (int i = 0; i < NumOfCornersPerQuad; i++)
                    {
                        QuadsVertexBuffer.Data[adjustedStartVertexIndex + i] = new CCV3F_C4B_T2F();
                    }

                    if (updateBuffer)
                    {
                        QuadsVertexBuffer.UpdateBuffer(adjustedStartVertexIndex, NumOfCornersPerQuad);
                    }

                    return;
                }
                else if (tileGID.Gid < TileSetInfo.FirstGid || tileGID.Gid > TileSetInfo.LastGid)
                {
                    return;
                }

                float left, right, top, bottom, vertexZ;

                vertexZ = TileMapLayer.TileVertexZ(flattenedTileIndex);


                CCSize  tileSize = TileSetInfo.TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;
                CCSize  texSize  = TileSetInfo.TilesheetSize;
                CCPoint tilePos  = TileMapLayer.TilePosition(flattenedTileIndex);

                var quadVertexData = QuadsVertexBuffer.Data;
                var quad           = new CCV3F_C4B_T2F_Quad();

                // vertices
                if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0)
                {
                    left   = tilePos.X;
                    right  = tilePos.X + tileSize.Height;
                    bottom = tilePos.Y + tileSize.Width;
                    top    = tilePos.Y;
                }
                else
                {
                    left   = tilePos.X;
                    right  = tilePos.X + tileSize.Width;
                    bottom = tilePos.Y + tileSize.Height;
                    top    = tilePos.Y;
                }

                float temp;

                if ((tileGID.Flags & CCTileFlags.Vertical) != 0)
                {
                    temp   = top;
                    top    = bottom;
                    bottom = temp;
                }

                if ((tileGID.Flags & CCTileFlags.Horizontal) != 0)
                {
                    temp  = left;
                    left  = right;
                    right = temp;
                }

                if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0)
                {
                    // FIXME: not working correcly
                    quad.BottomLeft.Vertices  = new CCVertex3F(left, bottom, vertexZ);
                    quad.BottomRight.Vertices = new CCVertex3F(left, top, vertexZ);
                    quad.TopLeft.Vertices     = new CCVertex3F(right, bottom, vertexZ);
                    quad.TopRight.Vertices    = new CCVertex3F(right, top, vertexZ);
                }
                else
                {
                    quad.BottomLeft.Vertices  = new CCVertex3F(left, bottom, vertexZ);
                    quad.BottomRight.Vertices = new CCVertex3F(right, bottom, vertexZ);
                    quad.TopLeft.Vertices     = new CCVertex3F(left, top, vertexZ);
                    quad.TopRight.Vertices    = new CCVertex3F(right, top, vertexZ);
                }

                // texcoords
                CCRect tileTexture = TileSetInfo.TextureRectForGID(tileGID.Gid);

                left   = ((tileTexture.Origin.X) / texSize.Width) + 0.5f / texSize.Width;
                right  = left + ((tileTexture.Size.Width) / texSize.Width) - 1.0f / texSize.Width;
                bottom = ((tileTexture.Origin.Y) / texSize.Height) + 0.5f / texSize.Height;
                top    = bottom + ((tileTexture.Size.Height) / texSize.Height) - 1.0f / texSize.Height;

                quad.BottomLeft.TexCoords  = new CCTex2F(left, bottom);
                quad.BottomRight.TexCoords = new CCTex2F(right, bottom);
                quad.TopLeft.TexCoords     = new CCTex2F(left, top);
                quad.TopRight.TexCoords    = new CCTex2F(right, top);

                quad.BottomLeft.Colors  = CCColor4B.White;
                quad.BottomRight.Colors = CCColor4B.White;
                quad.TopLeft.Colors     = CCColor4B.White;
                quad.TopRight.Colors    = CCColor4B.White;

                QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex]     = quad.TopLeft;
                QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 1] = quad.BottomLeft;
                QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 2] = quad.TopRight;
                QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 3] = quad.BottomRight;

                if (updateBuffer)
                {
                    QuadsVertexBuffer.UpdateBuffer(adjustedStartVertexIndex, NumOfCornersPerQuad);
                }
            }
コード例 #30
0
 public CCQuadCommand(float globalZOrder, CCTexture2D texture, CCBlendFunc blendType,
                      CCV3F_C4B_T2F_Quad quad, CCAffineTransform modelViewTransform, int flags = 0)
     : this(globalZOrder, texture, blendType, new CCV3F_C4B_T2F_Quad[] { quad }, 1,
            modelViewTransform, flags)
 {
 }
コード例 #31
0
ファイル: CCSprite.cs プロジェクト: h7ing/CocosSharp
        // Used externally by non-subclasses
        internal void InitWithTexture(CCTexture2D texture, CCRect? texRectInPixels=null, bool rotated=false)
        {
            // do not remove this
            // This sets up the atlas index correctly.  If not set correctly lot of weird sprite artifacts start showing up.
            BatchNode = null;

            IsTextureRectRotated = rotated;
            CCSize texSize = (texture != null) ? texture.ContentSizeInPixels : CCSize.Zero;

            textureRectInPixels = texRectInPixels ?? new CCRect(0.0f, 0.0f, texSize.Width, texSize.Height);

            opacityModifyRGB = true;
            BlendFunc = CCBlendFunc.AlphaBlend;

            AnchorPoint = CCPoint.AnchorMiddle;

            quad = new CCV3F_C4B_T2F_Quad();
            quad.BottomLeft.Colors = CCColor4B.White;
            quad.BottomRight.Colors = CCColor4B.White;
            quad.TopLeft.Colors = CCColor4B.White;
            quad.TopRight.Colors = CCColor4B.White;

            Texture = texture;

            // If content size not initialized, assume worldspace dimensions match texture dimensions
            if(ContentSize == CCSize.Zero)
                ContentSize = textureRectInPixels.Size;


            UpdateSpriteTextureQuads();
        }
コード例 #32
0
 public CCQuadCommand(float globalZOrder, CCTexture2D texture, CCBlendFunc blendType,
                      CCV3F_C4B_T2F_Quad quad)
     : this(globalZOrder, texture, blendType, new CCV3F_C4B_T2F_Quad[] { quad }, 1,
            CCAffineTransform.Identity, 0)
 {
 }
コード例 #33
0
ファイル: CCSprite.cs プロジェクト: h7ing/CocosSharp
        // For when using a batch node
        // In this instance, drawing will not make use of node's local matrix
        public void UpdateTransformedSpriteTextureQuads()
        {
            if(batchNode == null || AtlasIndex == CCMacros.CCSpriteIndexNotInitialized)
                return;
                
            transformedQuad = quad;

            // We can't use the AffineWorldTransform because that's the 2d projection of a 3d transformation
            // i.e. The Z coords of our quad would remain unaltered which in general incorrect
            // Instead, we need use the XnaWolrdTransform which incorporates any potential z-transforms
            Matrix worldMatrix = XnaWorldMatrix;
            Vector3 topLeft = quad.TopLeft.Vertices.XnaVector;
            Vector3 topRight = quad.TopRight.Vertices.XnaVector;
            Vector3 bottomLeft = quad.BottomLeft.Vertices.XnaVector;
            Vector3 bottomRight = quad.BottomRight.Vertices.XnaVector;

            topLeft = Vector3.Transform(topLeft, worldMatrix);
            topRight = Vector3.Transform(topRight, worldMatrix);
            bottomLeft = Vector3.Transform(bottomLeft, worldMatrix);
            bottomRight = Vector3.Transform(bottomRight, worldMatrix);

            transformedQuad.TopLeft.Vertices = new CCVertex3F(topLeft.X, topLeft.Y, topLeft.Z);
            transformedQuad.TopRight.Vertices = new CCVertex3F(topRight.X, topRight.Y, topRight.Z);
            transformedQuad.BottomLeft.Vertices = new CCVertex3F(bottomLeft.X, bottomLeft.Y, bottomLeft.Z);
            transformedQuad.BottomRight.Vertices = new CCVertex3F(bottomRight.X, bottomRight.Y, bottomRight.Z);

            if(textureAtlas != null && textureAtlas.TotalQuads > AtlasIndex)
                textureAtlas.UpdateQuad(ref transformedQuad, AtlasIndex);
        }
コード例 #34
0
ファイル: CCSprite.cs プロジェクト: netonjm/CocosSharp
        // For when using a batch node
        // In this instance, drawing will not make use of node's world matrix
        public void UpdateTransformedSpriteTextureQuads()
        {
            if(batchNode == null || AtlasIndex == CCMacros.CCSpriteIndexNotInitialized)
                return;

            transformedQuad = 
                AffineWorldTransform.Transform(quad);

            if(textureAtlas != null && textureAtlas.TotalQuads > AtlasIndex)
                textureAtlas.UpdateQuad(ref transformedQuad, AtlasIndex);
        }
コード例 #35
0
        public override void UpdateAtlasValues()
        {
            if (Scene == null)
            {
                return;
            }

            int n = m_sString.Length;

            CCTexture2D texture = TextureAtlas.Texture;

            float textureWide = texture.PixelsWide;
            float textureHigh = texture.PixelsHigh;
            float scaleFactor = 1.0f;

            float itemWidthInPixels  = ItemWidth * scaleFactor;
            float itemHeightInPixels = ItemHeight * scaleFactor;

            for (int i = 0; i < n; i++)
            {
                var   a   = (char)(m_sString[i] - m_cMapStartChar);
                float row = (a % ItemsPerRow);
                float col = (a / ItemsPerRow);

                #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
                // Issue #938. Don't use texStepX & texStepY
                float left   = (2 * row * itemWidthInPixels + 1) / (2 * textureWide);
                float right  = left + (itemWidthInPixels * 2 - 2) / (2 * textureWide);
                float top    = (2 * col * itemHeightInPixels + 1) / (2 * textureHigh);
                float bottom = top + (itemHeightInPixels * 2 - 2) / (2 * textureHigh);
                #else
                float left   = row * itemWidthInPixels / textureWide;
                float right  = left + itemWidthInPixels / textureWide;
                float top    = col * itemHeightInPixels / textureHigh;
                float bottom = top + itemHeightInPixels / textureHigh;
                #endif
                // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL

                CCV3F_C4B_T2F_Quad quad = new CCV3F_C4B_T2F_Quad();

                quad.TopLeft.TexCoords.U     = left;
                quad.TopLeft.TexCoords.V     = top;
                quad.TopRight.TexCoords.U    = right;
                quad.TopRight.TexCoords.V    = top;
                quad.BottomLeft.TexCoords.U  = left;
                quad.BottomLeft.TexCoords.V  = bottom;
                quad.BottomRight.TexCoords.U = right;
                quad.BottomRight.TexCoords.V = bottom;

                quad.BottomLeft.Vertices.X  = i * ItemWidth;
                quad.BottomLeft.Vertices.Y  = 0.0f;
                quad.BottomLeft.Vertices.Z  = 0.0f;
                quad.BottomRight.Vertices.X = i * ItemWidth + ItemWidth;
                quad.BottomRight.Vertices.Y = 0.0f;
                quad.BottomRight.Vertices.Z = 0.0f;
                quad.TopLeft.Vertices.X     = i * ItemWidth;
                quad.TopLeft.Vertices.Y     = ItemHeight;
                quad.TopLeft.Vertices.Z     = 0.0f;
                quad.TopRight.Vertices.X    = i * ItemWidth + ItemWidth;
                quad.TopRight.Vertices.Y    = ItemHeight;
                quad.TopRight.Vertices.Z    = 0.0f;


                quad.TopLeft.Colors = quad.TopRight.Colors = quad.BottomLeft.Colors = quad.BottomRight.Colors =
                    new CCColor4B(DisplayedColor.R, DisplayedColor.G, DisplayedColor.B, DisplayedOpacity);

                TextureAtlas.UpdateQuad(ref quad, i);
            }
        }
コード例 #36
0
        public CCV3F_C4B_T2F_Quad Transform(CCV3F_C4B_T2F_Quad quad)
        {
            Transform(ref quad);

            return(quad);
        }