Back to project page Cardboard.
The source code is released under:
Apache License
If you think the Android project Cardboard listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.google.vrtoolkit.cardboard.sensors.internal; /* w w w . j a va 2s .com*/ public class Vector3d { public double x; public double y; public double z; public Vector3d() { } public Vector3d(double xx, double yy, double zz) { set(xx, yy, zz); } public void set(double xx, double yy, double zz) { this.x = xx; this.y = yy; this.z = zz; } public void setComponent(int i, double val) { if (i == 0) { this.x = val; } else if (i == 1) { this.y = val; } else { this.z = val; } } public void setZero() { this.x = (this.y = this.z = 0.0D); } public void set(Vector3d other) { this.x = other.x; this.y = other.y; this.z = other.z; } public void scale(double s) { this.x *= s; this.y *= s; this.z *= s; } public void normalize() { double d = length(); if (d != 0.0D) { scale(1.0D / d); } } public static double dot(Vector3d a, Vector3d b) { return a.x * b.x + a.y * b.y + a.z * b.z; } public double length() { return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); } public boolean sameValues(Vector3d other) { return (this.x == other.x) && (this.y == other.y) && (this.z == other.z); } public static void sub(Vector3d a, Vector3d b, Vector3d result) { result.set(a.x - b.x, a.y - b.y, a.z - b.z); } public static void cross(Vector3d a, Vector3d b, Vector3d result) { result.set(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); } public static void ortho(Vector3d v, Vector3d result) { int k = largestAbsComponent(v) - 1; if (k < 0) { k = 2; } result.setZero(); result.setComponent(k, 1.0D); cross(v, result, result); result.normalize(); } public static int largestAbsComponent(Vector3d v) { double xAbs = Math.abs(v.x); double yAbs = Math.abs(v.y); double zAbs = Math.abs(v.z); if (xAbs > yAbs) { if (xAbs > zAbs) { return 0; } return 2; } if (yAbs > zAbs) { return 1; } return 2; } }