Esempio n. 1
0
        public void SetTileMap(int width, int height, TileSet tileset, float tilewidth = 1.0f, float tileheight = 1.0f)
        {
            tilemapdesc_ = new TilemapDesc();

            Width  = width;
            Height = height;

            tileset_ = tileset;

            TileSetWidth  = tileset.Width;
            TileSetHeight = tileset.Height;

            tilemapdesc_.TileWidth  = tileset.tilewidth_;
            tilemapdesc_.TileHeight = tileset.tileheight_;

            tilewidth_  = tilewidth;
            tileheight_ = tileheight;

            UpdateSize();

            InitializeTiles();
            InitializeTileMapTexture();

            // Ne pas oublier d'utiliser un sampler "pixel perfect" pour la tilemap
            SamplerState state = new SamplerState(ApplicationDX11.Instance.Device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = new Color4(0.0f, 1.0f, 0.0f, 1.0f),
                ComparisonFunction = Comparison.LessEqual,
                Filter             = Filter.MinLinearMagMipPoint,
                MaximumAnisotropy  = 0,
                MaximumLod         = 0,
                MinimumLod         = 0,
                MipLodBias         = 0
            });

            tilemapmaterial_ = new MaterialDX11("vDefault.cso", "pTileMapping.cso", "gDefault.cso");
            tilemapmaterial_.samplers.Add(state);
            tilemapmaterial_.AddConstantBuffer <TilemapDesc>(tilemapdesc_);
            tilemapmaterial_.AddTexture(tileset_.texture_);
            tilemapmaterial_.AddTexture(tilemaptex_.GetTexture2D());

            if (m_meshRenderer == null)
            {
                m_meshRenderer = new MeshRenderer(tilemapmaterial_, Quad.GetMesh());
                m_entity.AddComponent(m_meshRenderer);
            }
            else
            {
                m_meshRenderer.material_ = tilemapmaterial_;
                m_meshRenderer.model_    = Quad.GetMesh();
            }
        }
Esempio n. 2
0
        public void Initialize(Texture2D image, int offsetx, int offsety)
        {
            MaterialDX11 material = new MaterialDX11("vDefault.cso", "pUnlit.cso", "gDefault.cso");

            material.AddTexture(image);

            Texture = image;
            Width   = image.Description.Width;
            Height  = image.Description.Height;
            //modelrenderer_ = new MeshRenderer( material, Quad.GetMesh() );
            Resize();
        }
Esempio n. 3
0
        public SceneGrid()
        {
            MaterialDX11 mat    = new MaterialDX11();
            TImage       timage = new TImage(401, 401);

            for (int i = 0; i < timage.Height; i++)
            {
                for (int j = 0; j < timage.Width; j++)
                {
                    if (i % 40 == 0 || j % 40 == 0 || i == 1 || i == 399 || j == 1 || j == 399)
                    {
                        timage.SetPixel(j, i, 1.0f, 1.0f, 1.0f, 1.0f);
                    }
                    else
                    {
                        timage.SetPixel(j, i, 0.0f, 0.0f, 0.0f, 0.0f);
                    }
                }
            }

            SamplerState state = new SamplerState(ApplicationDX11.Instance.Device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = new Color4(0.0f, 1.0f, 0.0f, 1.0f),
                ComparisonFunction = Comparison.LessEqual,
                Filter             = Filter.MinLinearMagMipPoint,
                MaximumAnisotropy  = 0,
                MaximumLod         = 0,
                MinimumLod         = 0,
                MipLodBias         = 0
            });


            float scaleValue = 40.0f;

            mat.AddTexture(timage.GetTexture2D());
            mat.SetTextureHeight(0.1f * scaleValue);
            mat.SetTextureWidth(0.1f * scaleValue);
            mat.samplers.Add(state);
            //modelrenderer_ = new MeshRenderer( mat, Quad.GetMesh() );
            transform_.RotateEuler(0.0f, 3.141592f / 2.0f, 0.0f);
            transform_.SetScale(scaleValue, scaleValue, 1.0f);

            IsPickingActivated = false;
        }