/** * Projects a given {@link Vector3} with this {@link Matrix4} storing * the result in the given {@link Vector3}. * * @param vec {@link Vector3} The vector to multiply by. * * @return {@link Vector3} The resulting vector. */ @NonNull public Vector3 projectVector(@NonNull Vector3 vec) { double inv = 1.0 / (m[M30] * vec.x + m[M31] * vec.y + m[M32] * vec.z + m[M33]); vec.multiply(m); return vec.multiply(inv); }
public void normalize() { double inverseNormalLength = 1.0 / mNormal.length(); mNormal.multiply(inverseNormalLength); mD *= inverseNormalLength; } }
public Vector3 getWorldPosition() { if (mParentMatrix == null) { return mPosition; } Vector3 worldPos = mPosition.clone(); worldPos.multiply(mParentMatrix); return worldPos; }
/** * Multiplies this {@link Vector3} and the provided 4x4 matrix. * * @param matrix {@link Matrix4} to multiply this {@link Vector3} by. * * @return A reference to this {@link Vector3} to facilitate chaining. */ @NonNull public Vector3 multiply(@NonNull Matrix4 matrix) { return multiply(matrix.getDoubleValues()); }
/** * Performs a linear interpolation between this {@link Vector3} and to by the specified amount. * The result will be stored in the current object which means that the current * x, y, z values will be overridden. * * @param target {@link Vector3} Ending point. * @param t double [0-1] interpolation value. * * @return A reference to this {@link Vector3} to facilitate chaining. */ @NonNull public Vector3 lerp(@NonNull Vector3 target, double t) { return multiply(1.0 - t).add(target.x * t, target.y * t, target.z * t); }
/** * Calculates the side lengths that child nodes * of this node should have. */ protected void calculateChildSideLengths() { //Determine the distance on each axis Vector3 temp = Vector3.subtractAndCreate(mTransformedMax, mTransformedMin); temp.multiply(0.5f); //Divide it in half float overlap = 1.0f + mOverlap/100.0f; temp.multiply(overlap); temp.absoluteValue(); mChildLengths.setAll(temp); }
public void calculatePoint(Vector3 result, double t) { mCurrent = t; if(mCurrent <0) mCurrent=0; if(mCurrent >1) mCurrent=1; mTmpPoint1.setAll(mPoint1); mTmpPoint1.multiply((1-mCurrent) * (1-mCurrent)); mTmpPoint2.setAll(mControlPoint); mTmpPoint2.multiply(2 * (1-mCurrent) * t); mTmpPoint3.setAll(mPoint2); mTmpPoint3.multiply(mCurrent * mCurrent); mTmpPoint2.add(mTmpPoint3); result.addAndSet(mTmpPoint1, mTmpPoint2); }
public Vector3 getCurrentTangent() { double t = mCurrent; Vector3 startPortion = new Vector3(mStartTangent).multiply(3*(1-t)*(1-t)); Vector3 transferPortion = new Vector3(mTransferTangent).multiply(6*(1-t)*t); Vector3 endPortion = new Vector3(mEndTangent).multiply(3*t*t); Vector3 result = startPortion.add(transferPortion).add(endPortion); result.normalize(); return result; }
private boolean getIntersection( double fDst1, double fDst2, Vector3 P1, Vector3 P2) { if ((fDst1 * fDst2) >= 0.0f) return false; if (floatEqual(fDst1, fDst2)) return false; mHitPoint.multiply(0); mHitPoint.add(Vector3.subtractAndCreate(P2, P1)); mHitPoint.multiply(-fDst1/(fDst2-fDst1)); mHitPoint.add(P1); return true; }
public void transform(Matrix4 matrix) { mPosition.setAll(0, 0, 0); mPosition.multiply(matrix); matrix.getScaling(mTmpPos); mScale = mTmpPos.x > mTmpPos.y ? mTmpPos.x : mTmpPos.y; mScale = mScale > mTmpPos.z ? mScale : mTmpPos.z; }
/** * Projects {@link Vector3} u onto {@link Vector3} v and creates a new * {@link Vector3} for the result. * * @param u {@link Vector3} to be projected. * @param v {@link Vector3} the {@link Vector3} to be projected on. * * @return {@link Vector3} The result of the projection. */ @NonNull public static Vector3 projectAndCreate(@NonNull Vector3 u, @NonNull Vector3 v) { double d = u.dot(v); double d_div = d / v.length2(); return v.clone().multiply(d_div); }
public void calculatePoint(Vector3 result, final double t) { if (mCalculateTangents) { double prevt = t == 0 ? t + DELTA : t - DELTA; double nextt = t == 1 ? t - DELTA : t + DELTA; p(mCurrentTangent, prevt); p(mTempNext, nextt); mCurrentTangent.subtract(mTempNext); mCurrentTangent.multiply(.5); mCurrentTangent.normalize(); } p(result,t); }
@Test public void testMultiplyFromDouble() { final Vector3 v = new Vector3(1d, 2d, 3d); final Vector3 out = v.multiply(2d); assertNotNull(out); assertTrue(out == v); assertEquals(2d, v.x, 0); assertEquals(4d, v.y, 0); assertEquals(6d, v.z, 0); }
@Test public void testMultiplyFomDoubleMatrix() { final Vector3 v = new Vector3(1d, 2d, 3d); final double[] matrix = new double[]{1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d, 10d, 11d, 12d, 13d, 14d, 15d, 16d}; final Vector3 out = v.multiply(matrix); assertNotNull(out); assertTrue(out == v); assertEquals(51d, v.x, 0); assertEquals(58d, v.y, 0); assertEquals(65d, v.z, 0); }
@Test public void testMultiplyFromMatrix4() { final Vector3 v = new Vector3(1d, 2d, 3d); final double[] matrix = new double[]{1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d, 10d, 11d, 12d, 13d, 14d, 15d, 16d}; final Matrix4 matrix4 = new Matrix4(matrix); final Vector3 out = v.multiply(matrix4); assertNotNull(out); assertTrue(out == v); assertEquals(51d, v.x, 0); assertEquals(58d, v.y, 0); assertEquals(65d, v.z, 0); }
@Test public void testMultiplyFromVector3() { final Vector3 v = new Vector3(1d, 2d, 3d); final Vector3 v1 = new Vector3(2d, 3d, 4d); final Vector3 out = v.multiply(v1); assertNotNull(out); assertTrue(out == v); assertEquals(2d, v.x, 0); assertEquals(6d, v.y, 0); assertEquals(12d, v.z, 0); }