## 1/12/96

Problems
Problem 1 - Modifying the scene

```;;; Problem 2-1

(define M_PI 3.14159265358979323846)

;; create viewer and show it

(define viewer (new-SoXtExaminerViewer))
(-> viewer 'show)

;; root of scene graph

(define root (new-SoSeparator))
(-> root 'ref)

;; separator and nodes for left eye

(define left-eye-sep (new-SoSeparator))
(define left-eye-mat (new-SoMaterial))
(define left-eye-xform (new-SoTransform))

;; separator and nodes for right eye

(define right-eye-sep (new-SoSeparator))
(define right-eye-mat (new-SoMaterial))
(define right-eye-xform (new-SoTransform))
(-> (-> right-eye-xform 'translation) 'setValue 3 0 0)

;; separator and nodes for nose

(define nose-sep (new-SoSeparator))
(define nose-mat (new-SoMaterial))
(define nose-xform (new-SoTransform))
(-> (-> nose-xform 'translation) 'setValue 1.5 -3 0)

; turn nose upside down: rotation about x axis by

(-> (-> nose-xform 'rotation) 'setValue (new-SbVec3f 1 0 0) M_PI)

;; separator and nodes for mouth

(define mouth-sep (new-SoSeparator))
(define mouth-mat (new-SoMaterial))
(define mouth-xform (new-SoTransform))
(-> (-> mouth-xform 'translation) 'setValue 1.5 -6 0)

;; show scene graph

(-> viewer 'setSceneGraph root)

;; rotating cube so it stands on edge -- about z axis
;; this rotation is replaced by the next one, so re-evaluate
;; the following line to see its effect.

(-> (-> mouth-xform 'rotation) 'setValue (new-SbVec3f 0 0 1)
(/ M_PI 4))

;; rotating cube so it stands on corner
;; I used a TrackballManip to get these values.
;; Example of doing this:
;; (define my-manip (new-SoTrackballManip))
;; (define my-axis (new-SbVec3f))
;; (define my-angle 0.0)
;; (-> (-> my-manip 'rotation) 'getValue my-axis my-angle)

(-> (-> mouth-xform 'rotation) 'setValue
(new-SbVec3f
-0.614901661872864
0.315593332052231
0.722701013088226)
1.06886279582977)
```
Problem 2 - Using draggers to modify the scene

```;;; Problem 2-2

(define M_PI 3.14159265358979323846)

;; create viewer and show it

(define viewer (new-SoXtExaminerViewer))
(-> viewer 'show)

;; root of scene graph

(define root (new-SoSeparator))
(-> root 'ref)

;; separator and nodes for left eye

(define left-eye-sep (new-SoSeparator))
(define left-eye-mat (new-SoMaterial))
(define left-eye-xform (new-SoTransform))
(define left-eye (new-SoSphere))

; dragger to manipulate radius of left eye

(define left-eye-dragger (new-SoTranslate1Dragger))
(-> (-> left-eye-dragger 'translation) 'setValue 1 -8 0)

; hooking up the dragger using a decompose engine

(define left-eye-decomp (new-SoDecomposeVec3f))
(-> (-> left-eye-decomp 'vector) 'connectFrom
(-> left-eye-dragger 'translation))
(-> (-> left-eye 'radius) 'connectFrom (-> left-eye-decomp 'x))

;; separator and nodes for right eye

(define right-eye-sep (new-SoSeparator))
(define right-eye-mat (new-SoMaterial))
(define right-eye-xform (new-SoTransform))
(-> (-> right-eye-xform 'translation) 'setValue 3 0 0)

;; separator and nodes for nose

(define nose-sep (new-SoSeparator))
(define nose-mat (new-SoMaterial))
(define nose-xform (new-SoTransform))
(-> (-> nose-xform 'translation) 'setValue 1.5 -3 0)
(define nose (new-SoCone))

; turn nose upside down: rotation about x axis by

(-> (-> nose-xform 'rotation) 'setValue (new-SbVec3f 1 0 0) M_PI)

; dragger to manipulate radius of nose

; remember,
; nose is upside down!
(-> (-> nose-radius-dragger 'translation) 'setValue 1 6.5 0)

; hooking up the dragger using a decompose engine

;; separator and nodes for mouth

(define mouth-sep (new-SoSeparator))
(define mouth-mat (new-SoMaterial))
(define mouth-xform (new-SoTransform))
(-> (-> mouth-xform 'translation) 'setValue 1.5 -6 0)

;; show scene graph

(-> viewer 'setSceneGraph root)

;; change mode of viewer

(-> viewer 'setViewing 0)
```
Problem 3 - Further modifications with draggers

```;;; Problem 2-3

;; Cone with a Translate1Dragger for translation;
;; this dragger moves along with the cone.
;; RotateCylindricalDragger combined with engines for
;; rotation about the cone's x axis. This dragger does
;; not translate along with the cone.

(define viewer (new-SoXtExaminerViewer))
(-> viewer 'show)

(define root (new-SoSeparator))
(-> root 'ref)

(define drag (new-SoTranslate1Dragger))

;; Create subgraph for cone.
;; Note that we place the transform for the cone under a
;; separator, so it doesn't affect anything after it.

(define cone-sep (new-SoSeparator))

;; A transform node just for vertically positioning the cone.

(define transform2 (new-SoTransform))
(-> (-> transform2 'translation) 'setValue 0 2 0)

;; The transform that deals with the cone's rotation.

(define transform (new-SoTransform))

(define cone (new-SoCone))

;; Connect the translation field of the transform node to the
;; translation field of the dragger node.

(-> (-> transform 'translation) 'connectFrom
(-> drag 'translation))

;; Transform for RotateCylindrical dragger;
;; dragger appears to the right of the cone.

(define cd-xform (new-SoTransform))

;; Create and place new dragger

(define cdrag (new-SoRotateCylindricalDragger))
(-> (-> cd-xform 'translation) 'setValue 4 1 0)

;; DecomposeRotation engine for getting axis/angle of
;; RotateCylindricalDragger's rotation

(define decomprot (new-SoDecomposeRotation))
(-> (-> decomprot 'rotation) 'connectFrom (-> cdrag 'rotation))

;; DecomposeVec3f engine for decomposing the axis.
;; We need to do this because of a "feature" of the
;; DecomposeRotation engine; the axis flips 180
;; degrees during a 360 degree rotation.

(define decomp2 (new-SoDecomposeVec3f))
(-> (-> decomp2 'vector) 'connectFrom (-> decomprot 'axis))

;; ComposeVec3f engine for making the new axis of rotation.
;; Note that we only connect up the relevant value.

(define comp2 (new-SoComposeVec3f))
(-> (-> comp2 'x) 'connectFrom (-> decomp2 'y))

;; ComposeRotation engine for combining new axis and old angle

(define comprot (new-SoComposeRotation))
(-> (-> comprot 'axis) 'connectFrom (-> comp2 'vector))
(-> (-> comprot 'angle) 'connectFrom (-> decomprot 'angle))

;; Connect up the rotation field of the cone's transform

(-> (-> transform 'rotation) 'connectFrom (-> comprot 'rotation))

;; Show the scene

(-> viewer 'setSceneGraph root)

;; Change the viewing mode of the viewer

(-> viewer 'setViewing 0)
```