Exemplo n.º 1
0
        private static EntityGeometry Billboard(EntityData data, Texture2D propTexture)
        {
            ITextureDefintion texture = DefaultTextureDefinition.Instance;
            var textures = data.Textures;

            if (textures != null && textures.Length > 0)
            {
                texture = new TextureRectangle(textures[0], propTexture);
            }

            var size     = data.Size2;
            var vertices = RectangleComposer.Create(1f, 1f, texture);

            VertexTransformer.Rotate(vertices, new Vector3(data.billboardTilt, 0, 0));
            VertexTransformer.Scale(vertices, new Vector3(size.X, size.Y, 1f));
            if (size.Y != 1f)
            {
                VertexTransformer.Offset(vertices, new Vector3(0, (size.Y - 1f) / 2f, 0));
            }

            var geometry = new EntityGeometry
            {
                Vertices = vertices,
                Heights  = new[] { size.Y, size.Y, size.Y, size.Y },
                Size     = new Vector3(size.X, size.Y, size.X)
            };

            return(geometry);
        }
Exemplo n.º 2
0
        protected override void CreateGeometry()
        {
            var vertices = RectangleComposer.Create(1f, 1f);

            VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, 0, 0));
            Geometry.AddVertices(vertices);
        }
Exemplo n.º 3
0
        private static EntityGeometry Plane(EntityData data, Texture2D propTexture)
        {
            var size = data.Size2;

            ITextureDefintion texture = DefaultTextureDefinition.Instance;
            var textures = data.Textures;

            if (textures != null && textures.Length > 0)
            {
                var rect = textures[0];
                if (data.tileTexture)
                {
                    rect.Width  = (int)(rect.Width * size.X);
                    rect.Height = (int)(rect.Height * size.Y);
                }
                texture = new TextureRectangle(rect, propTexture);
            }
            else
            {
                if (data.tileTexture)
                {
                    texture = new TextureRectangle(0, 0, size.X, size.Y);
                }
            }

            VertexPositionNormalTexture[] vertices;
            float[] heights;

            var floorOffset = -0.5f;

            if (data.elevation == null || data.elevation.Length < 4)
            {
                vertices = RectangleComposer.Create(size.X, size.Y, texture);
                VertexTransformer.Offset(vertices, new Vector3(0, floorOffset, 0));
                heights = new float[] { 0, 0, 0, 0 };
            }
            else
            {
                var halfWidth  = size.X / 2f;
                var halfHeight = size.Y / 2f;
                vertices = RectangleComposer.Create(new[]
                {
                    new Vector3(-halfWidth, data.elevation[0] + floorOffset, -halfHeight),
                    new Vector3(halfWidth, data.elevation[1] + floorOffset, -halfHeight),
                    new Vector3(-halfWidth, data.elevation[2] + floorOffset, halfHeight),
                    new Vector3(halfWidth, data.elevation[3] + floorOffset, halfHeight),
                }, texture);
                heights = new float[] { data.elevation[0], data.elevation[1], data.elevation[2], data.elevation[3] };
            }

            var geometry = new EntityGeometry
            {
                Vertices = vertices,
                Heights  = heights,
                Size     = new Vector3(size.X, 1, size.Y)
            };

            return(geometry);
        }
