Principles of Computer Graphics: Teo/y

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Principles of Computer Graphics

T e o / y and Practice Using OpenGL and /Maya@


Principles of Computer Graphics
Theow and Practice Using OpenGL and ~ a ~ a *

Shalini Govil-Pai
Sunnyvale, CA, U.S.A.

a- Springer
Shalini Govil-Pai
896 Savory Drive,
Sunnyvale, CA 94087

Email: sgovil @gmail.com

Library of Congress Cataloging-in-Publication Data

Govil-Pai, Shalini
Principles of Computer Graphics: Theory and Practice Using OpenGL and Maya@/ Shalini
Govil-Pai
p.cm.
Includes bibliographical references and index.

ISBN: 0-387-95504-6 (HC) e-ISBN 0-387-25479-X Printed on acid-free paper


ISBN-13: 978-0387-95504-9 e-ISBN-13: 978-0387-25479-1

O 2004 Springer Science+Business Media, Inc.


All rights resewed. This work may not be translated or copied in whole or in part without
the written permission of the publisher (Springer Science+Business Media, Inc., 233 Spring
Street, New York, NY 10013, USA), except for brief excerpts in connection with reviews or
scholarly analysis. Use in connection with any form of information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar methodology now
know or hereafter developed is forbidden.
The use in this publication of trade names, trademarks, service marks and similar terms,
even if the are not identified as such, is not to be taken as an expression of opinion as to
whether or not they are subject to proprietary rights.

Printed in the United States of America.

Alias and Maya are registered trademarks of Alias Systems Corp. in the United States
andlor other countries.

9 8 7 6 5 4 3 2 1 SPIN 10879906 (HC) 1 11412601 (eBK)

springeronline.com
Contents
Preface vii

Section 1 1
1 From Pixels to Shapes 3
1.1 Complex Display Systems 4
1.2 Game Buffers 6
1.3 Coordinate Systems: How to identify pixel points 9
1.4 Shapes and Scan Converting 11

2 Making Them Move 27


2.1 Vectors and Matrices 28
2.2 2D Object Transformations 32
2.3 Homegenous Coordinates and Composition of
Matrix Transformations 41

3 Pixels, Images and Image Files 49


3.1 Raster Image Files 48
3.2 Bitmaps and Pixmaps 51
3.3 Computer Display Systems 56
3.4 Image Enhancements 60

4 Let The Games Begin 67


4.1 What is a Game? 68
4.2 Game Design 69
4.3 Implementing the Game 72

Section 2 81
5 3D Modeling 83
5.1 The 3D System 84
5.2 3D Modeling 90
5.3 3D Modeling Primitive Shapes 95
5.4 3D Modeling Generic Shapes 100
5.5 3D Transformation 104
5.6 Viewing in 3D 107
5.7 Hierarchical Modeling Using Transformations 118
vi
XV~ CONTENTS

6 Rendering, Shading and Lighting


6.1 What is Rendering
6.2 Hidden Surface Removal
6.3 Light Reflectance Model
6.4 CG: Reflectance Model
6.5 The Normal Vectors
6.6 Shading Models
6.7 Texture Mapping

7 Advanced Techniques
7.1 Advanced Modeling
7.2 Advanced Rendering Techniques

8 And Finally, Introducing Maya


8.1 Maya Basics
8.2 Modeling 3D Objects
8.3 Applying Surface Material
8.4 Composing the World
8.5 Lighting the Scene

Section 3
9 Animation
9.1 Traditional Animations
9.2 3D Computer Animation - Interpolations
9.3 The Principles of Animation
9.4 Advanced Animation Techniques

10 Viewpoint Animation
10.1 Animating the Camera inthe Snowy Animation
10.2 Building up a Real Time 3D Game

11 Lights, Camera, Action!


11.1 Pre-Production
11.2 Production
11.3 Post-Production
11.4 Finally, Our Movie!

Appendix A
Appendix B
Appendix C

