Exemplo n.º 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);
  }
Exemplo n.º 2
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;
 }