Exemplo n.º 1
0
        public void Draw(Duality.Drawing.IDrawDevice device)
        {
            Canvas canvas = new Canvas(device, buffer);

            DrawScore(canvas);
            DrawDrill(canvas);
        }
Exemplo n.º 2
0
        public void Draw(Duality.Drawing.IDrawDevice device)
        {
            // Find out about the into-camera-space transformation at the object's position
            this.posTemp   = device.RefCoord;
            this.posTemp.Z = Z;

            this.scaleTemp = 1.0f;
            device.PreprocessCoords(ref this.posTemp, ref this.scaleTemp);

            // Define the rect we're going to render
            backgroundSize   = device.TargetSize / this.scaleTemp;
            backgroundSize.X = backgroundSize.Y = MathF.Max(backgroundSize.X, backgroundSize.Y);

            Rect rectTemp = new Rect(backgroundSize * 2).WithOffset(-backgroundSize);

            this.topLeft     = rectTemp.TopLeft;
            this.bottomLeft  = rectTemp.BottomLeft;
            this.bottomRight = rectTemp.BottomRight;
            this.topRight    = rectTemp.TopRight;

            // Apply object rotation and (object + perspective) scale
            Vector2 xDot, yDot;

            MathF.GetTransformDotVec(0, scaleTemp, out xDot, out yDot);

            MathF.TransformDotVec(ref this.topLeft, ref xDot, ref yDot);
            MathF.TransformDotVec(ref this.bottomLeft, ref xDot, ref yDot);
            MathF.TransformDotVec(ref this.bottomRight, ref xDot, ref yDot);
            MathF.TransformDotVec(ref this.topRight, ref xDot, ref yDot);

            // Define vertices. Note how we completely ignore the XY position from PreprocessCoords above.
            // We just render out rect as we intended. It floats around as if stuck on the screen.
            uvDelta = (device.RefCoord.Xy - lastPosition) / (backgroundSize) * device.GetScaleAtZ(Z);

            this.vertices[0].Pos.Xy    = this.topLeft;
            this.vertices[0].Pos.Z     = this.posTemp.Z;
            this.vertices[0].TexCoord += this.uvDelta;
            this.vertices[0].Color     = this.ColorTint;

            this.vertices[1].Pos.Xy    = this.bottomLeft;
            this.vertices[1].Pos.Z     = this.posTemp.Z;
            this.vertices[1].TexCoord += this.uvDelta;
            this.vertices[1].Color     = this.ColorTint;

            this.vertices[2].Pos.Xy    = this.bottomRight;
            this.vertices[2].Pos.Z     = this.posTemp.Z;
            this.vertices[2].TexCoord += this.uvDelta;
            this.vertices[2].Color     = this.ColorTint;

            this.vertices[3].Pos.Xy    = this.topRight;
            this.vertices[3].Pos.Z     = this.posTemp.Z;
            this.vertices[3].TexCoord += this.uvDelta;
            this.vertices[3].Color     = this.ColorTint;

            device.AddVertices(Material.Checkerboard, VertexMode.Quads, this.vertices);
            this.lastPosition = device.RefCoord.Xy;
        }
