def hitTest(self, obj, x, y): y = self.root.height - y (local_x, local_y) = rotateAboutCenter(x, y, obj.center_x, obj.center_y, radians(-obj.rotation)) if obj.name == 'clock': local_y += 60 * obj.scale # offset because buttons hang off the video widget return (abs(local_x - obj.center_x) <= obj.width*obj.scale/2) and (abs(local_y - obj.center_y) <= obj.height*obj.scale/2)
def handleRotate(self, obj, gesture_event): theta = gesture_event.values['rotate_dtheta'] obj.picture.setR(obj.picture.getR() + theta) if gesture_event.n: # We need to convert Gestureworks coordinates to Panda3D coordinates gesture_x = float((gesture_event.x - SCREEN_WIDTH/2) / SCREEN_WIDTH) * 4 gesture_y = float((SCREEN_HEIGHT/2 - gesture_event.y) / SCREEN_HEIGHT) * 2 (new_x,new_y) = rotateAboutCenter(obj.picture.getX(), obj.picture.getZ(), gesture_x, gesture_y, radians(-theta)) obj.picture.setX(new_x) obj.picture.setZ(new_y)
def hitTest(self, x, y): for obj in self.touch_objects.values(): (local_x, local_y) = rotateAboutCenter(x, y, obj.picture.getX(), obj.picture.getZ(), radians(-obj.picture.getR())) if (local_x > (obj.picture.getX() - obj.scale) and local_x < (obj.picture.getX() + obj.scale) ): if (local_y > (obj.picture.getZ() - obj.scale) and local_y < (obj.picture.getZ() + obj.scale) ): return obj
def handleRotate(self, obj, gesture_event): theta = gesture_event.values['rotate_dtheta'] obj.rotation -= theta if gesture_event.n: obj.center = rotateAboutCenter(obj.center_x, obj.center_y, gesture_event.x, self.root.height - gesture_event.y, radians(-theta))
def hitTest(self, x, y): for obj in self.touch_objects.values(): (local_x, local_y) = rotateAboutCenter(x, y, obj.center_x, obj.center_y, radians(-obj.rotation)) if (abs(local_x - obj.center_x) <= obj.width*obj.scale/2) and (abs(local_y - obj.center_y) <= obj.height*obj.scale/2): return obj