Package org.pollux3d.gesture.handler

Source Code of org.pollux3d.gesture.handler.ClickGestureHandler

package org.pollux3d.gesture.handler;

import org.pollux3d.cam.Cam;
import org.pollux3d.core.Pollux;
import org.pollux3d.core.event.MapEntityClickEvent;
import org.pollux3d.core.event.NothingHitClickEvent;
import org.pollux3d.core.event.PolluxEventListener;
import org.pollux3d.map.MapEntity;
import org.pollux3d.state.CamAnimation;
import org.pollux3d.state.Map;

import com.jme3.collision.CollisionResults;
import com.jme3.math.Ray;
import com.jme3.math.Vector2f;

public class ClickGestureHandler extends GestureHandler{
 
  private Cam cam;
  private Map map;
  private PolluxEventListener listener = null;
 
  public ClickGestureHandler(Cam cam, Map map) {
    if (cam == null || map == null) throw new NullPointerException();
    this.cam = cam;
    this.map = map;
  }

  public void click(Vector2f point) {
    Ray clickRay = cam.getClickRay(point);
    CollisionResults results = map.getCollisions(clickRay);
    if (results.size() == 0) {
      if (listener != null) {
        listener.onPolluxEvent(new NothingHitClickEvent(this.getClass().getName()));
      }
    } else {
      for (int i = 0; i < results.size(); i++) {   
        try {
          MapEntity me = Pollux.get().getGeometryManager().getMapEntity(results.getCollision(i).getGeometry());
          if (listener != null) {
            listener.onPolluxEvent(new MapEntityClickEvent(this.getClass().getName(), me));
          }
        } catch (Exception e) {  }
         
      }
    }
  }

  public void longClick(Vector2f point) {}

  public void move(Vector2f move) {}

  public void rotate(float angle) {}

  public void up(Vector2f point) {}

  public void zoom(float zoom) {}

  /**
   * @param listener the PolluxEventListener to set
   */
  public void setListener(PolluxEventListener listener) {
    this.listener = listener;
  }

}
TOP

Related Classes of org.pollux3d.gesture.handler.ClickGestureHandler

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.