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))
Again, if you're not sure what to do with the bases once you've found them, refer back to the Projection lecture.
Now that our static tracks are set up, and we have the ability to select our points, let's add the ability to move them.
Probably the most immediate intuitive way to move the points is to move it in relation to the camera's view:
How do we accomplish this? Well, in essence we're moving the object in the camera's X and Y axes. So if we find the camera's X and Y axes, we will be able to move our object along the camera's X-Y plane.
Finding the Camera's Axes
So do we remember how to find the camera's X-Y plane from the Projection lecture? Fear not, we've reproduced it down below:
(Note: We've crossed out the y-axis being
up normalized because that's not always true.)
Now that we've found the desired axes that we want to move the points along, how do we move points along them?
Moving Points Along the Axes
Well, let's simplify the problem: how do we move a point along a single axis?
Let's say we have a point
p and the normalized vector
v that represents an axis. How do I move length one across the vector? We can simply add
p such that
result = p + v
How about moving one length in the opposite direction along
v? Well we can subtract
result = p - v
The common idea here is that we're moving along the axis
v by adding some scalar multiplication of
v. Thus moving the point along
v some arbitrary amount
s would look like:
result = p + s * v
Great! We've now seen how we can move a point an arbitrary amount along an axis. How about two axes? Well it turns out it's just the linear combination of those two axes. Let's say our x-axis is represented by
x and the y-axis by
y, and the desired amount of movement along each axis (for example, the amount the mouse moved) is
sy respectively. Our final equation would look like such:
result = p + sx * x + sy * y
There you have it. That's the equation to translate our point
p parallel to our camera's image plane.