Discussion8S16
Overview
Week 8 Discussion recap(05/16/16)
Slides: Download here
Mystery of the Orientation
As we move our coaster along the track, not only do we have to translate it, we must rotate it to look natural as well. How do we achieve this?
Well, since rotating the whole pod should be achievable by rotating the toWorld, let's think of this in terms of the toWorld's axis.
Our goal is to transform the axis on the left, to the one on the future. This is looking very much like a coordinate transformation, much like what we did with our cameras! (If coordinate transform doesn't ring a bell, read up on the Projection lecture to see how coordinate transformation are defined.)
Remember that the coordinate transformation matrix can be found by finding the x, y, and z basis vectors and the translation. So how will we go about finding those x, y, and z?
First off z is most simple right? It's simply the direction our pod is moving down the curve. In other words, it will be:
Z = target - pos
Well, we're not quite done yet though. We have to normalize that Z so that we don't unintentionally introduce a scale factor.
Z = normalize(target - pos)
Next, between X and Y, which do we look for first? Think back to the order in which we calculated the Camera Matrix. Only one of these is certain from Z, and that's going to be the X vector. As long as our pod is staying upright, we can assume our up vector is going to be <0, 1, 0>
, i.e. straight up in world coordinates. Given Z and up, we can find the vector that is perpendicular, to both of them, which will be our X vector.
X = normalize(cross(<0, 1, 0>, Z))
Now, finally we can find the final Y axis, by again finding the vector that is perpendicular to both the Z and X. Be careful of your ordering!
Y = normalize(cross(Z, X))
We can now complete this picture and find the basis vectors:
Again, if you're not sure what to do with the bases once you've found them, refer back to the Projection lecture.