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 transmied in any form or by any means, without the prior wrien permission of the publisher, except in the case of brief quotaons embedded in crical arcles or reviews. Every eort has been made in the preparaon of this book to ensure the accuracy of the informaon presented. However, the informaon 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 informaon about all of the companies and products menoned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this informaon. First published: June 2013 Producon 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 (girish.suryawanshi@gmail.com) www.it-ebooks.info Credits Author Ruth Kusterer Reviewers Peter Backx T. Joseph Duchesne Jens Hohmuth Dany Rioux Glauco Márdano Acquision Editor Antony Lowe Lead Technical Editor Mayur Hule Technical Editors Prasad Dalvi Pushpak Poddar Kir Pujari Project Coordinator Michelle Quadros Proofreaders Aaron Nash Jonathan Todd Indexer Tejal Soni Producon Coordinator Nitesh Thakur Cover Work Nitesh Thakur www.it-ebooks.info About the Author Ruth Kusterer became intrigued by Java and open source soware while compleng her degree in computaonal linguiscs. 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 soware. In her spare me, she hangs out on jMonkeyEngine.org and strives eternally to write the ulmate Java game. I would like to thank the jMonkeyEngine core team for answering a BigInteger of newbie quesons and helping out with non-trivial code samples. I would also like to thank all the jMonkeys posng inspiring videos of completed games, and a big shout-out to the NetBeans community whose NetBeans plaorm is the base of the jMonkeyEngine SDK. www.it-ebooks.info About the Reviewers Peter Backx is a soware developer and architect. He has used Java for more than a decade to shape unique user experiences and build rock-solid scalable soware. 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 soware-as-a-service web applicaons, primarily in backend infrastructure using a wide variety of technologies. In his free me, he enjoys video game development and has competed in open source/independent game development compeons. Joseph is currently Sr. Infrastructure and Soware Engineer at SimplyCast ( www.simplycast.com), an online soware-as-a-service markeng plaorm. 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 Soware Developer. At his day job at a German company, he works for banks and nancial services providers applying e-banking soluons on a wide range of dierent plaorms. Jens has experse in analysis, design, implementaon, and support of soware projects from small to large scale. He is an gile soware development follower and a natural born problem solver. Jens has outstanding training and presentaon skills, and created a popular Intel Protected Mode and MMX Tutorial series as his internship back in college. This tutorial is sll one of the top references for Intel Protected Mode today. At night me, he is a wannabe game developer and the founder of the open source Java GUI Framework "Niy GUI". Besides "Niy GUI" he has contributed to many other open source projects. When he's not coding he enjoys creang 2D and 3D art as well as playing his guitar and piano. In the summerme, you can nd 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 "Niy GUI" users (and crics) in the world for their connuing support. Dany Rioux received his programmer/analyst diploma more than 15 years ago at the Herzing College in Montreal, Canada. Although he le the programming side of things for numerous years to work in user support, he has come back to his rst love and has been acvely working on Disenthral, an RPG space game, based on the jMonkeyEngine3, for the past two years. www.it-ebooks.info www.PacktPub.com Support les, eBooks, discount offers and more You might want to visit www.PacktPub.com for support les and downloads related to your book. Did you know that Packt oers eBook versions of every book published, with PDF and ePub les available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entled 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 collecon of free technical arcles, sign up for a range of free newsleers and receive exclusive discounts and oers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant soluons to your IT quesons? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's enre 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 enrely free books. Simply use your login credenals for immediate access. www.it-ebooks.info www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Installing jMonkeyEngine 11 Installaon requirements for game developers 12 Time for acon – installing the jMonkeyEngine SDK 12 jMonkeyEngine SDK at your service 14 Can I work in other Java IDEs? 15 Time for acon – running a demo 15 Time for acon – creang a project 16 Assets and the art pipeline 19 Time for acon – distribung a game 20 Can I sell my jMonkeyEngine game? 21 Summary 22 Chapter 2: Creang Your First 3D Scene 23 A basic template to inialize scenes 23 Time for acon – inializing a scene step by step 24 Starng and stopping the applicaon 27 Time for acon – starng the applicaon 27 Orient yourself in 3D space 28 Time for acon – nding the spot 29 And how do I say that in Java? 31 Time for acon – posion it! 31 Time for acon – scale it! 33 Time for acon – rotate it! 34 Time for acon – rotate it again, Sam 35 Where am I? 36 Time for acon – navigang the scene 37 Populang the scene 38 Time for acon – node versus geometry 40 www.it-ebooks.info [...]... create www.it-ebooks.info Installing jMonkeyEngine In this chapter you will learn: • What the hardware and software requirements are • How to install the jMonkeyEngine SDK • How the tools in the jMonkeyEngine SDK make a developer's life easier • How to create and distribute jMonkeyEngine games Installation requirements for game developers At the time of printing, the jMonkeyEngine SDK needs 40 MB of memory,... our best to address it [ 10 ] www.it-ebooks.info 1 Installing jMonkeyEngine When a group of heroes set out on a quest, they grab their armor and weapons—when you set out on a game development adventure, you grab the jMonkeyEngine SDK The jMonkeyEngine Software Development Kit (SDK) contains everything that you need to get started quickly: the jMonkeyEngine libraries, Javadoc, sample code, and lots of... the jMonkeyEngine SDK The jMonkey team devised the jMonkeyEngine SDK to make the installation process as smooth as possible: 1 2 3 Go to http:/ /jmonkeyengine. org/downloads/ Download the jME3 SDK for your operating system and unzip it, if necessary Double-click on the installer and complete the installation wizard [ 12 ] www.it-ebooks.info Chapter 1 It's time for your first test run: 1 Find the jMonkeyEngine. .. www.it-ebooks.info Installing jMonkeyEngine The other two windows you can ignore for now Later you may use the FilterExplorer window to configure special effects, and the AssetPackBrowser window to bundle up collections of 3D models Congrats, your tools are ready, and you have accomplished your first mission Let's take a closer look at the jMonkeyEngine SDK jMonkeyEngine SDK at your service The jMonkeyEngine SDK... your graphical user interface for the jMonkeyEngine library The jMonkey team devised this integrated development environment (IDE) especially for 3D game development with Java The jMonkeyEngine SDK assists you from start to end, whether you write code, integrate game assets, lay out scenes, or deploy the finished application Creating your Java game projects with jMonkeyEngine SDK has the added value... Apache Ant build tool is already included when you install the SDK Did you know? jMonkeyEngine SDK is built on top of the NetBeans Platform This means that you can install all kinds of NetBeans IDE plugins The NetBeans plugins prepackaged in the jMonkeyEngine SDK include version control tools and a Java debugger Open the jMonkeyEngine SDK and choose Tools | Plugins from the menu, then click on Available... www.it-ebooks.info Chapter 1 Can I work in other Java IDEs? Although this book will repeatedly tell you how awesome the jMonkeyEngine SDK is, you are not forced to use it for coding The jMonkeyEngine library is open source software: If you download the latest binary bundle from http://www .jmonkeyengine. com/ nightly/, you can manually add the JAR files from the lib directory to your CLASSPATH, just like... external tools The jMonkeyEngine SDK does not include any multimedia editors This is because a game engine should not prescribe the artist's choice of design software You are free to create assets in any third-party tools that you fancy and have access to Just make certain that you can export the artwork in formats that jMonkeyEngine supports [ 19 ] www.it-ebooks.info Installing jMonkeyEngine The following... distributable builds of your BasicGame project that runs fine on your desktop, outside the jMonkeyEngine SDK Impressive—you have just built a basic 3D application that runs on the three most widely used operating systems Notice how you didn't have to configure any CLASSPATH or library paths Can I sell my jMonkeyEngine game? Yes, the jMonkeyEngine SDK is a free open source software released under the BSD license... source software released under the BSD license To answer the most common questions right away: You do not pay any fees to use the jMonkeyEngine libraries or SDK You can use the jMonkeyEngine for hobby, educational, or commercial purposes You can include the jMonkeyEngine libraries in a Java application that you sell or give away for free [ 21 ] www.it-ebooks.info . ps 30 9 Game-asset resources 30 9 Key input triggers 31 0 Mouse 31 0 Keyboard 31 1 Joysck 31 2 Seng up jMonkeyEngine in Eclipse 31 2 Downloading the soware 31 3 Creang a new game project 31 3 Seng. don'ts 30 1 Super powers – Go! 30 2 Keep it simple 30 3 Polishing o the last pages 30 4 Summary 30 5 Appendix B: Addional Resources for Fellow jMonkeys 30 7 Game-development resources 30 9 Game-development. color 1 30 Time for acon – oooh, shiny! 131 Time for acon – illuminated opaque textures 133 Time for acon – semitransparent texture 134 Time for acon – transparent textures 136 Mulmapping 138 Time