Android Open Source - Look Camera3 D






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./*from 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.ar.ar3D.core.camera;

import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLU;
import es.ucm.look.ar.math.geom.Point3;
import es.ucm.look.ar.math.geom.Vector3;

public class Camera3D {

  /**
   * Represents a vector pointing to the north in the scene. This vector will
   * be take as reference for some calculations
   */
  public static final Vector3 NORTH = new Vector3(0, 0, 1);

  /**
   * Represents a vector pointing towards the sky, and perpendicular to it
   */
  public static final Vector3 UP = new Vector3(0, 1, 0);

  /**
   * Point pointed by the camera
   */
  public Point3 eye;

  public Vector3 look;

  protected Vector3 up;

  protected Vector3 u, v, n;

  public Camera3D() {
    eye = new Vector3(0, 0, 0);
    look = new Vector3(NORTH);
    up = new Vector3(UP);
    n = new Vector3(0, 0, 0);
    u = new Vector3(0, 0, 0);
    v = new Vector3(0, 0, 0);
    calcVectors();
  }

  public void setCamera(GL10 gl) {
    GLU.gluLookAt(gl, eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.z);
  }

  public void setPosition(Point3 p) {
    eye.set(p);
  }

  public void calcVectors() {
    // n= eye - look
    n.set(eye.x - look.x, eye.y - look.y, eye.z - look.z);
    n.normalize();

    // u = up X n
    u = up.crossProduct(n);
    u.normalize();

    // v = n X u
    v = n.crossProduct(u);
  }

  public void roll(float angle) {
    float cos = (float) Math.cos(angle);
    float sin = (float) Math.sin(angle);

    Vector3 t = new Vector3(u.x, u.y, u.z);
    Vector3 s = new Vector3(v.x, v.y, v.z);

    u.set(cos * t.x + sin * s.x, cos * t.y + sin * s.y, cos * t.z + sin * s.z);
    u.normalize();
    v.set(-t.x * sin + s.x * cos, -t.y * sin + s.y * cos, -t.z * sin + s.z * cos);
    v.normalize();

    up.set(v.x, v.y, v.z);
  }

  public void pitch(float angle) {
    float cos = (float) Math.cos(angle);
    float sin = (float) Math.sin(angle);

    Vector3 t = new Vector3(v.x, v.y, v.z);
    Vector3 s = new Vector3(n.x, n.y, n.z);

    v.set(t.x * cos - s.x * sin, t.y * cos - s.y * sin, t.z * cos - s.z * sin);
    v.normalize();
    n.set(t.x * sin + s.x * cos, t.y * sin + s.y * cos, t.z * sin + s.z * cos);
    n.normalize();

    float module = Vector3.getVolatileVector(eye, look).module();

    look.set(n.x, n.y, n.z);
    look.scale(-module);
    look.add(eye);

    up.set(v.x, v.y, v.z);

  }

  public void yaw(float angle) {
    float cos = (float) Math.cos(angle);
    float sin = (float) Math.sin(angle);

    Vector3 t = new Vector3(n.x, n.y, n.z);
    Vector3 s = new Vector3(u.x, u.y, u.z);

    n.set(t.x * cos + s.x * sin, t.y * cos + s.y * sin, t.z * cos + s.z * sin);
    n.normalize();
    u.set(s.x * cos - t.x * sin, s.y * cos - t.y * sin, s.z * cos - t.z * sin);
    u.normalize();

    float module = Vector3.getVolatileVector(eye, look).module();

    look.set(n.x, n.y, n.z);
    look.scale(-module);
    look.add(eye);

  }
}




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