/** * Calculate the angle between two vectors, in radians * @param a A vector * @param b The other vector * @return the angle between the two vectors, in radians */ public static float angle(Vector3f a, Vector3f b) { float dls = dot(a, b) / (a.length() * b.length()); if (dls < -1f) dls = -1f; else if (dls > 1.0f) dls = 1.0f; return (float)Math.acos(dls); }
/** * Normalise this vector and place the result in another vector. * @param dest The destination vector, or null if a new vector is to be created * @return the normalised vector */ public Vector3f normalise(Vector3f dest) { float l = length(); if (dest == null) dest = new Vector3f(x / l, y / l, z / l); else dest.set(x / l, y / l, z / l); return dest; }
Vector3f dir = Vector3f.sub(destination, source, null); Vector3f dirC = Vector3f.cross(dir, new Vector3f(1, 0, 1), null); float distance = dir.length(); dir.normalise(dir); Vector3f front = new Vector3f(0, 0, -1);