/** * Updates the values of the given vector from the specified buffer at the index provided. * * @param vector * the vector to set data on * @param buf * the buffer to read from * @param index * the position (in terms of vectors, not floats) to read from the buffer */ public static void populateFromBuffer(final Vector4 vector, final FloatBuffer buf, final int index) { vector.setX(buf.get(index * 4)); vector.setY(buf.get(index * 4 + 1)); vector.setZ(buf.get(index * 4 + 2)); vector.setW(buf.get(index * 4 + 3)); }
/** * Updates the values of the given vector from the specified buffer at the index provided. * * @param vector * the vector to set data on * @param buf * the buffer to read from * @param index * the position (in terms of vectors, not floats) to read from the buffer */ public static void populateFromBuffer(final Vector4 vector, final FloatBuffer buf, final int index) { vector.setX(buf.get(index * 4)); vector.setY(buf.get(index * 4 + 1)); vector.setZ(buf.get(index * 4 + 2)); vector.setW(buf.get(index * 4 + 3)); }
/** * 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; }
/** * @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. * * 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"); }
/** * 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; }
/** * @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. * * 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"); }
@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)); }
@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)); }
/** * 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()); }
/** * 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; }
/** * 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()); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Multiplies the given vector by this matrix (M * v). If supplied, the result is stored into the supplied "store" * vector. * * @param vector * the vector to multiply this matrix by. * @param store * the vector to store the result in. If store is null, a new vector is created. Note that it IS safe for * vector and store to be the same object. * @return the store vector, or a new vector if store is null. * @throws NullPointerException * if vector is null */ @Override public Vector4 applyPost(final ReadOnlyVector4 vector, Vector4 store) { if (store == null) { store = new Vector4(); } final double x = vector.getX(); final double y = vector.getY(); final double z = vector.getZ(); final double w = vector.getW(); store.setX(_m00 * x + _m01 * y + _m02 * z + _m03 * w); store.setY(_m10 * x + _m11 * y + _m12 * z + _m13 * w); store.setZ(_m20 * x + _m21 * y + _m22 * z + _m23 * w); store.setW(_m30 * x + _m31 * y + _m32 * z + _m33 * w); return store; }
/** * 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; }
/** * 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; }
/** * Performs a linear interpolation between the given begin and end vectors, using the given scalar as a percent. * iow, if changeAmnt is closer to 0, the result will be closer to the begin value 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 beginVec * @param endVec * @param changeAmnt * the scalar as a percent. * @return this vector for chaining * * * @throws NullPointerException * if beginVec or endVec are null. */ public Vector4 lerpLocal(final ReadOnlyVector4 beginVec, final ReadOnlyVector4 endVec, final double scalar) { setX((1.0 - scalar) * beginVec.getX() + scalar * endVec.getX()); setY((1.0 - scalar) * beginVec.getY() + scalar * endVec.getY()); setZ((1.0 - scalar) * beginVec.getZ() + scalar * endVec.getZ()); setW((1.0 - scalar) * beginVec.getW() + scalar * endVec.getW()); return this; }
/** * Performs a linear interpolation between the given begin and end vectors, using the given scalar as a percent. * iow, if changeAmnt is closer to 0, the result will be closer to the begin value 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 beginVec * @param endVec * @param changeAmnt * the scalar as a percent. * @return this vector for chaining * * * @throws NullPointerException * if beginVec or endVec are null. */ public Vector4 lerpLocal(final ReadOnlyVector4 beginVec, final ReadOnlyVector4 endVec, final double scalar) { setX((1.0 - scalar) * beginVec.getX() + scalar * endVec.getX()); setY((1.0 - scalar) * beginVec.getY() + scalar * endVec.getY()); setZ((1.0 - scalar) * beginVec.getZ() + scalar * endVec.getZ()); setW((1.0 - scalar) * beginVec.getW() + scalar * endVec.getW()); return this; }
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); }