Android Open Source - model-explorer Vector3






From Project

Back to project page model-explorer.

License

The source code is released under:

Apache License

If you think the Android project model-explorer 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

package com.etaoin.myopengltest.util.geometry;
/*  ww  w.ja v  a  2s.  c om*/
/**
 * Class that represents a vector of 3 coordinates with common util operations.
 */
public class Vector3 {

  private float x;
  private float y;
  private float z;

  public Vector3(float x, float y, float z) {
    this.x = x;
    this.y = y;
    this.z = z;
  }

  @Override
  public Vector3 clone() {
    return new Vector3(x, y, z);
  }

  public Vector3 setX(float x) {
    this.x = x;
    return this;
  }

  public Vector3 setY(float y) {
    this.y = y;
    return this;
  }

  public Vector3 setZ(float z) {
    this.z = z;
    return this;
  }

  public float getX() {
    return this.x;
  }

  public float getY() {
    return this.y;
  }

  public float getZ() {
    return this.z;
  }

  public Vector3 add(Vector3 v) {
    this.x += v.x;
    this.y += v.y;
    this.z += v.z;
    return this;
  }

  public static Vector3 add(Vector3 v1, Vector3 v2) {
    Vector3 result = v1.clone();
    return result.add(v2);
  }

  public Vector3 sub(Vector3 v) {
    this.x -= v.x;
    this.y -= v.y;
    this.z -= v.z;
    return this;
  }

  public static Vector3 sub(Vector3 v1, Vector3 v2) {
    Vector3 result = v1.clone();
    return result.sub(v2);
  }

  public Vector3 mul(float scalar) {
    this.x *= scalar;
    this.y *= scalar;
    this.z *= scalar;
    return this;
  }

  public static Vector3 mul(Vector3 v, float scalar) {
    Vector3 result = v.clone();
    return result.mul(scalar);
  }

  public float dot(Vector3 v) {
    return this.x * v.x + this.y * v.y + this.z * v.z;
  }

  public Vector3 cross(Vector3 v) {
    float x = this.y * v.z - this.z * v.y;
    float y = this.z * v.x - this.x * v.z;
    float z = this.x * v.y - this.y * v.x;
    this.x = x;
    this.y = y;
    this.z = z;
    return this;
  }

  public static Vector3 cross(Vector3 v1, Vector3 v2) {
    Vector3 result = v1.clone();
    return result.cross(v2);
  }

  public float norm() {
    return (float) Math.sqrt(x * x + y * y + z * z);
  }

  public Vector3 normalize() {
    float norm = norm();
    x /= norm;
    y /= norm;
    z /= norm;
    return this;
  }

  public static Vector3 normalize(Vector3 v) {
    Vector3 result = v.clone();
    return result.normalize();
  }

  @Override
  public String toString() {
    return "[x: " + x + ", y: " + y + ", z: " + z + "]";
  }
}




Java Source Code List

com.etaoin.myopengltest.core.main.activity.MainGLActivity.java
com.etaoin.myopengltest.core.main.context.ContextManager.java
com.etaoin.myopengltest.core.main.context.Context.java
com.etaoin.myopengltest.core.main.context.GameContext.java
com.etaoin.myopengltest.core.main.events.UserEvent.java
com.etaoin.myopengltest.core.main.renderers.MainGLRenderer.java
com.etaoin.myopengltest.core.main.views.MainGLSurfaceView.java
com.etaoin.myopengltest.util.camera.Camera.java
com.etaoin.myopengltest.util.geometry.Face.java
com.etaoin.myopengltest.util.geometry.TriangleList.java
com.etaoin.myopengltest.util.geometry.Vector3List.java
com.etaoin.myopengltest.util.geometry.Vector3.java
com.etaoin.myopengltest.util.gl.MyGLES20DebugAll.java
com.etaoin.myopengltest.util.gl.MyGLES20DebugNone.java
com.etaoin.myopengltest.util.gl.MyGLES20Factory.java
com.etaoin.myopengltest.util.gl.MyGLES20.java
com.etaoin.myopengltest.util.gl.MyGenericGLES20.java
com.etaoin.myopengltest.util.io.FileReader.java
com.etaoin.myopengltest.util.io.ModelParserFactory.java
com.etaoin.myopengltest.util.io.ModelParser.java
com.etaoin.myopengltest.util.io.obj.ObjParser.java
com.etaoin.myopengltest.util.light.PointLight.java
com.etaoin.myopengltest.util.shaders.SampleFragmentShader.java
com.etaoin.myopengltest.util.shaders.SampleVertexShader.java
com.etaoin.myopengltest.util.shaders.ShaderFactory.java
com.etaoin.myopengltest.util.shaders.Shader.java
com.etaoin.myopengltest.util.shapes.Axis.java
com.etaoin.myopengltest.util.shapes.Background.java
com.etaoin.myopengltest.util.shapes.Drawable.java
com.etaoin.myopengltest.util.shapes.Model.java