Rendering Text on 3D with Windows Phone 7


This Short Post will show how to render 2D Text in a 3D World with XNA 4.0 (PC , Xbox 360 or Windows Phone 7).

The idea is pretty close to this one about classic 3D Billboards, so i wont wast your time explaining how things works.

To begin, we show our simple class that represents our 3D Text.

public class TextBillboard3D
    {
        public TextBillboard3D(String tex, Color color, Vector3 pos, float scale, SpriteFont SpriteFont = null)
        {
            this.Color = color;
            this.Message = tex;
            this.Position = pos;
            this.Scale = scale;
            this.SpriteFont = SpriteFont;
        }
        public SpriteFont SpriteFont;
        public Color Color;
        public float Scale;
        public String Message;
        public Vector3 Position;

    }

Here we Draw it as if it is a Spherical Billboard (Will Always point to the Camera)

        {
            Matrix invertY = Matrix.CreateScale(1, -1, 1);

            basicEffect.World = invertY;
            basicEffect.View = Matrix.Identity;
            basicEffect.Projection = activeProjection;

            spriteBatch.Begin(0, null, null, DepthStencilState.DepthRead, RasterizerState.CullNone, basicEffect);

            foreach (var item in Billboards)
            {
                SpriteFont font = item.SpriteFont == null ? SpriteFont : item.SpriteFont;
                Vector3 viewSpaceTextPosition = Vector3.Transform(item.Position, activeView * invertY);
                Vector2 textOrigin = font.MeasureString(item.Message) / 2;
                spriteBatch.DrawString(font, item.Message, new Vector2(viewSpaceTextPosition.X, viewSpaceTextPosition.Y), item.Color, 0, textOrigin, item.Scale, 0, viewSpaceTextPosition.Z);
            }                

            spriteBatch.End();
        }

And here as a Cylindrical Billboards (Points to the camera, but with an Axial Constraint)

{
            Matrix viewIT = Matrix.Invert(Matrix.Transpose(activeView));
            Vector3 position = new Vector3(viewIT.M14, viewIT.M24, viewIT.M34);

            foreach (var item in Billboards)
            {
                SpriteFont font = item.SpriteFont == null ? SpriteFont : item.SpriteFont;

                basicEffect.World = Matrix.CreateConstrainedBillboard(item.Position, position, Vector3.Down, null, null);

                basicEffect.View = activeView;
                basicEffect.Projection = activeProjection;

                spriteBatch.Begin(0, null, null, DepthStencilState.DepthRead, RasterizerState.CullNone, basicEffect);

                Vector2 textOrigin = font.MeasureString(item.Message) / 2;

                spriteBatch.DrawString(font, item.Message, Vector2.Zero, item.Color, 0, textOrigin, item.Scale, 0, 0);

                spriteBatch.End();
            }
        }
  1. #1 by belstaff bags sale on 21 de julho de 2017 - 3:27 pm

    Hello, I just desired to take the time to make a comment and say Ive really enjoyed reading your site. That was a really great article Please keep writing because I love your style a lot.
    belstaff bags sale http://www.belstaffuk.online

  2. #2 by coach purse outlet online on 21 de julho de 2017 - 3:28 pm

    wiadomosci aktualnosci tresci newsy newsy newsy informacje posty przeczytaj zwrot podatku dla ciebie aktualnosci nowosci naklejki scienne sprawdz to czytaj dalej
    coach purse outlet online http://www.unilorites.com/coach/

  3. #3 by louis vuitton wallet buy online on 21 de julho de 2017 - 3:28 pm

    Im happy I found this weblog, I couldnt find any info on this subject matter prior to. I also run a site and if you want to ever serious in a little bit of guest writing for me if feasible feel free to let me know, im always look for people to test out my site. Please stop by and leave a comment sometime!
    louis vuitton wallet buy online http://www.shopstylesale.online

  4. #4 by cavalli shoes sale on 21 de julho de 2017 - 3:28 pm

    Thanks for posting this. Was looking for this info all over the web.
    cavalli shoes sale http://www.robertocavallistore.online

  5. #5 by roberto cavalli online shop on 21 de julho de 2017 - 3:28 pm

    Wow, simply changed into aware of your post through Bing, and located that it is really informative. I’m gonna watch out for brussels. I’ll appreciate for those who proceed this in future. Lots of other people will be benefited from your post. Thanks in advance
    roberto cavalli online shop http://www.robertocavallioutlet.online

1 507 508 509
(não será publicado)