advanced linux 3d graphics programming

641 400 0
advanced linux 3d graphics programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TEAM LinG - Live, Informative, Non-cost and Genuine! Advanced Linux 3D Graphics Programming Norman Lin Wordware Publishing, Inc. TEAM LinG - Live, Informative, Non-cost and Genuine! Library of Congress Cataloging-in-Publication Data Lin, Norman. Advanced Linux 3D graphics programming / by Norman Lin. p. cm. Includes index. ISBN 1-55622-853-8 (pbk.) 1. Computer graphics. 2. Linux. 3. Three-dimensional display systems. I. Title. T385 .L5555 2001 006.6'93 dc21 2001026370 CIP © 2001, Wordware Publishing, Inc. All Rights Reserved 2320 Los Rios Boulevard Plano, Texas 75074 No part of this book may be reproduced in any form or by any means without permission in writing from Wordware Publishing, Inc. Printed in the United States of America ISBN 1-55622-853-8 10987654321 0106 Blender is a registered trademark of Not a Number B. V. Other product names mentioned are used for identification purposes only and may be trademarks of their respective companies. All inquiries for volume purchases of this book should be addressed to Wordware Publishing, Inc., at the above address. Telephone inquiries may be made by calling: (972) 423-0090 TEAM LinG - Live, Informative, Non-cost and Genuine! Contents Acknowledgments x Preface xi Introduction xii Chapter 1 Basic Linux 3D Graphics Concepts 1 2D Graphics Fundamentals 1 3D Graphics Fundamentals 3 3D Coordinate Systems and Vectors 4 Perspective Projection 5 Matrices 6 Specific Matrix Transformations 6 Other Matrix Properties 7 The l3d Library Classes 8 Sample l3d Program 8 l3d Directory Structure 12 The Five-Step Process of l3d Programs 13 Overview of l3d Classes 19 Applications and Events 19 2D Graphics 20 Concrete Factory Management 24 Specifying Geometry and Behavior 25 Fixed- and Floating-Point Math 29 Summary of l3d Classes 31 Linux Programming Tools 32 Linux 3D Modeling 32 Blender Interface and Commands 33 Exporting and Importing Blender Models 36 Summary 37 Chapter 2 Rendering and Animation Techniques for 3D Polygons 39 Vertex Animation and 3D Morphing 39 Sample Program: morph3d 40 Lighting 48 Mathematical Models for Computing Light 49 Self Lighting 49 Ambient Lighting 50 Diffuse Reflection 50 Specular Reflection 55 Multiple Light Sources and Components 57 Radiosity and Ray Tracing 58 Dynamic or Static Lighting Computations 58 Fog 59 Rendering Techniques for Drawing Light 60 Flat Shading 61 iii TEAM LinG - Live, Informative, Non-cost and Genuine! Gouraud Shading 61 Phong Shading 63 Light Maps 63 Texture Mapping 64 Step 1: Define a Texture 65 Storing Texture Data 66 Classes for Loading Textures from Disk 68 Practical Issues in Dealing with Texture Image Files 73 Step 2: Define a Texture Space 74 Step 3: Map Between Texture Space and World Space 76 Calc: A Symbolic Algebra Package 79 Starting and Exiting Calc 79 Stack-Based Computation 80 Entering and Editing Mathematical Entities 82 Solving Systems of Equations 85 Solving the Texture Mapping Equations with Calc 86 Step 4: Reverse Project from Screen Coordinates into Texture Coordinates 89 Step 5: Map Texture Coordinates to Integer Indices and Draw 92 An Optimized Texture Mapping Strategy: u/z, v/z, 1/z 93 The Division Operation and Texture Mapping 95 Associating Textures with 3D Polygons 96 Rasterization Classes for 3D Polygons 98 An Abstract 3D Rasterizer: l3d_rasterizer_3d 98 A Software 3D Rasterizer Implementation: l3d_rasterizer_3d_sw_imp 101 A Mesa/OpenGL 3D Rasterizer Implementation: l3d_rasterizer_3d_mesa_imp 115 Sample Program: textest 129 Light Mapping Revisited 135 Software Light Mapping 136 Surfaces 136 Surface Cache 141 Light Mapped Polygons 142 Software Rasterization of Light Maps 147 Hardware Light Mapping 147 Sample Program: lightmap 151 Shadows and Light Maps 159 Summary 160 Chapter 3 3D Modeling with Blender 161 Tutorial: Creating and Exporting Compatible, Textured 3D Morph Targets 161 The Starting Morph Mesh 162 Inserting Two Morph Targets into Blender 163 Deforming the Mesh 165 Applying a Texture and Assigning Texture Coordinates 167 Testing the Morph in Blender 173 Exporting the Two Morph Targets 173 Exporting the Texture Information 174 Importing the Morph Targets into a Program 175 Tutorial: Using Inverse Kinematics and Roto- scoping to Model a Walking Human Figure 180 Inverse Kinematics: Definition 181 Creating an Ika Chain in Blender 183 iv Contents TEAM LinG - Live, Informative, Non-cost and Genuine! Working with Ika Chains 183 Creating the Arm Ikas 184 Creating the Main Body Ika 185 Parenting the Ikas into a Hierarchy 185 Testing the Ika Chains 187 Animating the Ika Chains 188 Connecting Ika Chains and Meshes 189 Texturing and Exporting the Model 190 Importing the Textured Ika Meshes 192 Rotoscoping and Inverse Kinematics 197 Programming IK and FK 200 Summary 201 Chapter 4 Visible Surface Determination I: General Techniques 203 The Goals of VSD 204 Back-Face Culling 207 3D Convexity and Back-Face Culling 209 Sample Program: backface 209 Class l3d_World_Backface 214 View Frustum Culling 218 Defining a View Frustum 218 Computing the Frustum in World Coordinates 220 Class l3d_Viewing_Frustum 221 Using the Frustum Planes 223 Hierarchical View Frustum Culling 223 Bounding Spheres and the View Frustum 225 Computing Bounding Spheres 227 Class l3d_bounding_sphere 228 Other Bounding Volumes 231 Clipping Against the View Frustum 233 Sample Program: frustum 233 Class l3d_World_Frustum 236 The Painter’s Algorithm 242 The Z Buffer Algorithm 245 General Observations about the Z Buffer 246 A Software Z Buffer: Class l3d_rasterizer_3d_zbuf_sw_imp 248 Mesa/OpenGL Z Buffering 257 Factory Manager for Z Buffered Rasterizers 261 Sample Program: texzbuf 263 Z Buffer-like Algorithms 264 Summary 266 Chapter 5 Visible Surface Determination II: Space-partitioning Techniques 267 Binary Space Partitioning Trees, Octrees, and Regular Spatial Partitioning 267 Using a BSP Tree to Partially Pre-sort Polygons 271 Choosing a Splitting Plane 272 Back-to-Front Rendering (Painter’s Algorithm Revisited) 274 Front-to-Back Rendering 275 Combining BSP Trees and Bounding Volumes 275 Sample Program: bsp 276 Contents v TEAM LinG - Live, Informative, Non-cost and Genuine! Classes l3d_halfspace and l3d_bsptree 277 Class l3d_world_bsptree 286 The Main Program 290 The World Database, Revisited 293 Leafy BSP Trees: Automatic Convex Partitioning of Space 293 Creating a Leafy BSP Tree 295 Methods for Leafy BSP Trees in Class l3d_bsptree 296 Sample Program: leafybsp 297 Axis-aligned BSP Trees and Mini BSP Trees 302 BSP Tree as a Multi-resolution Solid-Modeling Representation 303 BSP Trees and Dimension Independence 306 Octrees 306 Regular Spatial Partitioning 308 Portals and Cells 308 The Main Ideas Behind the Portal Algorithm 308 Rendering a Portal World 310 Observations about the Portal Scheme 313 Portals as a Connectivity Graph 313 Advantages and Disadvantages 313 Back-Face Culling 314 Clipping 314 Convexity or Non-Convexity 315 Moving the Camera and Objects Within a Portal Environment 315 Portals and the Near Z Plane 316 Shadows 318 Mirrors 320 Portals and Other Rendering Methods 321 Classes for Portals and Sectors 322 Class l3d_polygon_3d_portal 322 Class l3d_sector 323 Class l3d_world_portal_textured_lightmapped_obj 329 Class l3d_rasterizer_2d_sw_lighter_imp 344 Class l3d_pipeline_world_lightmapped 351 Sample Program: porlotex 353 Other VSD Algorithms 356 Summary 357 Chapter 6 Blender and World Editing 359 World Editing 360 No World Editor 360 Write Your Own World Editor 361 Adapt an Existing Editor 362 Using Blender for Portal Worlds 363 Main Ideas of a Blender Portal World Editor 364 Step-by-Step Guide to World Design 367 Data Flow within the World Editing System 368 Creating Sectors and Portals 369 Tutorial: Creating Aligned Portals via Extrusion and Separation 371 Tutorial: Aligning Portals from Separate Meshes 374 Tips for Working with Portals 382 Portalization: Generating Portal Connectivity 385 vi Contents TEAM LinG - Live, Informative, Non-cost and Genuine! Perl Scripts 387 Architecture of the Perl Portalization System 389 Structural Modules 390 Parsing and Generator Modules 415 Controlling Scripts 429 Embedding Location, Orientation, Texture, Actor, and Other Information into Meshes 430 Basic Ideas of Associating Attributes with Objects 431 Store an ID, Location, and Orientation in Overlapping Edges 431 The Tool Blend_at: Remote Control of Blender 433 Configuration and Testing of blend_at 434 Specific Mesh Attributes Used by the Portalization System 437 The Name Attribute 437 The Type Attribute 437 Attributes for Sectors 437 Attributes for Actors 439 Parsing of Attributes by VidscParser.pm and vidinfo 440 Program Listings for blend_at 446 Class vertex 447 Class blender_config 447 Class blender_controller 448 Class blender_xcontroller 449 Tutorial: Creating a Textured Room with Actors 463 Tips for Working with Attributes 473 Summary of Blender and Portal Worlds 474 Other World Editing Ideas 475 Portalized Regular Spatial Partitioning 475 BSP Tree and Octree 476 Non-convex Sector-based Partitioning 476 Summary 478 Chapter 7 Additional Graphics Techniques 479 Special Effects 479 Environment Mapping 480 Billboards 484 Lens Flare 486 Particle Systems 487 Physics and Particle Systems 488 Real-Time Update 489 Sample Program: particle 490 Comments on the Sample Program’s Physics 496 Some Ideas for You to Try 496 Natural Phenomena 497 Bump Mapping 499 Multi-pass Techniques 500 Advanced Techniques 501 Curved Surfaces 501 Level of Detail 505 Billboards 506 Edge Collapse 506 BSPTree 507 Texture LOD Techniques: MIP Mapping 508 Contents vii TEAM LinG - Live, Informative, Non-cost and Genuine! Landscapes 509 Storing Landscapes as Height Fields 509 Generating Fractal Landscapes 510 Rendering and LOD Techniques for Landscapes 511 Camera Tracking 512 Summary 513 Chapter 8 Non-Graphical Techniques for Games and Interactive Environments 515 Sound 515 Basics of Digital Sound 516 The RPlay Server 519 Using TCP/IP Networking to Communicate with the Server 520 Class l3d_sound_client 521 Class l3d_sound_server_rplay 522 TCP/IP Networking 524 The Client 524 The Server 526 Running the Sample Server and Client 529 Non-Blocking Operations 529 What Data to Send 530 Collision Detection 530 Intersection Testing and Bounding Volumes 531 Sphere-to-Sphere 532 Ray-to-Polygon 532 Ray-to-Sphere 535 Sphere-to-Polygon 536 Tunneling and Sweep Tests 538 Multiple Simultaneous Collisions and Collision Response 541 Allowing Penetration 541 Avoiding Penetration with Temporal Search 542 Class l3d_collidable 543 Class l3d_collidable_sphere 544 Class l3d_polygon_3d_collidable 548 Class l3d_polygon_3d_textured_lightmapped_collidable 551 Class l3d_camera_collidable 552 Class l3d_world_portal_textured_lightmapped_obj_colldet 553 Plug-in Object Seeker, Class l3d_plugin_videoscape_mesh_seeker 563 Sample Program: collide 574 More Advanced Collision Detection and Response 576 Physics 577 Some Basic Concepts 577 Rigid Body Dynamics 578 Real-Time Update and Numerical Integration 579 Artificial Intelligence 580 Summary 582 Chapter 9 What Lies Ahead? 583 Content Development Systems 583 Game Blender/Blender 2.0 583 World Foundry 590 viii Contents TEAM LinG - Live, Informative, Non-cost and Genuine! What Does This Mean for 3D Programmers? 598 The Future 599 Summary 600 Perspective 600 Appendix 603 CD Installation 603 License 603 Contents of the CD-ROM 603 Quick Start Guide 604 Directories 604 Installing the Sample Programs and Other Software 605 Troubleshooting the Sample Programs 607 Some Comments on the Sample Programs 607 Hardware Acceleration 608 Porting the Code to Microsoft Windows 609 Tools Used to Prepare this Book 610 Resources 611 3D Graphics Programming 612 3D Modeling 612 3D Information and Applications 613 General Programming 613 Other 614 References 614 Index 617 Contents ix TEAM LinG - Live, Informative, Non-cost and Genuine! [...]... you can program real-time 3D graphics applications using free tools under Linux TEAM LinG - Live, Informative, Non-cost and Genuine! Introduction xv Let’s now look at the organization of the text itself Chapter 1 reviews the essentials of Linux 3D graphics, as covered in the introductory companion volume Linux 3D Graphics Programming We cover the fundamentals of 2D graphics, 3D coordinate systems, perspective... topic of 3D modeling, illustrating in detail how to use the professional 3D modeling package Blender, which is included on the CD-ROM, to create animated 3D models and portal worlds for use in our interactive 3D programs This second volume, titled Advanced Linux 3D Graphics Programming, covers more advanced techniques needed for realistic display of larger datasets often used in interactive 3D environments... industry practitioners 3D graphics is a field that illustrates this phenomenon well In the early days, 3D graphics was mostly confined to academic research labs The mathematics and geometry of 3D graphics were questioned and explored, and the field grew as a result Today, research in 3D graphics is still very active, but at the same time, 3D graphics has also become mainstream A number of graphics techniques... possible future direction of Linux and 3D graphics We begin with a look at two existing and exciting 3D content development systems under Linux: Game Blender and World Foundry We go through a brief tutorial of 3D game creation with each of these systems Some speculation about the future of Linux 3D graphics follows We close by relating the contents of the book to the field of 3D graphics as a whole The... these classes to illustrate newer and more advanced concepts The l3d classes are on the CD-ROM and are also available for download from the Internet at http://www .linux3 dgraphicsprogramming.org Sample l3d Program Before looking at the l3d classes themselves, let’s first look at a sample program which uses l3d This will give you a practical perspective on l3d before looking at the following sections,... programs are all in $L3D/source/app The primary binaries are in $L3D/binaries /linux_ x/float/app TEAM LinG - Live, Informative, Non-cost and Genuine! Chapter 1: Basic Linux 3D Graphics Concepts 13 The Five-Step Process of l3d Programs The drawdot program can be broken up into five steps, which are representative of programming with l3d In fact, these steps are representative of event-based programming in general,... mean to hold the first key while typing the second key TEAM LinG - Live, Informative, Non-cost and Genuine! 1 Chapter 1 Basic Linux 3D Graphics Concepts L inux 3D graphics is a young and exciting field The purpose of this chapter is to review the basic concepts of Linux 3D graphics programming in order to lay a groundwork for the more involved material in the following chapters This book was written based... that you take the time to read the companion volume to this book, Linux 3D Graphics Programming The companion book is aimed at the beginning 3D graphics programmer with little or no 3D experience Essentially, this chapter is a brief review of the most important concepts in the introductory companion volume 2D Graphics Fundamentals 2D raster graphics consist of plotted pixels on a display The pixels are... Informative, Non-cost and Genuine! Chapter 1: Basic Linux 3D Graphics Concepts 3 3D Graphics Fundamentals 3D graphics is the creation of a two-dimensional image or series of images on a flat computer screen such that the visual interpretation of the image or series of images is that of a three-dimensional image or series of images Figure 1-2: Definition of 3D graphics The visual interpretation of an image... software important for 3D graphics Therefore, Linux offers any programmer the chance to get involved with 3D graphics programming today, at no cost, without forcing the programmer to either pay thousands of dollars in software licensing fees or to spend literally man-years of software development time creating customized tools Linux already offers the tools you need to do serious 3D programming and the . 1 Basic Linux 3DBasic Linux 3D Graphics ConceptsGraphics Concepts L inux 3D graphics is a young and exciting field. The purpose of this chapter is to review the basic concepts of Linux 3D graphics programming. reviews the essentials of Linux 3D graphics, as covered in the introductory com- panion volume Linux 3D Graphics Programming. We cover the fundamentals of 2D graphics, 3D coordinate systems, perspective. with 3D Polygons 96 Rasterization Classes for 3D Polygons 98 An Abstract 3D Rasterizer: l3d_rasterizer _3d 98 A Software 3D Rasterizer Implementation: l3d_rasterizer _3d_ sw_imp 101 A Mesa/OpenGL 3D

Ngày đăng: 28/04/2014, 16:50

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan