Billboard Sprite, constraining the rotation to an axis.


I’ve got billboard sprites in my game. Given the nature of billboard sprites (2d textures translated into world space), their rotation is contained to the camera’s view. This is perfect for some effects, but I’m trying to understand the techniques used for constraining billboard rotation based on a value. I could use this create older style effects where I render two billboard sprites perpendicular to one another, like so:

I’ve searched this topic extensively, but most results are individuals looking for the effect I’ve already achieved. These are my potential thoughts on how to solve this, but I’m by no means an expert:

-Use blender to create a textured plane, then I can easily render the plane twice and rotate one on the Y-axis.
-Solve this using my existing billboard rendering method, based upon this:

To save you all time, this is the extent of my existing code. I’m not using a shader to render billboards because despite my attempts, I’m struggling to find good shaders that factor in world space, most “hello world” examples aren’t concerned with presenting more than sprites on a screen.

As always, thanks to anyone who assists. I’ve been working on this for days with not much luck. As per my usual logic, if it’s this hard, I’m probably doing it wrong.

            foreach (Sprite sprite in sprites)
                Vector3 textPosition = new Vector3(0, 45, 0);

                BasicEffect.World = Matrix.CreateScale(1, -1, 1) * Matrix.CreateTranslation(sprite.Position);
                BasicEffect.View = camera.View;
                BasicEffect.Projection = camera.Projection;

                SpriteBatch.Begin(0, null, SamplerState.PointWrap, DepthStencilState.DepthRead, RasterizerState.CullNone, BasicEffect);
                SpriteBatch.Draw(sprite.Texture, Vector2.Zero, Color.White);

Just to add another possibility. It could be that I render to a quad and rotate that based on an origin. It may be the case that a quad isn’t the right way either. I’ll try more tomorrow.

well, you could just draw the things like grass like any other 3d object in the world - so basically mul(position, worldviewprojection);

The normal world matrix is scale * rotationx,y,z * translation.

So your objects are static and do not look at the camera at all.

You can then go ahead and modify the specific rotation axis you want to change, for example y;

Get the vector from camera to object - (object.position - camera.position);
Get the Camera view direction vector

Now to get the angle (around the y axis) for these two vectors. I’m afraid you need to google that yourself.
I’m not sure, maybe you need the normal instead of the camera direction, just see how the rotation works out below.

Then for the new world matrix you would use

scale * rotationX(object.angle.x) * rotationY(object.angle.y + ourCalculatedAngle) * rotationZ(…)*translation(…)

I have no idea whether this is a good idea, but I’m sure it works.

Thanks for the guidance Kosmo, I suspect I can apply your recommendation.

I’m an idiot…

It wasn’t working because I was doing scale * translation * rotation instead of scale * rotation * translation.


I’ve worked with that for a long time now, but early on I constantly had to look up the order again and again :slight_smile:

1 Like

Slightly stupid question… :sleeping:

Why not simply [File Size and Memory Consumption aside] create two planes in your 3D design application and instance that instead? I think you were looking for a static plant correct or were you trying to create a slight animating effect where the two planes angle themselves based on the player position and distance from the object?

I am about to ‘hit the sack’ [Sleep] so maybe I cannot understand the need to constrain the orientation other than that already mentioned… is it to create said effect? I would like to understand this method if you would please :slight_smile:.