SoniaK

HellowNode with Scene

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