SoniaK

HelowNode

Apr 29th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package jme3test2.helloworld;
  7.  
  8. import com.jme3.app.SimpleApplication;
  9. import com.jme3.material.Material;
  10. import com.jme3.math.Vector3f;
  11. import com.jme3.scene.Geometry;
  12. import com.jme3.scene.shape.Box;
  13. import com.jme3.math.ColorRGBA;
  14.  
  15. /** Sample 1 - how to get started with the most simple JME 3 application.
  16. * Display a blue 3D cube and view from all sides by
  17. * moving the mouse and pressing the WASD keys. @author Sonia
  18. */
  19. public class HelloNode extends SimpleApplication {
  20.  
  21. public static void main(String[] args){
  22. HelloNode app = new HelloNode(); // instantiate the game
  23. app.start(); // start the game
  24. }
  25.  
  26. @Override
  27. public void simpleInitApp() {
  28.  
  29. /** create a blue box at coordinates (1,-1,1) */
  30. Box box1 = new Box(1, 1, 1); // create cube shape
  31. Geometry blue = new Geometry("Box", box1); // create cube geometry from the shape
  32. blue.setLocalTranslation(new Vector3f(1,-1,1));
  33. Material mat1 = new Material(assetManager,
  34. "Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
  35. mat1.setColor("Color", ColorRGBA.Blue);
  36. blue.setMaterial(mat1);
  37.  
  38. /** create a red box straight above the blue one at (1,3,1) */
  39. Box box2 = new Box(1,1,1);
  40. Geometry red = new Geometry("Box", box2);
  41. red.setLocalTranslation(new Vector3f(1,3,1));
  42. Material mat2 = new Material(assetManager,
  43. "Common/MatDefs/Misc/Unshaded.j3md");
  44. mat2.setColor("Color", ColorRGBA.Red);
  45. red.setMaterial(mat2);
  46.  
  47. /** Create a pivot node at (0,0,0) and attach it to the root node */
  48. Node pivot = new Node("pivot");
  49. rootNode.attachChild(pivot);
  50.  
  51. /** Attach the two boxes to the "pivot" node. (And transitively to the root node.) */
  52. pivot.attachChild(blue);
  53. pivot.attachChild(red);
  54.  
  55. /** Rotate the pivot node. Note that both boxes have rotated! */
  56. pivot.rotate(.4f,4f,0f);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment