Book Image

jMonkeyEngine 3.0 : Beginner's Guide

Book Image

jMonkeyEngine 3.0 : Beginner's Guide

Overview of this book

jMonkeyEngine 3.0 is a powerful set of free Java libraries that allows you to unlock your imagination, create 3D games and stunning graphics. Using jMonkeyEngine's library of time-tested methods, this book will allow you to unlock its potential and make the creation of beautiful interactive 3D environments a breeze."jMonkeyEngine 3.0 Beginner's Guide" teaches aspiring game developers how to build modern 3D games with Java. This primer on 3D programming is packed with best practices, tips and tricks and loads of example code. Progressing from elementary concepts to advanced effects, budding game developers will have their first game up and running by the end of this book.From basic concepts and project creation to building a complex 3D Game, you will learn to layout 3D scenes, make them interactive and add various multi-media effects.You will find answers to common questions including best practices and approaches, how game characters can act and interact, how to simulate solid walls and physical forces, how to take it online to play over a network and much more.From Zero to Hero, start your journey to make your game idea a reality.
Table of Contents (20 chapters)
jMonkeyEngine 3.0 Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – chase all the cubes!


The other cubes are mightily impressed by your new-found cube chasing skills. Can you change the code sample so that you can pick which cube you want to chase, simply by looking at it? Use the ray casting method that you learned in the earlier target picking examples!

  1. Since you will detect cubes with the help of ray casting, create a class field for the ray object.

    private Ray ray = new Ray();
  2. Completely remove the code pertaining to scaredCube—a real cube chaser doesn't need an extra class field to pick a cube.

  3. Put the following code in the simpleUpdate() method loop to keep the ray up-to-date. Use the ray.setOrigin(cam.getLocation()) method and the ray.setDirection(cam.getDirection()) method to aim the ray in the direction of the camera. Identify collisions and pick the closest geometry as the target. Test the distance and change the target's location, just as before.

    public void simpleUpdate(float tpf) {
        CollisionResults results = new CollisionResults...