3D Billboards On Windows Phone 7


Billboards are one of the most used “primitives” in rendering, principally in mobile environments where whe dont have GPU power avaliable to render millions of real triangles.

In this post i will show how to implement Cylindric and Spherical billboards using the simple XNA SpriteBatch.

The result is not cool/fast as using shaders, but is more than enough.

To begin, we show our simple class that represents any type of billboard.

public class Billboard3D
{
        public Billboard3D(Texture2D tex, Vector3 pos, Vector2 scale)
        {
            this.Texture = tex;
            this.Position = pos;
            this.Scale = scale;
        }

        public Vector2 Scale;
        public Texture2D Texture;
        public Vector3 position;
}

Here we show the code to render the Axial Billboard (Cylindric).
For the example, we constrained it to the Y axis (most common – Vector3.Up), you can change it the way you want. (you can put this as a parameter in Billboard3D class)

            Vector3 position = CAMERA_POSITION;

            foreach (var item in Billboards)
            {
                basicEffect.World = Matrix.CreateConstrainedBillboard(item.Position, position, Vector3.Up, null, null);

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

                spriteBatch.Begin(0, null, null, DepthStencilState.DepthRead, RasterizerState.CullNone, basicEffect);
                spriteBatch.Draw(item.Texture, Vector2.Zero, item.Texture.Bounds, Color.White, 0, new Vector2(item.Texture.Bounds.Center.X, item.Texture.Bounds.Center.Y), item.Scale, SpriteEffects.None, 1);
                spriteBatch.End();
            }

The basicEffect variable is an instance of the classic XNA Basic Effect class.
The next code shows how to render a Spherical Billboards (will always look to the camera).
There are some magic convertions cause the coordinate space of the basic effect and the SpriteBatch are different.

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)
            {
                Vector3 viewSpaceTextPosition = Vector3.Transform(item.Position, activeView * invertY);
                spriteBatch.Draw(item.Texture, new Vector2(viewSpaceTextPosition.X, viewSpaceTextPosition.Y), item.Texture.Bounds, Color.White, 0, new Vector2(item.Texture.Bounds.Center.X,item.Texture.Bounds.Center.Y), item.Scale, SpriteEffects.None, viewSpaceTextPosition.Z);
            }               

            spriteBatch.End();

There are others ways of drawing billboards on wp7 like creating teh vertices by hand every frame and render using RenderUserPrimitive function.

We always have pros and cons in all approaches, i prefer this =P

This technic can also be used to render Text in 3D, just change the spritebatch draw function to the equivalent draw text function.

