def __init__(self, cx, cy, radius): """ Initialize instance of ArcBall with no constraint on axis of rotation """ self.center_x = cx self.center_y = cy self.radius = radius self.v_down = PVector() self.v_drag = PVector() self.q_now = Quaternion() self.q_down = Quaternion() self.q_drag = Quaternion() self.axis_set = [ PVector(1.0, 0.0, 0.0), PVector(0.0, 1.0, 0.0), PVector(0.0, 0.0, 1.0) ] self.axis = -1
def __mouse2sphere(self, x, y): """ private map mouse to ArcBall (sphere) """ v = PVector() v.x = (x - self.center_x) / self.radius v.y = (y - self.center_y) / self.radius mag = v.x * v.x + v.y * v.y if (mag > 1.0): v.normalize() else: v.z = sqrt(1.0 - mag) if (self.axis != -1): v = self.__constrain(v, self.axis_set[self.axis]) return v