/** * Sets this quaternion to the rotation of the first normalized vector onto the second. * * @return a reference to this quaternion, for chaining. */ public Quaternion fromVectors (IVector3 from, IVector3 to) { float angle = from.angle(to); if (angle < MathUtil.EPSILON) { return set(IDENTITY); } if (angle <= FloatMath.PI - MathUtil.EPSILON) { return fromAngleAxis(angle, from.cross(to).normalizeLocal()); } // it's a 180 degree rotation; any axis orthogonal to the from vector will do Vector3 axis = new Vector3(0f, from.z(), -from.y()); float length = axis.length(); return fromAngleAxis(FloatMath.PI, length < MathUtil.EPSILON ? axis.set(-from.z(), 0f, from.x()).normalizeLocal() : axis.multLocal(1f / length)); }
/** * Sets this plane based on the three points provided. * * @return a reference to the plane (for chaining). */ public Plane fromPoints (IVector3 p1, IVector3 p2, IVector3 p3) { // compute the normal by taking the cross product of the two vectors formed p2.subtract(p1, _v1); p3.subtract(p1, _v2); _v1.cross(_v2, _normal).normalizeLocal(); // use the first point to determine the constant constant = -_normal.dot(p1); return this; }
/** * Creates an empty (invalid) frustum. */ public Frustum () { // initialize the vertices and planes of the frustum for (int ii = 0; ii < 8; ii++) { _vertices[ii] = new Vector3(); } for (int ii = 0; ii < 6; ii++) { _planes[ii] = new Plane(); } }
/** * Adds a vector in-place to this one. * * @return a reference to this vector, for chaining. */ public Vector3 addLocal (float x, float y, float z) { return add(x, y, z, this); }
@Override // from IPlane public float distance (IVector3 pt) { return _normal.dot(pt) + constant; }
/** * Computes the cross product of this and the specified other vector, storing the result * in this vector. * * @return a reference to this vector, for chaining. */ public Vector3 crossLocal (IVector3 other) { return cross(other, this); }
/** * Absolute-values this vector in-place. * * @return a reference to this vector, for chaining. */ public Vector3 absLocal () { return abs(this); }