@Override public void draw(final Renderer r) { initialize(r); updateTranslations(); final double camWaterDist = waterPlane.pseudoDistance(cam.getLocation()); aboveWater = camWaterDist >= 0; if (isSupported()) { waterShader.setUniform("tangent", tangent); waterShader.setUniform("binormal", binormal); waterShader.setUniform("useFadeToFogColor", useFadeToFogColor); waterShader.setUniform("waterColor", waterColorStart); waterShader.setUniform("waterColorEnd", waterColorEnd); waterShader.setUniform("normalTranslation", (float) normalTranslation); waterShader.setUniform("refractionTranslation", (float) refractionTranslation); waterShader.setUniform("abovewater", aboveWater); if (useProjectedShader) { waterShader.setUniform("cameraPos", cam.getLocation()); waterShader.setUniform("waterHeight", (float) waterPlane.getConstant()); waterShader.setUniform("amplitude", (float) waterMaxAmplitude); waterShader.setUniform("heightFalloffStart", (float) heightFalloffStart); waterShader.setUniform("heightFalloffSpeed", (float) heightFalloffSpeed); } final double heightTotal = clipBias + waterMaxAmplitude - waterPlane.getConstant(); final Vector4 clipPlane = Vector4.fetchTempInstance(); if (useReflection) { clipPlane.set( waterPlane.getNormal().getX(), waterPlane.getNormal().getY(), waterPlane.getNormal().getZ(), heightTotal); renderReflection(clipPlane); } if (useRefraction && aboveWater) { clipPlane.set( -waterPlane.getNormal().getX(), -waterPlane.getNormal().getY(), -waterPlane.getNormal().getZ(), -waterPlane.getConstant()); renderRefraction(clipPlane); } } if (fallbackTextureState != null) { fallbackTextureStateMatrix.setM31(normalTranslation); fallbackTexture.setTextureMatrix(fallbackTextureStateMatrix); } super.draw(r); }
/** * Divides the values of this vector by the given scalar value and returns the result in store. * * @param scalar * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return a new vector (this.x / scalar, this.y / scalar, this.z / scalar, this.w / scalar) */ @Override public Vector4 divide(final double scalar, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } return result.set(getX() / scalar, getY() / scalar, getZ() / scalar, getW() / scalar); }
/** * Creates a new unit length vector from this one by dividing by length. If the length is 0, (ie, * if the vector is 0, 0, 0, 0) then a new vector (0, 0, 0, 0) is returned. * * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return a new unit vector (or 0, 0, 0, 0 if this unit is 0 length) */ @Override public Vector4 normalize(final Vector4 store) { final double lengthSq = lengthSquared(); if (Math.abs(lengthSq) > MathUtils.EPSILON) { return multiply(MathUtils.inverseSqrt(lengthSq), store); } return store != null ? store.set(Vector4.ZERO) : new Vector4(Vector4.ZERO); }
/** * Divides the values of this vector by the given scale values and returns the result in store. * * @param x * @param y * @param z * @param w * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return a new vector (this.x / scale.x, this.y / scale.y, this.z / scale.z, this.w / scale.w) */ @Override public Vector4 divide( final double x, final double y, final double z, final double w, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } return result.set(getX() / x, getY() / y, getZ() / z, getW() / w); }
/** * Divides the values of this vector by the given scale values and returns the result in store. * * @param scale * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return a new vector (this.x / scale.x, this.y / scale.y, this.z / scale.z, this.w / scale.w) */ @Override public Vector4 divide(final ReadOnlyVector4 scale, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } return result.set( getX() / scale.getX(), getY() / scale.getY(), getZ() / scale.getZ(), getW() / scale.getW()); }
/** * Multiplies the values of this vector by the given scalar value and returns the result in store. * * @param x * @param y * @param z * @param w * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return a new vector (this.x * scale.x, this.y * scale.y, this.z * scale.z, this.w * scale.w) */ @Override public Vector4 multiply( final double x, final double y, final double z, final double w, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } return result.set(getX() * x, getY() * y, getZ() * z, getW() * w); }
/** * Subtracts the given values from those of this vector and returns them in store. * * @param x * @param y * @param z * @param w * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return (this.x - x, this.y - y, this.z - z, this.w - w) */ @Override public Vector4 subtract( final double x, final double y, final double z, final double w, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } return result.set(getX() - x, getY() - y, getZ() - z, getW() - w); }
/** * Adds the given values to those of this vector and returns them in store. * * @param x * @param y * @param z * @param w * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return (this.x + x, this.y + y, this.z + z, this.w + w) */ @Override public Vector4 add( final double x, final double y, final double z, final double w, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } return result.set(getX() + x, getY() + y, getZ() + z, getW() + w); }
/** * Performs a linear interpolation between this vector and the given end vector, using the given * scalar as a percent. iow, if changeAmnt is closer to 0, the result will be closer to the * current value of this vector and if it is closer to 1, the result will be closer to the end * value. The result is returned as a new vector object. * * @param endVec * @param scalar * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return a new vector as described above. * @throws NullPointerException if endVec is null. */ @Override public Vector4 lerp(final ReadOnlyVector4 endVec, final double scalar, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } final double x = (1.0 - scalar) * getX() + scalar * endVec.getX(); final double y = (1.0 - scalar) * getY() + scalar * endVec.getY(); final double z = (1.0 - scalar) * getZ() + scalar * endVec.getZ(); final double w = (1.0 - scalar) * getW() + scalar * endVec.getW(); return result.set(x, y, z, w); }