Focus on 3D Models.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
Y L F M A E T Team-Fly® Focus On 3D Models This page intentionally left blank Focus On 3D Models Evan Pipho © 2003 by Premier Press, a division of Course Technology. All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system without written permission from Premier Press, except for the inclusion of brief quotations in a review. The Premier Press logo and related trade dress are trademarks of Premier Press and may not be used without written permission. Publisher: Stacy L. Hiquet Marketing Manager: Heather Hurley Acquisitions Editor: Mitzi Foster Koontz Project/Copy Editor: Kezia Endsley Technical Reviewer: Kelly Dempski Interior Layout: Danielle Foster Cover Designer: Mike Tanamachi Indexer: Kelly Talbot Proofreader: Jenny Davidson Wolfenstein, Doom, and Quake are copyrights of id Software. Half-Life is a copyright of VALVe Software. Unreal is a copyright of Epic MegaGames. The Descent series of games are copyrights of Parallax. MilkShape 3D was created by the chUmbaLum sOft company. Discreet is a division of Autodesk, Inc., 3d Studio Max, 3D Studio VIZ, Character Studio, Fire, Flame, Flint, Frost, Inferno, Lightscape, Smoke, Stream, and Wire are registered trademarks, and Discreet, 3ds Max, Backdraft, Combustion, Jobnet, and Sparks are trademarks of Autodesk, Inc., Discreet Logic Inc. in the USA and/or other countries. Mental ray is a registered trademark of mental images GmbH & Co. KG. Vecta3D-MAX is a trademark of IdeaWorks3D, Ltd. All other brand names, product names, or trademarks belong to their respective holders. (c) Copyright 2002 Autodesk, Inc. All rights reserved. Important: Premier Press cannot provide software support. Please contact the appropriate software manufacturer’s technical support line or Web site for assistance. Premier Press and the author have attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer. Information contained in this book has been obtained by Premier Press from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources, Premier Press, or others, the Publisher does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from use of such information. Readers should be particularly aware of the fact that the Internet is an ever-changing entity. Some facts may have changed since this book went to press. ISBN: 1-59200-033-9 Library of Congress Catalog Card Number: 2002111229 Printed in the United States of America 03 04 05 06 07 BH 10 9 8 7 6 5 4 3 2 1 Premier Press, a division of Course Technology 2645 Erie Avenue, Suite 41 Cincinnati, Ohio 45208 Acknowledgments irst off, thanks to my parents for letting me do this; without their F support and putting up with not seeing me most of the summer this would have never been possible. A big thanks to Trent Polack for helping me secure this book deal and for being an awesome friend and programmer. Without you I would have never made it to where I am today. I can’t forget all of the great people over at gamedev.net, flipcode.com, and their associated chat rooms. You guys have been invaluable in helping me sort through problems, squash bugs, and are just great friends. There are too many to name, but a few who have proved to be invaluable have been Nicholas Cooper, Sean Kent, Denis Lukianov, Ron Penton, and Henrik Stuart. To my friend and lifesaver Amy for forcefully dragging me away from my computer and out of my room every so often; it kept me from going insane. Thanks to all of my other friends who put up with not seeing me much at all during the summer. Last, but definitely not least, a huge thanks to the people over at Premier Press, especially Mitzi for sticking with me the whole time I was writing. Your support has been terrific, even through computer, Internet, and communications problems. All of the editors who worked on this have been great; all of you have taught me many valuable lessons as I have worked on my first book. I hope to work with all of you again. This page intentionally left blank About the Author Evan Pipho has always been interested in computers and electronics. As a young child, he learned to operate his dad’s IBM PC, playing games, and experimenting with the many programs it contained. While playing with his dad’s Windows machine, he started to look at languages such as QBASIC and C and to pursue his life-long interest in game development. He had decided a long time ago that he wanted to pursue game development, so he dug right in. After some classes at the nearby community college and several maddening months in front of the computer, he was hooked! You can visit the author’s forums at http://www.codershq.com. Click the Forums link. If you prefer private email to public forums, you can contact him at [email protected]. This page intentionally left blank Contents at a Glance Letter from the Series Editor .............. xvi Introduction and Overview .................... xix Chapter 1 Reviewing Matrices and Vectors .............. 1 Chapter 2 Introduction to Quaternions ................. 23 Chapter 3 Quake II’s MD2 Models ....................... 37 Chapter 4 Loading OBJ Files ............................... 61 Chapter 5 An Introduction to Skeletal Animation ..... 71 Chapter 6 MilkShape 3D .................................... 87 Chapter 7 The 3ds Models ................................ 109 Chapter 8 MDL, The Legendary Half-Life Format ... 127 Chapter 9 Enter the Quake: Quake III’s MD3 Format .....................................135 Chapter 10 Tips, Tricks, and Methods ....................153 Appendix A Common 3D Model Formats ................. 165 Appendix B STL Vector Primer ........................... 169 Appendix C Going Above and Beyond .................... 183 Index .............................................. 191 This page intentionally left blank Y L F M A E T Team-Fly® Contents Letter from the Series Editor ..................... xvi Introduction and Overview ........................... xix CHAPTER 1 Reviewing Matrices and Vectors .......................... 1 Understanding and Using Matrices ......................................................................................... 2 The Zero and the Identity Matrices............................................................................... 3 Matrix Operations ............................................................................................................. 5 Determinants of Matrices ................................................................................................ 8 The Inverse of a Matrix..................................................................................................... 9 Using and Understanding Vectors .........................................................................................12 Vector Notation ............................................................................................................... 14 Magnitude and Unit Vectors ........................................................................................... 14 Vector Arithmetic .............................................................................................................14 Vector Products ................................................................................................................ 17 Transforming a Vector by a Matrix ............................................................................... 19 The CD’s Code ......................................................................................................................... 20 Conclusion .................................................................................................................................21 CHAPTER 2 Introduction to Quaternions .......................23 What Is a Quaternion and Why Are They Used? .............................................................. 24 Quaternion Operations .................................................................................................. 26 Quaternion Conversions ................................................................................................ 28 Interpolation with Quaternions ............................................................................................ 34 LERP (Linear Interpolation of Quaternions) .............................................................. 35 SLERP (Spherical Linear Interpolation) ....................................................................... 35 Conclusion .................................................................................................................................36 xii Contents CHAPTER 3 Quake II’s MD2 Models ....................... 37 Understanding the FILE * Functions.....................................................................................39 Looking at the Source Code .................................................................................................. 43 The Data: Frames and Vertices .............................................................................................. 46 Making It Solid: Triangles.......................................................................................................... 48 Rendering the Results for the First Time...........................................................................