Bibliography

Index of Terms
Preface
Computer Graphics: the term has become so widespread now, that we rarely stop
to think about what it means. What is Computer Graphics? Simply defined,
Computer Graphics (or CG) is the images generated or modified on a computer.
These images may be visualizations of real data or imaginary depictions of a
fantasy world.
The use of Computer Graphics effects in movies such as The Incredibles and
games such as Myst have dazzled millions of viewers worldwide. The success of
such endeavors is prompting more and more people to use the medium of
Computer Graphics to entertain, to educate, and to explore.
For doctors, CG provides a noninvasive way to probe the human body and to
research and discover new medications. For teachers, CG is an excellent tool to
visually depict concepts to their students. For business people, CG has come to
signify images of charts and graphs used for analysis of data. But for most of us,
CG translates into exciting video games, special effects and entire films-what are
often referred to as CG productions. This entertainment aspect of CG is what has
made it such a glamorous and sought-after field.
Ten years ago, CG was limited to high-end workstations, available only to an
elite few. Now, with the advances in PC processing power and the availability of
3D graphics cards, even high school students can work on their home PC to
create professional quality productions
The goal of this book is to expose you to the fundamental principles behind
modern computer graphics. We present these principles in a fun and simple
manner. We firmly believe that you don't have to be a math whiz or a high tech
computer programmer to understand CG. A basic knowledge of trigonometry,
algebra, and computer programming is more than sufficient.
As you read this book, you will learn the bits and bytes of how to transform
your ideas into stunning visual imagery. We will walk you through the processes
that professionals employ to create their productions, Based on the principles
that we discuss, you will follow these processes step and step, to design and
create your own games and animated movies.
We will introduce you to the OpenGL API—a graphics library that has
become the de facto standard on all desktops. We will also introduce you to the
workings of Maya, a 3D software package. We will demonstrate the workings of
the Maya Personal Learning Edition—a (free) download is required.
viii PREFACE

Organization of the Book


The book is organized into three sections. Every section has detailed OpenGL
code and examples. Appendix B details how to install these examples on your
desktop.

Section 1: The Basics


The first section introduces the most basic graphics principles. In Chapter 1, we
discuss how the computer represents color and images. We discuss how to
describe a two-dimensional (2D) world, and the objects that reside in this world.
Moving objects in a 2D world involves 2D transformations. Chapter 2 describes
the principles behind transformations and how they are used within the CG
world. Chapter 3 discusses how the computer saves images and the algorithms
used to manipulate these images. Finally, in Chapter 4, we combine all the
knowledge from the previous chapters to create our very own version of an
arcade game.

Section 2: It’s 3D time


Section 2 will expand your horizon from the 2D world to the 3D world. The 3D
world can be described very simply as an extension of the 2D world. In Chapter
5, we will introduce you to 3D modeling. Chapter 6 will discuss rendering: you
will have the opportunity to render your models from Chapter 5 to create
stunning visual effects. Chapter 7 is an advanced chapter for those interested in
more advance concepts of CG. We will introduce the concept of Nurbs as used
in modeling surfaces. We will also introduce you to advanced shading concepts
such as ray tracing. Chapter 8 focuses on teaching the basics of Maya and the
Maya Personal Learning Edition of Maya (Maya PLE). Maya is the most popular
software in the CG industry and is extensively used in every aspect of
production. Learning the basics of this package will be an invaluable tool for
those interested in pursuing this area further.

Section 3: Making Them Move


Section 3 discusses the principles of animation and how to deploy them on the
computer. In Chapter 9, we discuss the basic animation techniques. Chapter 10
discusses a mode of animation commonly deployed in games, namely, viewpoint
animation. In Chapter 11, you will have the opportunity to combine the working
knowledge from the previous chapters to create your own movie using Maya.

Appendices
In Appendix A, you will find detailed instructions on how to install the OpenGL
and GLUT libraries. Appendix B describes how to download, install the sample
code that is detailed in this book. You will also find details on how to compile
PREFACE ix

