コード例 #1
0
ファイル: TextureAtlas.cs プロジェクト: peon501/GTA2.NET
        protected virtual CompactRectangle Place(ImageEntry entry)
        {
            var source = GetBitmapFromZip(ZipStore, entry.ZipEntryIndex);

            Graphics.DrawImageUnscaled(source, entry.X + Padding, entry.Y + Padding);
            var rect = new CompactRectangle(entry.X + Padding, entry.Y + Padding, entry.Width - 2 * Padding, entry.Height - 2 * Padding);

            source.Dispose();
            return(rect);
        }
コード例 #2
0
        /// <summary>
        /// Gets a sprite from a position
        /// </summary>
        /// <param name="spriteID">The position of the sprite to get</param>
        /// <returns>A array with 4 positions where each position represent one of the vertices's of the sprite</returns>
        public Vector2[] GetSprite(UInt32 spriteID)
        {
            Vector2[] texturePosition = new Vector2[4];
            CompactRectangle tex = tileAtlas[(int)spriteID].Rectangle;

            texturePosition[3] = new Vector2((tex.X + 1) * pixelPerWidth, (tex.Y + 1) * pixelPerHeight);
            texturePosition[2] = new Vector2((tex.X + tex.Width - 1) * pixelPerWidth, (tex.Y + 1) * pixelPerHeight);
            texturePosition[0] = new Vector2((tex.X + 1) * pixelPerWidth, (tex.Y + tex.Height - 1) * pixelPerHeight);
            texturePosition[1] = new Vector2((tex.X + tex.Width - 1) * pixelPerWidth, (tex.Y + tex.Height - 1) * pixelPerHeight);

            return texturePosition;
        }
コード例 #3
0
ファイル: DeltaSubItem.cs プロジェクト: spritefun/gta2net
 public DeltaSubItem(DeltaType type, int width, int height)
 {
     Type = type;
     Rectangle = new CompactRectangle(0, 0, width, height);
 }
コード例 #4
0
ファイル: GameObject.cs プロジェクト: spritefun/gta2net
 /// <summary>
 /// Creates a instance of GameObject
 /// </summary>
 /// <param name="startUpPosition">The initial position for the object</param>
 /// <param name="startUpRotation">The initial rotation of the object</param>
 /// <param name="shape">The shape of the object</param>
 protected GameObject(Vector3 startUpPosition, float startUpRotation, CompactRectangle shape)
 {
     drawCoordinates = new FaceCoordinates(startUpPosition, shape.Width, shape.Height);
     Position3 = startUpPosition;
     RotationAngle = startUpRotation;
     this.shape = shape;
     this.spriteID = 0;
     verticesCollection = new List<VertexPositionNormalTexture>();
     indicesCollection = new List<int>();
 }
コード例 #5
0
ファイル: SpriteForm.cs プロジェクト: jpires/gta2net
 private static int DetectPalette(LockBitmap palettes, LockBitmap lockBmp, CompactRectangle rect)
 {
     var max = 0;
     var value = -1;
     var dict = new Dictionary<int, List<Color>>();
     for (var i = 0; i < palettes.Width; i++)
     {
         dict.Add(i, new List<Color>());
         for (var x = rect.X; x < rect.X + rect.Width; x++)
         {
             for (var y = rect.Y; y < rect.Y + rect.Height; y++)
             {
                 var orgColor = lockBmp.GetPixel(x, y);
                 for (var c = 0; c < 256; c++)
                 {
                     if (orgColor != palettes.GetPixel(i, c))
                         continue;
                     if (!dict[i].Contains(orgColor))
                         dict[i].Add(orgColor);
                     if (dict[i].Count <= max)
                         continue;
                     value = i;
                     max = dict[i].Count;
                 }
             }
         }
     }
     return value;
 }
コード例 #6
0
 /// <summary>
 /// Creates an instance of ControlableGameObject.
 /// </summary>
 /// <param name="startUpPosition">The initial position for the object.</param>
 /// <param name="startUpRotation">The initial rotation of the object.</param>
 /// <param name="shape">The shape for this object.</param>
 protected ControlableGameObject(Vector3 startUpPosition, float startUpRotation, CompactRectangle shape)
     : base(startUpPosition, startUpRotation, shape)
 {
 }
