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.
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);
Copy the code snippet that creates the blue cube and adjust it to create a second, yellow cube.
Name the
new Box
objectb2
, the geometrygeom2
, and the materialmat2
. (Make sure to rename all instances!)Change the
Color
parameter in the materialmat2
toColorRGBA.Yellow
.Move the second box to its new location
v
:geom2.setLocalTranslation(v);
Attach
geom2
to therootNode
to add it to the scene.Clean and build the
BasicGame
template, and right-click the class to run this file.
You should see a yellow cube behind the blue cube, but positioned a bit higher (y=1), a bit to the right (x=2), and further in the back (z=-3).