/** * * <code>negate</code> returns the negative of this vector. All values are * negated and set to a new vector. * * @return the negated vector. */ public Vector4f negate() { return new Vector4f(-x, -y, -z, -w); }
/** * Transform this <code>ColorRGBA</code> to a <code>Vector4f</code> using * x = r, y = g, z = b, w = a. * This method is useful for shader assignments. * @return A <code>Vector4f</code> containing the RGBA value of this <code>ColorRGBA</code>. */ public Vector4f toVector4f() { return new Vector4f(r, g, b, a); }
/** * <code>divide</code> divides the values of this vector by a scalar and * returns the result. The values of this vector remain untouched. * * @param scalar * the value to divide this vectors attributes by. * @return the result <code>Vector</code>. */ public Vector4f divide(float scalar) { scalar = 1f/scalar; return new Vector4f(x * scalar, y * scalar, z * scalar, w * scalar); }
/** * * <code>mult</code> multiplies this vector by a scalar. The resultant * vector is returned. * * @param scalar * the value to multiply this vector by. * @return the new vector. */ public Vector4f mult(float scalar) { return new Vector4f(x * scalar, y * scalar, z * scalar, w * scalar); }
/** * <code>divide</code> divides the values of this vector by a scalar and * returns the result. The values of this vector remain untouched. * * @param scalar * the value to divide this vectors attributes by. * @return the result <code>Vector</code>. */ public Vector4f divide(Vector4f scalar) { return new Vector4f(x / scalar.x, y / scalar.y, z / scalar.z, w / scalar.w); }
/** * * <code>subtract</code> subtracts the values of a given vector from those * of this vector creating a new vector object. If the provided vector is * null, null is returned. * * @param vec * the vector to subtract from this vector. * @return the result vector. */ public Vector4f subtract(Vector4f vec) { return new Vector4f(x - vec.x, y - vec.y, z - vec.z, w - vec.w); }
/** * * <code>add</code> adds the provided values to this vector, creating a * new vector that is then returned. * * @param addX * the x value to add. * @param addY * the y value to add. * @param addZ * the z value to add. * @return the result vector. */ public Vector4f add(float addX, float addY, float addZ, float addW) { return new Vector4f(x + addX, y + addY, z + addZ, w + addW); }
/** * * <code>subtract</code> * * @param vec * the vector to subtract from this * @param result * the vector to store the result in * @return result */ public Vector4f subtract(Vector4f vec, Vector4f result) { if(result == null) { result = new Vector4f(); } result.x = x - vec.x; result.y = y - vec.y; result.z = z - vec.z; result.w = w - vec.w; return result; }
/** * * <code>subtract</code> subtracts the provided values from this vector, * creating a new vector that is then returned. * * @param subtractX * the x value to subtract. * @param subtractY * the y value to subtract. * @param subtractZ * the z value to subtract. * @param subtractW * the w value to subtract. * @return the result vector. */ public Vector4f subtract(float subtractX, float subtractY, float subtractZ, float subtractW) { return new Vector4f(x - subtractX, y - subtractY, z - subtractZ, w - subtractW); }
/** * * <code>mult</code> multiplies this vector by a scalar. The resultant * vector is supplied as the second parameter and returned. * * @param scalar the scalar to multiply this vector by. * @param product the product to store the result in. * @return product */ public Vector4f mult(float scalar, Vector4f product) { if (null == product) { product = new Vector4f(); } product.x = x * scalar; product.y = y * scalar; product.z = z * scalar; product.w = w * scalar; return product; }
/** * * <code>add</code> adds a provided vector to this vector creating a * resultant vector which is returned. If the provided vector is null, null * is returned. * * @param vec * the vector to add to this. * @return the resultant vector. */ public Vector4f add(Vector4f vec) { if (null == vec) { logger.warning("Provided vector is null, null returned."); return null; } return new Vector4f(x + vec.x, y + vec.y, z + vec.z, w + vec.w); }
/** * <code>mult</code> multiplies a <code>Vector4f</code> about a rotation * matrix. The resulting vector is returned. * * @param vec * vec to multiply against. * @param store * a vector to store the result in. Created if null is passed. * @return the rotated vector. */ public Vector4f mult(Vector4f vec, Vector4f store) { if (null == vec) { logger.warning("Source vector is null, null result returned."); return null; } if (store == null) { store = new Vector4f(); } float vx = vec.x, vy = vec.y, vz = vec.z, vw = vec.w; store.x = m00 * vx + m01 * vy + m02 * vz + m03 * vw; store.y = m10 * vx + m11 * vy + m12 * vz + m13 * vw; store.z = m20 * vx + m21 * vy + m22 * vz + m23 * vw; store.w = m30 * vx + m31 * vy + m32 * vz + m33 * vw; return store; }
/** * <code>mult</code> multiplies a vector about a rotation matrix. The * resulting vector is returned. * * @param vec * vec to multiply against. * @param store * a vector to store the result in. created if null is passed. * @return the rotated vector. */ public Vector4f multAcross(Vector4f vec, Vector4f store) { if (null == vec) { logger.warning("Source vector is null, null result returned."); return null; } if (store == null) { store = new Vector4f(); } float vx = vec.x, vy = vec.y, vz = vec.z, vw = vec.w; store.x = m00 * vx + m10 * vy + m20 * vz + m30 * vw; store.y = m01 * vx + m11 * vy + m21 * vz + m31 * vw; store.z = m02 * vx + m12 * vy + m22 * vz + m32 * vw; store.w = m03 * vx + m13 * vy + m23 * vz + m33 * vw; return store; }
/** * <code>multLocal</code> multiplies a provided vector to this vector * internally, and returns a handle to this vector for easy chaining of * calls. If the provided vector is null, null is returned. * * @param vec * the vector to mult to this vector. * @param store result vector (null to create a new vector) * @return this */ public Vector4f mult(Vector4f vec, Vector4f store) { if (null == vec) { logger.warning("Provided vector is null, null returned."); return null; } if (store == null) store = new Vector4f(); return store.set(x * vec.x, y * vec.y, z * vec.z, w * vec.w); }
private static void toTangentsWithParity(IrVertex vertex) { if (vertex.tang != null && vertex.bitang != null) { float wCoord = vertex.norm.cross(vertex.tang).dot(vertex.bitang) < 0f ? -1f : 1f; vertex.tang4d = new Vector4f(vertex.tang.x, vertex.tang.y, vertex.tang.z, wCoord); vertex.tang = null; vertex.bitang = null; } }
/** * <code>normalize</code> returns the unit vector of this vector. * * @return unit vector of this vector. */ public Vector4f normalize() { // float length = length(); // if (length != 0) { // return divide(length); // } // // return divide(1); float length = x * x + y * y + z * z + w * w; if (length != 1f && length != 0f){ length = 1.0f / FastMath.sqrt(length); return new Vector4f(x * length, y * length, z * length, w * length); } return clone(); }
public Vector4f project(Vector4f other){ float n = this.dot(other); // A . B float d = other.lengthSquared(); // |B|^2 return new Vector4f(other).multLocal(n/d); }
DynamicArray<Float> vec = (DynamicArray<Float>) bPoints.get(j + i * pntsU).getFieldValue("vec"); if (blenderContext.getBlenderKey().isFixUpAxis()) { uControlPoints.add(new Vector4f(vec.get(0).floatValue(), vec.get(2).floatValue(), -vec.get(1).floatValue(), vec.get(3).floatValue())); } else { uControlPoints.add(new Vector4f(vec.get(0).floatValue(), vec.get(1).floatValue(), vec.get(2).floatValue(), vec.get(3).floatValue()));
public static Vector4f getHammersleyPoint(int i, final int nbrSample, Vector4f store) { if (store == null) { store = new Vector4f(); } float phi; long ui = i; store.setX((float) i / (float) nbrSample); /* From http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html * Radical Inverse : Van der Corput */ ui = (ui << 16) | (ui >> 16); ui = ((ui & 0x55555555) << 1) | ((ui & 0xAAAAAAAA) >>> 1); ui = ((ui & 0x33333333) << 2) | ((ui & 0xCCCCCCCC) >>> 2); ui = ((ui & 0x0F0F0F0F) << 4) | ((ui & 0xF0F0F0F0) >>> 4); ui = ((ui & 0x00FF00FF) << 8) | ((ui & 0xFF00FF00) >>> 8); ui = ui & 0xffffffff; store.setY(2.3283064365386963e-10f * (float) (ui)); /* 0x100000000 */ phi = 2.0f * PI * store.y; store.setZ(cos(phi)); store.setW(sin(phi)); return store; }
public Vector4f project(Vector4f other){ float n = this.dot(other); // A . B float d = other.lengthSquared(); // |B|^2 return new Vector4f(other).multLocal(n/d); }