소스 검색

Updated formating.

mitm 7 년 전
부모
커밋
476d003aca
1개의 변경된 파일91개의 추가작업 그리고 88개의 파일을 삭제
  1. 91 88
      src/docs/asciidoc/jme3/beginner/hello_node.adoc

+ 91 - 88
src/docs/asciidoc/jme3/beginner/hello_node.adoc

@@ -1,6 +1,6 @@
 = jMonkeyEngine 3 Tutorial (2) - Hello Node
-:author: 
-:revnumber: 
+:author:
+:revnumber:
 :revdate: 2016/03/17 20:48
 :keywords: beginner, rootNode, node, intro, documentation, color, spatial, geometry, scenegraph, mesh
 :relfileprefix: ../../
@@ -9,7 +9,7 @@ ifdef::env-github,env-browser[:outfilesuffix: .adoc]
 
 
 Previous: <<jme3/beginner/hello_simpleapplication#,Hello SimpleApplication>>,
-Next: <<jme3/beginner/hello_asset#,Hello Assets>>. 
+Next: <<jme3/beginner/hello_asset#,Hello Assets>>.
 
 In this tutorial we will have a look at the creation of a 3D scene.
 
@@ -18,11 +18,11 @@ In this tutorial we will have a look at the creation of a 3D scene.
 
 When creating a 3D game
 
-.  You create some scene objects like players, buildings, etc. 
+.  You create some scene objects like players, buildings, etc.
 .  You add the objects to the scene.
-.  You move, resize, rotate, color, and animate them. 
+.  You move, resize, rotate, color, and animate them.
 
-You will learn that the scene graph represents the 3D world, and why the rootNode is important. You will learn how to create simple objects, how to let them carry custom data (such as health points), and how to “transform them by moving, scaling, and rotating. You will understand the difference between the two types of “Spatials in the scene graph: Nodes and Geometries. 
+You will learn that the scene graph represents the 3D world, and why the rootNode is important. You will learn how to create simple objects, how to let them carry custom data (such as health points), and how to "`transform`" them by moving, scaling, and rotating. You will understand the difference between the two types of "`Spatials`" in the scene graph: Nodes and Geometries.
 
 
 == Code Sample
