- jMonkeyEngine 3.0 Beginner’s Guide
- Ruth Kusterer
- 416字
- 2021-08-13 17:02:09
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
:
- 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);
- Attaching
geom
andgeom2
to a new parent node implicitly detaches them from their previous parent node. - 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 ...
- … is an element of the scene graph.
- … groups nodes and geometries.
- … contains a mesh (shape) and a material.
- … can be loaded and saved.
- … is a visible object in the scene.
- … is used as an invisible handle.
- Extending Jenkins
- C語言程序設計基礎與實驗指導
- 游戲程序設計教程
- Hands-On RESTful Web Services with Go
- Java EE 8 Application Development
- HTML+CSS+JavaScript網(wǎng)頁設計從入門到精通 (清華社"視頻大講堂"大系·網(wǎng)絡開發(fā)視頻大講堂)
- Visual Studio Code 權威指南
- Programming Microsoft Dynamics? NAV 2015
- 零基礎學HTML+CSS
- TypeScript圖形渲染實戰(zhàn):2D架構設計與實現(xiàn)
- Visual Basic程序設計基礎
- Java EE輕量級解決方案:S2SH
- 小學生C++趣味編程從入門到精通
- Manage Your SAP Projects with SAP Activate
- R語言:邁向大數(shù)據(jù)之路