Jump to content
  • Advertisement
Sign in to follow this  
QuadMV

some help with billboard math please

This topic is 4833 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!