Android Open Source - Look World Entity






From Project

Back to project page Look.

License

The source code is released under:

====================== LOOK! LICENSING TERMS ====================== look! is licensed under the BSD 3-Clause (also known as "BSD New" or "BSD Simplified"), as follows: Copyright (c) 2010-2012, Look...

If you think the Android project Look listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
*-----------------------------------------------------------------------------
* Copyright (c) 2012, Look! Development Team
* All rights reserved.//ww  w  .  j  a  v a  2  s  .  c o m
*
* Distributed under the terms of the BSD Simplified License.
*
* The full license is in the LICENSE file, distributed with this software.
*-----------------------------------------------------------------------------
*/
package es.ucm.look.data;

import java.util.ArrayList;
import java.util.List;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;
import es.ucm.look.ar.ar2D.Drawable2D;
import es.ucm.look.ar.ar2D.drawables.Circle2D;
import es.ucm.look.ar.ar3D.Drawable3D;
import es.ucm.look.ar.ar3D.core.drawables.Entity3D;
import es.ucm.look.ar.listeners.CameraListener;
import es.ucm.look.ar.listeners.TouchListener;
import es.ucm.look.ar.math.geom.Point3;

/**
 * A world entity
 * 
 * @author ??ngel Serrano
 * 
 */
public class WorldEntity implements Drawable2D, Drawable3D {
  
  /**
   * Entity data
   */
  private EntityData data;

  /**
   * Entity's radius
   */
  private float radius;

  /**
   * Drawable 2D
   */
  private Drawable2D drawable2D;

  /**
   * Drawable 3D
   */
  private Drawable3D drawable3D;

  /**
   * If this entity is focusable
   */
  private boolean focusable;

  /**
   * If this entity is enabled to receive events
   */
  private boolean enable = true;

  /**
   * If this entity is touchable
   */
  private boolean touchable;

  /**
   * If this entity is visible
   */
  protected boolean visible = true;

  /**
   * Touch listeners list
   */
  private List<TouchListener> touchListeners;

  /**
   * Camera listeners list
   */
  private List<CameraListener> cameraListeners;

  /**
   * If 2D appearance has been initialized
   */
  private boolean initialized2D;

  /**
   * If 3D appearance has been initialized
   */
  private boolean initialized3D;

  private Drawable2D touchableArea;

  public WorldEntity( EntityData data ){
    this.data = data;
    focusable = false;
    touchable = false;
  }

  
  /**
   * Returns the entity's radius
   * 
   * @return the entity's radius
   */
  public float getRadius() {
    return radius;
  }

  public void setRadius(float radius) {
    this.radius = radius;
  }

  /**
   * @return the drawable2D
   */
  public Drawable2D getDrawable2D() {
    return drawable2D;
  }

  /**
   * @param drawable2d
   *            the drawable2D to set
   */
  public void setDrawable2D(Drawable2D drawable2d) {
    this.drawable2D = drawable2d;
  }

  /**
   * @return the drawable3D
   */
  public Drawable3D getDrawable3D() {
    return drawable3D;
  }

  /**
   * @param drawable3d
   *            the drawable3D to set
   */
  public void setDrawable3D(Drawable3D drawable3d) {
    drawable3D = drawable3d;
    if ( drawable3D instanceof Entity3D )
      radius = ((Entity3D) drawable3D ).getRadius();
    else
      radius = 50;
      
    
      this.touchableArea = new Circle2D(radius);
  }

  @Override
  public void draw(GL10 gl) {
    if (drawable3D != null) {
      if (!initialized3D) {
        initialized3D = true;
        init3D();
      }
      drawable3D.draw(gl);
    }
  }

  @Override
  public void draw(Canvas c) {
    if (drawable2D != null) {
      if (!initialized2D) {
        initialized2D = true;
        init2D();
      }
      drawable2D.draw(c);
    }
  }

  /**
   * @return If this entity is enabled to receive events
   */
  public boolean isEnable() {
    return enable;
  }

  /**
   * Sets if this entity is enabled to receive events
   * 
   * @param enable
   *            if this entity is enabled to receive events
   */
  public void setEnable(boolean enable) {
    this.enable = enable;
  }

  /**
   * 
   * @return if this entity is touchable
   */
  public boolean isTouchable() {
    return touchable;
  }

  /**
   * Sets if this entity is touchable.
   * 
   * @param touchable
   *            If <b>true</b>, it'll receive touch events
   */
  public void setTouchable(boolean touchable) {
    this.touchable = touchable;
  }

  /**
   * Sets if this entity is focusable
   * 
   * @param focusable
   *            if this entity is focusable
   */
  public void setFocusable(boolean focusable) {
    this.focusable = focusable;
  }