コード例 #7
0
ファイル: TextureAtlas.cs プロジェクト: peon501/GTA2.NET
        protected override void BuildTextureAtlas(CancellableContext context, out bool cancelled)
        {
            var entries = CreateImageEntries(context, out cancelled);

            if (cancelled)
            {
                return;
            }

            // Sort so the largest sprites get arranged first.
            var comparer = new ImageEntryComparer {
                CompareSize = true
            };

            entries.Sort(comparer);

            var outputWidth  = GuessOutputWidth(entries);
            var outputHeight = GuessOutputHeight(entries, outputWidth);

            if (context.IsCancelling)
            {
                cancelled = true;
                return;
            }

            // Sort the sprites back into index order.
            comparer.CompareSize = false;
            entries.Sort(comparer);

            var root = new Node(0, 0, outputWidth, outputHeight);

            CreateOutputBitmap(outputWidth, outputHeight);

            var itemsToRemove = new List <ItemToRemove>();

            foreach (var entry in entries)
            {
                if (context.IsCancelling)
                {
                    cancelled = true;
                    return;
                }

                CompactRectangle rect;
                if (entry.SameImageIndex == 0)
                {
                    if (entry.Width * entry.Height > 0)
                    {
                        var node = root.Insert(entry.Width, entry.Height);
                        if (node == null)
                        {
                            continue; //ToDo: the picture could not be inserted because there were not enough space. Increase the output image?
                        }
                        entry.X = node.Rectangle.X;
                        entry.Y = node.Rectangle.Y;
                        rect    = Place(entry);
                    }
                    else
                    {
                        rect = new CompactRectangle();
                    }
                }
                else
                {
                    var sameEntry         = entries[entry.SameImageIndex];
                    var sameSpriteDeltaId = _deltaIndexDictionary[sameEntry.FileName];
                    var sameSpriteId      = sameSpriteDeltaId[0];
                    var sameDeltaIndex    = sameSpriteDeltaId[1];
                    rect = DeltaDictionary[sameSpriteId].SubItems[sameDeltaIndex].Rectangle;
                }

                var spriteDeltaId = _deltaIndexDictionary[entry.FileName];
                var spriteId      = spriteDeltaId[0];
                var deltaIndex    = spriteDeltaId[1];
                var subDeltaItem  = DeltaDictionary[spriteId].SubItems[deltaIndex];
                if (entry.Width * entry.Height > 0)
                {
                    var cachedRect = _cachedRectDictionary[entry.SameImageIndex == 0 ? entry.ZipEntryIndex : entry.SameImageIndex];
                    subDeltaItem.RelativePosition = new Point(cachedRect.X, cachedRect.Y);
                    subDeltaItem.Rectangle        = rect;
                }
                else
                {
                    var itemToRemove = new ItemToRemove {
                        SpriteId = spriteId, DeltaSubItem = subDeltaItem
                    };
                    itemsToRemove.Add(itemToRemove);
                }
            }

            foreach (var itemToRemove in itemsToRemove)
            {
                var deltaIndexToRemove = -1;
                for (var i = 0; i < DeltaDictionary[itemToRemove.SpriteId].SubItems.Count; i++)
                {
                    if (DeltaDictionary[itemToRemove.SpriteId].SubItems[i].Type != itemToRemove.DeltaSubItem.Type)
                    {
                        continue;
                    }
                    deltaIndexToRemove = i;
                    break;
                }
                if (deltaIndexToRemove > -1)
                {
                    DeltaDictionary[itemToRemove.SpriteId].SubItems.RemoveAt(deltaIndexToRemove);
                }
            }

            Image.Save(Globals.GraphicsSubDir + Path.DirectorySeparatorChar + ImagePath, ImageFormat.Png);
            Serialize(Globals.GraphicsSubDir + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(ImagePath) + Globals.XmlFormat);
        }