, ,

  1. #1 by http://hpmusik.se/style/lib/117.html on 27 de agosto de 2016 - 9:01 pm

    It is an awesome present of your very own family. I would strongly incourage people to go for this one information technology makes a ideal present. Their transmitter can a good time work at getting the actual products upon duration. I bought our material on a daily basis back and I reveived it certainly fast.

  2. #2 by http://www.villakohlanta.nu/wp-content/plugins/widget/155.html on 28 de agosto de 2016 - 12:17 am

    I had gotten your gifts for the the mom concerning Christmas as she is actually the best precious jewelry freak. That something she cannot don a lot out of was, bracelets. I purchased her your allure bracelet to where she opened this yesterday she absolutley liked information technology! Right now the issue are, her buying this regarding as well as off of simply by by herself. Haha… total awesome item, this shipped then arrived really early additionally the mom is enjoying they. Thank we.

  3. #3 by http://dyg.se/page/174.html on 28 de agosto de 2016 - 12:17 am

    I had gotten that gifts of the mom towards Holiday as she are any precious jewelry freak. The one thing she cannot use a lot to are, bracelets. I purchased her that appeal bracelet and once she launched that it yesterday she absolutley loved that! Right now the issue is, her acquiring that it on top of plus down by just by herself. Haha… general great item, it shipped and/or came massively very early and/or my personal mother was experiencing this. Thank you.

  4. #4 by http://ashishbagga.com/html/325.html on 28 de agosto de 2016 - 2:05 am

    Your headset ended up being like stunning like in photo. That it arrived quickly. I’d suggest choosing a towel during each coating while you click they out w / a vapor iron. It doesn’t steam out alongside merely a steamer. On iron was needed. It is very delicate, when you you should not trust yourself aided by the towel and vapor iron, after that just take things up to a certified. Pretty noise.

  5. #5 by http://www.wieseversa.no/JavaScript/lib/216.html on 28 de agosto de 2016 - 2:05 am

    Your headset ended up being as breathtaking since in image. Things arrived immediately. I would recommend using a towel during every one coating as you hit this out w / any vapor iron. It doesn’t steam outside along with only a steamer. Their iron had been essential. It is very sensitive, when you do not trust yourself with the towel plus steam iron, therefore accept that up to a certified. Stunning audio.

  6. #6 by Lyn Evey on 28 de agosto de 2016 - 4:56 am

    Hi to all, how is everything, I think every one is getting more from this website, and your views are nice for new people. lords mobile hacks for bike

  7. #7 by Zaproszenia Slubne Sklep on 28 de agosto de 2016 - 5:32 am

    Normally I don’t learn article on blogs, however I would like to say that this write-up very pressured me to take a look at and do it! Your writing style has been amazed me. Thank you, very great post.

  8. #8 by deus ex mankind divided gameplay on 28 de agosto de 2016 - 9:19 am

    724789 1459You ought to get involved in a contest personally with the finest blogs on-line. I will recommend this page! 820627

  9. #9 by http://dammbindning.nu/settings/app/293.html on 28 de agosto de 2016 - 9:31 am

    It is an awesome gifts for the loved ones. I would highly incourage people to pick our they makes a very good gifts. The sender will a great evening duty in buying that items regarding time. I requested the items a day ago and I also reveived it really fast.

  10. #10 by http://www.forpackningsutveckling.se/code/202.html on 28 de agosto de 2016 - 9:32 am

    Recieved this product prior to the day presented in a really terrific gift package . The picture that is presented for the bracelet is what you will recieve. This might be most fine though the striking part regarding jewelry which will continue mainly because iof their toggle clasp which is most solid so the bracelet eill not really come off.

  11. #11 by Fabiola Frankenfield on 28 de agosto de 2016 - 10:05 am

    An extremely fascinating go through, I may not concur entirely, nonetheless you do make some genuinely legitimate factors.

  12. #12 by http://www.nbwinos.com/upload/file/126.html on 28 de agosto de 2016 - 1:54 pm

    it comes in a breathtaking package styles very good however it really is somewhat little much of our moms wrist but it appearances awesome only really want it ended up being longer

  13. #13 by http://pendelprognos.se/scripts/99.html on 28 de agosto de 2016 - 1:55 pm

    I got the present for the the mom concerning Christmas mainly because she are letter jewelry freak. That the something she cannot don a great deal to are, bracelets. I purchased the lady this one allure bracelet to once she opened that yesterday she absolutley loved that it! This time the problem are, the lady buying that in then off of with herself. Haha… on the whole great item, that it delivered and also came quite early as well as my personal mother is actually experiencing they. Thank you.

  14. #14 by http://fjallpuben.se/wp-content/content/157.html on 28 de agosto de 2016 - 3:42 pm

    This headset had been while breathtaking since inside visualize. That it arrived quickly. I would recommend choosing a towel done each and every coating while you click that away w / one vapor iron. It doesn’t steam away through only a steamer. That the iron had been needed. It can be delicate, so if you don’t trust your self with all the towel to vapor iron, then accept this up to a expert. Pretty audio.

  15. #15 by email bdomains mediolex@gmail.com on 28 de agosto de 2016 - 4:46 pm

    This is really interesting, You are a very skilled blogger. I’ve joined your rss feed and look forward to seeking more of your great post. Also, I have shared your site in my social networks!

  16. #16 by email bdomains mediolex@gmail.com on 28 de agosto de 2016 - 5:18 pm

    I really appreciate this post. I¦ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thank you again

  17. #17 by email bdomains mediolex@gmail.com on 28 de agosto de 2016 - 5:25 pm

    It is perfect time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I wish to suggest you some interesting things or tips. Maybe you can write next articles referring to this article. I wish to read even more things about it!

  18. #18 by Will on 28 de agosto de 2016 - 7:04 pm

    I truly love your site.. Excellent colors & theme. Did you make this
    amazing site yourself? Please reply back as I’m wanting to create my own site and would love
    to find out where you got this from or just what the theme
    is named. Thanks! http://bing.co.uk

1 166 167 168
(não será publicado)