and link your code using the OpenGL libraries. Appendix C describes the Maya
PLE and how to download it.

OpenGL and Maya

Every concept discussed in the book is followed by examples and exercises


using C and the OpenGL API. We also make heavy use of the GLUT library,
which is a cross-platform OpenGL utility toolkit. The examples will enable you
to visually see and appreciate the theory explained. We do not expect you to
know OpenGL, but we do expect basic knowledge in C and C++ and knowledge
of compiling and running these programs. Some chapters detail the workings of
Maya, a popular 3D software package. Understanding Maya will enable you to
appreciate the power of the CG concepts that we learn in the book.

Why are we using OpenGL and GLUT?


OpenGL is now a widely accepted industry standard and is used by many (if not
all) professional production houses. It is not a programming language but an
API. That is, it provides a library of graphics functions for you to use within your
programming environment. It provides all the necessary communication
between your software and the graphics hardware on your system.
GLUT is a utility library for cross-platform programming. Although our code
has been written for the Windows platform, GLUT makes it easier to compile the
example code on other platforms such as Linux or Mac. GLUT also eliminates
the need to understand basic Windows programming so that we can focus on
graphics issues only.

Why are we using Maya?


Some concepts in the book will be further illustrated with the help of industry
leading 3D software Maya. Academy-Award winning Maya 3D animation and
effects software has been inspired by the film and video artists, computer game
developers, and design professionals who use it daily to create engaging digital
imagery, animation, and visual effects. Maya is used in almost every production
house now, so learning the basics of it will prove to be extremely useful for any
CG enthusiast. In addition, the good folks at Alias now let you download a free
version of Maya (Maya PLE) to use for learning purposes.

The system requirements for running the examples in this book, as well as for
running Maya PLE are as follows:

Software Requirements
• Windows 2000 or higher
•C/C++ compiler such as Microsoft Visual Studio on Windows or GCC
(Gnu Compiler Collection) on Unix
x PREFACE

Hardware Requirements
• Intel Pentium II or higher/AMD Athlon processor
• 512 MB RAM
• Hardware-accelerated graphics card (comes standard on most systems)

In addition, we expect some kind of Internet connectivity so that you can


download required software.

Intended Audience
This book is aimed at undergraduate students who wish to gain an overview of
Computer Graphics. The book can be used as a text or as a course supplement
for a basic Computer Graphics course.
The book can also serve as an introductory book for hobbyists who would
like to know more about the exciting field of Computer Graphics, and to help
them decide if they would like to pursue a career in it.

Acknowledgments

The support needed to write and produce a book like this is immense. I would
like to acknowledge several people who have helped turn this idea into a reality,
and supported me through the making of it:
First, my husband, Rajesh Pai, who supported me through thick and thin. You
have been simply awesome and I couldn't have done it without your constant
encouragement.
A big thanks to my parents, Anuradha and Girjesh Govil, who taught me to
believe in myself, and constantly egged me on to publish the book.
Thanks to Carmela Bourassa of Alias software, who helped provide
everything I needed to make Maya come alive.
A very special thanks to my editor, Wayne Wheeler, who bore with me
through the making of this book and to the entire Springer staff who helped to
produce this book in its final form.
I would like to dedicate this book to my kids, Sonal and Ronak Pai, who
constantly remind me that there is more to life than CG.
PREFACE xi

CG technology is emerging and changing every day. For example, these days,
sub-division surfaces, radiosity, and vertex shaders are in vogue. We cannot
hope to cover every technology in this book. The aim of the book is to empower
you with the basics of CG-providing the stepping-stone to pick up on any CG
concept that comes your way.
A key tenet of this book is that computer graphics is fun. Learning about it
should be fun too. In the past 30 years, CG has become pervasive in every aspect
of our lives. The time to get acquainted with it is now—so read on!

You might also like