Jmonkeyengine 3.0 Beginner's Guide
Total Page:16
File Type:pdf, Size:1020Kb
www.it-ebooks.info jMonkeyEngine 3.0 Beginner's Guide Develop professional 3D games for desktop, web, and mobile, all in the familiar Java programming language Ruth Kusterer BIRMINGHAM - MUMBAI www.it-ebooks.info jMonkeyEngine 3.0 Beginner's Guide Copyright © 2013 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 author, 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: June 2013 Production Reference: 1180613 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84951-646-4 www.packtpub.com Cover Image by Girish Suryawanshi ([email protected]) www.it-ebooks.info Credits Author Project Coordinator Ruth Kusterer Michelle Quadros Reviewers Proofreaders Peter Backx Aaron Nash T. Joseph Duchesne Jonathan Todd Jens Hohmuth Dany Rioux Indexer Tejal Soni Glauco Márdano Production Coordinator Acquisition Editor Nitesh Thakur Antony Lowe Cover Work Lead Technical Editor Nitesh Thakur Mayur Hule Technical Editors Prasad Dalvi Pushpak Poddar Kirti Pujari www.it-ebooks.info About the Author Ruth Kusterer became intrigued by Java and open source software while completing her degree in computational linguistics. In 2005, she joined Sun Microsystems, Inc. as a technical writer for netbeans.org where she wrote 100 NetBeans IDE Tips & Tricks. Since 2010, she has been working for CA Technologies, Inc. where she's a senior technical writer for security software. In her spare time, she hangs out on jMonkeyEngine.org and strives eternally to write the ultimate Java game. I would like to thank the jMonkeyEngine core team for answering a BigInteger of newbie questions and helping out with non-trivial code samples. I would also like to thank all the jMonkeys posting inspiring videos of completed games, and a big shout-out to the NetBeans community whose NetBeans platform is the base of the jMonkeyEngine SDK. www.it-ebooks.info About the Reviewers Peter Backx is a software developer and architect. He has used Java for more than a decade to shape unique user experiences and build rock-solid scalable software. He received a PhD in Computer Sciences from Ghent University, Belgium. Peter maintains a technical blog at http://www.streamhead.com. T. Joseph Duchesne holds a Computer Engineering degree from Dalhousie University and works in software-as-a-service web applications, primarily in backend infrastructure using a wide variety of technologies. In his free time, he enjoys video game development and has competed in open source/independent game development competitions. Joseph is currently Sr. Infrastructure and Software Engineer at SimplyCast (www.simplycast.com), an online software-as-a-service marketing platform. www.it-ebooks.info Jens Hohmuth graduated in Computer Science in 1998 from the University of Applied Sciences of Zwickau, Germany. Jens has been working for more than 10 years as a professional Software Developer. At his day job at a German company, he works for banks and financial services providers applying e-banking solutions on a wide range of different platforms. Jens has expertise in analysis, design, implementation, and support of software projects from small to large scale. He is an gile software development follower and a natural born problem solver. Jens has outstanding training and presentation skills, and created a popular Intel Protected Mode and MMX Tutorial series as his internship back in college. This tutorial is still one of the top references for Intel Protected Mode today. At night time, he is a wannabe game developer and the founder of the open source Java GUI Framework "Nifty GUI". Besides "Nifty GUI" he has contributed to many other open source projects. When he's not coding he enjoys creating 2D and 3D art as well as playing his guitar and piano. In the summertime, you can find him outside on his mountain bike (probably with his Macbook Air in the backpack). I'd like to thank all the jMonkeyEngine core members for being extremely friendly and a great joy to work with. And of course all the "Nifty GUI" users (and critics) in the world for their continuing support. Dany Rioux received his programmer/analyst diploma more than 15 years ago at the Herzing College in Montreal, Canada. Although he left the programming side of things for numerous years to work in user support, he has come back to his first love and has been actively working on Disenthral, an RPG space game, based on the jMonkeyEngine3, for the past two years. www.it-ebooks.info www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@ packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? Fully searchable across every book published by Packt Copy and paste, print and bookmark content On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt Publishing at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. www.it-ebooks.info www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Installing jMonkeyEngine 11 Installation requirements for game developers 12 Time for action – installing the jMonkeyEngine SDK 12 jMonkeyEngine SDK at your service 14 Can I work in other Java IDEs? 15 Time for action – running a demo 15 Time for action – creating a project 16 Assets and the art pipeline 19 Time for action – distributing a game 20 Can I sell my jMonkeyEngine game? 21 Summary 22 Chapter 2: Creating Your First 3D Scene 23 A basic template to initialize scenes 23 Time for action – initializing a scene step by step 24 Starting and stopping the application 27 Time for action – starting the application 27 Orient yourself in 3D space 28 Time for action – finding the spot 29 And how do I say that in Java? 31 Time for action – position it! 31 Time for action – scale it! 33 Time for action – rotate it! 34 Time for action – rotate it again, Sam 35 Where am I? 36 Time for action – navigating the scene 37 Populating the scene 38 Time for action – node versus geometry 40 www.it-ebooks.info Table of Contents Extending SimpleApplication 41 Make a big scene 43 Time for action – configuring display settings 43 Keeping an eye on your FPS 45 Time for action – checking vital stats 45 Navigating the scene with a mouse and a keyboard 46 Time for action – move it! 47 Summary 49 Chapter 3: Interacting with the User 51 The digital Dungeon Master 52 Time for action – from input to output in slow motion 52 Time for action – pushing the right buttons 54 Time for action – trigger meets mapping 55 Time for action – mapping meets listeners 56 Time for action – listeners meet actions 58 Click me if you can 60 Time for action – pick a brick (using crosshairs) 60 Time for action – pick a brick (crosshairs with ray casting) 62 Time for action – pick a brick (using the mouse pointer) 65 Time for action – pick a brick (pointer with ray casting) 66 How to steer spatials 69 Time for action – you are the CubeChaser 69 Time for action – chase all the cubes! 72 Time for action – get these cubes under control 73 Time for action – get into the right AppState of mind 76 Time for action – call me maybe? 79 Coordinating global game mechanics 80 The beauty of AppStates and controls 82 Summary 86 Chapter 4: Adding Character to Your Game 87 Making a Mesh 87 Time for action – meshing around with cubes 88 Time for action – meshing around with spheres 89 From mesh to geometry 91 Beg, steal, or borrow 92 The right wrench to pound in the screw 93 Time for action – installing the Blender-to-Ogre3D plugin 94 Time for action – sculpting the mesh 95 Time for action – coloring the mesh 96 [ ii ] www.it-ebooks.info Table of Contents Time for action – a model for to go, please 98 Time for action – loading a model (just testing) 99 Time for action – loading a model (for real) 101 Managing assets – best practices 102 Time for action – sorting your stuff out 102 Time for action – saving and loading .j3o files 104 Animating a model 107 Time for action