Exemplo n.º 4
0
        protected override void CreateGeometry()
        {
            var random    = new Random();
            var halfWidth = _width / 2f;
            var halfDepth = _depth / 2f;

            for (var y = 0; y < _height; y += 2)
            {
                for (var z = 0; z < _depth; z += 2)
                {
                    var textureIndex = 0;
                    if (z % 3 != 0)
                    {
                        textureIndex = random.Next(1, 3);
                    }

                    Geometry.AddVertices(RectangleComposer.Create(new[]
                    {
                        new Vector3(-halfWidth - 1f, y + 1f, z - 1f - halfDepth),
                        new Vector3(-halfWidth - 1f, y + 1f, z + 1f - halfDepth),
                        new Vector3(-halfWidth - 1f, y - 1f, z - 1f - halfDepth),
                        new Vector3(-halfWidth - 1f, y - 1f, z + 1f - halfDepth),
                    }, new GeometryTextureIndex(textureIndex)));

                    Geometry.AddVertices(RectangleComposer.Create(new[]
                    {
                        new Vector3(halfWidth - 1f, y + 1f, z - 1f - halfDepth),
                        new Vector3(halfWidth - 1f, y + 1f, z + 1f - halfDepth),
                        new Vector3(halfWidth - 1f, y - 1f, z - 1f - halfDepth),
                        new Vector3(halfWidth - 1f, y - 1f, z + 1f - halfDepth),
                    }, new GeometryTextureIndex(textureIndex)));
                }
                for (var x = 0; x < _width; x += 2)
                {
                    var textureIndex = 0;
                    if (x % 3 != 0)
                    {
                        textureIndex = random.Next(1, 3);
                    }

                    Geometry.AddVertices(RectangleComposer.Create(new[]
                    {
                        new Vector3(x - 1f - halfWidth, y + 1f, -halfDepth - 1f),
                        new Vector3(x + 1f - halfWidth, y + 1f, -halfDepth - 1f),
                        new Vector3(x - 1f - halfWidth, y - 1f, -halfDepth - 1f),
                        new Vector3(x + 1f - halfWidth, y - 1f, -halfDepth - 1f),
                    }, new GeometryTextureIndex(textureIndex)));

                    Geometry.AddVertices(RectangleComposer.Create(new[]
                    {
                        new Vector3(x - 1f - halfWidth, y + 1f, halfDepth - 1f),
                        new Vector3(x + 1f - halfWidth, y + 1f, halfDepth - 1f),
                        new Vector3(x - 1f - halfWidth, y - 1f, halfDepth - 1f),
                        new Vector3(x + 1f - halfWidth, y - 1f, halfDepth - 1f),
                    }, new GeometryTextureIndex(textureIndex)));
                }
            }
        }
Exemplo n.º 5
0
        private static EntityGeometry HouseInside(EntityData data, Texture2D propTexture)
        {
            ITextureDefintion texture = DefaultTextureDefinition.Instance;
            var textures = data.Textures;

            if (textures != null && textures.Length > 0)
            {
                texture = new TextureRectangle(textures[0], propTexture);
            }

            var size        = data.Size3;
            var allVertices = new List <VertexPositionNormalTexture>();

            // back
            {
                var vertices = RectangleComposer.Create(1f, 1f, texture);
                VertexTransformer.Scale(vertices, new Vector3(size.X, size.Y, 1f));
                VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, 0, 0));
                VertexTransformer.Offset(vertices, new Vector3(0, 0, -size.Z / 2f));
                allVertices.AddRange(vertices);
            }
            // left
            {
                var vertices = RectangleComposer.Create(1f, 1f, texture);
                VertexTransformer.Scale(vertices, new Vector3(size.Z, size.Y, 1f));
                VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, MathHelper.PiOver2, 0));
                VertexTransformer.Offset(vertices, new Vector3(-size.X / 2f, 0, 0));
                allVertices.AddRange(vertices);
            }
            // right
            {
                var vertices = RectangleComposer.Create(1f, 1f, texture);
                VertexTransformer.Scale(vertices, new Vector3(size.Z, size.Y, 1f));
                VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, -MathHelper.PiOver2, 0));
                VertexTransformer.Offset(vertices, new Vector3(size.X / 2f, 0, 0));
                allVertices.AddRange(vertices);
            }
            // floor
            {
                var vertices = RectangleComposer.Create(1f, 1f, texture);
                VertexTransformer.Scale(vertices, new Vector3(size.X, 1f, size.Z));
                VertexTransformer.Offset(vertices, new Vector3(0, -0.499f, 0)); // do not put 0.5 to not interfer with floors
                allVertices.AddRange(vertices);
            }

            var geometry = new EntityGeometry
            {
                Vertices = allVertices.ToArray(),
                Heights  = new[] { size.Y, size.Y, size.Y, size.Y },
                Size     = new Vector3(size.X, size.Y, size.Z)
            };

            return(geometry);
        }
