Package de.nameless.graphicEngine

Source Code of de.nameless.graphicEngine.NEGraphicServer

/**
*
*/
package de.nameless.graphicEngine;

import java.awt.image.renderable.RenderableImage;
import java.util.Collection;
import java.util.Vector;

import de.nameless.gameEngine.system.ThreadHolder;
import de.nameless.graphicEngine.animation.NEAnimationManager;
import de.nameless.graphicEngine.animation.NEAnimator;
import de.nameless.graphicEngine.lib.NECamera;
import de.nameless.graphicEngine.lib.NETopDownCamera;
import de.nameless.graphicEngine.model.NEModelManager;
import de.nameless.graphicEngine.texture.NEMaterialManager;

/**
* @author Stefan Wittek
*
*/
public class NEGraphicServer implements ThreadHolder {
 
 
  /**
   * Der Renderer, welcher verwand werden soll
   */
  private Renderer renderer;
 
  /**
   * Das OGL Fenster
   */
  private GLDisplay display;
 
  /**
   * Verwaltet alle Objekte auf dem Server
   */
  private NEGraphicalObjectManager gojManager;
 
 
  /**
   * Verwaltet alle Texturen auf dem Server
   */
  private NEMaterialManager textureManager;
 
 
  private NEAnimator animator; 
 
  private NEAnimationManager aManager;
 
  /**
   * Hier wird die kamera gespeichert.
   */
  private NECamera camera;
 
  private InputAdapter IA;
 
  /**
   * Initialisiert alle teile des NEGraphicServer
   */
  public NEGraphicServer() {   
    gojManager=new NEGraphicalObjectManager();
    textureManager = NEMaterialManager.getInstance();
    aManager = new NEAnimationManager();   
    gojManager.setAnimationManager(aManager);
   
    camera = new NETopDownCamera(0,0,100);
    this.addGraphicObject(camera);
  }
 
  /**
   * Startet den Grafikserver und offnet ein fenster welches den inhalt des servers darstellt.
   * An dieser stelle Wird gewartet bis die OGL umgebung vollst�ndig initialisiert ist.
   */
  public void start(){
    startRenderer();
    startAnimator();
    createDisplay();
    setCameraPos(0, 0, 10);   
  }
 
  /**
   * Startet den Renderer; Erst jetzt werden objekte Gerendert.
   */
  public void startRenderer(){
    renderer = new Renderer();
    renderer.setNETextureManager(textureManager);
    renderer.setGojmanager(gojManager);   
  }
 
  /**
   * Startet den Animator auf dem aktuellen Renderer. ist der Renderer nicht gestarter,
   * so gieschiet die nun.
   */
  public void startAnimator(){
    if(renderer ==null){
      startRenderer();
    }
    animator = new NEAnimator();   
    animator.setAnimationManager(aManager);
    renderer.setAnimator(animator);   
  }
 
  /**
   * liefert Den GL-Display, falls n�tig wird er initialisiert.
   */
  public GLDisplay getDisplay(){
    if (display == null){
      createDisplay();
    }
    return display;
  }
 
 
  /**
   * starte den GL-Display und registriert den Renderer.
   * Dieser wird fals n�tig auch gestarter.
   * @return der GL-Display
   */
  public GLDisplay createDisplay(){
    if(renderer ==null){
      startRenderer();
    }
    if(display == null){
      display = GLDisplay.createGLDisplay("Status",800,800);
      display.addGLEventListener(renderer);
      renderer.setDisplay(display);
      display.start();
     
      while(!renderer.isInit()){     
        try {
          Thread.sleep(500);
        } catch (InterruptedException e) {         
          e.printStackTrace();
        }
      }
     
    }
    return display;
  }


  /**
   * F�gt eine objekt ein, das ab jetzt auf dem Display gerendert wird.
   * @param e das anzuf�gende Objekt
   */
  public void addGraphicObject(NEabstractGraphicObject e) {
    e.setHoldingServer(this);
    gojManager.addNextFlush(e);
  }

  /**
   * F�gt eine objekt ein, das ab jetzt auf dem Display gerendert wird.
   * @param e das anzuf�gende Objekt
   */
  public void addGraphicObjectAll(NEabstractGraphicObject[] e) {   
    for (int i = 0; i < e.length; i++) {
      this.addGraphicObject(e[i]);
    }
  } 
 
  public void addGraphicObjectAll(Vector<NEabstractGraphicObject>e) {   
    for (NEabstractGraphicObject o : e) {
      this.addGraphicObject(o);
    }
     
  }
 
 
 
  public boolean removeAllGraphicObjects(Collection<NEabstractGraphicObject> arg0) {
    return gojManager.removeAll(arg0);
  }

  /**
   * @return the camera
   */
  /*
  public NECamera getCamera() {
    return camera;
  }
  */
 
 
  /**
   * @param camera the camera to set
   */
  public void setCamera(NECamera camera) {
    this.gojManager.remove(this.camera);   
    this.addGraphicObject(camera);
    this.camera = camera;
  }
 
  public NECamera getCamera(){   
    return camera;
  }
 
  public void setCameraPos(float x, float y , float z){
    camera.x = x;
    camera.y = y;
    camera.z = z;
  }

  public float getCameraX(){
    return camera.x;
  }
 
  public float getCameraY(){
    return camera.y;
  }
 
  public float getCameraZ(){
    return camera.z;
  }

  public Renderer getRenderer() {
    return renderer;
  }

  public InputAdapter getInputAdapter(){
    if(IA ==null){
      IA = new InputAdapter();     
      IA.RegisterIn(this);
    }
    return IA;
  }
 
  public void removeAllGraphicObject(){
    gojManager.removeAllElements();
  }
 
}
TOP

Related Classes of de.nameless.graphicEngine.NEGraphicServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.