Exemple #1
0
 public GroundPlane(Vector3 position, Vector2 size, Shader shader)
 {
     _meshes.Add(new Mesh(
                     PrimitiveUtils.CreateTopVertices(position, size, 0),
                     Enumerable.Empty <Vector2>(), // untextured flat colored plane
                     shader));
 }
 private Mesh CreateTexturedCube(Vector3 position, Vector2 area, float height)
 {
     return(new Mesh(
                PrimitiveUtils.CreateCubeVertices(position, area, height),
                PrimitiveUtils.CreateCubeUVs(),
                new[] { _texture },
                _shader));
 }
        public FullScreenQuad(IEnumerable <Texture> textures, Shader shader)
        {
            _textures = textures;
            _shader   = shader;

            _meshes.Add(new Mesh(
                            PrimitiveUtils.CreateNDCFullscreenGuiVertices(),
                            PrimitiveUtils.CreateNDCFullscreenUVs(),
                            _textures,
                            _shader));
        }
        private void CreateBackLight()
        {
            var vertices = PrimitiveUtils.CreateFrontVertices(new Vector3(0), new Vector2(2), 1);
            var uvs      = PrimitiveUtils.CreateFrontUvs();

            var mesh = new Mesh(vertices, uvs, _rearLightShader)
            {
                IsInstanced = true
            };

            _meshes.Add(mesh);
        }
        private void CreateHeadLight()
        {
            var vertices = PrimitiveUtils.CreateBacksideVertices(new Vector3(0), new Vector2(2), 1);
            var uvs      = PrimitiveUtils.CreateBackUVs();

            var mesh = new Mesh(vertices, uvs, _headlightShader)
            {
                IsInstanced = true
            };

            _meshes.Add(mesh);
        }
        public Billboard CreateWestFacingBillboard(Vector3 position, Vector2 area, float height)
        {
            var texture = _billboardTextures.ElementAt(_random.Next(_billboardTextures.Length));
            var width   = CalculateBillboardWidth(height);

            area.Y      = width;
            position.X -= 0.05f;

            return(new Billboard(
                       texture,
                       _shader,
                       PrimitiveUtils.CreateLeftVertices(position, area, height),
                       PrimitiveUtils.CreateLeftUVs()));
        }
Exemple #7
0
        public IEnumerable <IRenderable> CreateStreetLights(IEnumerable <GroundNode> sites)
        {
            var lightColor = _lightColors[_random.Next(_lightColors.Count)];

            _lightShader.SetUniformValue("u_color", new Vector3Uniform
            {
                Value = lightColor
            });
            _logger.Information($"Set streetlight color to: {lightColor}");

            var areaBorder = new Vector2(_config.AreaBorderSize - 4);
            var lightSize  = new Vector2(2, 2);

            foreach (var site in sites)
            {
                var position = new Vector3(site.StartPosition.X + areaBorder.X, 0, site.StartPosition.Y + areaBorder.Y);
                var area     = site.EndPosition - site.StartPosition - (areaBorder * 2);

                for (int i = (int)position.X + 2 + 1; i <= position.X + area.X; i += 12)
                {
                    var northPosition = new Vector3(i, position.Y, position.Z);
                    var northVertices = PrimitiveUtils.CreateTopVertices(northPosition, lightSize, 0.2f);
                    var northUvs      = PrimitiveUtils.CreateTopUVs(1, 1);

                    yield return(new StreetLightStrip(northVertices, northUvs, _lightShader));

                    var southPosition = new Vector3(i, position.Y, position.Z + area.Y + 2);
                    var southVertices = PrimitiveUtils.CreateTopVertices(southPosition, lightSize, 0.2f);
                    var southUvs      = PrimitiveUtils.CreateTopUVs(1, 1);

                    yield return(new StreetLightStrip(southVertices, southUvs, _lightShader));
                }

                for (int i = (int)position.Z + 2 + 1; i <= position.Z + area.Y; i += 12)
                {
                    var westPosition = new Vector3(position.X, position.Y, i);
                    var westVertices = PrimitiveUtils.CreateTopVertices(westPosition, lightSize, 0.2f);
                    var westUvs      = PrimitiveUtils.CreateTopUVs(1, 1);

                    yield return(new StreetLightStrip(westVertices, westUvs, _lightShader));

                    var eastPosition = new Vector3(position.X + area.X + 2, position.Y, i);
                    var eastVertices = PrimitiveUtils.CreateTopVertices(eastPosition, lightSize, 0.2f);
                    var eastUvs      = PrimitiveUtils.CreateTopUVs(1, 1);

                    yield return(new StreetLightStrip(eastVertices, eastUvs, _lightShader));
                }
            }
        }
        public Billboard CreateEastFacingBillboard(Vector3 position, Vector2 area, float height)
        {
            var texture = _billboardTextures.ElementAt(_random.Next(_billboardTextures.Length));
            var width   = CalculateBillboardWidth(height);

            position.Z  = position.Z + area.Y - width; //compensate position because of the worldspace coordinates
            area.Y      = width;
            position.X += 0.05f;

            return(new Billboard(
                       texture,
                       _shader,
                       PrimitiveUtils.CreateRightVertices(position, area, height),
                       PrimitiveUtils.CreateRightUVs()));
        }
        public Character(Shader shader, Texture texture, CharProperties charConfig, Vector2 originPosition, float scale)
        {
            _texture = texture;
            _shader  = shader;
            Advance  = charConfig.Advance * scale;

            var height  = charConfig.Height * scale;
            var width   = charConfig.Width * scale;
            var originX = charConfig.OriginX * scale;
            var originY = charConfig.OriginY * scale;

            var originYOffset = height - originY;
            var bottomY       = originPosition.Y + originYOffset;
            var topY          = bottomY - height;
            var left          = originPosition.X - originX;

            var vertices = PrimitiveUtils.CreateSpriteVertices(new Vector2(left, topY), width, height);

            var s   = (float)charConfig.X / texture.Width;
            var t   = (float)charConfig.Y / texture.Height;
            var uvs = PrimitiveUtils.CreateSpriteUVs(new Vector2(s, t), (float)charConfig.Width / texture.Width, (float)charConfig.Height / texture.Height);

            _meshes.Add(new Mesh(vertices, uvs, new[] { _texture }, _shader));
        }
        public bool IsOnRightSite(Vector2d point, double epsilon)
        {
            var direction = point - A;

            return(PrimitiveUtils.OrthogonalRight(U).Dot(direction) > -epsilon);
        }