  /**
   * Return whether this entity is focusable
   * 
   * @return if this entity is focusable
   */
  public boolean isFocusable() {
    return focusable;
  }

  /**
   * 
   * @return If this entity is visible
   */
  public boolean isVisible() {
    return visible;
  }

  /**
   * Sets if this entity is visible
   * 
   * @param visible
   * 
   */
  public void setVisible(boolean visible) {
    this.visible = visible;
  }

  /**
   * Adds a touch listener to this entity, and makes this entity touchable
   * 
   * @param t
   *            the touch listener
   */
  public void addTouchListener(TouchListener t) {
    if (t == null)
      return;
    touchable = true;
    if (touchListeners == null)
      touchListeners = new ArrayList<TouchListener>();

    touchListeners.add(t);
  }

  /**
   * Adds a camera listener to this entity, and makes this entity focusable
   * 
   * @param c
   *            the camera listener
   */
  public void addCameraListener(CameraListener c) {
    if (c == null)
      return;
    focusable = true;
    if (cameraListeners == null)
      cameraListeners = new ArrayList<CameraListener>();

    cameraListeners.add(c);
  }

  /**
   * Camera pointed to this entity
   */
  public void cameraEntered() {
    if (cameraListeners != null)
      for (CameraListener c : cameraListeners) {
        c.onCameraEntered(this);
      }
  }

  /**
   * Camera pointed to this entity
   */
  public void cameraExited() {
    if (cameraListeners != null)
      for (CameraListener c : cameraListeners) {
        c.onCameraExited(this);
      }
  }

  /**
   * Entity receives a touch event
   * 
   * @param action
   *            touch's action
   * @return true if the event was processed by the entity
   */
  public boolean touch(MotionEvent event) {
    if (touchListeners != null) {
      float x = event.getX();
      float y = event.getY();
      for (TouchListener t : touchListeners) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          return t.onTouchDown(this, x, y);
        case MotionEvent.ACTION_UP:
          return t.onTouchUp(this, x, y);
        case MotionEvent.ACTION_MOVE:
          return t.onTouchMove(this, x, y);
        }
      }
    }
    return false;
  }

  public boolean equals(Object o) {
    if (o instanceof WorldEntity) {
      return this.data.getId() == ((WorldEntity) o).data.getId();
    }
    return false;
  }

  @Override
  public void update(long elapsed) {
    if (drawable2D != null)
      drawable2D.update(elapsed);

    if (drawable3D != null)
      drawable3D.update(elapsed);

  }

  @Override
  public void drawTouchableArea(Canvas c, Paint p) {
    if (drawable2D != null)
      drawable2D.drawTouchableArea(c, p);
    if (touchableArea != null)
      touchableArea.drawTouchableArea(c, p);

  }

  /**
   * Initializes 2D appearance. Must be overridden for inheriting classes
   */
  public void init2D() {

  }

  /**
   * Initializes 3D appearance. Must be overridden for inheriting classes
   */
  public void init3D() {

  }

  /**
   * Returns the entity's position
   * @return
   */
  public Point3 getLocation() {
    return data.getLocation();
  }


  /**
   * Returns the entity's id
   * @return the id
   */
  public int getId() {
    return data.getId();
  }
  
  /**
   * Returns entity's data
   * @return
   */
  public EntityData getData( ){
    return data;
  }


  /**
   * Returns entity's type
   * @return
   */
  public String getType() {
    return data.getType();
  }

}




Java Source Code List

