def __init__(self, x=0, y=0, z=0): __pvector__.__init__(self, x, y, z) self.add = self.__instance_add__ self.sub = self.__instance_sub__ self.mult = self.__instance_mult__ self.div = self.__instance_div__ self.cross = self.__instance_cross__ self.dist = self.__instance_dist__
def __instance_lerp__(self, *args): if len(args) == 4: x = args[0] y = args[1] z = args[2] t = args[3] elif len(args) == 2: v = args[0] x = v.x y = v.y z = v.z t = args[1] else: raise Exception('lerp takes either (x, y, z, t) or (v, t)') __pvector__.lerp(self, x, y, z, t)
def __constrain(self, vector, axis): """ private constrain (used to constrain axis) """ vector.sub(axis.mult(axis, PVector.dot(axis, vector))) vector.normalize() return vector
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
def add(cls, a, b, dest=None): return __pvector__.add(a, b, dest)
def __div__(a, b): if isinstance(b, __pvector__): raise TypeError("The / operator can only be used to divide a PVector by a scalar") return __pvector__.div(a, float(b), None)
def __add__(a, b): return __pvector__.add(a, b, None)
def mult(cls, a, b, dest=None): return RealPVector.mult(a, b, dest)
def sub(cls, a, b, dest=None): return __pvector__.sub(a, b, dest)
def dot(cls, a, b): return __pvector__.dot(a, b)
def dist(cls, a, b): return RealPVector.dist(a, b)
def dot(cls, a, b): return RealPVector.dot(a, b)
def angleBetween(cls, a, b): return RealPVector.angleBetween(a, b)
def cross(cls, a, b, dest=None): return RealPVector.cross(a, b, dest)
def div(cls, a, b, dest=None): return RealPVector.div(a, b, dest)
def sub(cls, a, b, dest=None): return RealPVector.sub(a, b, dest)
def add(cls, a, b, dest=None): return RealPVector.add(a, b, dest)
def div(cls, a, b, dest=None): return __pvector__.div(a, float(b), dest)
def angleBetween(cls, a, b): return __pvector__.angleBetween(a, b)
def random3D(cls, *args): jpv = __pvector__.random3D(*args) return PVector(jpv.x, jpv.y, jpv.z)
def fromAngle(cls, a, target=None): return __pvector__.fromAngle(a, target)
def mult(cls, a, b, dest=None): return __pvector__.mult(a, float(b), dest)
def cross(cls, a, b, dest=None): return __pvector__.cross(a, b, dest)
def __rmul__(a, b): if not isinstance(b, Number): raise TypeError("The * operator can only be used to multiply a PVector by a number") return PVector.mult(a, float(b), None)
def random3D(cls): return __pvector__.random3D()
def __div__(a, b): if not isinstance(b, Number): raise TypeError("The / operator can only be used to divide a PVector by a number") return PVector.div(a, float(b), None)
def __sub__(a, b): return __pvector__.sub(a, b, None)
def __rmul__(a, b): if isinstance(b, __pvector__): raise TypeError("The * operator can only be used to multiply a PVector by a scalar") return __pvector__.mult(a, float(b), None)
def __magSq__(a): return __pvector__.magSq(a)
def dist(cls, a, b): return __pvector__.dist(a, b)
def random2D(cls): return __pvector__.random2D()
def fromAngle(cls, *args): jpv = __pvector__.fromAngle(*args) return PVector(jpv.x, jpv.y, jpv.z)