/** * * <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); }
/** * <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(); }
/** * Sets the data contained in the given vector4 into the FloatBuffer at the * specified index. * * @param vec * the {@link Vector4f} to insert * @param buf * the buffer to insert into * @param index * the position to place the data; in terms of vector4 not floats */ public static void setInBuffer(Vector4f vec, FloatBuffer buf, int index) { buf.position(index * 4); buf.put(vec.getX()); buf.put(vec.getY()); buf.put(vec.getZ()); buf.put(vec.getW()); }
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); }
/** * <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); }
Vector3f dir = dl.getDirection(); tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex); lightDataIndex++; Vector3f pos = pl.getPosition(); float invRadius = pl.getInvRadius(); tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex); lightDataIndex++; float invRange = sl.getInvSpotRange(); float spotAngleCos = sl.getPackedAngleCos(); tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex); lightDataIndex++; tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex); lightDataIndex++; break;
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; }
Vector3f pp = ivm.mult(point); Vector3f pn = ivm.multNormal(clipPlane.getNormal(), null); Vector4f clipPlaneV = new Vector4f(pn.x * sideFactor, pn.y * sideFactor, pn.z * sideFactor, -(pp.dot(pn)) * sideFactor); Vector4f v = new Vector4f(0, 0, 0, 0); v.w = (1.0f + p.m22) / p.m23; float dot = clipPlaneV.dot(v);//clipPlaneV.x * v.x + clipPlaneV.y * v.y + clipPlaneV.z * v.z + clipPlaneV.w * v.w; Vector4f c = clipPlaneV.mult(2.0f / dot);
/** * Constructor instantiates a new <code>Vector3f</code> that is a copy * of the provided vector * @param copy The Vector3f to copy */ public Vector4f(Vector4f copy) { this.set(copy); }
Vector3f pp = ivm.mult(point, vars.vect2); Vector3f pn = ivm.multNormal(clipPlane.getNormal(), vars.vect3); Vector4f clipPlaneV = vars.vect4f1.set(pn.x * sideFactor, pn.y * sideFactor, pn.z * sideFactor, -(pp.dot(pn)) * sideFactor); Vector4f v = vars.vect4f2.set(0, 0, 0, 0); v.w = (1.0f + p.m22) / p.m23; float dot = clipPlaneV.dot(v);//clipPlaneV.x * v.x + clipPlaneV.y * v.y + clipPlaneV.z * v.z + clipPlaneV.w * v.w; Vector4f c = clipPlaneV.multLocal(2.0f / dot);
public IrVertex deepClone() { IrVertex v = new IrVertex(); v.pos = pos != null ? pos.clone() : null; v.norm = norm != null ? norm.clone() : null; v.tang4d = tang4d != null ? tang4d.clone() : null; v.tang = tang != null ? tang.clone() : null; v.bitang = bitang != null ? bitang.clone() : null; v.uv0 = uv0 != null ? uv0.clone() : null; v.uv1 = uv1 != null ? uv1.clone() : null; v.color = color != null ? color.clone() : null; v.material = material; v.smoothing = smoothing; if (boneWeightsIndices != null) { v.boneWeightsIndices = new IrBoneWeightIndex[boneWeightsIndices.length]; for (int i = 0; i < boneWeightsIndices.length; i++) { v.boneWeightsIndices[i] = (IrBoneWeightIndex) boneWeightsIndices[i].clone(); } } return v; }
/** * <code>angleBetween</code> returns (in radians) the angle between two vectors. * It is assumed that both this vector and the given vector are unit vectors (iow, normalized). * * @param otherVector a unit vector to find the angle against * @return the angle in radians. */ public float angleBetween(Vector4f otherVector) { float dotProduct = dot(otherVector); float angle = FastMath.acos(dotProduct); return angle; }
/** * <code>distance</code> calculates the distance between this vector and * vector v. * * @param v the second vector to determine the distance. * @return the distance between the two vectors. */ public float distance(Vector4f v) { return FastMath.sqrt(distanceSquared(v)); }
/** * Returns true if this vector is a unit vector (length() ~= 1), * returns false otherwise. * * @return true if this vector is a unit vector (length() ~= 1), * or false otherwise. */ public boolean isUnitVector(){ float len = length(); return 0.99f < len && len < 1.01f; }
tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f); rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex); lightDataIndex++; Vector3f pos = pl.getPosition(); float invRadius = pl.getInvRadius(); tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f); rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex); lightDataIndex++; float invRange = sl.getInvSpotRange(); float spotAngleCos = sl.getPackedAngleCos(); tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f); rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex); lightDataIndex++; tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f); rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); tmpVec.normalizeLocal(); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex); lightDataIndex++; break;
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); }
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; }
/** * <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); }
@Override protected void preFrame(float tpf) { shadowRenderer.preFrame(tpf); if( instanceRendering ) { material.setMatrix4("ViewProjectionMatrixInverseRight", rightCamera.getViewProjectionMatrix().invert()); Matrix4f m = rightCamera.getViewProjectionMatrix(); material.setVector4("ViewProjectionMatrixRow2Right", temp4f2.set(m.m20, m.m21, m.m22, m.m23)); } material.setMatrix4("ViewProjectionMatrixInverse", viewPort.getCamera().getViewProjectionMatrix().invert()); Matrix4f m = viewPort.getCamera().getViewProjectionMatrix(); material.setVector4("ViewProjectionMatrixRow2", temp4f.set(m.m20, m.m21, m.m22, m.m23)); }
Vector3f pp = ivm.mult(point, vars.vect2); Vector3f pn = ivm.multNormal(clipPlane.getNormal(), vars.vect3); Vector4f clipPlaneV = vars.vect4f1.set(pn.x * sideFactor, pn.y * sideFactor, pn.z * sideFactor, -(pp.dot(pn)) * sideFactor); Vector4f v = vars.vect4f2.set(0, 0, 0, 0); v.w = (1.0f + p.m22) / p.m23; float dot = clipPlaneV.dot(v);//clipPlaneV.x * v.x + clipPlaneV.y * v.y + clipPlaneV.z * v.z + clipPlaneV.w * v.w; Vector4f c = clipPlaneV.multLocal(2.0f / dot);