def interpolate(self, time): """.""" # Handle boundary conditions for matrix interpolation if (not self.actually_animated or time <= self.start_time): return Transform.from_transform(self.start_transform) if (time >= self.endTime): return self.end_transform dt = (time - self.start_time) / (self.end_ime - self.start_time) # Interpolate translation at _dt_ trans = (1.0 - dt) * self.t_0 + dt * self.t_1 # Interpolate rotation at _dt_ rotate = slerp(dt, self.r_0, self.r_1) # Interpolate scale at _dt_ scale = Matrix4x4() for i in range(3): for j in range(3): scale.m[i][j] = lerp(dt, self.s_o.m[i][j], self.s_1.m[i][j]) # Compute interpolated matrix as product of interpolated components return translate(trans) * \ rotate.to_transform() * \ Transform(scale)
def test_slerp(self): transform1 = rotate_z(30.0) q1 = Quaternion.from_transform(transform1) transform2 = rotate_z(90.0) q2 = Quaternion.from_transform(transform2) q_interp = slerp(0.5, q1, q2) transform3 = rotate_z(60) q3 = Quaternion.from_transform(transform3) self.assertEqual(q_interp, q3) self.assertEqual(q_interp.to_transform(), transform3)