Exemplo n.º 3
0
 public bool IsVisible(Duality.Drawing.IDrawDevice device)
 {
     if ((device.VisibilityMask & VisibilityFlag.ScreenOverlay) == VisibilityFlag.None)
     {
         return(false);
     }
     if ((device.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 4
0
        public void Draw(Duality.Drawing.IDrawDevice device)
        {
            // Find out about the into-camera-space transformation at the object's position
            this.posTemp = this.transform.Pos;

            // Vertical or Both
            if (this.Scrolling != ScrollingMode.Horiziontal)
            {
                this.posTemp.Y = device.RefCoord.Y;
            }
            // Horizontal or Both
            if (this.Scrolling != ScrollingMode.Vertical)
            {
                this.posTemp.X = device.RefCoord.X;
            }

            this.scaleTemp = 1.0f;
            device.PreprocessCoords(ref this.posTemp, ref this.scaleTemp);

            Vector2 textureSize = Vector2.One;
            Vector2 uvSize      = Vector2.Zero;

            if (this.CustomMaterial.IsAvailable)
            {
                textureSize = this.CustomMaterial.Res.MainTexture.Res.Size;
                uvSize      = this.CustomMaterial.Res.MainTexture.Res.UVRatio;
            }
            else
            {
                textureSize = this.SharedMaterial.Res.MainTexture.Res.Size;
                uvSize      = this.SharedMaterial.Res.MainTexture.Res.UVRatio;
            }

            // How big will the texture appear on screen
            Vector2 textureScaled = textureSize * this.transform.Scale * this.scaleTemp;

            // and how much will we have to scale it to make it fill the screen
            Vector2 textureScale = device.TargetSize / textureScaled;

            // Multiply by 2 to be sure that the sprite doesn't end exactly on the side of the screen
            // (for rotation purposes)
            if (this.Scrolling != ScrollingMode.Horiziontal)
            {
                textureSize.Y *= textureScale.Y * 2;
            }
            if (this.Scrolling != ScrollingMode.Vertical)
            {
                textureSize.X *= textureScale.X * 2;
            }

            Rect rectTemp = new Rect(textureSize).WithOffset(-textureSize / 2);

            this.topLeft     = rectTemp.TopLeft;
            this.bottomLeft  = rectTemp.BottomLeft;
            this.bottomRight = rectTemp.BottomRight;
            this.topRight    = rectTemp.TopRight;

            // Calculate the "actual" texture size on screen
            textureSize *= this.transform.Scale * this.scaleTemp;

            this.uvDelta = uvSize / textureScaled;
            uvSize      *= textureSize / textureScaled;

            uvDelta *= (device.RefCoord.Xy - this.Offset);
            if (this.Scrolling == ScrollingMode.Horiziontal)
            {
                this.uvDelta.Y = 0;
            }
            if (this.Scrolling == ScrollingMode.Vertical)
            {
                this.uvDelta.X = 0;
            }

            Rect uvRect = new Rect(uvSize).WithOffset(-uvSize / 2);

            if (this.Scrolling == ScrollingMode.Horiziontal)
            {
                uvRect = uvRect.WithOffset(0, uvSize.Y / 2);
            }
            if (this.Scrolling == ScrollingMode.Horiziontal)
            {
                uvRect = uvRect.WithOffset(uvSize.X / 2, 0);
            }

            this.uvDelta *= this.transform.Scale * this.scaleTemp * this.ScrollingMultiplier;

            // Apply object rotation and (object + perspective) scale
            Vector2 xDot, yDot;

            MathF.GetTransformDotVec(this.transform.Angle, this.transform.Scale * this.scaleTemp, out xDot, out yDot);

            MathF.TransformDotVec(ref this.topLeft, ref xDot, ref yDot);
            MathF.TransformDotVec(ref this.bottomLeft, ref xDot, ref yDot);
            MathF.TransformDotVec(ref this.bottomRight, ref xDot, ref yDot);
            MathF.TransformDotVec(ref this.topRight, ref xDot, ref yDot);

            // Define vertices.
            this.vertices[0].Pos.X    = this.posTemp.X + this.topLeft.X;
            this.vertices[0].Pos.Y    = this.posTemp.Y + this.topLeft.Y;
            this.vertices[0].Pos.Z    = this.posTemp.Z;
            this.vertices[0].TexCoord = uvRect.TopLeft + this.uvDelta;
            this.vertices[0].Color    = this.ColorTint;

            this.vertices[1].Pos.X    = this.posTemp.X + this.bottomLeft.X;
            this.vertices[1].Pos.Y    = this.posTemp.Y + this.bottomLeft.Y;
            this.vertices[1].Pos.Z    = this.posTemp.Z;
            this.vertices[1].TexCoord = uvRect.BottomLeft + this.uvDelta;
            this.vertices[1].Color    = this.ColorTint;

            this.vertices[2].Pos.X    = this.posTemp.X + this.bottomRight.X;
            this.vertices[2].Pos.Y    = this.posTemp.Y + this.bottomRight.Y;
            this.vertices[2].Pos.Z    = this.posTemp.Z;
            this.vertices[2].TexCoord = uvRect.BottomRight + this.uvDelta;
            this.vertices[2].Color    = this.ColorTint;

            this.vertices[3].Pos.X    = this.posTemp.X + this.topRight.X;
            this.vertices[3].Pos.Y    = this.posTemp.Y + this.topRight.Y;
            this.vertices[3].Pos.Z    = this.posTemp.Z;
            this.vertices[3].TexCoord = uvRect.TopRight + this.uvDelta;
            this.vertices[3].Color    = this.ColorTint;

            if (this.AlignToPixelGrid)
            {
                this.vertices[0].Pos.X = MathF.Round(this.vertices[0].Pos.X);
                this.vertices[1].Pos.X = MathF.Round(this.vertices[1].Pos.X);
                this.vertices[2].Pos.X = MathF.Round(this.vertices[2].Pos.X);
                this.vertices[3].Pos.X = MathF.Round(this.vertices[3].Pos.X);

                if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
                {
                    this.vertices[0].Pos.X += 0.5f;
                    this.vertices[1].Pos.X += 0.5f;
                    this.vertices[2].Pos.X += 0.5f;
                    this.vertices[3].Pos.X += 0.5f;
                }

                this.vertices[0].Pos.Y = MathF.Round(this.vertices[0].Pos.Y);
                this.vertices[1].Pos.Y = MathF.Round(this.vertices[1].Pos.Y);
                this.vertices[2].Pos.Y = MathF.Round(this.vertices[2].Pos.Y);
                this.vertices[3].Pos.Y = MathF.Round(this.vertices[3].Pos.Y);

                if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
                {
                    this.vertices[0].Pos.Y += 0.5f;
                    this.vertices[1].Pos.Y += 0.5f;
                    this.vertices[2].Pos.Y += 0.5f;
                    this.vertices[3].Pos.Y += 0.5f;
                }
            }

            if (this.CustomMaterial.IsAvailable)
            {
                device.AddVertices(this.CustomMaterial, VertexMode.Quads, this.vertices);
            }
            else
            {
                device.AddVertices(this.SharedMaterial, VertexMode.Quads, this.vertices);
            }
        }
Exemplo n.º 5
0
 public bool IsVisible(Duality.Drawing.IDrawDevice device)
 {
     return((device.VisibilityMask & VisibilityFlag.AllGroups) != VisibilityFlag.None &&
            (device.VisibilityMask & VisibilityFlag.ScreenOverlay) == VisibilityFlag.None);
 }