Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Viewpoint oriented billboard

Started by SiS-Shadowman Sep 23, 2010 at 5:13 AM 2 replies 2.8k views
Original Post
SiS-Shadowman
SiS-Shadowman
I'm trying to create a rotation matrix that rotates a quad so that it always faces the cameras viewpoint.
I figured that I need to come up with 3 base vectors, but I guess there's still an error in my code, because the quads show some squeezing as soon as I apply the rotation to them.

This is what the quads look like after transforming (they fly straight upwards).


// XNA Code// p.position is the center of the particleMatrix translation = Matrix.CreateTranslation(p.position);Matrix rotation = Matrix.Identity;Vector3 viewUp = new Vector3(0, 1, 0);rotation.Forward = Vector3.Normalize(camera.Position - p.position);rotation.Right = Vector3.Cross(viewUp, rotation.Forward);rotation.Up = Vector3.Cross(rotation.Forward, rotation.Right);// All those vectors have a length of approx. 1float fl = rotation.Forward.Length();float rl = rotation.Right.Length();float ul = rotation.Up.Length();// AddQuad creates the quad and rotates each point by the given matrix// Without the rotation, the quads don't show the mentioned squeezingcreator.AddQuad(rotation * translation);


I can't really explain that squeezing: The quads should still appear to have roughly the same size because their distance to the camera doesn't change that much and thus perspective can't be the cause.
I suspect I'm creating the matrix in the wrong way, but I'm not totally sure. Can anybody help?
SiS-Shadowman
SiS-Shadowman
Thanks for the quick answer. I had to revert the order (first rotate, then translate) but now it works. I assume this method doesn't align the billboards towards the view point, but the view plane instead, though this shouldn't really be a problem for me: It looks good enough.

Though I am curious what was wrong about my previous method. I thought I had understood matrices well enough now. All I required was a change of basis from the standard orthonormal basis to the one that represents the cameras orientation. I'm still unsure if those 3 bases make up the rows or the columns, but I tried both ways and neither produced the desired results.

Still, thanks very much :)
Gage64
Gage64
Here's a method I suggested in another thread, in pseudo-code. I think it gives a viewpoint oriented billboard:

Vector3 toCam = normalize(camPos - quadPos);Vector3 right = crossProduct(camUpVector, toCam);Vector3 up = crossProduct(toCam, right);// Use the vectors as rowsMatrix4x4 orientMat = Matrix4x4(right, up, toCam);


It seems to have worked, but you might want to look at some references on billboarding, like this and this.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.