Let's do something more interactive than just look at rotating cubes. Can you write code that lets you chase one of the cubes? By chase we mean, if the camera moves closer than 10 WU to this cube, the cube should move away from the camera.
Make another copy of the
BasicGame
object'sMain.java
template.Rename the copy to
CubeChaser.java
. Remember to also refactor the first line of themain()
method to the following:CubeChaser app = new CubeChaser();
Delete the blue cube and copy the
myBox()
convenience method from one of the previous target picking examples. Don't forget to copy themesh
class field.Add a
makeCubes(40);
call to thesimpleInitApp()
method and fill the scene with 40 randomly positioned and randomly colored cubes. Use the built-in methodFastMath.nextRandomInt(min,max)
(fromcom.jme3.math
) to generate random coordinates in the interval betweenmin
andmax
.private void makeCubes(int number) { for (int i = 0; i < number; i++) { ...