1 ;; add a new "mouse mode", with menu title, cusror and mouse method name
2 (send spin-proto
:add-mouse-mode
'hand-rotate
3 :title
"Hand Rotate" :cursor
'hand
:click
:do-hand-rotate
)
5 ;; set up local environment with function to project (x, y) point onto
6 ;; "globe" overthe plot
7 (flet ((calcsphere (x y
)
8 (let* ((norm-2 (+ (* x x
) (* y y
)))
10 (z (if (< norm-2 rad-2
) (sqrt (- rad-2 norm-2
)) 0)))
13 (let ((r (sqrt (max norm-2 rad-2
))))
14 (list (/ x r
) (/ y r
) (/ z r
)))))))
16 ;; define the :DO-HAND-ROTATE method in the local environment
17 (defmeth spin-proto
:do-hand-rotate
(x y m1 m2
)
18 (let* ((oldp (apply #'calcsphere
19 (send self
:canvas-to-scaled x y
)))
21 (vars (send self
:content-variables
))
22 (trans (identity-matrix (send self
:num-variables
))))
23 (send self
:idle-on nil
)
24 (send self
:while-button-down
27 (setf p
(apply #'calcsphere
28 (send self
:canvas-to-scaled x y
)))
29 (setf (select trans vars vars
) (make-rotation oldp p
))
31 (send self
:slot-value
'rotation-type trans
)
32 (send self
:idle-on t
))