Exemplo n.º 1
0
        public Billboard()
        {
            MaterialDX11 mat = new MaterialDX11("vBillboarding.cso", "pUnlit.cso", "gBillboarding.cso");

            mat.SetMainColor(0.0f, 0.0f, 1.0f, 1.0F);

            PointMesh pm = new PointMesh();

            pm.AddVertex(new StandardVertex(new Vector3(0.0f, 0.0f, 0.0f)));
            pm.UpdateBuffers();

            //modelrenderer_ = new MeshRenderer( mat, pm );

            desc = new BillboardDesc()
            {
                CameraUpVector = new Vector3(1.0f, 0.0f, 0.0f),
                ScaleValue     = new Vector3(1.0f, 1.0f, 1.0f)
            };

            buffer_ = new CBuffer <BillboardDesc>(6, desc);
        }
Exemplo n.º 2
0
        public void SetText(string text)
        {
            float offset = 0.0f;

            Width  = 0.0f;
            Height = 0.0f;

            for (int i = 0; i < text.Length; i++)
            {
                float coef = 0.1f;

                AtlasNode atlasnode = atlasfont.atlas.GetNode(text[i]);

                MaterialDX11 mat = new MaterialDX11("vDefault.cso", "pText.cso");
                mat.SetMainColor(1.0f, 0.0f, 0.0f, 1.0f);

                mat.AddShaderResourceView(atlasfont.atlas.SRV);

                Entity entity = new Entity();

                // On utilise XOffset et xadvance pour déterminer la position des caractères dans la ligne
                offset += atlasnode.XOffset * coef;

                entity.transform_.Translate(
                    offset + (( float )atlasnode.Width / 2.0f * coef),
                    -(atlasnode.Height * coef / 2.0f) - atlasnode.YOffset * coef,
                    0.0f);

                offset += atlasnode.XAdvance * coef;

                entity.transform_.SetScale(
                    atlasnode.Width * coef,
                    atlasnode.Height * coef,
                    1.0f);

                Width += atlasnode.Width * coef + atlasnode.XOffset * coef + atlasnode.XAdvance * coef;
                Height = atlasnode.Height * coef + atlasnode.YOffset * coef;

                Append(entity);

                //entity.modelrenderer_ = new MeshRenderer( mat, Quad.GetMesh() );

                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
                });
                mat.samplers.Add(state);
                mat.SetTextureXOffset(( float )atlasnode.X / ( float )atlasfont.atlas.Width);
                mat.SetTextureYOffset(( float )atlasnode.Y / ( float )atlasfont.atlas.Height);
                mat.SetTextureWidth(( float )atlasnode.Width / ( float )atlasfont.atlas.Width);
                mat.SetTextureHeight(( float )atlasnode.Height / ( float )atlasfont.atlas.Height);
            }

            if (CenterText)
            {
                transform_.Translate(-Width / 4.0f, Height / 2.0f, 0.0f);
            }
        }