Sign in to follow this  

Problem with axial billboards

This topic is 2657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to implment arbitrary axial billboards. I am doing the implementation in DirectX 9.0 using SlimDX C#.

First I tried to get (0, 0, 1) to work as an arbitrary axis. To get that to work I had to switch the up and forward vectors in the billboard matrix. That felt weird. I tried to see if (0, 1, 0) was working with that configuration as well, of course it didn't, then I had to change around the vectors in some other order, and to get it working with arbitrary axes I realized something else must be wrong than the order of the vectors in the rotationmatrix.

Here is the sourcecode that I am trying to get to work correctly:


private Matrix TurnToCameraAroundAxis(Vector3 axis, Vector3 worldPosBillboard)
{
// Scene is a global variable containing the camera position.
Vector3 look = Scene.Camera.Position - worldPosBillboard;
look = Vector3.Normalize(look);
Vector3 up = axis;
up = Vector3.Normalize(up);
Vector3 right = Vector3.Cross(look, up);
right = Vector3.Normalize(right);
look = Vector3.Cross(up, right);
look = Vector3.Normalize(look);
// One line of pseudocode
Matrix billboardRotationMatrix = (right, up, forward, worldPosBillboard);
...
...
}




Any help or advice on this issue would be much appreciated.

Thanks, Patrik

[Edited by - Sealion on September 2, 2010 2:55:32 AM]

Share this post


Link to post
Share on other sites
What are entity.Translation and positionOfBillboard? If positionOfBillboard is the world position of the billboard, you should use that in your first "look" calc.

Can you explain a little more why you add "pos" to entity.Translation?

Share this post


Link to post
Share on other sites
Ok, problem is now solved.

The correct version of the code looks as follows:


private Matrix TurnToCameraAroundAxis(Vector3 axis, Vector3 worldPosBillboard)
{
// Scene is a global variable containing the camera position.
Vector3 look = Scene.Camera.Position - worldPosBillboard;
look = Vector3.Normalize(look);
Vector3 forward = axis;
forward = Vector3.Normalize(forward);
Vector3 right = Vector3.Cross(look, forward);
right = Vector3.Normalize(right);
look = Vector3.Cross(forward, right);
look = Vector3.Normalize(look);
Matrix billboardRotationMatrix = Common.Math.MatrixFromVectors(right, look, forward, worldPosBillboard);
return billboardRotationMatrix;
}



The guide I originally followed was following OpenGL's coordinate system which is right-handed. I knew that so I changed the order of the parameters given to the cross products. That was not enough. When I was going through the operations I realized a few inconsistencies which are corrected in the code above.

The Common.Math.MatrixFromVectors makes rows out of the parameter vectors. In my previous post I had the function to create columns according to the OpenGL tutorial which also caused troubles.

Regards, Patrik

Share this post


Link to post
Share on other sites

This topic is 2657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this