Ejemplo n.º 1
0
 public void CopySprite(int x, int y, int z, AnimChunk c)
 {
     for (int xx = 0; xx < c.X_SIZE; xx++)
     {
         for (int yy = 0; yy < c.Y_SIZE; yy++)
         {
             for (int zz = 0; zz < c.Z_SIZE; zz++)
             {
                 if (c.Voxels[xx, yy, zz].Active)
                 {
                     SetVoxel(x + xx, y + ((c.Z_SIZE - 1) - zz), z + yy, true, 0, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void CopySprite(int x, int y, int z, AnimChunk c)
 {
     for (int xx = 0; xx < c.X_SIZE; xx++)
     {
         for (int yy = 0; yy < c.Y_SIZE; yy++)
         {
             for (int zz = 0; zz < c.Z_SIZE; zz++)
             {
                 if (c.Voxels[xx, yy, zz].Active)
                 {
                     SetVoxel(x + xx, y + ((c.Z_SIZE - 1) - zz), z + yy, true, 0, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public void Draw(GraphicsDevice gd)
        {
            drawEffect.World = Matrix.CreateTranslation(Position);

            drawEffect.DiffuseColor = new Vector3(1f, 1f - hitAlpha, 1f - hitAlpha);
            foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                AnimChunk c = shipSprite.AnimChunks[0];
                if (c == null)
                {
                    continue;
                }

                if (c == null || c.VertexArray == null || c.VertexArray.Length == 0)
                {
                    continue;
                }
                gd.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
            }


            drawEffect.World = Matrix.CreateScale(0.75f) * (Matrix.CreateRotationX(orbRotation.X) * Matrix.CreateRotationY(orbRotation.Y) * Matrix.CreateRotationZ(orbRotation.Z)) * Matrix.CreateTranslation(orbPosition);

            drawEffect.DiffuseColor = Color.White.ToVector3();

            foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                AnimChunk c = shipSprite.AnimChunks[1];
                if (c == null)
                {
                    continue;
                }

                if (c == null || c.VertexArray == null || c.VertexArray.Length == 0)
                {
                    continue;
                }
                gd.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
            }
        }
Ejemplo n.º 4
0
        public void CopySprite(int x, int y, int z, AnimChunk c)
        {
            for (int xx = 0; xx < c.X_SIZE; xx++)
            {
                for (int yy = 0; yy < c.Y_SIZE; yy++)
                {
                    for (int zz = 0; zz < c.Z_SIZE; zz++)
                    {
                        if (c.Voxels[xx, yy, zz].Active)
                        {
                            SetVoxel(x + xx, y + ((c.Z_SIZE - 1) - zz), z + yy, true, 1, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                        }
                    }
                }
            }

            AddToUpdateQueue(GetChunkAtWorldPosition(x,y,z));
            if(x>Chunk.X_SIZE) AddToUpdateQueue(GetChunkAtWorldPosition(x-1, y, z));
        }
Ejemplo n.º 5
0
        public void CopySprite(int x, int y, int z, AnimChunk c)
        {
            for (int xx = 0; xx < c.X_SIZE; xx++)
            {
                for (int yy = 0; yy < c.Y_SIZE; yy++)
                {
                    for (int zz = 0; zz < c.Z_SIZE; zz++)
                    {
                        if (c.Voxels[xx, yy, zz].Active)
                        {
                            SetVoxel(x + xx, y + ((c.Z_SIZE - 1) - zz), z + yy, true, 1, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                        }
                    }
                }
            }

            AddToUpdateQueue(GetChunkAtWorldPosition(x, y, z));
            if (x > Chunk.X_SIZE)
            {
                AddToUpdateQueue(GetChunkAtWorldPosition(x - 1, y, z));
            }
        }
Ejemplo n.º 6
0
        public static void LoadSprite(string fn, ref VoxelSprite sprite)
        {
            byte[] buffer;

            using (FileStream gstr = new FileStream(fn, FileMode.Open))
            {
                byte[] lb = new byte[4];
                gstr.Position = gstr.Length - 4;
                gstr.Read(lb, 0, 4);
                int msgLength = BitConverter.ToInt32(lb, 0);

                buffer = new byte[msgLength];

                gstr.Position = 0;

                using (GZipStream str = new GZipStream(gstr, CompressionMode.Decompress))
                {
                    str.Read(buffer, 0, msgLength);
                }
            }

            int pos = 0;

            int xs     = buffer[0];
            int ys     = buffer[1];
            int zs     = buffer[2];
            int frames = buffer[3];

            sprite = new VoxelSprite(xs, ys, zs);
            sprite.AnimChunks.Clear();
            sprite.ChunkRTs.Clear();

            pos = 4;

            for (int i = 0; i < 10; i++)
            {
                // don't need swatches in game!
                pos += 3;
            }


            for (int frame = 0; frame < frames; frame++)
            {
                sprite.AddFrame(false);

                AnimChunk c = sprite.AnimChunks[frame];

                while (pos < buffer.Length)
                {
                    if (Convert.ToChar(buffer[pos]) != 'c')
                    {
                        //str.Seek(-1, SeekOrigin.Current);
                        //str.Read(ba, 0, 10);
                        int   vx  = buffer[pos];
                        int   vy  = buffer[pos + 1];
                        int   vz  = buffer[pos + 2];
                        Color top = new Color(buffer[pos + 3], buffer[pos + 4], buffer[pos + 5]);

                        c.SetVoxel(vx, vy, vz, true, top);
                        pos += 6;
                    }
                    else
                    {
                        pos++;
                        break;
                    }
                }

                c.UpdateMesh();
            }

            GC.Collect();
        }