Computer Graphics Workshop '97 PS2 Solutions | 1/10/97 |
;;; Problem 2-1 (define M_PI 3.14159265358979323846) ;; root of scene graph (define root (new-SoSeparator)) (-> root 'ref) ;; create viewer and show it (define viewer (examiner root)) ;; separator and nodes for left eye (define left-eye-sep (new-SoSeparator)) (-> root 'addChild left-eye-sep) (define left-eye-mat (new-SoMaterial)) (-> left-eye-sep 'addChild left-eye-mat) (define left-eye-xform (new-SoTransform)) (-> left-eye-sep 'addChild left-eye-xform) (-> left-eye-sep 'addChild (new-SoSphere)) ;; separator and nodes for right eye (define right-eye-sep (new-SoSeparator)) (-> root 'addChild right-eye-sep) (define right-eye-mat (new-SoMaterial)) (-> right-eye-sep 'addChild right-eye-mat) (define right-eye-xform (new-SoTransform)) (-> right-eye-sep 'addChild right-eye-xform) (-> (-> right-eye-xform 'translation) 'setValue 3 0 0) (-> right-eye-sep 'addChild (new-SoSphere)) ;; separator and nodes for nose (define nose-sep (new-SoSeparator)) (-> root 'addChild nose-sep) (define nose-mat (new-SoMaterial)) (-> nose-sep 'addChild nose-mat) (define nose-xform (new-SoTransform)) (-> nose-sep 'addChild nose-xform) (-> (-> nose-xform 'translation) 'setValue 1.5 -3 0) (-> nose-sep 'addChild (new-SoCone)) ; turn nose upside down: rotation about x axis by ; 180 degrees (pi radians) (-> (-> nose-xform 'rotation) 'setValue (new-SbVec3f 1 0 0) M_PI) ;; separator and nodes for mouth (define mouth-sep (new-SoSeparator)) (-> root 'addChild mouth-sep) (define mouth-mat (new-SoMaterial)) (-> mouth-sep 'addChild mouth-mat) (define mouth-xform (new-SoTransform)) (-> (-> mouth-xform 'translation) 'setValue 1.5 -6 0) (-> mouth-sep 'addChild mouth-xform) (-> mouth-sep 'addChild (new-SoCube)) ;; 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-2 (define M_PI 3.14159265358979323846) ;; root of scene graph (define root (new-SoSeparator)) (-> root 'ref) ;; create viewer and show it (define viewer (examiner root)) ;; separator and nodes for left eye (define left-eye-sep (new-SoSeparator)) (-> root 'addChild left-eye-sep) (define left-eye-mat (new-SoMaterial)) (-> left-eye-sep 'addChild left-eye-mat) (define left-eye-xform (new-SoTransform)) (-> left-eye-sep 'addChild left-eye-xform) (define left-eye (new-SoSphere)) (-> left-eye-sep 'addChild left-eye) ; dragger to manipulate radius of left eye (define left-eye-dragger (new-SoTranslate1Dragger)) (-> left-eye-sep 'addChild left-eye-dragger) (-> (-> 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)) (-> root 'addChild right-eye-sep) (define right-eye-mat (new-SoMaterial)) (-> right-eye-sep 'addChild right-eye-mat) (define right-eye-xform (new-SoTransform)) (-> right-eye-sep 'addChild right-eye-xform) (-> (-> right-eye-xform 'translation) 'setValue 3 0 0) (-> right-eye-sep 'addChild (new-SoSphere)) ;; separator and nodes for nose (define nose-sep (new-SoSeparator)) (-> root 'addChild nose-sep) (define nose-mat (new-SoMaterial)) (-> nose-sep 'addChild nose-mat) (define nose-xform (new-SoTransform)) (-> nose-sep 'addChild nose-xform) (-> (-> nose-xform 'translation) 'setValue 1.5 -3 0) (define nose (new-SoCone)) (-> nose-sep 'addChild nose) ; turn nose upside down: rotation about x axis by ; 180 degrees (pi radians) (-> (-> nose-xform 'rotation) 'setValue (new-SbVec3f 1 0 0) M_PI) ; dragger to manipulate radius of nose (define nose-radius-dragger (new-SoTranslate1Dragger)) (-> nose-sep 'addChild nose-radius-dragger) ; remember, ; nose is upside down! (-> (-> nose-radius-dragger 'translation) 'setValue 1 6.5 0) ; hooking up the dragger using a decompose engine (define nose-radius-decomp (new-SoDecomposeVec3f)) (-> (-> nose-radius-decomp 'vector) 'connectFrom (-> nose-radius-dragger 'translation)) (-> (-> nose 'bottomRadius) 'connectFrom (-> nose-radius-decomp 'x)) ;; separator and nodes for mouth (define mouth-sep (new-SoSeparator)) (-> root 'addChild mouth-sep) (define mouth-mat (new-SoMaterial)) (-> mouth-sep 'addChild mouth-mat) (define mouth-xform (new-SoTransform)) (-> (-> mouth-xform 'translation) 'setValue 1.5 -6 0) (-> mouth-sep 'addChild mouth-xform) (-> mouth-sep 'addChild (new-SoCube)) ;; change mode of viewer (-> viewer 'setViewing 0)
;;; 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 root (new-SoSeparator)) (-> root 'ref) (define viewer (examiner root)) (define drag (new-SoTranslate1Dragger)) (-> root 'addChild drag) ;; 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)) (-> root 'addChild cone-sep) ;; A transform node just for vertically positioning the cone. (define transform2 (new-SoTransform)) (-> (-> transform2 'translation) 'setValue 0 2 0) (-> cone-sep 'addChild transform2) ;; The transform that deals with the cone's rotation. (define transform (new-SoTransform)) (-> cone-sep 'addChild transform) (define cone (new-SoCone)) (-> cone-sep 'addChild cone) ;; 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)) (-> root 'addChild cd-xform) ;; Create and place new dragger (define cdrag (new-SoRotateCylindricalDragger)) (-> root 'addChild cdrag) (-> (-> 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)) ;; Change the viewing mode of the viewer (-> viewer 'setViewing 0)
$Id: index.html,v 1.5 1997/01/03 08:27:46 kbrussel Exp $