Example #1
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);
  }
Example #2
0
 @Override
 public void read(final InputCapsule capsule) throws IOException {
   setX(capsule.readDouble("x", 0));
   setY(capsule.readDouble("y", 0));
   setZ(capsule.readDouble("z", 0));
   setW(capsule.readDouble("w", 0));
 }
Example #3
0
 /**
  * Used with serialization. Not to be called manually.
  *
  * @param in ObjectInput
  * @throws IOException
  * @throws ClassNotFoundException
  */
 @Override
 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
   setX(in.readDouble());
   setY(in.readDouble());
   setZ(in.readDouble());
   setW(in.readDouble());
 }
Example #4
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 stored back in this vector.
  *
  * @param endVec
  * @param scalar
  * @return this vector for chaining
  * @throws NullPointerException if endVec is null.
  */
 public Vector4 lerpLocal(final ReadOnlyVector4 endVec, final double scalar) {
   setX((1.0 - scalar) * getX() + scalar * endVec.getX());
   setY((1.0 - scalar) * getY() + scalar * endVec.getY());
   setZ((1.0 - scalar) * getZ() + scalar * endVec.getZ());
   setW((1.0 - scalar) * getW() + scalar * endVec.getW());
   return this;
 }
Example #5
0
 /**
  * Sets the value of this vector to the (x, y, z, w) values of the provided source vector.
  *
  * @param source
  * @return this vector for chaining
  * @throws NullPointerException if source is null.
  */
 public Vector4 set(final ReadOnlyVector4 source) {
   setX(source.getX());
   setY(source.getY());
   setZ(source.getZ());
   setW(source.getW());
   return this;
 }
Example #6
0
 /**
  * Sets the value of this vector to (x, y, z, w)
  *
  * @param x
  * @param y
  * @param z
  * @param w
  * @return this vector for chaining
  */
 public Vector4 set(final double x, final double y, final double z, final double w) {
   setX(x);
   setY(y);
   setZ(z);
   setW(w);
   return this;
 }
Example #7
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;
  }
Example #8
0
 /**
  * @param index which field index in this vector to set.
  * @param value to set to one of x, y, z or w.
  * @throws IllegalArgumentException if index is not one of 0, 1, 2, 3.
  *     <p>if this vector is read only
  */
 public void setValue(final int index, final double value) {
   switch (index) {
     case 0:
       setX(value);
       return;
     case 1:
       setY(value);
       return;
     case 2:
       setZ(value);
       return;
     case 3:
       setW(value);
       return;
   }
   throw new IllegalArgumentException("index must be either 0, 1, 2 or 3");
 }