@@ -23,13 +23,14 @@ def __init__(self, cx, cy, radius):
23
23
24
24
def selectAxis (self , axis ):
25
25
"""
26
- call this from sketch (typically keyPressed() to constrain rotation to one axis)
26
+ call this from sketch (typically in keyPressed() to constrain rotation to one axis)
27
+ valid input 0, 1, 2 or -1
27
28
"""
28
29
self .axis = axis
29
30
30
- def mouseToSphere (self , x , y ):
31
+ def __mouse2sphere (self , x , y ):
31
32
"""
32
- Map mouse to ArcBall (sphere)
33
+ private map mouse to ArcBall (sphere)
33
34
"""
34
35
v = PVector ()
35
36
v .x = (x - self .center_x ) / self .radius
@@ -39,24 +40,27 @@ def mouseToSphere(self, x, y):
39
40
v .normalize ()
40
41
else :
41
42
v .z = sqrt (1.0 - mag )
42
- return v if (self .axis == - 1 ) else (self .constrainVector (v , self .axisSet [self .axis ]))
43
+ return v if (self .axis == - 1 ) else (self .__constrain (v , self .axisSet [self .axis ]))
43
44
44
45
def mousePressed (self , x , y ):
45
46
"""
46
47
pass in mouse.x and mouse.y parameters from sketch
47
48
"""
48
- self .v_down = self .mouseToSphere (x , y )
49
+ self .v_down = self .__mouse2sphere (x , y )
49
50
self .q_down .copy (self .q_now )
50
51
self .q_drag .reset ()
51
52
52
53
def mouseDragged (self , x , y ):
53
54
"""
54
55
pass in mouse.x and mouse.y parameters from sketch
55
56
"""
56
- self .v_drag = self .mouseToSphere (x , y )
57
+ self .v_drag = self .__mouse2sphere (x , y )
57
58
self .q_drag .set (PVector .dot (self .v_down , self .v_drag ), self .v_down .cross (self .v_drag ))
58
59
59
- def constrainVector (self , vector , axis ):
60
+ def __constrain (self , vector , axis ):
61
+ """
62
+ private constrain (used to constrain axis)
63
+ """
60
64
res = PVector .sub (vector , PVector .mult (axis , PVector .dot (axis , vector )))
61
65
res .normalize ()
62
66
return res
@@ -66,11 +70,11 @@ def update(self):
66
70
Call this function in the sketch draw loop to get rotation matrix as an array
67
71
"""
68
72
self .q_now = Quaternion .mult (self .q_drag , self .q_down )
69
- return self .quat2Matrix (self .q_now )
73
+ return self .__quat2matrix (self .q_now )
70
74
71
- def quat2Matrix (self , q ) :
75
+ def __quat2matrix (self , q ) :
72
76
"""
73
- Return matrix as array
77
+ private return matrix as array
74
78
"""
75
79
rot = q .getValue ()
76
80
return rot
0 commit comments