Billboarding and Euler Angles!

Started by
4 comments, last by GameDev.net 18 years, 7 months ago
Hey guys -- this one has me a bit stumped: I'm trying to calculate the set of Euler angles needed to rotate vector V0 so that it's orientation is identical to vector V1. In other words, I'm trying to make a billboard! (If I can figure out the rotations needed to make the billboard normal equal to the vector pointing to the camera's position, I'm set) Is this a simple problem to solve? I can't seem to figure it out! It seems like I'll run into divide by zero cases when V0 and V1 are orthogonal... Any help would be appreciated!
Advertisement
We were recently discussing how to align one vector with another in this thread, so you might take a look there.

As I mentioned in the other thread, I would advise against thinking of the billboarding problem in terms of Euler angles, but rather approach it in terms of constructing an orthonormal basis that meets the given criteria.

There are various types of billboards: aimed at the camera, aligned with the view plane, aimed at the camera and aligned with the camera up axis, and aimed at the camera and constrained to an axis. The first type can be used for sprites with perfect radial symmetry. The next two types might be used for lens flares, particles, clouds, etc., while the last type might be used for trees, lasers, and so on. If you need more specific info, you might tell us which of these you're trying to implement.
If you want to make the billboards parallel the camera's view plane (particles, for example), then simply use the camera's up and left/right vectors to determine the offsets to the corners of the billboard.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Thanks for the link to that thread -- I was able to get it working based on what you posted :) Thanks again!
Quote:Thanks for the link to that thread -- I was able to get it working based on what you posted :) Thanks again!
No problem. I will add that the solution in the other thread gives an arbitrary basis derived only from the direction vector. This method can exhibit 'popping' in the billboard orientation, so is probably only suitable for billboards with perfect radial symmetry.

You should be able to fix this by substituting the camera up vector for the initial world axis in the code I posted. This will have a failure case, but it will generally occur when the billboard is not visible.

Axial billboards are basically a re-arrangement of the above method, and John posted the solution for viewplane-aligned billboards.
For billboards I use a function that rotates from the base vector (0, 0, 1) to a normalized direction vector. For this I've derived an efficient method, so I thought this might be useful.

The only thing I do is calculate a rotation matrix. This matrix looks like this:

| -v.z - sqr(v.y) / (1 + v.z), v.x * v.y / (1 + v.z) , v.x |
| v.x * v.y / (1 + v.z) , -v.z - sqr(v.x) / (1 + v.z), v.y |
| v.x , v.y , v.z |

With v the normalized direction vector. As you can see, no trigonometric or sqrt functions are used, so this should be fast.
However I don't know whether this is in lefthand or righthand coordinate system, so you might have to play with that.

Kevil

This topic is closed to new replies.

Advertisement