Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.08 KB | None | 0 0
  1. package org.nhl.containing;
  2.  
  3. import com.jme3.asset.AssetManager;
  4. import com.jme3.font.BitmapFont;
  5. import com.jme3.font.BitmapText;
  6. import com.jme3.material.Material;
  7. import com.jme3.math.ColorRGBA;
  8. import com.jme3.math.FastMath;
  9. import com.jme3.math.Quaternion;
  10. import com.jme3.math.Vector3f;
  11. import com.jme3.renderer.queue.RenderQueue;
  12. import com.jme3.scene.Node;
  13. import com.jme3.scene.Spatial;
  14.  
  15. /**
  16.  *
  17.  * @author Jeroen
  18.  */
  19. public class Container extends Node {
  20.  
  21.     private AssetManager assetManager;
  22.     private String owner;
  23.     private String containerID;
  24.     private String transportType;
  25.     private Vector3f Location;
  26.  
  27.     public Container(AssetManager assetManager, String owner, String containerID, String transportType, Vector3f Location) {
  28.         this.assetManager = assetManager;
  29.         this.owner = owner;
  30.         this.containerID = containerID;
  31.         this.transportType = transportType;
  32.         this.Location = Location;
  33.         initContainer();
  34.     }
  35.  
  36.     /**
  37.      * Initialize a container.
  38.      */
  39.     public void initContainer() {
  40.         // Load a model.
  41.         Spatial container = assetManager.loadModel("Models/medium/container/container.j3o");
  42.         Material mat = new Material(assetManager,
  43.           "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
  44.         mat.setColor("Color", ColorRGBA.White);   // set color of material to blue
  45.         mat.setColor("Color", ColorRGBA.randomColor());
  46.         container.setMaterial(mat);
  47.         this.attachChild(container);
  48.         //create a random text color
  49.         ColorRGBA textColor = ColorRGBA.randomColor();
  50.         //place the company name on the side
  51.         drawText(1.2f, 2.6f, 6, textColor, new Quaternion().fromAngleAxis(FastMath.PI/2,   new Vector3f(0,1,0)));
  52.         drawText(-1.2f, 2.6f, -6, textColor, new Quaternion().fromAngleAxis(FastMath.PI * 1.5f ,   new Vector3f(0,1,0)));
  53.     }
  54.  
  55.     public Vector3f getLocation() {
  56.         return Location;
  57.     }
  58.  
  59.     public String getContainerID() {
  60.         return containerID;
  61.     }
  62.  
  63.     public String getOwner() {
  64.         return owner;
  65.     }
  66.  
  67.     public String getTransportType() {
  68.         return transportType;
  69.     }
  70.  
  71.     public void setLocation(Vector3f Location) {
  72.         this.Location = Location;
  73.     }  
  74.     /**
  75.      * This method writes the company name on the side of the container
  76.      * Has parameters for placing the text on the right and left side.
  77.      */
  78.     public void drawText(float x, float y, float z, ColorRGBA color, Quaternion rotation){
  79.         BitmapFont guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
  80.         BitmapText companyText = new BitmapText(guiFont, false);          
  81.         companyText.setSize(1);      // font size
  82.         companyText.setColor(color);                             // font color
  83.         companyText.setText(owner);             // the text
  84.         companyText.rotate(rotation);
  85.         companyText.setLocalTranslation(x, y, z); // position
  86.         companyText.setQueueBucket(RenderQueue.Bucket.Translucent);
  87.         this.attachChild(companyText);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement