/** * Creates a matrix out of a quadric surface solution vector in homogeneous * coordinates. * * @see #solveVector(Collection) * @return a matrix representing the polynomial solution vector in an * algebraic form. */ private Matrix4d toQuadricMatrix(final double[] solution) { // I'm not a clever man, so I'm using local variables to // better follow the matrix assignment. final double a = solution[0]; final double b = solution[1]; final double c = solution[2]; final double d = solution[3]; final double e = solution[4]; final double f = solution[5]; final double g = solution[6]; final double h = solution[7]; final double i = solution[8]; // @formatter:off return new Matrix4d( a, d, e, g, d, b, f, h, e, f, c, i, g, h, i, -1 ); // @formatter:on } }
/** * Set this matrix to a rotation transformation about the Z axis to align the local <code>+X</code> towards <code>(dirX, dirY)</code>. * <p> * The vector <code>(dirX, dirY)</code> must be a unit vector. * * @param dirX * the x component of the normalized direction * @param dirY * the y component of the normalized direction * @return this */ public Matrix4d rotationTowardsXY(double dirX, double dirY) { if ((properties & PROPERTY_IDENTITY) == 0) this._identity(); this.m00 = dirY; this.m01 = dirX; this.m10 = -dirX; this.m11 = dirY; properties = PROPERTY_AFFINE | PROPERTY_ORTHONORMAL; return this; }
public void getf(Matrix4d m, int offset, FloatBuffer src) { m._m00(src.get(offset)); m._m01(src.get(offset+1)); m._m02(src.get(offset+2)); m._m03(src.get(offset+3)); m._m10(src.get(offset+4)); m._m11(src.get(offset+5)); m._m12(src.get(offset+6)); m._m13(src.get(offset+7)); m._m20(src.get(offset+8)); m._m21(src.get(offset+9)); m._m22(src.get(offset+10)); m._m23(src.get(offset+11)); m._m30(src.get(offset+12)); m._m31(src.get(offset+13)); m._m32(src.get(offset+14)); m._m33(src.get(offset+15)); }
public void readExternal(ObjectInput in) throws IOException { super.readExternal(in); curr = in.readInt(); mats = new Matrix4dStack[curr]; for (int i = 0; i < curr; i++) { Matrix4d m = new Matrix4d(); m.readExternal(in); mats[i] = m; } }
this.zero(); this._m00((zNear + zNear) / width); this._m11((zNear + zNear) / height); boolean farInf = zFar > 0 && Double.isInfinite(zFar); boolean nearInf = zNear > 0 && Double.isInfinite(zNear); this._m22(e - 1.0); this._m32((e - (zZeroToOne ? 1.0 : 2.0)) * zNear); } else if (nearInf) { double e = 1E-6f; this._m22((zZeroToOne ? 0.0 : 1.0) - e); this._m32(((zZeroToOne ? 1.0 : 2.0) - e) * zFar); } else { this._m22((zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar)); this._m32((zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar)); this._m23(-1.0); properties = PROPERTY_PERSPECTIVE; return this;
double xw = quat.x() * quat.w(), dxw = xw + xw; if ((properties & PROPERTY_IDENTITY) == 0) this._identity(); _m00(w2 + x2 - z2 - y2); _m01(dxy + dzw); _m02(dxz - dyw); _m10(-dzw + dxy); _m11(y2 - z2 + w2 - x2); _m12(dyz + dxw); _m20(dyw + dxz); _m21(dyz - dxw); _m22(z2 - y2 - x2 + w2); properties = PROPERTY_AFFINE | PROPERTY_ORTHONORMAL; return this;
double xw = quat.x() * quat.w(), dxw = xw + xw; if ((properties & PROPERTY_IDENTITY) == 0) this._identity(); _m00(w2 + x2 - z2 - y2); _m01(dxy + dzw); _m02(dxz - dyw); _m10(-dzw + dxy); _m11(y2 - z2 + w2 - x2); _m12(dyz + dxw); _m20(dyw + dxz); _m21(dyz - dxw); _m22(z2 - y2 - x2 + w2); properties = PROPERTY_AFFINE | PROPERTY_ORTHONORMAL; return this;
this.zero(); this._m00((zNear + zNear) / width); this._m11((zNear + zNear) / height); boolean farInf = zFar > 0 && Double.isInfinite(zFar); boolean nearInf = zNear > 0 && Double.isInfinite(zNear); this._m22(e - 1.0); this._m32((e - (zZeroToOne ? 1.0 : 2.0)) * zNear); } else if (nearInf) { double e = 1E-6f; this._m22((zZeroToOne ? 0.0 : 1.0) - e); this._m32(((zZeroToOne ? 1.0 : 2.0) - e) * zFar); } else { this._m22((zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar)); this._m32((zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar)); this._m23(-1.0); properties = PROPERTY_PERSPECTIVE; return this;
public void readExternal(ObjectInput in) throws IOException { super.readExternal(in); curr = in.readInt(); mats = new Matrix4dStack[curr]; for (int i = 0; i < curr; i++) { Matrix4d m = new Matrix4d(); m.readExternal(in); mats[i] = m; } }
public void getf(Matrix4d m, int offset, FloatBuffer src) { m._m00(src.get(offset)); m._m01(src.get(offset+1)); m._m02(src.get(offset+2)); m._m03(src.get(offset+3)); m._m10(src.get(offset+4)); m._m11(src.get(offset+5)); m._m12(src.get(offset+6)); m._m13(src.get(offset+7)); m._m20(src.get(offset+8)); m._m21(src.get(offset+9)); m._m22(src.get(offset+10)); m._m23(src.get(offset+11)); m._m30(src.get(offset+12)); m._m31(src.get(offset+13)); m._m32(src.get(offset+14)); m._m33(src.get(offset+15)); }
double xw = quat.x() * quat.w(), dxw = xw + xw; if ((properties & PROPERTY_IDENTITY) == 0) this._identity(); _m00(w2 + x2 - z2 - y2); _m01(dxy + dzw); _m02(dxz - dyw); _m10(-dzw + dxy); _m11(y2 - z2 + w2 - x2); _m12(dyz + dxw); _m20(dyw + dxz); _m21(dyz - dxw); _m22(z2 - y2 - x2 + w2); properties = PROPERTY_AFFINE | PROPERTY_ORTHONORMAL; return this;
/** * Create a new {@link Matrix4dStack} of the given size. * <p> * Initially the stack pointer is at zero and the current matrix is set to identity. * * @param stackSize * the size of the stack. This must be at least 1, in which case the {@link Matrix4dStack} simply only consists of <code>this</code> * {@link Matrix4d} */ public Matrix4dStack(int stackSize) { if (stackSize < 1) { throw new IllegalArgumentException("stackSize must be >= 1"); //$NON-NLS-1$ } mats = new Matrix4d[stackSize - 1]; // Allocate all matrices up front to keep the promise of being "allocation-free" for (int i = 0; i < mats.length; i++) { mats[i] = new Matrix4d(); } }
/** * Set this matrix to a rotation transformation about the Z axis to align the local <code>+X</code> towards <code>(dirX, dirY)</code>. * <p> * The vector <code>(dirX, dirY)</code> must be a unit vector. * * @param dirX * the x component of the normalized direction * @param dirY * the y component of the normalized direction * @return this */ public Matrix4d rotationTowardsXY(double dirX, double dirY) { if ((properties & PROPERTY_IDENTITY) == 0) this._identity(); this.m00 = dirY; this.m01 = dirX; this.m10 = -dirX; this.m11 = dirY; properties = PROPERTY_AFFINE | PROPERTY_ORTHONORMAL; return this; }
public void get(Matrix4d m, int offset, ByteBuffer src) { m._m00(src.getDouble(offset)); m._m01(src.getDouble(offset+8)); m._m02(src.getDouble(offset+16)); m._m03(src.getDouble(offset+24)); m._m10(src.getDouble(offset+32)); m._m11(src.getDouble(offset+40)); m._m12(src.getDouble(offset+48)); m._m13(src.getDouble(offset+56)); m._m20(src.getDouble(offset+64)); m._m21(src.getDouble(offset+72)); m._m22(src.getDouble(offset+80)); m._m23(src.getDouble(offset+88)); m._m30(src.getDouble(offset+96)); m._m31(src.getDouble(offset+104)); m._m32(src.getDouble(offset+112)); m._m33(src.getDouble(offset+120)); }
double xw = quat.x() * quat.w(), dxw = xw + xw; if ((properties & PROPERTY_IDENTITY) == 0) this._identity(); _m00(w2 + x2 - z2 - y2); _m01(dxy + dzw); _m02(dxz - dyw); _m10(-dzw + dxy); _m11(y2 - z2 + w2 - x2); _m12(dyz + dxw); _m20(dyw + dxz); _m21(dyz - dxw); _m22(z2 - y2 - x2 + w2); properties = PROPERTY_AFFINE | PROPERTY_ORTHONORMAL; return this;
/** * Create a new {@link Matrix4dStack} of the given size. * <p> * Initially the stack pointer is at zero and the current matrix is set to identity. * * @param stackSize * the size of the stack. This must be at least 1, in which case the {@link Matrix4dStack} simply only consists of <code>this</code> * {@link Matrix4d} */ public Matrix4dStack(int stackSize) { if (stackSize < 1) { throw new IllegalArgumentException("stackSize must be >= 1"); //$NON-NLS-1$ } mats = new Matrix4d[stackSize - 1]; // Allocate all matrices up front to keep the promise of being "allocation-free" for (int i = 0; i < mats.length; i++) { mats[i] = new Matrix4d(); } }
/** * Set this matrix to be a simple translation matrix. * <p> * The resulting matrix can be multiplied against another transformation * matrix to obtain an additional translation. * * @param x * the offset to translate in x * @param y * the offset to translate in y * @param z * the offset to translate in z * @return this */ public Matrix4d translation(double x, double y, double z) { if ((properties & PROPERTY_IDENTITY) == 0) this._identity(); m30 = x; m31 = y; m32 = z; m33 = 1.0; properties = PROPERTY_AFFINE | PROPERTY_TRANSLATION | PROPERTY_ORTHONORMAL; return this; }
public void get(Matrix4d m, int offset, DoubleBuffer src) { m._m00(src.get(offset)); m._m01(src.get(offset+1)); m._m02(src.get(offset+2)); m._m03(src.get(offset+3)); m._m10(src.get(offset+4)); m._m11(src.get(offset+5)); m._m12(src.get(offset+6)); m._m13(src.get(offset+7)); m._m20(src.get(offset+8)); m._m21(src.get(offset+9)); m._m22(src.get(offset+10)); m._m23(src.get(offset+11)); m._m30(src.get(offset+12)); m._m31(src.get(offset+13)); m._m32(src.get(offset+14)); m._m33(src.get(offset+15)); }
@Test public void testMatrixElements() { final Matrix4dc solution = (Matrix4dc) ops.run(Quadric.class, unitSpherePoints); assertEquals("The matrix element is incorrect", 1.0, solution.m00(), 1e-12); assertEquals("The matrix element is incorrect", 1.0, solution.m11(), 1e-12); assertEquals("The matrix element is incorrect", 1.0, solution.m22(), 1e-12); assertEquals("The matrix element is incorrect", 0.0, solution.m01(), 1e-12); assertEquals("The matrix element is incorrect", 0.0, solution.m02(), 1e-12); assertEquals("The matrix element is incorrect", 0.0, solution.m03(), 1e-12); assertEquals("The matrix element is incorrect", 0.0, solution.m12(), 1e-12); assertEquals("The matrix element is incorrect", 0.0, solution.m13(), 1e-12); assertEquals("The matrix element is incorrect", 0.0, solution.m23(), 1e-12); assertEquals("The matrix element is incorrect", -1.0, solution.m33(), 1e-12); final Matrix4d transposed = new Matrix4d(); solution.transpose(transposed); assertEquals("Matrix is not symmetric", solution, transposed); } }
/** * Set this matrix to be a simple translation matrix. * <p> * The resulting matrix can be multiplied against another transformation * matrix to obtain an additional translation. * * @param x * the offset to translate in x * @param y * the offset to translate in y * @param z * the offset to translate in z * @return this */ public Matrix4d translation(double x, double y, double z) { if ((properties & PROPERTY_IDENTITY) == 0) this._identity(); m30 = x; m31 = y; m32 = z; m33 = 1.0; properties = PROPERTY_AFFINE | PROPERTY_TRANSLATION | PROPERTY_ORTHONORMAL; return this; }