es.ucm.look.ar.LookAR.java
es.ucm.look.ar.Preview.java
es.ucm.look.ar.ar2D.AR2D.java
es.ucm.look.ar.ar2D.Drawable2D.java
es.ucm.look.ar.ar2D.HUDElement.java
es.ucm.look.ar.ar2D.drawables.Circle2D.java
es.ucm.look.ar.ar2D.drawables.Image2D.java
es.ucm.look.ar.ar2D.drawables.Text2D.java
es.ucm.look.ar.ar3D.Drawable3D.java
es.ucm.look.ar.ar3D.Renderer3D.java
es.ucm.look.ar.ar3D.core.Color4.java
es.ucm.look.ar.ar3D.core.TextureFactory.java
es.ucm.look.ar.ar3D.core.camera.Camera3D.java
es.ucm.look.ar.ar3D.core.camera.OrientedCamera.java
es.ucm.look.ar.ar3D.core.drawables.DrawablesDataBase.java
es.ucm.look.ar.ar3D.core.drawables.Entity3D.java
es.ucm.look.ar.ar3D.core.drawables.Mesh3D.java
es.ucm.look.ar.ar3D.core.drawables.primitives.CirclePrimitive.java
es.ucm.look.ar.ar3D.core.drawables.primitives.Cube.java
es.ucm.look.ar.ar3D.core.drawables.primitives.Grid.java
es.ucm.look.ar.ar3D.core.drawables.primitives.LinePrimitive.java
es.ucm.look.ar.ar3D.core.drawables.primitives.LinesLoopPrimitive.java
es.ucm.look.ar.ar3D.core.drawables.primitives.ObjMesh3D.java
es.ucm.look.ar.ar3D.core.drawables.primitives.PointPrimitive.java
es.ucm.look.ar.ar3D.core.drawables.primitives.Ring.java
es.ucm.look.ar.ar3D.core.drawables.primitives.SquarePrimitive.java
es.ucm.look.ar.ar3D.core.drawables.primitives.TrianglePrimitive.java
es.ucm.look.ar.ar3D.core.drawables.primitives.extra.ImagePrimitive.java
es.ucm.look.ar.ar3D.parser.MeshObjParser.java
es.ucm.look.ar.hud.ActionListener.java
es.ucm.look.ar.hud.BasicHud.java
es.ucm.look.ar.hud.Button.java
es.ucm.look.ar.hud.HUD.java
es.ucm.look.ar.listeners.CameraListener.java
es.ucm.look.ar.listeners.TouchListener.java
es.ucm.look.ar.math.collision.Armature.java
es.ucm.look.ar.math.collision.SphericalArmature.java
es.ucm.look.ar.math.collision.SquareArmature.java
es.ucm.look.ar.math.collision.debug.DebugArmature.java
es.ucm.look.ar.math.collision.debug.SphericalDebugArmature.java
es.ucm.look.ar.math.collision.debug.SquareDebugArmature.java
es.ucm.look.ar.math.geom.Matrix3.java
es.ucm.look.ar.math.geom.Plane.java
es.ucm.look.ar.math.geom.Point2.java
es.ucm.look.ar.math.geom.Point3.java
es.ucm.look.ar.math.geom.Ray.java
es.ucm.look.ar.math.geom.Triangle.java
es.ucm.look.ar.math.geom.Vector3.java
es.ucm.look.ar.util.CameraParametersHelper.java
es.ucm.look.ar.util.DeviceOrientation.java
es.ucm.look.ar.util.LookARUtil.java
es.ucm.look.ar.util.PositionTimerTask.java
es.ucm.look.data.EntityData.java
es.ucm.look.data.LookData.java
es.ucm.look.data.WorldEntityFactory.java
es.ucm.look.data.WorldEntity.java
es.ucm.look.data.World.java
es.ucm.look.data.filesManager.LookFilesManager.java
es.ucm.look.data.interfaces.DataGetter.java
es.ucm.look.data.interfaces.DataHandler.java
es.ucm.look.data.interfaces.DataSetter.java
es.ucm.look.data.local.BasicDataHandler.java
es.ucm.look.data.local.DBDataHandler.java
es.ucm.look.data.local.contentprovider.LookContentProvider.java
es.ucm.look.data.local.contentprovider.sql.LookSQLContentProvider.java
es.ucm.look.data.local.contentprovider.sql.LookSQLHelper.java
es.ucm.look.data.remote.ConfigNet.java
es.ucm.look.data.remote.LookProperties.java
es.ucm.look.data.remote.RemoteDBHandler.java
es.ucm.look.data.remote.restful.LookService.java
es.ucm.look.data.remote.restful.RestMethod.java
es.ucm.look.data.remote.restful.ServiceManager.java
es.ucm.look.location.LocationManager.java
es.ucm.look.locationProvider.DeviceSensor.java
es.ucm.look.locationProvider.InertialNavigationSystem.java
es.ucm.look.locationProvider.LocationProvider.java
es.ucm.look.locationProvider.Motion.java
es.ucm.look.locationProvider.Positioning.java
es.ucm.look.locationProvider.Util.java
es.ucm.look.locationProviderWifi.Cliente.java
es.ucm.look.locationProviderWifi.WifiLocation.java
es.ucm.look.locationProviderWifi.WifiService.java
es.ucm.look.locationProviderWifi.util.DateUtils.java
es.ucm.look.locationProviderWifi.util.DeviceReader.java
es.ucm.look.locationProviderWifi.util.DeviceWriter.java
es.ucm.look.locationProviderWifi.wifi.Lugar.java
es.ucm.look.locationProviderWifi.wifi.Lugares.java
es.ucm.look.locationProviderWifi.wifi.NodoWifi.java
es.ucm.look.locationProvider.map.Mapa.java
es.ucm.look.locationProvider.test.java