logo资料库

OpenSceneGraph 3.0 Beginners Guide.pdf

第1页 / 共412页
第2页 / 共412页
第3页 / 共412页
第4页 / 共412页
第5页 / 共412页
第6页 / 共412页
第7页 / 共412页
第8页 / 共412页
资料共412页,剩余部分请下载后查看
Cover
Copyright
Credits
Foreword
About the Authors
About the Reviewers
Table of Contents
Preface
Chapter 1: The Journey into OpenSceneGraph
A quick overview of rendering middleware
Scene graphs
The Birth and development of OSG
Components
Why OSG?
Who uses OSG?
Have a quick taste
Time for action – say "Hello World" OSG style
Live in community
Summary
Chapter 2: Compilation and Installation of OpenSceneGraph
System requirements
Using the installer
Time for action – installing OSG
Running utilities
Time for action – playing with osgviewer
Using the project wizard
Time for action – creating your solution with one click
Prebuilts making trouble?
Cross-platform building
Starting CMake
Time for action – running CMake in GUI mode
Setting up options
Generating packages using Visual Studio
Time for action – building with a Visual Studio solution
Generating packages using gcc
Time for action – building with a UNIX makefile
Configuring environment variables
Summary
Chapter 3: Creating Your First OSG Program
Constructing your own projects
Time for action – building applications with CMake
Using a root node
Time for action – improving the "Hello World" example
Understanding memory management
ref_ptr<> and Referenced classes
Collecting garbage: why and how
Tracing the managed entities
Time for action – monitoring counted objects
Parsing command-line arguments
Time for action – reading the model filename from the
command line
Tracing with the notifier
Redirecting the notifier
Time for action – saving the log file
Summary
Chapter 4: Building Geometry Models
How OpenGL draws objects
Geode and Drawable classes
Rendering basic shapes
Time for action – quickly creating simple objects
Storing array data
Vertices and vertex attributes
Specifying drawing types
Time for action – drawing a colored quad
Indexing primitives
Time for action – drawing an octahedron
Using polygonal techniques
Time for action – tessellating a polygon
Rereading geometry attributes
Customizing a primitive functor
Time for action – collecting triangle faces
Implementing your own drawables
Using OpenGL drawing calls
Time for action – creating the famous OpenGL teapot
Summary
Chapter 5: Managing Scene Graph
The Group interface
Managing parent nodes
Time for action – adding models to the scene graph
Traversing the scene graph
Transformation nodes
Understanding the matrix
The MatrixTransform class
Time for action – performing translations of child nodes
Switch nodes
Time for action – switching between the normal and
damaged Cessna
Level-of-detail nodes
Time for action – constructing a LOD Cessna
Proxy and paging nodes
Time for action – loading a model at runtime
Customizing your own NodeKits
Time for action – animating the switch node
The visitor design pattern
Visiting scene graph structures
Time for action – analyzing the Cessna structure
Summary
Chapter 6: Creating Realistic Rendering Effects
Encapsulating the OpenGL state machine
Attributes and modes
Time for action – setting polygon modes of different nodes
Inheriting render states
Time for action – lighting the glider or not
Playing with fixed-function effects
Time for action – applying simple fog to models
Lights and light sources
Time for action – creating light sources in the scene
The Image class
The basis of texture mapping
Time for action – loading and applying 2D textures
Handling rendering order
Time for action – achieving the translucent effect
Understanding graphics shaders
Using uniforms
Time for action – implementing a cartoon cow
Working with the geometry shader
Time for action – generating a Bezier curve
Summary
Chapter 7: Viewing the World
From world to screen
The Camera class
Rendering order of cameras
Time for action – creating an HUD camera
Using a single viewer
Digging into the simulation loop
Time for action – customizing the simulation loop
Using a composite viewer
Time for action – rendering more scenes at one time
Changing global display settings
Time for action – enabling global multisampling
Stereo visualization
Time for action – rendering anaglyph stereo scenes
Rendering to textures
Frame buffer, pixel buffer, and FBO
Time for action – drawing aircrafts on a loaded terrain
Summary
Chapter 8: Animating Scene Objects
Taking references to functions
List of callbacks
Time for action – switching nodes in the update traversal
Avoiding conflicting modifications
Time for action – drawing a geometry dynamically
Understanding ease motions
Animating the transformation nodes
Time for action – making use of the animation path
Changing rendering states
Time for action – fading in
Playing movies on textures
Time for action – rendering a flashing spotlight
Creating complex key-frame animations
Channels and animation managers
Time for action – managing animation channels
Loading and rendering characters
Time for action – creating and driving a character system
Summary
Chapter 9: Interacting with Outside Elements
Various events
Handling mouse and keyboard inputs
Time for action – driving the Cessna
Adding customized events
Time for action – creating a user timer
Picking objects
Intersection
Time for action – clicking and selecting geometries
Windows, graphics contexts, and cameras
The Traits class
Time for action – configuring the traits of a rendering window
Integrating OSG into a window
Time for action – attaching OSG with a window handle in Win32
Summary
Chapter 10: Saving and Loading Files
Understanding file I/O plugins
Discovery of specified extension
Supported file formats
The pseudo-loader
Time for action – reading files from the Internet
Configuring third-party dependencies
Time for action – adding libcurl support for OSG
Writing your own plugins
Handling the data stream
Time for action – designing and parsing a new file format
Serializing OSG native scenes
Creating serializers
Time for action – creating serializers for user-defined classes
Summary
Chapter 11: Developing Visual Components
Creating billboards in a scene
Time for action – creating banners facing you
Creating texts
Time for action – writing descriptions for the Cessna
Creating 3D texts
Time for action – creating texts in the world space
Creating particle animations
Time for action – building a fountain in the scene
Creating shadows on the ground
Time for action – receiving and casting shadows
Implementing special effects
Time for action – drawing the outline of models
Playing with more NodeKits
Summary
Chapter 12: Improving Rendering Efficiency
OpenThreads basics
Time for action – using a separate data receiver thread
Understanding multithreaded rendering
Time for action – switching between different threading models
Dynamic scene culling
Occluders and occludees
Time for action – adding occluders to a complex scene
Improving your application
Time for action – sharing textures with a customized callback
Paging huge scene data
Making use of the quad-tree
Time for action – building a quad-tree for massive rendering
Summary
Appendix: Pop Quiz Answers
Chapter 2
Dependencies of osgviewer
The difference between ALL_BUILD and 'build all'
Chapter 3
Configuring OSG path options yourselves
Release a smart pointer
Chapter 4
Results of different primitive types
Optimizing indexed geometries
Chapter 5
Fast dynamic casting
Matrix multiplications
Chapter 6
Lights without sources
Replacements of built-in uniforms
Chapter 7
Changing model positions in the HUD camera
Another way to display the same scene in different views
Chapter 8
Adding or setting callbacks
Choosing the alpha setter and the callback
Chapter 9
Handling events within nodes
Global and node-related events
Chapter 10
Getting rid of pseudo-loaders
Understanding the inheritance relations
Chapter 11
Text positions and the projection matrix
Chapter 12
Carefully blocking threads
Number of created levels and files
问题章节
Indexing primitives
Reading geometry attributes
Index
OpenSceneGraph 3.0 Beginner's Guide Create high-performance virtual reality applications with OpenSceneGraph, one of the best 3D graphics engines Rui Wang Xuelei Qian BIRMINGHAM - MUMBAI
OpenSceneGraph 3.0 Beginner's Guide Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: December 2010 Production Reference: 1081210 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849512-82-4 www.packtpub.com Cover Image by Ed Maclean (edmaclean@gmail.com)
Credits Authors Rui Wang Xuelei Qian Reviewers Jean-Sébastien Guay Cedric Pinson Acquisition Editor Usha Iyer Development Editor Maitreya Bhakal Technical Editors Conrad Sardinha Vanjeet D'souza Indexers Tejal Daruwale Hemangini Bari Monica Ajmera Mehta Editorial Team Leader Akshara Aware Project Team Leader Lata Basantani Project Coordinator Leena Purkait Proofreader Dirk Manuel Graphics Nilesh Mohite Production Coordinator Adline Swetha Jesuthas Cover Work Adline Swetha Jesuthas
Foreword Scene graphs have been the foundation of real-time graphics applications for the last two decades, whether it is a 3D game on a phone or a professional flight simulator costing millions of pounds, a virtual reality application through to the latest 3D real-time visualization on television, scene graphs are there under the hood, quietly churning out high quality visuals. However, even powerful tools like scene graphs don't write world leading graphics applications by themselves, they still need developers with the skill and knowledge to make best use of them and the hardware that they run on. This expertise isn't something that you can gain by reading a few pages on the web—graphics hardware and software continues to evolve and you need to keep up with it... It's a journey of learning and exploration undertaken throughout your career. OpenSceneGraph itself is the world's leading scene graph API, and has been written by, and to fulfil the needs of, professional graphics application developers. It is written to be powerful and productive to use rather than cut down and easy to use. Your first encounter with OpenSceneGraph may well be daunting; it's a professional grade scene graph containing many hundreds of classes and modules. But with this sophistication comes the ability to write very powerful graphics applications quickly so it's well worth the effort in learning how to make best use of it. The authors of this book are users and contributors to the OpenSceneGraph software and its community. For me it's rewarding to see this open source project reach out across the world and inspire people, such as Rui Wang and Xuelei Qian, not only to use and contribute to the software, but also to write a book about it so that others can start their own journey into real-time graphics.
With this book their aim has been to take you from your first steps through to being able to use advanced features of the OpenSceneGraph and the graphics hardware that it runs on. Learning new concepts and APIs can often be dry and awkward, but once you get your first applications on screen you'll glimpse the potential, and it won't be long before you are seeing complex worlds come life. As a real-time graphics geek myself, I can't think anything more rewarding than immersing yourself in 3D worlds that you help create. Some familiarity with linear algebra, such like 3D vectors, quaternion numbers and matrix transformations, is helpful, too. Robert Osfield. OpenSceneGraph Project Lead
About the Authors Rui Wang is a software engineer at the Chinese Academy of Surveying and Mapping and the manager of osgChina, the largest OSG discussion website in China. He is one of the most active members of the official OSG community, who contributes to the serialization I/O, GPU-based particle functionalities, BVH and animated GIF plugins, and other fixes and improvements to the OSG project. He translated Paul Martz's OpenSceneGraph Quick Start Guide into Chinese in 2008, and wrote his own Chinese book OpenSceneGraph Design and Implementation in 2009, cooperating with Xuelei Qian. He is also a novel writer and a guitar lover. Xuelei Qian received his B.Sc. degree in Precision Instrument Engineering from Southeast University, Jiangsu, China, and his Ph.D. degree in applied graphic computing from the University of Derby, Derby, UK in 1998 and 2005, respectively. Upon completion of his Ph.D. degree, he worked as a postdoctoral research fellow in the Dept. of Precision Instrument and Mechanology at Tsinghua University and his current research interests include E-manufacturing, STEP-NC and intelligent CNC, and virtual reality engineering.
Acknowledgement We'd like to first thank Don Burns and Robert Osfield for their creative efforts in giving birth to OpenSceneGraph, as well as thousands of members in the OSG core community, for their supports and contributions all the time. Thanks again to Robert Osfield, a pure open source enthusiast and father of a happy family, for his tremendous passion in leading the development the OSG project for so many years (since 1999). He also took time out of his busy schedule to write the foreword for this book. We must express our deep gratitude to Rakesh Shejwal, Usha Iyer, Leena Purkait, Priya Mukherji, and the entire Packt Publishing team for their talented work in producing yet another product, as well as Jean-Sébastien Guay and Cedric Pinson for reviewing the first drafts of the book and providing insightful feedback. We would like to acknowledge John F. Richardson and Marek Teichmann, who announced the book at the OpenSceneGraph BOF at SIGGRAPH 2010. We also offer special thanks to Zhanying Wei, Xuexia Chen, Shixing Yang, Peng Xiao, Qingliang Liu, Su Jiang, and a number of other people who contributed to the completion of this book in different ways. Finally, we owe the most sincere thanks to Paul Martz, who dedicates the first non-commercial book to OSG beginners all over the world and provides great help in supporting the publication of our past and current books.
分享到:
收藏