Exemplo n.º 6
0
        protected override void CreateGeometry()
        {
            Geometry.AddVertices(RectangleComposer.Create(new[]
            {
                new Vector3(-0.5f, 0.25f, -0.25f),
                new Vector3(0.5f, 0.25f, -0.25f),
                new Vector3(-0.5f, -0.25f, 0),
                new Vector3(0.5f, -0.25f, 0),
            }));

            var textureRectangle = new GeometryTextureRectangle(new Rectangle(1, 1, 1, 1), _texture, 1);

            Geometry.AddVertices(RectangleComposer.Create(new[]
            {
                new Vector3(-0.5f, 0.25f, -0.25f),
                new Vector3(-0.5f, -0.25f, 0),
                new Vector3(-0.5f, 0f, -0.5f),
                new Vector3(-0.5f, -0.25f, -0.4f),
            }, textureRectangle));

            Geometry.AddVertices(RectangleComposer.Create(new[]
            {
                new Vector3(0.5f, 0.25f, -0.25f),
                new Vector3(0.5f, -0.25f, 0),
                new Vector3(0.5f, 0f, -0.5f),
                new Vector3(0.5f, -0.25f, -0.4f),
            }, textureRectangle));

            Geometry.AddVertices(RectangleComposer.Create(new[]
            {
                new Vector3(0.5f, 0.25f, -0.25f),
                new Vector3(0.5f, 0f, -0.5f),
                new Vector3(-0.5f, 0.25f, -0.25f),
                new Vector3(-0.5f, 0f, -0.5f),
            }, textureRectangle));

            Geometry.AddVertices(RectangleComposer.Create(new[]
            {
                new Vector3(0.5f, 0f, -0.5f),
                new Vector3(0.5f, -0.25f, -0.4f),
                new Vector3(-0.5f, 0f, -0.5f),
                new Vector3(-0.5f, -0.25f, -0.4f),
            }, textureRectangle));

            var test = Geometry.Vertices.Select(v => v.TextureIndex).ToArray();
        }
Exemplo n.º 7
0
 protected override void CreateGeometry()
 {
     Geometry.AddVertices(RectangleComposer.Create(new[]
     {
         new Vector3(-4f, 4f, 0f),
         new Vector3(4f, 4f, 0f),
         new Vector3(-4f, -4f, 0f),
         new Vector3(4f, -4f, 0f),
     }));
     Geometry.AddVertices(RectangleComposer.Create(new[]
     {
         new Vector3(0f, 4f, -4f),
         new Vector3(0f, 4f, 4f),
         new Vector3(0f, -4f, -4f),
         new Vector3(0f, -4f, 4f),
     }));
 }
Exemplo n.º 8
0
        private static EntityGeometry Wall(EntityData data, Texture2D propTexture)
        {
            var size = data.Size3;

            ITextureDefintion texture = DefaultTextureDefinition.Instance;
            var textures = data.Textures;

            if (textures != null && textures.Length > 0)
            {
                var rect = textures[0];
                if (data.tileTexture)
                {
                    rect.Width  = (int)(rect.Width * size.X);
                    rect.Height = (int)(rect.Height * size.Y);
                }
                texture = new TextureRectangle(rect, propTexture);
            }
            else
            {
                if (data.tileTexture)
                {
                    texture = new TextureRectangle(0, 0, size.X, size.Y);
                }
            }

            var vertices = RectangleComposer.Create(size.X, size.Y, texture);

            VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, 0, 0));
            VertexTransformer.Offset(vertices, new Vector3(0, 0, 0.5f));

            var geometry = new EntityGeometry
            {
                Vertices = vertices,
                Heights  = new[] { size.Y, size.Y, size.Y, size.Y },
                Size     = new Vector3(size.X, size.Y, size.Z)
            };

            return(geometry);
        }
Exemplo n.º 9
0
        protected override void CreateGeometry()
        {
            var left = RectangleComposer.Create(new[]
            {
                new Vector3(-WIDTH, HEIGHT, 0f),
                new Vector3(0f, HEIGHT, -DEPTH),
                new Vector3(-WIDTH, -HEIGHT, 0f),
                new Vector3(0f, -HEIGHT, -DEPTH),
            },
                                                new GeometryTextureRectangle(0, 0, 0.5f, 1f));

            var right = RectangleComposer.Create(new[]
            {
                new Vector3(0f, HEIGHT, -DEPTH),
                new Vector3(WIDTH, HEIGHT, 0f),
                new Vector3(0f, -HEIGHT, -DEPTH),
                new Vector3(WIDTH, -HEIGHT, 0f),
            },
                                                 new GeometryTextureRectangle(0.5f, 0, 0.5f, 1f));

            Geometry.AddVertices(left);
            Geometry.AddVertices(right);
        }
Exemplo n.º 10
0
        protected override void CreateGeometry()
        {
            var vertices = RectangleComposer.Create(1000f, 1000f);

            Geometry.AddVertices(vertices);
        }
Exemplo n.º 11
0
 protected override void CreateGeometry()
 {
     Geometry.AddVertices(RectangleComposer.Create(1f, 1f));
 }
Exemplo n.º 12
0
        protected override void CreateGeometry()
        {
            var vertices = RectangleComposer.Create(1000f, 1000f, new GeometryTextureMultiplier(1000f));

            Geometry.AddVertices(vertices);
        }
Exemplo n.º 13
0
 protected override void CreateGeometry()
 {
     Geometry.AddVertices(RectangleComposer.Create(_size.X, _size.Y, new GeometryTextureMultiplier(_size)));
 }