All pastes #777884 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-11-17 02:31 UTC
rendered paste body
            for (int y = startY; y < maxY; y++)
            {
                for (int x = startX; x < maxX; x++)
                {
                    count++;
                    Vector3 drawOffset = new Vector3();
                    Tile tile = tileMatrix.GetLandTile(x, y);

                    int xIndex = x - startX;
                    int yIndex = y - startY;

                    drawOffset.X = xIndex * 44;
                    drawOffset.Y = yIndex * 44;

                    int z = (tile.Z << 2);

                    int vertexIndex = (staticsOffset + ((yIndex * displaySize) + (xIndex))) * 6;
                    int textureIndex = (staticsOffset + ((yIndex * displaySize) + (xIndex)));

                    drawSets[textureIndex].Id = tile.ID;
                    drawSets[textureIndex].DrawType = DrawType.Texture;

                    Artwork.EnsureTextmap(GraphicsDevice, tile.ID);

                    Tile eastTile = tileMatrix.GetLandTile(x + 1, y);//right
                    Tile southTile = tileMatrix.GetLandTile(x, y + 1);//bottom
                    Tile downTile = tileMatrix.GetLandTile(x + 1, y + 1);//bottom right

                    int east = (eastTile.Z - tile.Z) << 2;
                    int south = (southTile.Z - tile.Z) << 2;
                    int down = (downTile.Z - tile.Z) << 2;

                    vertices[vertexIndex].Position = drawOffset + new Vector3(0 - z, 0 - z, 0);
                    vertices[vertexIndex].TextureCoordinate = new Vector2(0, 0);
                    vertices[vertexIndex + 1].Position = drawOffset + new Vector3(44 - z - east, 0 - z - east, 0);
                    vertices[vertexIndex + 1].TextureCoordinate = new Vector2(1, 0);
                    vertices[vertexIndex + 2].Position = drawOffset + new Vector3(44 - z - down, 44 - z - down, 0);
                    vertices[vertexIndex + 2].TextureCoordinate = new Vector2(1, 1);
                    vertices[vertexIndex + 3].Position = drawOffset + new Vector3(0 - z - south, 44 - z - south, 0);
                    vertices[vertexIndex + 3].TextureCoordinate = new Vector2(0, 1);
                    vertices[vertexIndex + 4] = vertices[vertexIndex];
                    vertices[vertexIndex + 5] = vertices[vertexIndex + 2];

                    HuedTile[] statics = SortStatics(tileMatrix.GetStaticTiles(x, y));                   

                    for (int i = 0; i < statics.Length; i++, staticsOffset++, count++)
                    {
                        int staticIndex = (vertexIndex + 6) + (i * 6);
                        textureIndex++;

                        int heightOffset = 0;

                        for (int a = 0; a < i; a++)
                        {
                            heightOffset = TileData.ItemTable[statics[a].ID & 0x3FFF].CalcHeight;
                        }
                                                
                        drawSets[textureIndex].Id = statics[i].ID;
                        drawSets[textureIndex].DrawType = DrawType.Static;

                        Artwork.EnsureStatic(GraphicsDevice, statics[i].ID);
                        Texture2D texture = Artwork.GetTexture(statics[i].ID, DrawType.Static);

                        z = (heightOffset + statics[i].Z) << 2;

                        Vector3[] srcVectors = new Vector3[4];

                        float width = texture.Width * 1.40f;
                        float height = texture.Height * 1.40f;

                        Vector3 rotationPoint = new Vector3(-width / 2, -height / 2, 0);
                        Matrix rotationMatrix = Matrix.CreateTranslation(rotationPoint) *
                            Matrix.CreateRotationZ(MathHelper.ToRadians(-45));

                        srcVectors[0] = Vector3.Transform(new Vector3(0, 0 - z, 0), rotationMatrix);
                        srcVectors[1] = Vector3.Transform(new Vector3(width, 0 - z, 0), rotationMatrix);
                        srcVectors[2] = Vector3.Transform(new Vector3(width, height - z, 0), rotationMatrix);
                        srcVectors[3] = Vector3.Transform(new Vector3(0, height - z, 0), rotationMatrix);

                        vertices[staticIndex + 0].Position = drawOffset + srcVectors[0];
                        vertices[staticIndex + 1].Position = drawOffset + srcVectors[1];
                        vertices[staticIndex + 2].Position = drawOffset + srcVectors[2];
                        vertices[staticIndex + 3].Position = drawOffset + srcVectors[3];

                        vertices[staticIndex + 0].TextureCoordinate = new Vector2(0, 0);
                        vertices[staticIndex + 1].TextureCoordinate = new Vector2(1, 0);
                        vertices[staticIndex + 2].TextureCoordinate = new Vector2(1, 1);
                        vertices[staticIndex + 3].TextureCoordinate = new Vector2(0, 1);

                        vertices[staticIndex + 4] = vertices[staticIndex + 0];
                        vertices[staticIndex + 5] = vertices[staticIndex + 2];
                    }
                }
            }