3Д БУМ

3Д принтеры и всё что с ними связано

Interpolation with Quaternions

Now, after all that, you get to learn about the coolest thing in quater­nions: interpolation. Interpolation is very important when working with 3D models. Imagine that you are working on a game that includes enemies who patrol an area, back and forth. All you have to work with are the endpoints of the patrol path and the time it should take for the enemy to get from one to the other. This poses a problem because you don’t actually know the points where the enemy would be at any given time. Using interpolation, you can calculate where the enemies should be, no matter how much time has elapsed since they started patrolling.

Interpolation is the act of producing the points in between two end points. This can help produce smooth animation because you can generate an unlimited number of midpoints, allowing the jumps between points to be very small and—hopefully—imperceptible to your game players. Interpolation is the real reason you should be using quaternions. It is pretty easy to use and it results in super-smooth animation. In this section, you will learn about the two main types of quaternion interpolation: LERP and SLERP. Linear interpolation (LERP) interpolates in a straight line. Spherical linear interpolation (SLERP), on the other hand, interpolates in an arc. SLERP generally produces a smoother animation, and will always stay at a constant speed, whereas a LERPed animation will tend to speed up in the middle and slow down at the ends. Figure 2.9 shows a two-dimensional sketch of SLERP and LERP.

In general, you want to use SLERP to interpolate between two sets of rotations. This allows the path to actually rotate, rather than simply be connected by a straight line. Unfortunately, SLERP becomes unreli­able as the distance between the rotations becomes smaller. When this is the case, you must fall back to LERP (see Figure 2.9).

Notice in the figure that the intervals are all the same size on the SLERP path, but are close together toward the middle of the LERP path. This is why SLERP is used for rotation interpolation in most places; it simply looks better. Now, you’ll learn how to actually perform these operations on quaternions in the next sections.

Для любых предложений по сайту: [email protected]