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 compute_sub_window(self, num, count): """Compute the sub window position.""" dx = self.x_pixel_end - self.x_pixel_start dy = self.y_pixel_end - self.y_pixel_start nx = count ny = 1 while (((nx & 0x1) == 0) and ((2 * dx * ny) < (dy * nx))): nx >>= 1 ny <<= 1 # compute x and y pixel sample range for sub-window xo = num % nx yo = num / nx tx0 = float(xo) / float(nx) tx1 = float(xo + 1) / float(nx) ty0 = float(yo) / float(ny) ty1 = float(yo + 1) / float(ny) x_start = int(lerp(tx0, self.x_pixel_start, self.x_pixel_end)) x_end = int(lerp(tx1, self.x_pixel_start, self.x_pixel_end)) y_start = int(lerp(ty0, self.y_pixel_start, self.y_pixel_end)) y_end = int(lerp(ty1, self.y_pixel_start, self.y_pixel_end)) return x_start, x_end, y_start, y_end
def compute_sub_window(self, num, count): """Compute the sub window position.""" dx = self.x_pixel_end - self.x_pixel_start dy = self.y_pixel_end - self.y_pixel_start nx = count ny = 1 while(((nx & 0x1) == 0) and ((2*dx*ny) < (dy*nx))): nx >>= 1 ny <<= 1 # compute x and y pixel sample range for sub-window xo = num % nx yo = num / nx tx0 = float(xo) / float(nx) tx1 = float(xo+1) / float(nx) ty0 = float(yo) / float(ny) ty1 = float(yo+1) / float(ny) x_start = int(lerp(tx0, self.x_pixel_start, self.x_pixel_end)) x_end = int(lerp(tx1, self.x_pixel_start, self.x_pixel_end)) y_start = int(lerp(ty0, self.y_pixel_start, self.y_pixel_end)) y_end = int(lerp(ty1, self.y_pixel_start, self.y_pixel_end)) return x_start, x_end, y_start, y_end
def motion_bounds(self, bbox, use_inverse): """.""" if (not self.actually_animated): return inverse(self.start_transform)(bbox) ret = BBox() n_steps = 128 for i in range(n_steps): t = Transform() time = lerp( float(i) / float(n_steps - 1), self.start_time, self.end_time) t = self.Interpolate(time) if (use_inverse): t = inverse(t) raise Exception("check_code_next_line") # ret = union(ret, t(b)) return ret
def motion_bounds(self, bbox, use_inverse): """.""" if (not self.actually_animated): return inverse(self.start_transform)(bbox) ret = BBox() n_steps = 128 for i in range(n_steps): t = Transform() time = lerp(float(i)/float(n_steps-1), self.start_time, self.end_time) t = self.Interpolate(time) if (use_inverse): t = inverse(t) raise Exception("check_code_next_line") # ret = union(ret, t(b)) return ret
def lerp(self, tx, ty, tz): """Linear Interpolation between p_min and p_max.""" return Point(lerp(tx, self.p_min.x, self.p_max.x), lerp(ty, self.p_min.y, self.p_max.y))
def test_lerp(self): v1 = 10.0 v2 = 20.0 self.assertEqual(lerp(0.0, v1, v2), v1) self.assertEqual(lerp(1.0, v1, v2), v2) self.assertEqual(lerp(0.5, v1, v2), 0.5*(v1+v2))