graphical objects and scene graphs 1 angel: interactive computer graphics 5e © addison-wesley 2009
TRANSCRIPT
![Page 1: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/1.jpg)
Graphical Objects and Scene Graphs
1Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
![Page 2: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/2.jpg)
2Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Objectives
• Introduce graphical objects•Generalize the notion of objects to include lights, cameras, attributes
• Introduce scene graphs • Introduce space partitioning approaches
![Page 3: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/3.jpg)
3Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Limitations of Immediate Mode Graphics
•When we define a geometric object in an application, upon execution of the code the object is passed through the pipeline
• It then disappears from the graphical system
•To redraw the object, either changed or the same, we must reexecute the code
•Display lists provide only a partial solution to this problem
![Page 4: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/4.jpg)
4Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
OpenGL and Objects
•OpenGL lacks an object orientation•Consider, for example, a green sphere
We can model the sphere with polygons or use OpenGL quadrics
Its color is determined by the OpenGL state and is not a property of the object
•Defies our notion of a physical object•We can try to build better objects in code using object-oriented languages/techniques
![Page 5: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/5.jpg)
5Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Imperative Programming Model
•Example: rotate a cube
•The rotation function must know how the cube is represented
Vertex list Edge list
Application glRotate
cube data
results
![Page 6: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/6.jpg)
6Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Object-Oriented Programming Model
Application Cube Object
• In this model, the representation is stored with the object
• The application sends a message to the object• The object contains functions (methods) which allow it to transform itself
message
![Page 7: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/7.jpg)
7Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
C/C++
•Can try to use C structs to build objects •C++ provides better support
Use class construct
Can hide implementation using public, private, and protected members in a class
Can also use friend designation to allow classes to access each other
![Page 8: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/8.jpg)
8Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Cube Object
•Suppose that we want to create a simple cube object that we can scale, orient, position and set its color directly through code such ascube mycube;
mycube.color[0]=1.0;
mycube.color[1]= mycube.color[2]=0.0;
mycube.matrix[0][0]=………
![Page 9: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/9.jpg)
9Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Cube Object Functions
•We would also like to have functions that act on the cube such as mycube.translate(1.0, 0.0,0.0);mycube.rotate(theta, 1.0, 0.0, 0.0);setcolor(mycube, 1.0, 0.0, 0.0);
•We also need a way of displaying the cubemycube.render();
![Page 10: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/10.jpg)
10Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Building the Cube Object
class cube {
public:
float color[3];
float matrix[4][4];
// public methods
private:
// implementation
}
![Page 11: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/11.jpg)
11Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
The Implementation
•Can use any implementation in the private part such as a vertex list
•The private part has access to public members and the implementation of class methods can use any implementation without making it visible
•Render method is tricky but it will invoke the standard OpenGL drawing functions such as glVertex
![Page 12: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/12.jpg)
12Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Other Objects
•Other objects have geometric aspects Cameras
Light sources
•But we should be able to have nongeometric objects too
Materials
Colors
Transformations (matrices)
![Page 13: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/13.jpg)
13Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Application Code
cube mycube;
material plastic;
mycube.setMaterial(plastic);
camera frontView;
frontView.position(x ,y, z);
![Page 14: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/14.jpg)
14Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Light Object
class light { // match Phong model public: boolean type; //ortho or perspective boolean near; float position[3]; float orientation[3]; float specular[3]; float diffuse[3]; float ambient[3];}
![Page 15: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/15.jpg)
15Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Scene Descriptions
• If we recall figure model, we saw that We could describe model either by tree or by
equivalent code
We could write a generic traversal to display
• If we can represent all the elements of a scene (cameras, lights,materials, geometry) as C++ objects, we should be able to show them in a tree
Render scene by traversing this tree
![Page 16: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/16.jpg)
16Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Scene Graph
![Page 17: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/17.jpg)
17Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Preorder Traversal
glPushAttrib
glPushMatrix
glColor
glTranslate
glRotate
Object1
glTranslate
Object2
glPopMatrix
glPopAttrib
…
![Page 18: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/18.jpg)
18Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Group Nodes
•Necessary to isolate state chages Equivalent to OpenGL Push/Pop
•Note that as with the figure model We can write a universal traversal algorithm
The order of traversal can matter • If we do not use the group node, state changes
can persist
![Page 19: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/19.jpg)
19Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Inventor and Java3D
• Inventor and Java3D provide a scene graph API
• Scene graphs can also be described by a file (text or binary)
Implementation independent way of transporting scenes
Supported by scene graph APIs
• However, primitives supported should match capabilities of graphics systems
Hence most scene graph APIs are built on top of OpenGL or DirectX (for PCs)
![Page 20: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/20.jpg)
20Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
VRML
•Want to have a scene graph that can be used over the World Wide Web
•Need links to other sites to support distributed data bases
•Virtual Reality Markup Language Based on Inventor data base
Implemented with OpenGL
![Page 21: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/21.jpg)
Open Scene Graph
•Supports very complex geometries by adding occulusion culling in first path
•Supports translucently through a second pass that sorts the geometry
•First two passes yield a geometry list that is rendered by the pipeline in a third pass
21Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
![Page 22: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/22.jpg)
Space Partitioning
•Organizes and structures the space •Makes searching the space more efficient and directed
•Can significantly improve operation such as collision detection and hidden surface removal
22Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
![Page 23: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/23.jpg)
Octree
•How many collision tests must we do?
•How can we reduce this? Only test objects that are in
the same area
•Update tree for moving objects
23Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
http://www.piko3d.com/tutorials/space-partitioning-tutorial-piko3ds-dynamic-octree
(In 2D = Quadtree)
![Page 24: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/24.jpg)
Binary Space Partitioning Tree
• Binary Search• Hierarchy of oriented planes• + and - halfspaces
24Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
+
-
![Page 25: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/25.jpg)
BSP Trees
•As an efficient object representation
25Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
![Page 26: Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009](https://reader030.vdocuments.us/reader030/viewer/2022032604/56649e6c5503460f94b6b9c0/html5/thumbnails/26.jpg)
BSP Trees
•Collisions •hidden surface removal
Only pass triangles through the pipeline that will be visible
•Made this possible:
26Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009