/** * The method computes the UV coordinates of the face middle point. * @param face * the face of the mesh * @return a map whose key is the name of the UV set and value is the UV coordinate of the face's middle point */ private Map<String, Vector2f> computeFaceUVs(Face face) { Map<String, Vector2f> result = null; Map<String, List<Vector2f>> uvSets = face.getUvSets(); if (uvSets != null && uvSets.size() > 0) { result = new HashMap<String, Vector2f>(uvSets.size()); for (Entry<String, List<Vector2f>> entry : uvSets.entrySet()) { Vector2f faceUV = new Vector2f(); for (Vector2f uv : entry.getValue()) { faceUV.addLocal(uv); } faceUV.divideLocal(entry.getValue().size()); result.put(entry.getKey(), faceUV); } } return result; }
@Override public Vector2f getAxisDeltaSinceLastCall(int controllerIndex, VRInputType forAxis) { int index; switch (forAxis) { case OculusTriggerAxis: index = 0; break; case OculusGripAxis: index = 1; break; case OculusThumbstickAxis: index = 2; break; default: return null; } Vector2f last = lastAxises[controllerIndex][index]; if (last == null) { last = lastAxises[controllerIndex][index] = new Vector2f(); } Vector2f current = getAxis(controllerIndex, forAxis); // TODO could this lead to accuracy problems? current.subtractLocal(last); last.addLocal(current); return current; }
/** * Add to a Vector2f in-buffer. * * @param toAdd * the vector to add from * @param buf * the buffer to find the Vector2f within * @param index * the position (in terms of vectors, not floats) of the vector * to add to */ public static void addInBuffer(Vector2f toAdd, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector2f tempVec2 = vars.vect2d; populateFromBuffer(tempVec2, buf, index); tempVec2.addLocal(toAdd); setInBuffer(tempVec2, buf, index); vars.release(); }
/** * Get the transformed texture coordinate for a given input location. * @param previousLocation The old texture coordinate. * @return The new texture coordinate inside the atlas. */ public Vector2f getLocation(Vector2f previousLocation) { float x = (float) getX() / (float) atlasWidth; float y = (float) getY() / (float) atlasHeight; float w = (float) getWidth() / (float) atlasWidth; float h = (float) getHeight() / (float) atlasHeight; Vector2f location = new Vector2f(x, y); float prevX = previousLocation.x; float prevY = previousLocation.y; location.addLocal(prevX * w, prevY * h); return location; }
/** * Add to a Vector2f in-buffer. * * @param toAdd * the vector to add from * @param buf * the buffer to find the Vector2f within * @param index * the position (in terms of vectors, not floats) of the vector * to add to */ public static void addInBuffer(Vector2f toAdd, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector2f tempVec2 = vars.vect2d; populateFromBuffer(tempVec2, buf, index); tempVec2.addLocal(toAdd); setInBuffer(tempVec2, buf, index); vars.release(); }
/** * Add to a Vector2f in-buffer. * * @param toAdd * the vector to add from * @param buf * the buffer to find the Vector2f within * @param index * the position (in terms of vectors, not floats) of the vector * to add to */ public static void addInBuffer(Vector2f toAdd, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector2f tempVec2 = vars.vect2d; populateFromBuffer(tempVec2, buf, index); tempVec2.addLocal(toAdd); setInBuffer(tempVec2, buf, index); vars.release(); }
/** * Get the transformed texture coordinate for a given input location. * @param previousLocation The old texture coordinate. * @return The new texture coordinate inside the atlas. */ public Vector2f getLocation(Vector2f previousLocation) { float x = (float) getX() / (float) atlasWidth; float y = (float) getY() / (float) atlasHeight; float w = (float) getWidth() / (float) atlasWidth; float h = (float) getHeight() / (float) atlasHeight; Vector2f location = new Vector2f(x, y); float prevX = previousLocation.x; float prevY = previousLocation.y; location.addLocal(prevX * w, prevY * h); return location; }