/** * Increments the values of this vector with the x, y, z and w values of the given vector. * * @param source * @return this vector for chaining * @throws NullPointerException * if source is null. */ public Vector4 addLocal(final ReadOnlyVector4 source) { return addLocal(source.getX(), source.getY(), source.getZ(), source.getW()); }
/** * Increments the values of this vector with the x, y, z and w values of the given vector. * * @param source * @return this vector for chaining * @throws NullPointerException * if source is null. */ public Vector4 addLocal(final ReadOnlyVector4 source) { return addLocal(source.getX(), source.getY(), source.getZ(), source.getW()); }
/** * Add to a Vector4 in-buffer. * * @param toAdd * the vector to add from * @param buf * the buffer to find the Vector4 within * @param index * the position (in terms of vectors, not floats) of the vector to add to */ public static void addInBuffer(final ReadOnlyVector4 toAdd, final FloatBuffer buf, final int index) { final Vector4 temp = Vector4.fetchTempInstance(); populateFromBuffer(temp, buf, index); temp.addLocal(toAdd); setInBuffer(temp, buf, index); Vector4.releaseTempInstance(temp); }
/** * Add to a Vector4 in-buffer. * * @param toAdd * the vector to add from * @param buf * the buffer to find the Vector4 within * @param index * the position (in terms of vectors, not floats) of the vector to add to */ public static void addInBuffer(final ReadOnlyVector4 toAdd, final FloatBuffer buf, final int index) { final Vector4 temp = Vector4.fetchTempInstance(); populateFromBuffer(temp, buf, index); temp.addLocal(toAdd); setInBuffer(temp, buf, index); Vector4.releaseTempInstance(temp); }
private void calculateIntersection(final double planeHeight, final ReadOnlyVector2 screenPosition, final ReadOnlyMatrix4 modelViewProjectionInverseMatrix) { origin.set(screenPosition.getX() * 2 - 1, screenPosition.getY() * 2 - 1, -1, 1); direction.set(screenPosition.getX() * 2 - 1, screenPosition.getY() * 2 - 1, 1, 1); modelViewProjectionInverseMatrix.applyPre(origin, origin); modelViewProjectionInverseMatrix.applyPre(direction, direction); direction.subtractLocal(origin); // final double t = (planeHeight * origin.getW() - origin.getY()) // / (direction.getY() - planeHeight * direction.getW()); if (Math.abs(direction.getY()) > MathUtils.EPSILON) { final double t = (planeHeight - origin.getY()) / direction.getY(); direction.multiplyLocal(t); } else { direction.normalizeLocal(); direction.multiplyLocal(mainCamera.getFrustumFar()); } origin.addLocal(direction); }
private void calculateIntersection(final double planeHeight, final ReadOnlyVector2 screenPosition, final ReadOnlyMatrix4 modelViewProjectionInverseMatrix) { origin.set(screenPosition.getX() * 2 - 1, screenPosition.getY() * 2 - 1, -1, 1); direction.set(screenPosition.getX() * 2 - 1, screenPosition.getY() * 2 - 1, 1, 1); modelViewProjectionInverseMatrix.applyPre(origin, origin); modelViewProjectionInverseMatrix.applyPre(direction, direction); direction.subtractLocal(origin); // final double t = (planeHeight * origin.getW() - origin.getY()) // / (direction.getY() - planeHeight * direction.getW()); if (Math.abs(direction.getY()) > MathUtils.EPSILON) { final double t = (planeHeight - origin.getY()) / direction.getY(); direction.multiplyLocal(t); } else { direction.normalizeLocal(); direction.multiplyLocal(mainCamera.getFrustumFar()); } origin.addLocal(direction); }
@Test public void testAdd() { final Vector4 vec1 = new Vector4(); final Vector4 vec2 = new Vector4(Vector4.ONE); vec1.addLocal(1, 2, 3, 4); assertEquals(new Vector4(1, 2, 3, 4), vec1); vec1.addLocal(-1, -2, -3, -4); assertEquals(Vector4.ZERO, vec1); vec1.zero(); vec1.addLocal(vec2); assertEquals(Vector4.ONE, vec1); vec1.zero(); final Vector4 vec3 = vec1.add(vec2, new Vector4()); assertEquals(Vector4.ZERO, vec1); assertEquals(Vector4.ONE, vec3); final Vector4 vec4 = vec1.add(0, 0, 0, 1, null); assertEquals(Vector4.ZERO, vec1); assertEquals(Vector4.UNIT_W, vec4); }