Computer Graphics Workshop '96 Lecture Notes | 1/26/96 |
We have already used one of these conversions; recall that all the inputs and outputs to the Compose and Decompose engines in the second problem set were MF fields, but that we were hooking up single-value, or SF, fields to them.
Sensors allow more general functions to be performed than engines do, but engines have the advantage that they automatically update their values; this allows simple animation tasks to be delegated to engines while the rest of the application works on more complicated tasks. for more information on engines, see Chapter 13 of the Inventor Mentor, and see the examples from this chapter in /mit/thingworld/Ivy/Mentor/.
A perspective camera views the scene in the same fashion as the human eye; that is, objects farther away from the camera appear smaller. This type of viewing style is known as a perspective projection. An orthographic camera has no perspective; it uses a parallel projection so that objects far away from the camera look the same size as those near the camera. Each type of camera has associated fields whose values can be changed to alter the parameters of the view. An orthographic camera has a field, height, which specifies the height of the view volume; this, combined with the aspect ratio of the camera, specifies how much of the scene fits within the camera view. A perspective camera has a heightAngle field which performs a similar function. Both types of cameras have several fields inherited from the parent class, SoCamera, such as the position, orientation, and aspectRatio of the camera.
(define viewer (new-SoXtExaminerViewer)) ;;; ...Additional code for showing viewer, ;;; and setting up scene graph... ;;; This is a simple example: (define root (new-SoSeparator)) (-> root 'ref) (define draw-style (new-SoDrawStyle)) (-> (-> draw-style 'style) 'setValue SoDrawStyle::LINES) (-> root 'addChild draw-style) (-> root 'addChild (new-SoCube)) (-> viewer 'setSceneGraph root) ;;; Extract the camera from the viewer. (define camera (-> viewer 'getCamera)) (define other-camera '()) (if (= 1 (-> camera 'isOfType (SoPerspectiveCamera::getClassTypeId))) (set! other-camera (SoPerspectiveCamera-cast camera)) (set! other-camera (SoOrthographicCamera-cast camera)))We can also set the camera type of the viewer manually. Note, as described in the manual page, that the change does not take effect until the next time the viewer's scene graph is set:
(-> viewer 'setCameraType (SoOrthographicCamera::getClassTypeId)) (-> viewer 'setSceneGraph root)
Directional lights cause the fastest rendering of shapes, because they do not require shading over the surface of a polygon. Point lights are the next fastest, and spot lights are the slowest. You will probably find it best to use only directional lights, if needed, in your scenes.
Let's look at the difference between these three types of lights:
;;; Example of point, spot, and directional lights. ;;; Three viewers, one per light (define v1 (new-SoXtExaminerViewer)) (-> v1 'show) (-> v1 'setHeadlight 0) (define v2 (new-SoXtExaminerViewer)) (-> v2 'show) (-> v2 'setHeadlight 0) (define v3 (new-SoXtExaminerViewer)) (-> v3 'show) (-> v3 'setHeadlight 0) ;;; Three scenegraph roots, one per type of light. (define point-root (new-SoSeparator)) (-> point-root 'ref) (define spot-root (new-SoSeparator)) (-> spot-root 'ref) (define dir-root (new-SoSeparator)) (-> dir-root 'ref) ;;; Group node for holding point light ;;; and associated transform. (define point-light-group (new-SoTransformSeparator)) (-> point-root 'addChild point-light-group) (define light-xform (new-SoTransform)) (-> (-> light-xform 'translation) 'setValue 0.5 -0.5 -0.5) (-> point-light-group 'addChild light-xform) (define light (new-SoPointLight)) (-> point-light-group 'addChild light) (-> (-> light 'intensity) 'setValue 1.0) (define sphere (new-SoSphere)) (-> point-light-group 'addChild sphere) (-> (-> sphere 'radius) 'setValue 0.1) ;;; Group node for holding spot light ;;; and associated transform. (define spot-light-group (new-SoTransformSeparator)) (-> spot-root 'addChild spot-light-group) (define light-xform (new-SoTransform)) (-> (-> light-xform 'rotation) 'setValue (new-SbVec3f -0.356368511915207 0.0632830709218979 -0.932199954986572) 1.46062397956848) (-> (-> light-xform 'translation) 'setValue 1.6 0.0 2.0) (-> spot-light-group 'addChild light-xform) (define light (new-SoSpotLight)) (-> spot-light-group 'addChild light) (-> (-> light 'intensity) 'setValue 1.0) (-> (-> light 'dropOffRate) 'setValue 0.1) ;;; Group node for holding directional light ;;; and associated transform. (define dir-light-group (new-SoTransformSeparator)) (-> dir-root 'addChild dir-light-group) (define light-xform (new-SoTransform)) (-> (-> light-xform 'translation) 'setValue 0.5 -0.5 -0.5) (-> dir-light-group 'addChild light-xform) (define light (new-SoDirectionalLight)) (-> dir-light-group 'addChild light) (-> (-> light 'intensity) 'setValue 1.0) (-> (-> light 'direction) 'setValue -1 -1.3 -3.0) ;;; Group node for holding the three cubes. ;;; Shared among the three scene graphs. (define cube-group (new-SoGroup)) ;; Complexity node improves the shading of the cubes ;; at the expense of rendering speed. (define complexity (new-SoComplexity)) (-> cube-group 'addChild complexity) (-> (-> complexity 'value) 'setValue 0.7) (define mat (new-SoMaterial)) (-> cube-group 'addChild mat) (-> (-> mat 'diffuseColor) 'setValue 0.2 0.2 0.9) (define xform0 (new-SoTransform)) (-> cube-group 'addChild xform0) (-> (-> xform0 'rotation) 'setValue (new-SbVec3f 0.551838874816895 -0.806114614009857 -0.213665723800659) 0.859030544757843) (define cube1 (new-SoCube)) (-> cube-group 'addChild cube1) (-> (-> cube1 'width) 'setValue 0.25) (define xform1 (new-SoTransform)) (-> cube-group 'addChild xform1) (-> (-> xform1 'translation) 'setValue 1.125 0 -1.125) (define cube2 (new-SoCube)) (-> cube-group 'addChild cube2) (-> (-> cube2 'depth) 'setValue 0.25) (define xform2 (new-SoTransform)) (-> cube-group 'addChild xform2) (-> (-> xform2 'translation) 'setValue 0 -1.125 1.125) (define cube3 (new-SoCube)) (-> cube-group 'addChild cube3) (-> (-> cube3 'height) 'setValue 0.25) (-> point-root 'addChild cube-group) (-> spot-root 'addChild cube-group) (-> dir-root 'addChild cube-group) (-> v1 'setSceneGraph point-root) (-> v2 'setSceneGraph spot-root) (-> v3 'setSceneGraph dir-root)
(-> viewer 'setHeadlight 0) ;; turns off headlight (-> viewer 'setHeadlight 1) ;; turns on headlight
$Id: index.html,v 1.4 1996/01/18 22:58:49 kbrussel Exp $