Пример #1
0
 /**
  * Internally modifies this vector by multiplying its values with a given scale value, then adding
  * a given "add" value.
  *
  * @param scale the value to multiply this vector by.
  * @param add the value to add to the result
  * @return this vector for chaining
  */
 public Vector4 scaleAddLocal(final double scale, final Vector4 add) {
   _x = _x * scale + add.getX();
   _y = _y * scale + add.getY();
   _z = _z * scale + add.getZ();
   _w = _w * scale + add.getW();
   return this;
 }
Пример #2
0
  /**
   * 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);
  }
Пример #3
0
  /**
   * 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);
  }
Пример #4
0
  /**
   * 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());
  }
Пример #5
0
  /**
   * 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);
  }
Пример #6
0
  /**
   * 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);
  }
Пример #7
0
  /**
   * 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);
  }
Пример #8
0
  @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);
  }
Пример #9
0
  /**
   * 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);
  }
Пример #10
0
  /**
   * Scales this vector by multiplying its values with a given scale value, then adding a given
   * "add" value. The result is store in the given store parameter.
   *
   * @param scale the value to multiply by.
   * @param add the value to add
   * @param store the vector to store the result in for return. If null, a new vector object is
   *     created and returned.
   * @return the store variable
   */
  @Override
  public Vector4 scaleAdd(final double scale, final ReadOnlyVector4 add, final Vector4 store) {
    Vector4 result = store;
    if (result == null) {
      result = new Vector4();
    }

    result.setX(_x * scale + add.getX());
    result.setY(_y * scale + add.getY());
    result.setZ(_z * scale + add.getZ());
    result.setW(_w * scale + add.getW());
    return result;
  }
Пример #11
0
  /**
   * 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);
  }
Пример #12
0
  private void modifyProjectionMatrix(final Vector4 clipPlane) {
    // Get the current projection matrix
    projectionMatrix = cam.getProjectionMatrix().toArray(projectionMatrix);

    // Get the inverse transpose of the current modelview matrix
    final ReadOnlyMatrix4 modelViewMatrixInvTrans =
        tRenderer.getCamera().getModelViewMatrix().invert(tmpMatrix).transposeLocal();
    modelViewMatrixInvTrans.applyPre(clipPlane, clipPlane);

    // Calculate the clip-space corner point opposite the clipping plane
    // as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
    // transform it into camera space by multiplying it
    // by the inverse of the projection matrix
    cornerPoint.setX((sign(clipPlane.getX()) + projectionMatrix[8]) / projectionMatrix[0]);
    cornerPoint.setY((sign(clipPlane.getY()) + projectionMatrix[9]) / projectionMatrix[5]);
    cornerPoint.setZ(-1.0);
    cornerPoint.setW((1.0 + projectionMatrix[10]) / projectionMatrix[14]);

    // Calculate the scaled plane vector
    final Vector4 scaledPlaneVector =
        clipPlane.multiply((2.0 / clipPlane.dot(cornerPoint)), cornerPoint);

    // Replace the third row of the projection matrix
    projectionMatrix[2] = scaledPlaneVector.getX();
    projectionMatrix[6] = scaledPlaneVector.getY();
    projectionMatrix[10] = scaledPlaneVector.getZ() + 1.0;
    projectionMatrix[14] = scaledPlaneVector.getW();

    // Load it back into OpenGL
    final Matrix4 newProjectionMatrix = tmpMatrix.fromArray(projectionMatrix);
    tRenderer.getCamera().setProjectionMatrix(newProjectionMatrix);
  }