Time for action – position it!

To practice positioning objects, we create a second cube and place it next to the first one. Open the BasicGame template and look at the simpleInitApp() method.

  1. Create a com.jme3.math.Vector3f object. This is the target location for the second cube:
    Vector3f v = new Vector3f(2.0f , 1.0f , -3.0f);
  2. Copy the code snippet that creates the blue cube and adjust it to create a second, yellow cube.
  3. Name the new Box object b2, the geometry geom2, and the material mat2. (Make sure to rename all instances!)
  4. Change the Color parameter in the material mat2 to ColorRGBA.Yellow.
  5. Move the second box to its new location v:
    geom2.setLocalTranslation(v);
  6. Attach geom2 to the rootNode to add it to the scene.
  7. Clean and build the BasicGame template, ...

Get jMonkeyEngine 3.0 Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.