home *** CD-ROM | disk | FTP | other *** search
- ; book pp.309-310
-
- (send spin-proto :add-mouse-mode 'hand-rotate
- :title "Hand Rotate"
- :cursor 'hand
- :click :do-hand-rotate)
- (defmeth spin-proto :canvas-to-sphere (x y rad)
- (let* ((p (send self :canvas-to-scaled x y))
- (x (first p))
- (y (second p))
- (norm-2 (+ (* x x) (* y y)))
- (rad-2 (^ rad 2))
- (z (sqrt (max (- rad-2 norm-2) 0))))
- (if (< norm-2 rad-2)
- (list x y x)
- (let ((r (sqrt (/ norm-2 rad-2))))
- (list (/ x r) (/ y r) (/ z r))))))
- (defmeth spin-proto :do-hand-rotate (x y m1 m2)
- (let* ((m (send self :num-variables))
- (range (send self :scaled-range 0))
- (rad (/ (apply #'- range) 2))
- (oldp (send self :canvas-to-sphere x y rad))
- (p oldp)
- (vars (send self :content-variables))
- (trans (identity-matrix m)))
- (flet ((spin-sphere (x y)
- (setf oldp p)
- (setf p (send self :canvas-to-sphere x y rad))
- (setf (select trans vars vars) (make-rotation oldp p))
- (when m1
- (send self :rotation-type trans)
- (send self :idle-on t))
- (send self :apply-transformation trans)))
- (send self :idle-on nil)
- (send self :while-button-down #'spin-sphere))))
-
-