ebook img

Essential Java 3d Fast PDF

285 Pages·2001·20.878 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Essential Java 3d Fast

Essential Series Springer London Berlin Heidelberg New York Barcelona Hong Kong Milan Paris Singapore Tokyo Also in this series: John Cowell John Cowell Essential Visual Basic 5.0 fast Essential Visual Basic 6.0 fast 3-540-76148-9 1-85233-071-6 Duncan Reed and Peter Thomas Ian Chivers Essential HTML fast Essential Visual C++ 6.0 fast 3-540-76199-3 1-85233-170-4 John Hunt John Vince Essential JavaBeans fast Essential Computer Animation fast 1-85233-032-5 1-85233-141-0 John Vince Aladdin Ayesh Essential Virtual Reality fast Essential Dynamic HTML fast 1-85233-012-0 1-85233-626-9 John Cowell David Thew Essential Visual J++ 6.0 fast Essential Access 2000 fast 1-85233-013-9 1-85233-295-6 John Cowell Essential Java 2 fast 1-85233-071-6 Ian Palmer Essential Java3Dfast Developing 3D Graphics Applications in Java Springer Ian Palmer, BSc, MSc, DPhil EIMC, University of Bradford, Bradford, BD7 lDP Series Editor John Cowell, BSc (Hons), MPhil, PhD Department of Computer Science, De Montfort University, The Gateway, Leicester LEI 9BH British Library Cataloguing in Publication Data Palmer, 1. C. (Ian C.) Essential Java 3D fast: developing 3D graphics applications in Java. - (Essentials) 1. Java (Computer program language) 2. Computer graphics 1. Title 006.6'93 ISBN 1852333944 Library of Congress Cataloging-in-Publication Data Palmer, Ian, 1966- Essential Java3D fast/Ian Palmer. p. cm. - (Essential series) Includes bibliographical references and index. ISBN 1-85233-394-4 (aile paper) 1. Java (~omputer'Program language 2. Computer graphics. 1. Title. II. EssentihLseries (Springer-Verlag) QA76.73.J38 P34 2001 006.6'633-dc21 00-052660 Apart from any fair dealing for the purposes of research or private study, or criticism or review, as permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing of the publishers, or in the case of reprographic reproduction in accordance with the terms of licences issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to the publishers. ISBN 1-85233-394-4 Springer-Verlag London Berlin Heidelberg A member of BertelsmannSpringer Science+Business Media GmbH http://www.springer.co. uk © Springer-Verlag London Limited 2001 The use of registered names, trademarks etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant laws and regulations and therefore free for general use. The publisher makes no representation, express or implied, with regard to the accuracy of the information contained in this book and cannot accept any legal responsibility or liability for any errors or omissions that may be made. Typesetting: Camera-ready by author Printed and bound at The Cromwell Press, Trowbridge, Wiltshire 34/3830-543210 Printed on acid-free paper SPIN 10784923 Contents 1. INTRODUCTION ..........•..••......••................... 1 Introduction.................................................................................................................... 2 What is Java 3D?............................................................................................................ 2 Running Java 3D programs ........................................................................................... 3 How to use this book ..................................................................................................... 3 2. OUR FIRST JAVA 3D PROGRAM ................ 5 Introduction.................................................................................................................... 6 The Scene Graph............................................................................................................. 6 The View Branch............................................................................................................. 7 The Content Branch ....................................................................................................... 9 The Simple World Program............................................................................................. 9 Summary......................................................................................................................... 15 3. CREATING SBA.PES.................................... 17 Introduction.................................................................................................................... 18 Geometric primitives in the utility library.................................................................... 18 Geometry arrays............................................................................................................. 21 Using the QuadArray class............................................................................ 21 The IndexedQuadArray: defining quads..................................................... 24 Using triangles: the IndexedTriangleArray ................................................. 26 Loading pre-made geometric models.......................................................................... 27 The Wavefront Object (or 'OBJ') loader....................................................... 28 Loading entire scenes of objects using the Lightwave3D loader ............. 33 Summary......................................................................................................................... 35 4. LIGHTING AND APPEARANCE ....•.............. 37 Introduction.................................................................................................................... 38 The lighting model......................................................................................................... 38 Surfaces.......................................................................................................... 38 Lights.............................................................................................................. 39 The lighting equation ................................................................................... 40 The Appearance class..................................................................................................... 42 Using the Material class to define the surface............................................ 46 Adding more light types................................................................................................ 47 Point lights..................................................................................................... 48 Spot lights...................................................................................................... 48 Essential Java 3D fast Lighting geometry array objects.................................................................................. 50 Using textures ................................................................................................................ 54 Textures in Java 3D....................................................................................... 54 Creating and applying a texture.................................................................. 55 Generating texture coordinates .................................................................. 59 Summary........................................................................................................................ 61 5. GROUPS AND TRANSFORMATIONS .......... 63 Introduction ................................................................................................................... 64 The BranchGroup........................................................................................................... 64 The Tr ansformGroup ..................................................................................................... 65 The Switch class............................................................................................................. 71 Summary........................................................................................................................ 72 6. ANIMATION ................................................ 73 Introduction ................................................................................................................... 74 Interpolators and their features......................................... .......................................... 74 Alpha values.................................................................................................. 75 Ar otation interpolator example.................................................................................... 76 Full example ....................................................... :.......................................... 79 Path Interpolator cI~sses................................................................................................ 81 Performirfg 3D mor.phing.............................................................................................. 84 Summary ...................~ .................................................................................................... 91 7. INTERACTION AND BERAV IOUR............... 93 Introduction ................................................................................................................... 94 Use of behaviours and their features........................................................................... 94 Behavior: the base behaviour class.............................................................................. 96 The wake up criteria ...................................................................................................... 97 Af irst behaviour: simple morph................................................................................... 98 User input utilities ......................................................................................................... 101 Using the MouseRotate behaviour.............................................................. 101 Using the pick utility behaviours................................................................. 102 Extending the PickMouseBehaviour ........................................................... 104 Using the keyboard utilities......................................................................... 107 Collision detection and response................................................................................. 108 Creating our own collision detector............................................................ 109 Summary ........................................................................................................................ 113 8. ADVANCED TOPiCS. ................................... 115 Introduction ................................................................................................................... 116 Compiling scene graph content ................................................................................... 116 Billboards........................................................................................................................ 117 Contents Level of detail................................................................................................................. 120 Sound.............................................................................................................................. 121 Summary......................................................................................................................... 125 9. DUCK SHOOT! ..•••.•....•...•.•..•.•........•••..•...••.. 127 Introduction.................................................................................................................... 128 The program elements .................................................................................................. 128 The duck......................................................................................................... 128 The gun and ball............................................................................................ 132 Putting it all together ................................................................................... 135 Summary......................................................................................................................... 136 APPENDIX A. SOURCE CODE ......................... 137 Introduction.................................................................................................................... 138 Chapter 2......................................................................................................................... 139 simpleWorld application.............................................................................. 139 Chapter 3......................................................................................................................... 143 simpleCone application................................................................................ 143 simplelndexedQuadArray ............................................................................ 145 simplelndexTriangleArray............................................................................ 148 ObjectLoader ................................................................................................. 150 LightwaveLoader .......................................................................................... 154 Chapter 4......................................................................................................................... 157 simpleWireFrame.......................................................................................... 157 simpleDirLight............................................................................................... 160 simplespotLights.......................................................................................... 163 simplelndexedQuadNormals ....................................................................... 166 simplelndexQuadsmooth ............................................................................ 170 simpleTexture............................................................................................... 174 simpleTextureGen......................................................................................... 178 Chapter 5......................................................................................................................... 183 simpleCombine............................................................................................. 183 simpleTransform........................................................................................... 188 simpleswitch................................................................................................. 192 Cha pter 6......................................................................................................................... 196 Simple Rotator.................................................................... ............................ 196 simplelnterpolator........................................................................................ 199 simpleMorph................................................................................................. 203 Chapter 7......................................................................................................................... 209 simpleMorphBehaviour................................................................................ 209 simpleMorph2............................................................................................... 210 simpleMouse................................................................................................. 215 simpleKeyNav................................................................................................ 218 simplePickBehaviour .................................................................................... 221 simplePickBehaviour (version 2) ................................................................. 223 Essential Java 80 fa.t SimplePick..................................................................................................... 225 Collision Detector dass.................................................................................. 228 SimpleCollision application ......................................................................... 229 CoilisionDetector2 class ............................................................................... 234 SimpieCoilision2 application ....................................................................... 236 Chapter 8........................................................................................................................ 242 SimpleBillboard............................................................................................. 242 SimpleLOD..................................................................................................... 245 SimpleSounds ............................................................................................... 249 Chapter 9 ........................................................................................................................ 254 DuckBehaviour.............................................................................................. 254 GunBehaviour ............................................................................................... 256 SimpleGame.................................................................................................. 258 APPENDIX B. EXAMPLE DATA FILES ........... 265 Introduction ................................................................................................................... 266 Lightwave scene file..................................................................................... 266 Object file using materials ........................................................................... 269 Object material file ....................................................................................... 270 ••••••••••••••••••••••••••••••••••••••••••••••••••• ~1r1C~lI~IC!i ~~lL General Java .................................................................................................. 272 Java 3D .......~ ................................................................................................... 272 General graphics........................................................................................... 272 Openlnventor................................................................................................ 272 VRML.............................................................................................................. 272 Lighwave3D .................................................................................................. 272 3D file formats............................................................................................... 273 •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• 1!lJ)IC~ ~~fi Introduction I. Palmer, Essential Java 3D fast © Springer-Verlag London Limited 2001

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.