@@ -56,16 +56,16 @@ public class HelloNode extends SimpleApplication {
         Box box1 = new Box(1,1,1);
         Geometry blue = new Geometry("Box", box1);
         blue.setLocalTranslation(new Vector3f(1,-1,1));
-        Material mat1 = new Material(assetManager, 
+        Material mat1 = new Material(assetManager,
                 "Common/MatDefs/Misc/Unshaded.j3md");
         mat1.setColor("Color", ColorRGBA.Blue);
         blue.setMaterial(mat1);
 
         /** create a red box straight above the blue one at (1,3,1) */
-        Box box2 = new Box(1,1,1);      
+        Box box2 = new Box(1,1,1);
         Geometry red = new Geometry("Box", box2);
         red.setLocalTranslation(new Vector3f(1,3,1));
-        Material mat2 = new Material(assetManager, 
+        Material mat2 = new Material(assetManager,
                 "Common/MatDefs/Misc/Unshaded.j3md");
         mat2.setColor("Color", ColorRGBA.Red);
         red.setMaterial(mat2);
@@ -92,22 +92,22 @@ In this tutorial, you learn some new terms:
 [cols="2", options="header"]
 |===
 
-a|What you want to do
+a|What you want to do?
 a|How you say it in JME3 terminology
 
-a|Lay out the 3D scene
-a|Populate the scene graph
+a|Lay out the 3D scene.
+a|Populate the scene graph.
 
-a|Create scene objects
-a|Create Spatials (e.g. create Geometries)
+a|Create scene objects.
+a|Create Spatials. (e.g. create Geometries)
 
-a|Make an object appear in the scene
-a|Attach a Spatial to the rootNode
+a|Make an object appear in the scene.
+a|Attach a Spatial to the rootNode.
 
-a|Make an object disappear from the scene
-a|Detach the Spatial from the rootNode
+a|Make an object disappear from the scene.
+a|Detach the Spatial from the rootNode.
 
-a|Position/move, turn, or resize an object
+a|Position/move, turn, or resize an object.
 a|Translate, or rotate, or scale an object = transform an object.
 
 |===
@@ -121,21 +121,21 @@ Every JME3 application has a rootNode: Your game automatically inherits the `roo
 [cols="10,45,45", options="header"]
 |===
 
-<a|  
-a| Geometry 
-a| Node 
+<a|
+a| Geometry
+a| Node
 
-a| Visibility: 
-a| A Geometry is a visible scene object. 
-a| A Node is an invisible “handle for scene objects. 
+a| Visibility:
+a| A Geometry is a visible scene object.
+a| A Node is an invisible "`handle`" for scene objects.
 
-a| Purpose: 
-a| A Geometry stores an object's looks. 
-a| A Node groups Geometries and other Nodes together. 
+a| Purpose:
+a| A Geometry stores an object's looks.
+a| A Node groups Geometries and other Nodes together.
 
-a| Examples: 
-a| A box, a sphere, a player, a building, a piece of terrain, a vehicle, missiles, NPCs, etc… 
-a| The `rootNode`, a floor node grouping several terrains, a custom vehicle-with-passengers node, a player-with-weapon node, an audio node, etc… 
+a| Examples:
+a| A box, a sphere, a player, a building, a piece of terrain, a vehicle, missiles, NPCs, etc…
+a| The `rootNode`, a floor node grouping several terrains, a custom vehicle-with-passengers node, a player-with-weapon node, an audio node, etc…
 
 |===
 
@@ -148,7 +148,7 @@ What happens in the code snippet? You use the `simpleInitApp()` method that was
 **  Create a Box shape with extents of (1,1,1), that makes the box 2x2x2 world units big.
 **  Position the box at (1,-1,1) using the setLocalTranslation() method.
 **  Wrap the Box shape into a Geometry.
-**  Create a blue material. 
+**  Create a blue material.
 **  Apply the blue material to the Box Geometry.
 +
 [source,java]
@@ -164,12 +164,11 @@ What happens in the code snippet? You use the `simpleInitApp()` method that was
 
 
 .  You create a second box Geometry.
-+
 **  Create a second Box shape with the same size.
 **  Position the second box at (1,3,1). This is straight above the first box, with a gap of 2 world units inbetween.
 **  Wrap the Box shape into a Geometry.
-**  Create a red material. 
-**  Apply the red material to the Box Geometry. 
+**  Create a red material.
+**  Apply the red material to the Box Geometry.
 +
 [source,java]
 ----
@@ -184,33 +183,35 @@ What happens in the code snippet? You use the `simpleInitApp()` method that was
 ----
 
 
-.  You create a pivot Node. 
-+
-**  Name the Node “pivot.
-**  By default the Node is positioned at (0,0,0). 
+.  You create a pivot Node.
+**  Name the Node "`pivot`".
+**  By default the Node is positioned at (0,0,0).
 **  Attach the Node to the rootNode.
-**  The Node has no visible appearance in the scene. 
+**  The Node has no visible appearance in the scene.
 +
+--
 [source,java]
 ----
 
     Node pivot = new Node("pivot");
     rootNode.attachChild(pivot);
 ----
-+
-If you run the application with only the code up to here, the scene appears empty. This is because a Node is invisible, and you have not yet attached any visible Geometries to the rootNode. 
 
+If you run the application with only the code up to here, the scene appears empty. This is because a Node is invisible, and you have not yet attached any visible Geometries to the rootNode.
+--
 
-.  Attach the two boxes to the pivot node. 
+.  Attach the two boxes to the pivot node.
 +
+--
 [source,java]
 ----
 
         pivot.attachChild(blue);
         pivot.attachChild(red);
 ----
-+
+
 If you run the app with only the code up to here, you see two cubes: A red cube straight above a blue cube.
+--
 
 .  Rotate the pivot node.
 +
@@ -218,50 +219,52 @@ If you run the app with only the code up to here, you see two cubes: A red cube
 ----
         pivot.rotate( 0.4f , 0.4f , 0.0f );
 ----
-+
-If you run the app now, you see two boxes on top of each other – both tilted at the same angle.
 
+If you run the app now, you see two boxes on top of each other – both tilted at the same angle.
 
 
 === What is a Pivot Node?
 
 You can transform (e.g. rotate) Geometries around their own center, or around a user defined center point. A user defined center point for one or more Geometries is called a pivot.
 
-*  In this example, you have grouped two Geometries by attaching them to one pivot Node. You use the pivot Node as a handle to rotate the two Geometries together around one common center. Rotating the pivot Node rotates all attached Geometries, in one step. The pivot node is the center of the rotation. Before attaching the other Geometries, make certain that the pivot node is at (0,0,0). Transforming a parent Node to transform all attached child Spatials is a common task. You will use this method a lot in your games when you move Spatials around. +
-*Examples:* A vehicle and its driver move together; a planet with its moon orbits the sun. 
-*  Contrast this case with the other option: If you don't create an extra pivot node and transform a Geometry, then every transformation is done relative to the Geometry's origin (typically the center). +
+In this example, you have grouped two Geometries by attaching them to one pivot Node. You use the pivot Node as a handle to rotate the two Geometries together around one common center. Rotating the pivot Node rotates all attached Geometries, in one step. The pivot node is the center of the rotation. Before attaching the other Geometries, make certain that the pivot node is at (0,0,0). Transforming a parent Node to transform all attached child Spatials is a common task. You will use this method a lot in your games when you move Spatials around.
+
+*Examples:* A vehicle and its driver move together; a planet with its moon orbits the sun.
+
+Contrast this case with the other option. If you don't create an extra pivot node and transform a Geometry, then every transformation is done relative to the Geometry's origin (typically the center).
+
 *Examples:* If you rotate each cube directly (using `red.rotate(0.1f , 0.2f , 0.3f);` and `blue.rotate(0.5f , 0.0f , 0.25f);`), then each cube is rotated individually around its center. This is similar to a planet rotating around its own center.
 
 
 == How do I Populate the Scenegraph?
-[cols="2", options="header"]
+[cols="30,70", options="header"]
 |===
 
-a| Task…? 
-a| Solution! 
+a| Task…?
+a| Solution!
 
-a| Create a Spatial 
-a| Create a Mesh shape, wrap it into a Geometry, and give it a Material. For example: 
+a| Create a Spatial.
+a| Create a Mesh shape, wrap it into a Geometry, and give it a Material. For example:
 [source,java]
 ----
 Box mesh = new Box(Vector3f.ZERO, 1, 1, 1); // a cuboid default mesh
-Geometry thing = new Geometry("thing", mesh); 
+Geometry thing = new Geometry("thing", mesh);
 Material mat = new Material(assetManager,
    "Common/MatDefs/Misc/ShowNormals.j3md");
 thing.setMaterial(mat);
 ----
 
 
-a| Make an object appear in the scene 
-a| Attach the Spatial to the `rootNode`, or to any node that is attached to the rootNode. 
+a| Make an object appear in the scene.
+a| Attach the Spatial to the `rootNode`, or to any node that is attached to the rootNode.
 [source,java]
 ----
 rootNode.attachChild(thing);
 ----
 
 
-a| Remove objects from the scene 
-a| Detach the Spatial from the `rootNode`, and from any node that is attached to the rootNode. 
+a| Remove objects from the scene.
+a| Detach the Spatial from the `rootNode`, and from any node that is attached to the rootNode.
 [source,java]
 ----
 rootNode.detachChild(thing);
@@ -273,8 +276,8 @@ rootNode.detachAllChildren();
 ----
 
 
-a| Find a Spatial in the scene by the object's name, or ID, or by its position in the parent-child hierarchy. 
-a| Look at the node's children or parent: 
+a| Find a Spatial in the scene by the object's name, or ID, or by its position in the parent-child hierarchy.
+a| Look at the node's children or parent:
 [source,java]
 ----
 Spatial thing = rootNode.getChild("thing");
@@ -291,8 +294,8 @@ Spatial parent = myNode.getParent();
 ----
 
 
-a| Specify what should be loaded at the start 
-a| Everything you initialize and attach to the `rootNode` in the `simpleInitApp()` method is part of the scene at the start of the game. 
+a| Specify what should be loaded at the start.
+a| Everything you initialize and attach to the `rootNode` in the `simpleInitApp()` method is part of the scene at the start of the game.
 
 |===
 
@@ -303,19 +306,19 @@ There are three types of 3D transformation: Translation, Scaling, and Rotation.
 [cols="55,15,15,15", options="header"]
 |===
 
-a| Translation moves Spatials 
-a| X-axis 
-a| Y-axis 
-a| Z-axis 
+a| Translation moves Spatials
+a| X-axis
+a| Y-axis
+a| Z-axis
 
 a| Specify the new location in three dimensions: How far away is it from the origin going right-up-forward? +
-To move a Spatial _to_ specific coordinates, such as (0,40.2f,-2), use: 
+To move a Spatial _to_ specific coordinates, such as (0,40.2f,-2), use:
 [source,java]
 ----
 thing.setLocalTranslation( new Vector3f( 0.0f, 40.2f, -2.0f ) );
 ----
 
- To move a Spatial _by_ a certain amount, e.g. higher up (y=40.2f) and further back (z=-2.0f): 
+ To move a Spatial _by_ a certain amount, e.g. higher up (y=40.2f) and further back (z=-2.0f):
 
 [source,java]
 ----
@@ -330,15 +333,15 @@ a|+forward -backward
 [cols="55,15,15,15", options="header"]
 |===
 
-a| Scaling resizes Spatials 
-a| X-axis 
-a| Y-axis 
-a| Z-axis 
+a| Scaling resizes Spatials
+a| X-axis
+a| Y-axis
+a| Z-axis
 
 a|Specify the scaling factor in each dimension: length, height, width. +
 A value between 0.0f and 1.0f shrinks the Spatial; bigger than 1.0f stretches it; 1.0f keeps it the same. +
 Using the same value for each dimension scales proportionally, different values stretch it. +
-To scale a Spatial 10 times longer, one tenth the height, and keep the same width: 
+To scale a Spatial 10 times longer, one tenth the height, and keep the same width:
 [source,java]
 ----
 thing.scale( 10.0f, 0.1f, 1.0f );
@@ -352,23 +355,23 @@ a|width
 [cols="55,15,15,15", options="header"]
 |===
 
-a| Rotation turns Spatials 
+a| Rotation turns Spatials
 a| X-axis (Pitch)
 a| Y-axis (Yaw)
 a| Z-axis (Roll)
 
 a|3-D rotation is a bit tricky (<<jme3/rotate#,learn details here>>). In short: You can rotate around three axes: Pitch, yaw, and roll. You can specify angles in degrees by multiplying the degrees value with `FastMath.DEG_TO_RAD`. +
-To roll an object 180° around the z axis: 
+To roll an object 180° around the z axis:
 [source,java]
 ----
 thing.rotate( 0f , 0f , 180*FastMath.DEG_TO_RAD );
 ----
 
-Tip: If your game idea calls for a serious amount of rotations, it is worth looking into <<jme3/quaternion#,quaternions>>, a data structure that can combine and store rotations efficiently. 
+Tip: If your game idea calls for a serious amount of rotations, it is worth looking into <<jme3/quaternion#,quaternions>>, a data structure that can combine and store rotations efficiently.
 
 [source,java]
 ----
-thing.setLocalRotation( 
+thing.setLocalRotation(
   new Quaternion().fromAngleAxis(180*FastMath.DEG_TO_RAD, new Vector3f(1,0,0)));
 ----
 
@@ -385,25 +388,25 @@ If you get unexpected results, check whether you made the following common mista
 [cols="40,60", options="header"]
 |===
 
-a| Problem? 
-a| Solution! 
+a| Problem?
+a| Solution!
 
-a| A created Geometry does not appear in the scene. 
+a| A created Geometry does not appear in the scene.
 a| Have you attached it to (a node that is attached to) the rootNode? +
 Does it have a Material? +
 What is its translation (position)? +
 Is it behind the camera or covered up by another Geometry? +
 Is it too tiny or too gigantic to see? +
-Is it too far from the camera? (Try link:http://javadoc.jmonkeyengine.org/com/jme3/renderer/Camera.html#setFrustumFar(float)[cam.setFrustumFar](111111f); to see further) 
+Is it too far from the camera? (Try link:http://javadoc.jmonkeyengine.org/com/jme3/renderer/Camera.html#setFrustumFar(float)[cam.setFrustumFar](111111f); to see further)
 
-a| A Spatial rotates in unexpected ways. 
+a| A Spatial rotates in unexpected ways.
 a| Did you use radian values, and not degrees? (If you used degrees, multiply them with FastMath.DEG_TO_RAD to convert them to radians)  +
 Did you create the Spatial at the origin (Vector.ZERO) before moving it? +
 Did you rotate around the intended pivot node or around something else? +
-Did you rotate around the right axis? 
+Did you rotate around the right axis?
 
-a| A Geometry has an unexpected Color or Material. 
-<a| Did you reuse a Material from another Geometry and have inadvertently changed its properties? (If so, consider cloning it: mat2 = mat.clone(); )  
+a| A Geometry has an unexpected Color or Material.
+<a| Did you reuse a Material from another Geometry and have inadvertently changed its properties? (If so, consider cloning it: mat2 = mat.clone(); )
 
 |===
 
@@ -412,7 +415,7 @@ a| A Geometry has an unexpected Color or Material.
 
 Many Spatials represent game characters or other entities that the player can interact with. The above code that rotates the two boxes around a common center (pivot) could be used for a spacecraft docked to a orbiting space station, for example.
 
-Depending on your game, game entities do not only change their position, rotation, or scale (the transformations that you just learned about). Game entities also have custom properties, such as health, inventory carried, equipment worn for a character, or hull strength and fuel left for a spacecraft. In Java, you represent entity data as class variables, e.g. floats, Strings, or Arrays. 
+Depending on your game, game entities do not only change their position, rotation, or scale (the transformations that you just learned about). Game entities also have custom properties, such as health, inventory carried, equipment worn for a character, or hull strength and fuel left for a spacecraft. In Java, you represent entity data as class variables, e.g. floats, Strings, or Arrays.
 
 You can add custom data directly to any Node or Geometry. *You do not need to extend the Node class to include variables*!
 For example, to add a custom id number to a node, you would use:
@@ -426,7 +429,7 @@ To read this Node's id number elsewhere, you would use:
 
 [source,java]
 ----
-int id = pivot.getUserData( "pivot id" ); 
+int id = pivot.getUserData( "pivot id" );
 ----
 
 By using different Strings keys (here the key is `pivot id`), you can get and set several values for whatever data the Spatial needs to carry. When you start writing your game, you might add a fuel value to a car node, speed value to an airplane node, or number of gold coins to a player node, and much more. However, one should note that only custom objects that implements Savable can be passed.