TWild

I am trying to create a Sun textured quad billboard to rotate around my skydome. I came across the Matrix.CreateBillboard method, but I'm not sure how I am supposed to be using it.


Here is my call:

Matrix billboard = new Matrix();

billboard = Matrix.CreateBillboard(entity.Position, camera.Position, camera.Up, camera.Forward);

Am I supposed to be using the resulting matrix as the quad's World when I pass it into my shader I tried that and multiplying it by the quad's world passing it into the shader, but in both instances I get nothing to show up.

Any help appreciated!


Re: XNA Framework Matrix.CreateBillboard

Malmer

Havn't tried any of that, but the most natural thing for the method would be to generate a WorldView matrix. So all that is left is your projection matrix. Not sure though. Havn't tested. Could be that it simple creates a view matrix, but probably not.



Re: XNA Framework Matrix.CreateBillboard

TWild

The position of the (ugly) textured quad is at {0.0, 0.0, -50.0}.

At first, I see nothing at all...

<a href="http://imageshack.us"><img src="http://img360.imageshack.us/img360/7053/atquadpositionjb6.jpg" border="0" alt="Image Hosted by ImageShack.us" /></a>

As you can see, the quad stays in front of centered with the camera no matter which way I move.

<a href="http://imageshack.us"><img src="http://img488.imageshack.us/img488/8154/strafingrightvw9.jpg" border="0" alt="Image Hosted by ImageShack.us" /></a>

Here is part of my code:

Matrix billboard = Matrix.CreateConstrainedBillboard(entity.Position, camera.Position, new Vector3(0.0f, 1.0f, 0.0f), camera.Forward, null);

billboard *= Matrix.CreateTranslation(entity.Position);

...

m_Effect.Parameters["gWVP"].SetValue(billboard * camera.Projection);





Re: XNA Framework Matrix.CreateBillboard

TWild

This is from a simple transform/texture fx file I'm using

uniform extern float4x4 gWVP;

...

Out.position = mul(float4(Pos, 1.0f), gWVP);

-that's the only calculation in the fx file that has to do with transforming the vertices





Re: XNA Framework Matrix.CreateBillboard

TWild

Ok, I figured it out...

(used CreateBillboard instead of CreateConstrainedBillboard)

First, I created a billboard matrix manually:

Matrix lookAt = entity.World;

lookAt.Forward = Vector3.Normalize(camera.Position - entity.Position);

lookAt.Right = Vector3.Normalize(Vector3.Cross(new Vector3(0.0f, 1.0f, 0.0f), lookAt.Forward));

lookAt.Up = Vector3.Cross(lookAt.Forward, lookAt.Right);

Which, after starting the program, had the following values:

lookAt:
+ Forward {X:0.7715393 Y:-0.6361816 Z:0 }
+ Up {X:0.6361815 Y:0.7715393 Z:0 }
+ Right {X:0 Y:0 Z:-0.9999999}
+ Translation {X:-57 Y:57 Z:0 }

Then, I created a matrix using the Matrix.CreateBillboard method:

Matrix billboard = Matrix.CreateBillboard(entity.Position, camera.Position, camera.Up, camera.Forward);

Which, after starting the program had the following values:

+ Forward {X:0.7715393 Y:-0.6361816 Z:0 }
+ Up {X:0.6361815 Y:0.7715393 Z:0 }
+ Right {X:0 Y:0 Z:0.9999999}
+ Translation {X:-57 Y:57 Z:0 }

Notice that lookAt's Right property (which displays properly) has a - value, whereas, billboard's does not.

So, I simply negated it

billboard.Right = -billboard.Right;

And then setting the shader parameter:

m_Effect.Parameters["gWVP"].SetValue(billboard * camera.View * camera.Projection);

So, I'm not sure if this is a bug in Matrix.CreateBillboard or I'm just not using it correctly.