Site icon ProVideo Coalition

Measuring Rotation in After Effects

Measuring Rotation in After Effects 1

Last week, we posted a short tutorial on using expressions to measure the distance between two points. This was triggered by playing around with the new Face Tracker in After Effects CC 2015, which in Detailed Features mode generated a number of point controls that track different facial features including the eyes, corners of the mouth, and so on. A reader asked, “so what if you want to know the angle instead of distance?”

Last week, we posted a short tutorial on using expressions to measure the distance between two points. This was triggered by playing around with the new Face Tracker in After Effects CC 2015, which in Detailed Features mode generated a number of point controls that track different facial features including the eyes, corners of the mouth, and so on. A reader asked, “so what if you want to know the angle instead of distance?”

The short answer is to use the expression code lookAt instead of length. However, it’s not quite as simple as that, as lookAt works in 3D, not 2D – even if you feed it a pair of 2D points for reference. If you just want a simple 2D rotation, you need to do a little work to extract it.

The simplest approach is to add Effect > Expression Controls > 3D Point Control to your layer. Option/Alt click its animation stopwatch to enable expressions, then add the expression:

lookAt(Point1, Point2)

Select Point1, and use the pick whip to choose the first Position or effect point control value of the two you’re measuring. Then select Point2 and pick whip to the second. If you were using the Face Tracking (Detailed Features) trick we demonstrated last week, that expression would look like:

lookAt(effect(“Face Track Points”)(“Right Pupil”), effect(“Face Track Points”)(“Left Pupil”))

The resulting Y value in the 3D Point Control will contain the angle, in degrees, as shown here. If you like, you can then pick whip something else such as a data display or effect control to this value (just the Y value – not the entire 3D Point Control results!) to put it to work. If the angle seems to be backward, swap the order of the points you used for Point1 and Point2 to get it to measure in the opposite direction.

Why Y? Technically, when we’re looking at the rotation between two 2D points, the result is Z rotation (a pivot perpendicular to the screen). The reason you have to use the Y instead of the Z value is that lookAt is actually a “face towards” command rather than a “point at” command. If you applied to the Orientation of a 3D layer, you would find it rotated so that the surface of the layer faced toward the point that was being tracked – that’s why you see X and Z rotation at variations of 90 degrees in the result shown at right. Because of this flip around, the additional rotation would be in the layer’s local Y dimension.

If you want to extract the Y rotation without resulting to targeted pick whipping, you would need an only slightly more complex expression. To test this, add Effect > Expression Controls > Angle Control, enable expressions for it, and add the following two-line expression:

MyOrientation = lookAt(Point1, Point2);
MyOrientation[1]

Wire up Point1 and Point2 to the two points you want to track, and MyOrientation[1] will extract just the Y rotation from lookAt’s result. This will give you a core bit of code you can use in other more complex expressions.

After going through all these gyrations, it’s worth pointing out that the Face Tracker can generate a lot of this data automatically for you. After performing Face Tracking (Detailed Features), move the Current Time Indicator to a good representative pose of the face, make sure the mask is selected and click the Set Reset Pose button in the Tracker panel. Then click the larger button Extract & Copy Face Measurements in the same panel. This will add another “effect” to the layer named Face Measurements (shown here), which contains keyframed values for most of the measurements you might want such as Face Orientation (in 3D!). But at least you now know how to create your own measurements if you need to.

 

 

 

 

Exit mobile version