Exemple #1
0
        public override void Visit(ref CCAffineTransform parentWorldTransform)
        {
            if (!Visible || Scene == null)
            {
                return;
            }

            var worldTransform       = CCAffineTransform.Identity;
            var affineLocalTransform = AffineLocalTransform;

            CCAffineTransform.Concat(ref affineLocalTransform, ref parentWorldTransform, out worldTransform);


            if (Grid != null && Grid.Active)
            {
                renderGrid.GlobalDepth = worldTransform.Tz;
                Renderer.AddCommand(renderGrid);

                renderBeginGrid.WorldTransform = worldTransform;

                Renderer.PushGroup();
                Renderer.AddCommand(renderBeginGrid);
            }

            SortAllChildren();

            VisitRenderer(ref worldTransform);

            if (Target != null)
            {
                Target.Visit(ref worldTransform);
            }

            if (Children != null)
            {
                var elements = Children.Elements;
                for (int i = 0, N = Children.Count; i < N; ++i)
                {
                    var child = elements[i];
                    if (child.Visible)
                    {
                        child.Visit(ref worldTransform);
                    }
                }
            }

            if (Grid != null && Grid.Active)
            {
                renderEndGrid.GlobalDepth = worldTransform.Tz;
                Renderer.AddCommand(renderEndGrid);
                Renderer.PopGroup();
            }
        }
Exemple #2
0
        public override void Visit(ref CCAffineTransform parentWorldTransform)
        {
            if (!Visible || Scene == null)
            {
                return;
            }

            var worldTransform       = CCAffineTransform.Identity;
            var affineLocalTransform = AffineLocalTransform;

            CCAffineTransform.Concat(ref affineLocalTransform, ref parentWorldTransform, out worldTransform);


            if (Grid != null && Grid.Active)
            {
                Grid.BeforeDraw();
            }

            SortAllChildren();

            VisitRenderer(ref worldTransform);

            if (Target != null)
            {
                Target.Visit(ref worldTransform);
            }

            if (Children != null)
            {
                var elements = Children.Elements;
                for (int i = 0, N = Children.Count; i < N; ++i)
                {
                    var child = elements[i];
                    if (child.Visible)
                    {
                        child.Visit(ref worldTransform);
                    }
                }
            }

            if (Grid != null && Grid.Active)
            {
                Grid.AfterDraw(this);
                Renderer.AddCommand(renderGrid);
            }
        }
Exemple #3
0
        private void UpdatePositionTransform()
        {
            // Since we are extending SpriteBatchNode we will have to do our own transforms on the sprites.

            // Translate values
            float x = Position.X;
            float y = Position.Y;

            var affineLocalTransform = CCAffineTransform.Identity;

            if (IgnoreAnchorPointForPosition)
            {
                x += anchorPointInPoints.X;
                y += anchorPointInPoints.Y;
            }

            // Rotation values
            // Change rotation code to handle X and Y
            // If we skew with the exact same value for both x and y then we're simply just rotating
            float cx = 1, sx = 0, cy = 1, sy = 0;

            if (RotationX != 0 || RotationY != 0)
            {
                float radiansX = -CCMacros.CCDegreesToRadians(RotationX);
                float radiansY = -CCMacros.CCDegreesToRadians(RotationY);
                cx = (float)Math.Cos(radiansX);
                sx = (float)Math.Sin(radiansX);
                cy = (float)Math.Cos(radiansY);
                sy = (float)Math.Sin(radiansY);
            }

            bool needsSkewMatrix = (SkewX != 0f || SkewY != 0f);

            // optimization:
            // inline anchor point calculation if skew is not needed
            if (!needsSkewMatrix && !anchorPointInPoints.Equals(CCPoint.Zero))
            {
                x += cy * -anchorPointInPoints.X * ScaleX + -sx * -anchorPointInPoints.Y * ScaleY;
                y += sy * -anchorPointInPoints.X * ScaleX + cx * -anchorPointInPoints.Y * ScaleY;
            }

            // Build Transform Matrix
            // Adjusted transform calculation for rotational skew
            affineLocalTransform.A  = cy * ScaleX;
            affineLocalTransform.B  = sy * ScaleX;
            affineLocalTransform.C  = -sx * ScaleY;
            affineLocalTransform.D  = cx * ScaleY;
            affineLocalTransform.Tx = x;
            affineLocalTransform.Ty = y;

            // XXX: Try to inline skew
            // If skew is needed, apply skew and then anchor point
            if (needsSkewMatrix)
            {
                var skewMatrix = new CCAffineTransform(
                    1.0f, (float)Math.Tan(CCMacros.CCDegreesToRadians(SkewY)),
                    (float)Math.Tan(CCMacros.CCDegreesToRadians(SkewX)), 1.0f,
                    0.0f, 0.0f);

                affineLocalTransform = CCAffineTransform.Concat(skewMatrix, affineLocalTransform);

                // adjust anchor point
                if (!anchorPointInPoints.Equals(CCPoint.Zero))
                {
                    affineLocalTransform = CCAffineTransform.Translate(affineLocalTransform,
                                                                       -anchorPointInPoints.X,
                                                                       -anchorPointInPoints.Y);
                }
            }

            if (Children != null && Children.Count != 0)
            {
                CCNode[] elements = Children.Elements;
                for (int i = 0, count = Children.Count; i < count; i++)
                {
                    var sprite = elements[i] as CCSprite;
                    if (sprite.Visible)
                    {
                        var pos = affineLocalTransform.Transform(sprite.Position);

                        sprite.PositionX = pos.X;
                        sprite.PositionY = pos.Y;
                        sprite.ScaleX    = ScaleX;
                        sprite.ScaleY    = ScaleY;
                        sprite.SkewX     = SkewX;
                        sprite.SkewY     = SkewY;
                    }
                }
            }
        }
 public void Concat(ref CCAffineTransform m)
 {
     CCAffineTransform.Concat(ref this, ref m, out this);
 }