官术网_书友最值得收藏!

Time for action – node versus geometry

Geometries are the objects in your scene. They represent loaded models, characters, terrains, and all kinds of other visible objects.

Nodes are a typical means of grouping other nodes and geometries. The typical use case for nodes is transformation, where they are used as handles for groups of spatials. If you group a driver geometry and a car geometry by attaching them to a common vehicle node, you can move both of them by simply translating the vehicle node.

Another use case for nodes is rotation. Do you intend to rotate around the geometry's center, or around another point? If you intend to rotate around a non-central point, create an invisible pivot node and attach the geometry to it. Then, apply the rotation to the pivot node and not to the geometry itself.

The following example shows two geometries rotated around a common, invisible center node, pivot:

  1. Add the following lines at the end of your simpleInitApp() method:
    Node pivot = new Node("pivot node");
    pivot.attachChild(geom);
    pivot.attachChild(geom2);
    pivot.rotate(00, 0, FastMath.DEG_TO_RAD * 45);
    rootNode.attachChild(pivot);
  2. Attaching geom and geom2 to a new parent node implicitly detaches them from their previous parent node.
  3. Clean and build the BasicGame template, and run the file.

Both geom and geom2 are now attached to the pivot node, and the pivot node is attached to the rootNode. The rotation affects both the nodes that are grouped under the pivot node.

What just happened?

Spatials are Java objects that are used to load and save information about elements of the scene graph. There are two distinct types of spatials in the jMonkeyEngine—nodes and geometries.

Remember that you never create a new Spatial() instance—spatials are abstract. You only use the Spatial data type in methods that return either nodes and geometries (for example, the load() method), or in methods that accept either nodes and geometries as arguments (for example, the save() method). In these cases, you create a Node or Geometry object, and the method implicitly casts it to the Spatial data type.

Pop quiz – the truth about spatials

Q1. Combine the following sentence fragments to form six true statements:

a. A node ... b. A geometry ... c. A spatial ...

  1. … is an element of the scene graph.
  2. … groups nodes and geometries.
  3. … contains a mesh (shape) and a material.
  4. … can be loaded and saved.
  5. … is a visible object in the scene.
  6. … is used as an invisible handle.
主站蜘蛛池模板: 米林县| 阿城市| 彰化县| 高淳县| 平顺县| 瓦房店市| 霍山县| 巴彦县| 乌审旗| 元氏县| 岫岩| 仙桃市| 玉环县| 兖州市| 南昌县| 安阳市| 永兴县| 双柏县| 凌云县| 德阳市| 邵武市| 石河子市| 常德市| 绿春县| 滨州市| 天等县| 滨州市| 平陆县| 肇庆市| 定襄县| 十堰市| 凤凰县| 崇礼县| 故城县| 阳西县| 二连浩特市| 酒泉市| 垣曲县| 广平县| 大兴区| 油尖旺区|