INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Object-Oriented Modeling David Carr Fundamentals of Computer Graphics Spring 2004 1 L Feb-15-04 SMD159, Object-Oriented Modeling Overview • Motivation • Hierarchical models, trees, and DAGs • Scene graphs • Jazz, an example scene graph system • Other graphical trees 2 L Feb-15-04 SMD159, Object-Oriented Modeling INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Motivation 3 L Feb-15-04 SMD159, Object-Oriented Modeling 1
Why Object Oriented? • Strong tie between object-oriented design and graphics - Often hand-in-hand • Concentration on drawing has drawbacks - Interactivity is awkward - Independent movement (animation) is awkward - Pruning the display list is difficult - Reuse is difficult 4 L Feb-15-04 SMD159, Object-Oriented Modeling Advantages of Object-Oriented Models • Can define objects and create many instances - E.g. a car has 4 wheels + Define the wheels once + Create 4 instances in different locations - Separates location from structure • Simplifies Animation Wheels rotate independently of the car 5 L Feb-15-04 SMD159, Object-Oriented Modeling INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Hierarchical Models, Trees, and DAGs 6 L Feb-15-04 SMD159, Object-Oriented Modeling 2
Object Models • Consider the car example • We would want: - Wheels made of tires, rims, and hub caps - Windows made of glass - Body panels made of metal and painted - Lens for lights made of different colors of plastic - Lights with different intensities - … • Note there are many common components 7 L Feb-15-04 SMD159, Object-Oriented Modeling Simplified Car Object • Easily represented as a tree • But, requires 4 copies of the wheel • Better structure, DAG - Directed Acyclic Graph 8 L Feb-15-04 SMD159, Object-Oriented Modeling Trees versus DAGs • Logically the same • Tree requires unique nodes, DAG can share • DAG representations of trees are loop free • For object models: - DAGs require separation of common properties from specific properties - I.E., the values of parameters must be separated from parameter existence. 9 L Feb-15-04 SMD159, Object-Oriented Modeling 3
Storing Trees • Binary trees are simple - Left and right children • But, arbitrary trees don’t easily fit • Left child, Right sibling - List representation - Natural for pre-order traversal using recursive traversal 10 L Feb-15-04 SMD159, Object-Oriented Modeling Traversal and OpenGL • Consider a hierarchical model - Each level is defined relative to the one above (its container) - We need a uniform way to handle changes • If we use recursive traversal - Associated with each left-child there is: + A new sub-model + A new graphical context - Associated with each right-sibling + The sub-model context is unchanged + But, the sibling may have its own graphical context • So: - A push-draw node/draw sub-model-pop applies to the graphics - The program can’t do this for us, we must do it explicitly 11 L Feb-15-04 SMD159, Object-Oriented Modeling Pseudo Code • Method DrawTree - glPushMatrix, glPushParameters, … - Modify to create map local coordinates, parameters - DrawTree on left child - Draw self - DrawTree on right sibling - glPopMatrix, glPopParameters, … - Return 12 L Feb-15-04 SMD159, Object-Oriented Modeling 4
Example, a Humanoid Figure • Head and limbs attached to torso as children. - Top figure shows block diagram - Bottom figure is tree • Matrix traversal if M is transform for torso - M fi MM h head fi M torso fi - MM lua fi MM lua M lla left-lower arm fi - MM lua Left-upper arm fi M … 13 L Feb-15-04 SMD159, Object-Oriented Modeling Graphical Objects • How should we implement an object-oriented graphics system? • What are the characteristics of objects? - Topology - Geometry - Surface material • What other things do we need? - Lights - Viewers (more than one per scene?) - Operations on objects such as rendering 14 L Feb-15-04 SMD159, Object-Oriented Modeling Simple Example, a Cube (Topology) • 6 faces, with 8 vertices • Same length sides • Right angles in each corner • Canonical cube - Front, lower-left corner at (0,0,0) - Unit sides - Vertices (0,0,0), (1,0,0), (1,1,0), (0,1,0), repeat z=1 - Faces (0,1,2,3), (1,5,6,2), … - Note, could define based on center! 15 L Feb-15-04 SMD159, Object-Oriented Modeling 5
Cube (Other attributes) • Geometry • Materials and/or Color • Location in world or relative - By face to parent - By entire cube - Only light properties - Front, lower-left corner ( center ) • Methods • Size - Render - Length of side • Orientation - Direction of front, bottom edge - Direction from center to a vertex 16 L Feb-15-04 SMD159, Object-Oriented Modeling INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Scene Graphs 17 L Feb-15-04 SMD159, Object-Oriented Modeling Motivation • Need a structure to construct hierarchical representations of a scene • Would like to describe the scene and then modify only small parts • Would like to avoid (re)writing the code to display the hierarchical representation - Reuse - Reduced chance of error • Would like to save the scene in a file for reuse 18 L Feb-15-04 SMD159, Object-Oriented Modeling 6
Scene Graphs • We’ve see how trees (DAGs) can represent objects - Nodes are the objects - Links are their relationship • What if we extend the idea? We could - Have nodes for transformations - Represent cameras as nodes fi Scene Graphs 19 L Feb-15-04 SMD159, Object-Oriented Modeling Scene Graph Basics • Different types of nodes for: - Transformations - Object aggregation - Material properties - Cameras + Limited parts of the hierarchy + Different views + Special properties - Types are application dependent • Links for relationships • Graph compiler - API or language • Rendering engine 20 L Feb-15-04 SMD159, Object-Oriented Modeling Scene Graph Systems • Open Inventor - SGI, API - Based on GL (now OpenGL) • VRML - Text description language - Based on Open Inventor • X3D - Extension of VRML adding XML syntax, semantics • Java 3D - Java-based API - Based on OpenGL • Jazz - Java-based, 2D API for Zooming User Interfaces (ZUIs) • Piccolo - Simplified version of Jazz 21 L Feb-15-04 SMD159, Object-Oriented Modeling 7
INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Jazz, an Example Scene Graph System 22 L Feb-15-04 SMD159, Object-Oriented Modeling Zooming User Interfaces • Problems with Overlapping • ZUI an Alternate Paradigm Windows - Infinite canvas, infinitely stretchable - Significant time managing - No icons, overlapping windows windows. • Navigation by zoom and pan - Replacement causes a disruptive - Smooth context switch maintains context switch spatial continuity - Even a “rooms” metaphor causes - Small windows effectively icons the context switch - Rooms are groups of windows - Scrolling is not an appropriate - Semantic zooming browsing method • Navigation aids and shortcuts + For many applications - Windows may be views of the + But, it’s all you usually get. canvas - Windows may be pasted to the display instead of the canvas 23 L Feb-15-04 SMD159, Object-Oriented Modeling Why a Special Scene Graph System? • ZUIs have unique requirements. They must support: - Custom non-rectangular or transparent graphics - Large numbers of objects - Arbitrary transforms and hierarchical grouping - Continuous and smooth zooms and pans - Rendering objects differently in different (simultaneous) contexts - Multiple views - Event handlers for individual elements and groups of objects • Standard tool kits don’t met these requirements 24 L Feb-15-04 SMD159, Object-Oriented Modeling 8
Jazz Architecture • Nodes, visual components, and cameras • Nodes - Hierarchy, which represents relationships between objects - No visual appearance - Based on light-weight ZNode object - Specify where something is in the visual hierarchy (structure) • Visual Components - Provide appearance - Attached to visual leaf nodes and visual group nodes - Specify what something looks like (content) 25 L Feb-15-04 SMD159, Object-Oriented Modeling Jazz Architecture • Cameras - Views of the scene graph - Implement a drawing surface that is a Swing component - Can also be interior to a scene graph, provide an embedded view of the graph (portals) - Contains a list of layers 26 L Feb-15-04 SMD159, Object-Oriented Modeling Jazz Events • Follow the Java model - Listeners attached to scene graph nodes - Multiple listeners allowed • May be associated with any scene graph node • Two kinds - Input, mouse events, etc. - Object, result from modifications of the scene graph • Events are passed up the tree to ancestors by default • Are dispatched in the “event thread” - Jazz is not thread safe - Same restrictions as Swing and AWT apply 27 L Feb-15-04 SMD159, Object-Oriented Modeling 9
Recommend
More recommend