Esempio n. 1
0
        private void AddNew(object texture, VerticeSpriteSpecific data)
        {
            if (texture == null)
            {
                return;
            }

            lock (_textureSprites) {
                // Create new segment with initial values
                var newSegment = new SpriteSegment {
                    Texture = texture,
                    Sprites = { data }
                };

                _sprites.Add(newSegment);

                // Create reference for segment in dictionary
                if (!_textureSprites.ContainsKey(texture))
                {
                    // Thread.Sleep(100);
                    _textureSprites.Add(texture, new List <SpriteSegment>());
                    // Task.Run(() => AcToolsLogging.Write(s));
                }

                _textureSprites[texture].Add(newSegment);
                _spriteCount++;
                CheckForFullBuffer();
            }
        }
Esempio n. 2
0
        private void AddNew(object texture, VerticeSpriteSpecific data)
        {
            // Create new segment with initial values
            var newSegment = new SpriteSegment {
                Texture = texture,
                Sprites = { data }
            };

            _sprites.Add(newSegment);

            // Create reference for segment in dictionary
            if (!_textureSprites.ContainsKey(texture))
            {
                _textureSprites.Add(texture, new List <SpriteSegment>());
            }

            _textureSprites[texture].Add(newSegment);
            _spriteCount++;
            CheckForFullBuffer();
        }
Esempio n. 3
0
 private void AddIn(SpriteSegment segment, VerticeSpriteSpecific data)
 {
     segment.Sprites.Add(data);
     _spriteCount++;
     CheckForFullBuffer();
 }
Esempio n. 4
0
        /// <summary>
        /// Draws a region of a texture on the screen.
        /// </summary>
        /// <param name="texture">The shader resource view of the texture to draw</param>
        /// <param name="position">Position of the center of the texture in the chosen coordinate system</param>
        /// <param name="size">Size of the texture in the chosen coordinate system. The size is specified in the screen's coordinate system.</param>
        /// <param name="center">Specify the texture's center in the chosen coordinate system. The center is specified in the texture's local coordinate system. E.g. for <paramref name="coordinateType"/>=CoordinateType.SNorm, the texture's center is defined by (0, 0).</param>
        /// <param name="rotationAngle">The angle in radians to rotate the texture. Positive values mean counter-clockwise rotation. Rotations can only be applied for relative or absolute coordinates. Consider using the Degrees or Radians helper structs.</param>
        /// <param name="coordinateType">A custom coordinate system in which to draw the texture</param>
        /// <param name="color">The color with which to multiply the texture</param>
        /// <param name="texCoords">Texture coordinates for the top left corner</param>
        /// <param name="texCoordsSize">Size of the region in texture coordinates</param>
        protected internal void Draw(object texture, Vector2 position, Vector2 size, Vector2 center, double rotationAngle, Vector2 texCoords,
                                     Vector2 texCoordsSize, Color4 color, CoordinateType coordinateType)
        {
            if (texture == null)
            {
                return;
            }

            size.X = Math.Abs(size.X);
            size.Y = Math.Abs(size.Y);

            // Difference vectors from the center to the texture edges (in screen coordinates).
            Vector2 left, up, right, down;

            if (coordinateType == CoordinateType.UNorm)
            {
                left  = new Vector2(0 - center.X * size.X, 0);
                up    = new Vector2(0, 0 - center.Y * size.Y);
                right = new Vector2((1 - center.X) * size.X, 0);
                down  = new Vector2(0, (1 - center.Y) * size.Y);
            }
            else if (coordinateType == CoordinateType.SNorm)
            {
                left  = new Vector2((-1 - center.X) * size.X / 2, 0);
                up    = new Vector2(0, (1 - center.Y) * size.Y / 2);
                right = new Vector2((1 - center.X) * size.X / 2, 0);
                down  = new Vector2(0, (-1 - center.Y) * size.Y / 2);
            }
            else
            {
                left  = new Vector2(-center.X, 0);
                up    = new Vector2(0, -center.Y);
                right = new Vector2(size.X - center.X, 0);
                down  = new Vector2(0, size.Y - center.Y);
            }

            if (rotationAngle != 0)
            {
                if (coordinateType != CoordinateType.Absolute && coordinateType != CoordinateType.Relative)
                {
                    // Normalized coordinates tend to be skewed when applying rotation
                    throw new ArgumentException("Rotation is only allowed for relative or absolute coordinates", nameof(rotationAngle));
                }

                var sine   = (float)Math.Sin(rotationAngle);
                var cosine = (float)Math.Cos(rotationAngle);
                left  = Rotate(left, sine, cosine);
                right = Rotate(right, sine, cosine);
                up    = Rotate(up, sine, cosine);
                down  = Rotate(down, sine, cosine);
            }

            var data = new VerticeSpriteSpecific {
                TexCoord     = texCoords,
                TexCoordSize = texCoordsSize,
                Color        = color.ToArgb(),
                TopLeft      = ConvertCoordinate(position + up + left, coordinateType),
                TopRight     = ConvertCoordinate(position + up + right, coordinateType),
                BottomLeft   = ConvertCoordinate(position + down + left, coordinateType),
                BottomRight  = ConvertCoordinate(position + down + right, coordinateType)
            };

            if (AllowReorder)
            {
                // Is there already a sprite for this texture?
                if (_textureSprites.ContainsKey(texture))
                {
                    // Add the sprite to the last segment for this texture
                    var segment = _textureSprites[texture].Last();
                    AddIn(segment, data);
                }
                else
                {
                    // Add a new segment for this texture
                    AddNew(texture, data);
                }
            }
            else
            {
                // Add a new segment for this texture
                AddNew(texture, data);
            }
        }