def transform_with_touch(self, touch): # just do a simple one finger drag if len(self._touches) == 1: return self._apply_drag(touch) # we have more than one touch... points = [Vector(*self._last_touch_pos[t]) for t in self._touches] # we only want to transform if the touch is part of the two touches # furthest apart! So first we find anchor, the point to transform # around as the touch farthest away from touch anchor = max(points, key=lambda p: p.distance(touch.pos)) # now we find the touch farthest away from anchor, if its not the # same as touch. Touch is not one of the two touches used to transform farthest = max(points, key=anchor.distance) if points.index(farthest) != self._touches.index(touch): return # ok, so we have touch, and anchor, so we can actually compute the # transformation old_line = Vector(*touch.dpos) - anchor new_line = Vector(*touch.pos) - anchor angle = radians( new_line.angle(old_line) ) * self._do_rotation scale = new_line.length() / old_line.length() new_scale = scale * self.scale if new_scale < self.scale_min or new_scale > self.scale_max: scale = 1.0 self.apply_transform(rotation_matrix(angle, (0, 0, 1)), anchor=anchor) self.apply_transform(scale_matrix(scale), anchor=anchor) #dispatch on_transform with th touch that caused it self.dispatch_event('on_transform', touch)
def transform_with_touch(self, touch): # just do a simple one finger drag if len(self._touches) == 1: return self._apply_drag(touch) # we have more than one touch... points = [Vector(*self._last_touch_pos[t]) for t in self._touches] # we only want to transform if the touch is part of the two touches # furthest apart! So first we find anchor, the point to transform # around as the touch farthest away from touch anchor = max(points, key=lambda p: p.distance(touch.pos)) # now we find the touch farthest away from anchor, if its not the # same as touch. Touch is not one of the two touches used to transform farthest = max(points, key=anchor.distance) if points.index(farthest) != self._touches.index(touch): return # ok, so we have touch, and anchor, so we can actually compute the # transformation old_line = Vector(*touch.dpos) - anchor new_line = Vector(*touch.pos) - anchor angle = radians(new_line.angle(old_line)) * self._do_rotation scale = new_line.length() / old_line.length() new_scale = scale * self.scale if new_scale < self.scale_min or new_scale > self.scale_max: scale = 1.0 self.apply_transform(rotation_matrix(angle, (0, 0, 1)), anchor=anchor) self.apply_transform(scale_matrix(scale), anchor=anchor) #dispatch on_transform with th touch that caused it self.dispatch_event('on_transform', touch)
def get_rigid_rotation(self, dstpts): ''' Extract the rotation to apply to a group of points to minimize the distance to a second group of points. The two groups of points are assumed to be centered. This is a simple version that just pick an angle based on the first point of the gesture. ''' if len(self.strokes) < 1 or len(self.strokes[0].points) < 1: return 0 if len(dstpts.strokes) < 1 or len(dstpts.strokes[0].points) < 1: return 0 target = Vector( [dstpts.strokes[0].points[0].x, dstpts.strokes[0].points[0].y] ) source = Vector( [self.strokes[0].points[0].x, self.strokes[0].points[0].y] ) return source.angle(target)
def get_rigid_rotation(self, dstpts): ''' Extract the rotation to apply to a group of points to minimize the distance to a second group of points. The two groups of points are assumed to be centered. This is a simple version that just pick an angle based on the first point of the gesture. ''' if len(self.strokes) < 1 or len(self.strokes[0].points) < 1: return 0 if len(dstpts.strokes) < 1 or len(dstpts.strokes[0].points) < 1: return 0 target = Vector( [dstpts.strokes[0].points[0].x, dstpts.strokes[0].points[0].y]) source = Vector( [self.strokes[0].points[0].x, self.strokes[0].points[0].y]) return source.angle(target)
def _get_rotation(self): v1 = Vector(0, 10) v2 = Vector(*self.to_parent(*self.pos)) - self.to_parent( self.x, self.y + 10) return -1.0 * (v1.angle(v2) + 180) % 360
def _get_rotation(self): v1 = Vector(0, 10) v2 = Vector(*self.to_parent(*self.pos)) - self.to_parent(self.x, self.y + 10) return -1.0 *(v1.angle(v2) + 180) % 360
def _get_rotation(self): # v1 = vetor from (0,0) to (0,10) # v2 = vector from center to center + (0,10) (in widget space) v1 = Vector(0,10) v2 = Vector(*self.to_parent(*self.pos)) - self.to_parent(self.x, self.y+10) return -1.0 *(v1.angle(v2) + 180) % 360