jMonkeyEngine 3.0 Beginner’s Guide
上QQ阅读APP看书,第一时间看更新

Orient yourself in 3D space

When you initialize your game world, you want to fill the empty scene. Maybe you add a ground with streets and some buildings, or a terrain with forests and caves. You strategically place your players and enemies, and you sprinkle some treasure and traps on the map. Now how exactly do you tell the jMonkeyEngine where to place an object? You need a way to orient yourself in 3D space—through a coordinate system.

The following figure is based on an image created by Sakurambo, and can be found at http://de.wikipedia.org/w/index.php?title=Datei:3D_coordinate_system.svg.

The jMonkeyEngine uses a right-handed coordinate system, just as the Open Graphics Library (OpenGL) does.

Tip

If the concept of coordinates is new to you, you may want to start with a quick visual introduction on our web page, which can be found at:

http://jmonkeyengine.org/wiki/doku.php/jme3:scenegraph_for_dummies

Let's have a look at the illustration and recapitulate the concepts behind the Cartesian coordinate system:

  • The central point of the 3D scene is called the origin.
  • The origin is always at coordinate (0,0,0).
  • The three coordinate axes stand at 90 degree angles to one another, and meet in the origin. In the previous screenshot:
    • The x axis goes from left to right
    • The y axis goes from down to up
    • The z axis starts away from you and goes towards you

This means that, if you see positive numbers, you follow the arrow along the axis. If you see negative numbers, you move in the direction against the arrow.

It's important to understand these concepts, since all distances, directions, and locations in a 3D scene are expressed in relation to this coordinate system. It's an easy principle, as you will see in the following example.