# some help with billboard math please

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

## Recommended Posts

Hi, I currently have the following math to create a World-Y alligned billboard. At least that's what I call it. I use this for trees and plants, so they only rotate along the Y axis and stay planted on the ground: Can someone show me the similar math to make it X aligned and Z aligned please?
				// We set the UP vector to WORLD UP
up.x = 0;
up.y = 1;
up.z = 0;
D3DXVec3Normalize(&up, &up);

// We take our line of site from the camera to the billboard
v1 = at-from;
D3DXVec3Normalize(&v1, &v1);

// Calculating the perpendicular line between the Z and the line of site should
// produce the up vector
D3DXVec3Cross(&right, &v1, &up);
D3DXVec3Normalize(&right, &right);
// Taking the new up vector and our z vector, we should end up with an
// appropriate look vector fot the billboard
D3DXVec3Cross(&lookv, &up, &right);
D3DXVec3Normalize(&lookv, &lookv);

// Taking our vectors we now assemble an appropriate translation matrix
// for our WORLD orientation of the billboard
look._11 = right.x;
look._12 = right.y;
look._13 = right.z;
look._14 = 0;

look._21 = up.x;
look._22 = up.y;
look._23 = up.z;
look._24 = 0;

look._31 = lookv.x;
look._32 = lookv.y;
look._33 = lookv.z;
look._34 = 0;

look._41 = from.x;
look._42 = from.y;
look._43 = from.z;
look._44 = 1;



##### Share on other sites
I think you can just set your 'up' vector to the desired axis and leave the rest as is.

Note that you're normalizing 'up' after setting it to a unit vector, which probably isn't necessary. Also, this algorithm may fail when the camera is directly above or below the billboard, but given certain restrictions on the environment that won't be an issue.

##### Share on other sites
I had tried just changing the up vector, and it didn't produce the results I expected?

##### Share on other sites
try swapping y->x, z->y, x->z.

-Josh

##### Share on other sites
Hm. I tested it out and it worked fine, but I think I constructed the basis a little differently than you're doing it. Here's how I did it:

Vector3 up = inputAxis;
Vector3 forward = normalize(camPos - billboardPos);
Vector3 side = normalize(cross(up, forward));
forward = cross(side, up);

You might try that and see if it helps (the difference is in the order of the cross product terms). If not, perhaps you can describe in what way it's not working.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 40
• ### Forum Statistics

• Total Topics
634130
• Total Posts
3015704
×