org.joml.Math Java Examples

The following examples show how to use org.joml.Math. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrbitCamera.java    From WraithEngine with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the position of the camera based on the current yaw and pitch. This
 * method will also clamp the yaw and pitch into the acceptable range if
 * required.
 */
public void updatePosition()
{
    yaw %= Math.PI * 2;
    pitch = (float) Math.max(-Math.PI / 2f, Math.min(Math.PI / 2f, pitch));

    Quaternionf rot = camera.getTransform()
                            .getRotation();

    rot.identity()
       .rotateLocalX(pitch)
       .rotateLocalY(yaw);

    camera.getTransform()
          .getPosition()
          .set(0f, 0f, distance)
          .rotate(rot)
          .add(offset);
}
 
Example #2
Source File: Convolution.java    From JOML with MIT License 6 votes vote down vote up
/**
 * Generate a Gaussian convolution kernel with the given number of rows and columns, and store
 * the factors in row-major order in <code>dest</code>.
 *
 * @param rows
 *          the number of rows (must be an odd number)
 * @param cols
 *          the number of columns (must be an odd number)
 * @param sigma
 *          the standard deviation of the filter kernel values
 * @param dest
 *          will hold the kernel factors in row-major order
 */
public static void gaussianKernel(int rows, int cols, float sigma, float[] dest) {
    if ((rows & 1) == 0) {
        throw new IllegalArgumentException("rows must be an odd number");
    }
    if ((cols & 1) == 0) {
        throw new IllegalArgumentException("cols must be an odd number");
    }
    if (dest == null) {
        throw new IllegalArgumentException("dest must not be null");
    }
    if (dest.length < rows * cols) {
        throw new IllegalArgumentException("dest must have a size of at least " + (rows * cols));
    }
    float sum = 0.0f;
    for (int i = 0, y = -(rows - 1) / 2; y <= (rows - 1) / 2; y++) {
        for (int x = -(cols - 1) / 2; x <= (cols - 1) / 2; x++, i++) {
            float k = (float) Math.exp(-(y * y + x * x) / (2.0 * sigma * sigma));
            dest[i] = k;
            sum += k;
        }
    }
    for (int i = 0; i < rows * cols; i++) {
        dest[i] = dest[i] / sum;
    }
}
 
Example #3
Source File: ColorPicker.java    From LWJGUI with MIT License 6 votes vote down vote up
private void setFromHex() {
	if (hexField.getText().length() == 0)
		return;

	ignoreUpdateHex = true;
	{
		try {
			Color color = new Color(hexField.getText());

			if (!calculatingFromText) {
				calculatingFromText = true;
				Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), this.internalHSV);
				this.setAlpha(Math.min(1, Math.max(0, color.getAlphaF())));
			}

			this.setHue(this.internalHSV[0]);
			this.setSB(this.internalHSV[1], this.internalHSV[2]);
		} catch (Exception e) {
			//
		}
	}
	ignoreUpdateHex = false;
	calculatingFromText = false;
}
 
Example #4
Source File: PolygonPointIntersectionTest.java    From JOML with MIT License 6 votes vote down vote up
public static void testBigCircle() {
    int polyN = 1024 * 256;
    float[] verticesXY = new float[polyN * 2];
    for (int i = 0; i < polyN; i++) {
        float x = (float) Math.cos(2.0 * Math.PI * i / polyN);
        float y = (float) Math.sin(2.0 * Math.PI * i / polyN);
        verticesXY[2 * i + 0] = x;
        verticesXY[2 * i + 1] = y;
    }
    PolygonsIntersection isect = new PolygonsIntersection(verticesXY, new int[0], polyN);
    // Center
    assertTrue(isect.testPoint(0, 0));
    // Left outside
    assertFalse(isect.testPoint(-1.1f, 0));
    // Top right outside
    assertFalse(isect.testPoint(0.8f, 0.8f));
    // Top edge
    assertTrue(isect.testPoint(1.0f, 0));
    // Bottom edge <- algorithm only detects top edges as 'inside'
    assertFalse(isect.testPoint(-1.0f, 0));
}
 
Example #5
Source File: MathTest.java    From JOML with MIT License 6 votes vote down vote up
public static void testClamp(){
    // Integer value tests
    assertEquals(Math.clamp(10,20,0),10);
    assertEquals(Math.clamp(10,20,12),12);
    assertEquals(Math.clamp(10,20,30),20);

    // Double value tests
    assertEquals(Math.clamp(10f,20f,0f),10f,.0001f);
    assertEquals(Math.clamp(10f,20f,12f),12f,.0001f);
    assertEquals(Math.clamp(10f,20f,30f),20f,.0001f);

    // Float value tests
    assertEquals(Math.clamp(10.0,20.0,0.0),10.0,.0001);
    assertEquals(Math.clamp(10.0,20.0,12.0),12.0,.0001);
    assertEquals(Math.clamp(10.0,20.0,30.0),20.0,.0001);
}
 
Example #6
Source File: Matrix4dTest.java    From JOML with MIT License 6 votes vote down vote up
/**
 * Test that project and unproject are each other's inverse operations.
 */
public static void testProjectUnproject() {
    /* Build some arbitrary viewport. */
    int[] viewport = {0, 0, 800, 800};

    Vector3d expected = new Vector3d(1.0f, 2.0f, -3.0f);
    Vector3d actual = new Vector3d();

    /* Build a perspective projection and then project and unproject. */
    Matrix4d m = new Matrix4d()
    .perspective((float) Math.toRadians(45.0f), 1.0f, 0.01f, 100.0f);
    m.project(expected, viewport, actual);
    m.unproject(actual, viewport, actual);

    /* Check for equality of the components */
    assertEquals(expected.x, actual.x, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT);
    assertEquals(expected.y, actual.y, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT);
    assertEquals(expected.z, actual.z, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT);
}
 
Example #7
Source File: Matrix4dTest.java    From JOML with MIT License 6 votes vote down vote up
public static void testFrustumRay() {
    Vector3d dir = new Vector3d();
    Matrix4d m = new Matrix4d()
            .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f)
            .rotateY((float) Math.toRadians(90));
    Vector3d expectedDir;
    m.frustumRayDir(0, 0, dir);
    expectedDir = new Vector3d(1, -1, -1).normalize();
    TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(1, 0, dir);
    expectedDir = new Vector3d(1, -1, 1).normalize();
    TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(0, 1, dir);
    expectedDir = new Vector3d(1, 1, -1).normalize();
    TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(1, 1, dir);
    expectedDir = new Vector3d(1, 1, 1).normalize();
    TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f);
}
 
Example #8
Source File: Matrix4dTest.java    From JOML with MIT License 6 votes vote down vote up
public static void testFrustumRay2() {
    Vector3d dir = new Vector3d();
    Matrix4d m = new Matrix4d()
            .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f)
            .rotateZ((float) Math.toRadians(45));
    Vector3d expectedDir;
    m.frustumRayDir(0, 0, dir);
    expectedDir = new Vector3d(-(float)Math.sqrt(2), 0, -1).normalize();
    TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(1, 0, dir);
    expectedDir = new Vector3d(0, -(float)Math.sqrt(2), -1).normalize();
    TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(0, 1, dir);
    expectedDir = new Vector3d(0, (float)Math.sqrt(2), -1).normalize();
    TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(1, 1, dir);
    expectedDir = new Vector3d((float)Math.sqrt(2), 0, -1).normalize();
    TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f);
}
 
Example #9
Source File: Matrix4fTest.java    From JOML with MIT License 6 votes vote down vote up
/**
 * Test that project and unproject are each other's inverse operations.
 */
public static void testProjectUnproject() {
    /* Build some arbitrary viewport. */
    int[] viewport = {0, 0, 800, 800};

    Vector3f expected = new Vector3f(1.0f, 2.0f, -3.0f);
    Vector3f actual = new Vector3f();

    /* Build a perspective projection and then project and unproject. */
    Matrix4f m = new Matrix4f()
    .perspective((float) Math.toRadians(45.0f), 1.0f, 0.01f, 100.0f);
    m.project(expected, viewport, actual);
    m.unproject(actual, viewport, actual);

    /* Check for equality of the components */
    assertEquals(expected.x, actual.x, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT);
    assertEquals(expected.y, actual.y, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT);
    assertEquals(expected.z, actual.z, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT);
}
 
Example #10
Source File: Matrix4fTest.java    From JOML with MIT License 6 votes vote down vote up
public static void testFrustumRay() {
    Vector3f dir = new Vector3f();
    Matrix4f m = new Matrix4f()
            .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f)
            .rotateY((float) Math.toRadians(90));
    Vector3f expectedDir;
    m.frustumRayDir(0, 0, dir);
    expectedDir = new Vector3f(1, -1, -1).normalize();
    TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(1, 0, dir);
    expectedDir = new Vector3f(1, -1, 1).normalize();
    TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(0, 1, dir);
    expectedDir = new Vector3f(1, 1, -1).normalize();
    TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(1, 1, dir);
    expectedDir = new Vector3f(1, 1, 1).normalize();
    TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
}
 
Example #11
Source File: Matrix4fTest.java    From JOML with MIT License 6 votes vote down vote up
public static void testFrustumRay2() {
    Vector3f dir = new Vector3f();
    Matrix4f m = new Matrix4f()
            .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f)
            .rotateZ((float) Math.toRadians(45));
    Vector3f expectedDir;
    m.frustumRayDir(0, 0, dir);
    expectedDir = new Vector3f(-(float)Math.sqrt(2), 0, -1).normalize();
    TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(1, 0, dir);
    expectedDir = new Vector3f(0, -(float)Math.sqrt(2), -1).normalize();
    TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(0, 1, dir);
    expectedDir = new Vector3f(0, (float)Math.sqrt(2), -1).normalize();
    TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
    m.frustumRayDir(1, 1, dir);
    expectedDir = new Vector3f((float)Math.sqrt(2), 0, -1).normalize();
    TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
}
 
Example #12
Source File: Matrix4fTest.java    From JOML with MIT License 6 votes vote down vote up
public static void testOrthoCropWithPerspective() {
    Matrix4f lightView = new Matrix4f()
            .lookAt(0, 5, 0,
                    0, 0, 0,
                    0, 0, -1);
    Matrix4f crop = new Matrix4f();
    Matrix4f fin = new Matrix4f();
    new Matrix4f().perspective((float) Math.toRadians(90), 1.0f, 5, 10).invertPerspective().orthoCrop(lightView, crop).mulOrthoAffine(lightView, fin);
    Vector3f p = new Vector3f();
    fin.transformProject(p.set(0, 0, -5));
    assertEquals(+0.0f, p.x, 1E-6f);
    assertEquals(-1.0f, p.y, 1E-6f);
    assertEquals(+0.0f, p.z, 1E-6f);
    fin.transformProject(p.set(0, 0, -10));
    assertEquals(+0.0f, p.x, 1E-6f);
    assertEquals(+1.0f, p.y, 1E-6f);
    assertEquals(+0.0f, p.z, 1E-6f);
    fin.transformProject(p.set(-10, 10, -10));
    assertEquals(-1.0f, p.x, 1E-6f);
    assertEquals(+1.0f, p.y, 1E-6f);
    assertEquals(-1.0f, p.z, 1E-6f);
}
 
Example #13
Source File: Matrix4dTest.java    From JOML with MIT License 6 votes vote down vote up
public static void testOrthoCropWithPerspective() {
    Matrix4d lightView = new Matrix4d()
            .lookAt(0, 5, 0,
                    0, 0, 0,
                    0, 0, -1);
    Matrix4d crop = new Matrix4d();
    Matrix4d fin = new Matrix4d();
    new Matrix4d().perspective((float) Math.toRadians(90), 1.0f, 5, 10).invertPerspective().orthoCrop(lightView, crop).mulOrthoAffine(lightView, fin);
    Vector3d p = new Vector3d();
    fin.transformProject(p.set(0, 0, -5));
    assertEquals(+0.0f, p.x, 1E-6f);
    assertEquals(-1.0f, p.y, 1E-6f);
    assertEquals(+0.0f, p.z, 1E-6f);
    fin.transformProject(p.set(0, 0, -10));
    assertEquals(+0.0f, p.x, 1E-6f);
    assertEquals(+1.0f, p.y, 1E-6f);
    assertEquals(+0.0f, p.z, 1E-6f);
    fin.transformProject(p.set(-10, 10, -10));
    assertEquals(-1.0f, p.x, 1E-6f);
    assertEquals(+1.0f, p.y, 1E-6f);
    assertEquals(-1.0f, p.z, 1E-6f);
}
 
Example #14
Source File: OrbitCamera.java    From WraithEngine with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the position of the camera based on the current yaw and pitch. This
 * method will also clamp the yaw and pitch into the acceptable range if
 * required.
 */
public void updatePosition()
{
    yaw %= Math.PI * 2;
    pitch = (float) Math.max(-Math.PI / 2f, Math.min(Math.PI / 2f, pitch));

    Quaternionf rot = camera.getTransform()
                            .getRotation();

    rot.identity()
       .rotateLocalX(pitch)
       .rotateLocalY(yaw);

    camera.getTransform()
          .getPosition()
          .set(0f, 0f, distance)
          .rotate(rot)
          .add(offset);
}
 
Example #15
Source File: ColorPicker.java    From LWJGUI with MIT License 6 votes vote down vote up
private void setFromRGBAText() {
	ignoreUpdateRGBA = true;
	{
		int r = (int) toNumber(redField.getText());
		int g = (int) toNumber(greenField.getText());
		int b = (int) toNumber(blueField.getText());
		float a = 1.0f;
		if (alphaField != null)
			a = ((int) (toNumber(alphaField.getText()) * 100)) / 100f;

		if (!calculatingFromText) {
			calculatingFromText = true;
			Color.RGBtoHSB(r, g, b, this.internalHSV);
			this.setAlpha(Math.min(1, Math.max(0, a)));
		}

		this.setHue(this.internalHSV[0]);
		this.setSB(this.internalHSV[1], this.internalHSV[2]);
	}
	ignoreUpdateRGBA = false;
	calculatingFromText = false;
}
 
Example #16
Source File: IntersectionfTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testSphereSphere() {
    assertTrue(Intersectionf.testSphereSphere(0, 0, 0, 1, 0.5f, 0, 0, 1));
    Vector4f res = new Vector4f();
    assertTrue(Intersectionf.intersectSphereSphere(0, 0, 0, 1, 0.5f, 0, 0, 1, res));
    // intersection point is (0.25, 0, 0) <- middle between both spheres with equal
    // radii
    TestUtil.assertVector3fEquals(new Vector3f(0.25f, 0, 0), new Vector3f(res.x, res.y, res.z), 1E-6f);
    // cos(a) = adjside/hyp
    // cos(a) * hyp = adjside
    // acos(cos(a) * hyp) = acos(adjside)
    // y = sin(acos(adjside))
    float expectedRadius = (float) Math.sin(Math.acos(0.25));
    assertEquals(expectedRadius, res.w, 1E-6f);
}
 
Example #17
Source File: Convolution.java    From JOML with MIT License 5 votes vote down vote up
/**
 * Generate a Gaussian convolution kernel with the given number of rows and columns, and store
 * the factors in row-major order in <code>dest</code>.
 *
 * @param rows
 *          the number of rows (must be an odd number)
 * @param cols
 *          the number of columns (must be an odd number)
 * @param sigma
 *          the standard deviation of the filter kernel values
 * @param dest
 *          will hold the kernel factors in row-major order
 */
public static void gaussianKernel(int rows, int cols, float sigma, FloatBuffer dest) {
    if ((rows & 1) == 0) {
        throw new IllegalArgumentException("rows must be an odd number");
    }
    if ((cols & 1) == 0) {
        throw new IllegalArgumentException("cols must be an odd number");
    }
    if (dest == null) {
        throw new IllegalArgumentException("dest must not be null");
    }
    if (dest.remaining() < rows * cols) {
        throw new IllegalArgumentException("dest must have at least " + (rows * cols) + " remaining values");
    }
    float sum = 0.0f;
    int pos = dest.position();
    for (int i = 0, y = -(rows - 1) / 2; y <= (rows - 1) / 2; y++) {
        for (int x = -(cols - 1) / 2; x <= (cols - 1) / 2; x++, i++) {
            float k = (float) Math.exp(-(y * y + x * x) / (2.0 * sigma * sigma));
            dest.put(pos + i, k);
            sum += k;
        }
    }
    for (int i = 0; i < rows * cols; i++) {
        dest.put(pos + i, dest.get(pos + i) / sum);
    }
}
 
Example #18
Source File: Matrix4fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testNormal() {
    Matrix4f r = new Matrix4f().rotateY((float) Math.PI / 2);
    Matrix4f s = new Matrix4f(r).scale(0.2f);
    Matrix4f n = new Matrix4f();
    s.normal(n);
    n.normalize3x3();
    TestUtil.assertMatrix4fEquals(r, n, 1E-8f);
}
 
Example #19
Source File: Matrix4fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testPositiveZRotateX() {
    Vector3f dir = new Vector3f();
    Matrix4f m = new Matrix4f()
            .rotateX((float) Math.toRadians(90));
    m.positiveZ(dir);
    TestUtil.assertVector3fEquals(new Vector3f(0, 1, 0), dir, 1E-7f);
}
 
Example #20
Source File: Matrix4fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testPositiveYRotateX() {
    Vector3f dir = new Vector3f();
    Matrix4f m = new Matrix4f()
            .rotateX((float) Math.toRadians(90));
    m.positiveY(dir);
    TestUtil.assertVector3fEquals(new Vector3f(0, 0, -1), dir, 1E-7f);
}
 
Example #21
Source File: Matrix4fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testPositiveXRotateY() {
    Vector3f dir = new Vector3f();
    Matrix4f m = new Matrix4f()
            .rotateY((float) Math.toRadians(90));
    m.positiveX(dir);
    TestUtil.assertVector3fEquals(new Vector3f(0, 0, 1), dir, 1E-7f);
}
 
Example #22
Source File: Matrix4x3fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testLookAt() {
    Matrix4x3f m1, m2;
    m1 = new Matrix4x3f().lookAt(0, 2, 3, 0, 0, 0, 0, 1, 0);
    m2 = new Matrix4x3f().translate(0, 0, -(float) Math.sqrt(2 * 2 + 3 * 3)).rotateX(
            (float) Math.atan2(2, 3));
    TestUtil.assertMatrix4x3fEquals(m1, m2, 1E-5f);
    m1 = new Matrix4x3f().lookAt(3, 2, 0, 0, 0, 0, 0, 1, 0);
    m2 = new Matrix4x3f().translate(0, 0, -(float) Math.sqrt(2 * 2 + 3 * 3))
            .rotateX((float) Math.atan2(2, 3)).rotateY((float) Math.toRadians(-90));
    TestUtil.assertMatrix4x3fEquals(m1, m2, 1E-4f);
}
 
Example #23
Source File: Matrix4fTest.java    From JOML with MIT License 5 votes vote down vote up
/**
 * Test computing the frustum planes with a combined view-projection matrix with translation.
 */
public static void testFrustumPlanePerspectiveRotateTranslate() {
    Vector4f left = new Vector4f();
    Vector4f right = new Vector4f();
    Vector4f top = new Vector4f();
    Vector4f bottom = new Vector4f();
    Vector4f near = new Vector4f();
    Vector4f far = new Vector4f();

    /*
     * Build a perspective transformation and
     * move the camera 5 units "up" and rotate it clock-wise 90 degrees around Y.
     */
    Matrix4f m = new Matrix4f()
    .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f)
    .rotateY((float) Math.toRadians(90))
    .translate(0, -5, 0);
    m.frustumPlane(Matrix4fc.PLANE_NX, left);
    m.frustumPlane(Matrix4fc.PLANE_PX, right);
    m.frustumPlane(Matrix4fc.PLANE_NY, bottom);
    m.frustumPlane(Matrix4fc.PLANE_PY, top);
    m.frustumPlane(Matrix4fc.PLANE_NZ, near);
    m.frustumPlane(Matrix4fc.PLANE_PZ, far);

    Vector4f expectedLeft = new Vector4f(1, 0, 1, 0).normalize3();
    Vector4f expectedRight = new Vector4f(1, 0, -1, 0).normalize3();
    Vector4f expectedTop = new Vector4f(1, -1, 0, 5).normalize3();
    Vector4f expectedBottom = new Vector4f(1, 1, 0, -5).normalize3();
    Vector4f expectedNear = new Vector4f(1, 0, 0, -0.1f).normalize3();
    Vector4f expectedFar = new Vector4f(-1, 0, 0, 100.0f).normalize3();

    TestUtil.assertVector4fEquals(expectedLeft, left, 1E-5f);
    TestUtil.assertVector4fEquals(expectedRight, right, 1E-5f);
    TestUtil.assertVector4fEquals(expectedTop, top, 1E-5f);
    TestUtil.assertVector4fEquals(expectedBottom, bottom, 1E-5f);
    TestUtil.assertVector4fEquals(expectedNear, near, 1E-5f);
    TestUtil.assertVector4fEquals(expectedFar, far, 1E-4f);
}
 
Example #24
Source File: Matrix4fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testLookAt() {
    Matrix4f m1, m2;
    m1 = new Matrix4f().lookAt(0, 2, 3, 0, 0, 0, 0, 1, 0);
    m2 = new Matrix4f().translate(0, 0, -(float) Math.sqrt(2 * 2 + 3 * 3)).rotateX(
            (float) Math.atan2(2, 3));
    TestUtil.assertMatrix4fEquals(m1, m2, 1E-2f);
    m1 = new Matrix4f().lookAt(3, 2, 0, 0, 0, 0, 0, 1, 0);
    m2 = new Matrix4f().translate(0, 0, -(float) Math.sqrt(2 * 2 + 3 * 3))
            .rotateX((float) Math.atan2(2, 3)).rotateY((float) Math.toRadians(-90));
    TestUtil.assertMatrix4fEquals(m1, m2, 1E-2f);
}
 
Example #25
Source File: Matrix4x3fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testPositiveXRotateY() {
    Vector3f dir = new Vector3f();
    Matrix4x3f m = new Matrix4x3f()
            .rotateY((float) Math.toRadians(90));
    m.positiveX(dir);
    TestUtil.assertVector3fEquals(new Vector3f(0, 0, 1), dir, 1E-7f);
}
 
Example #26
Source File: QuaternionfInterpolatorTest.java    From JOML with MIT License 5 votes vote down vote up
/**
 * Average between three quaternions, each with a weight of 1/3.
 */
public static void testOneThird() {
    Quaternionf q0 = new Quaternionf().rotateX((float) Math.toRadians(90));
    Quaternionf q1 = new Quaternionf().rotateY((float) Math.toRadians(90));
    Quaternionf q2 = new Quaternionf().rotateZ((float) Math.toRadians(90));
    Quaternionf dest = new Quaternionf();
    QuaternionfInterpolator inter = new QuaternionfInterpolator();
    inter.computeWeightedAverage(new Quaternionf[] { q0, q1, q2 }, new float[] { 1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f }, 30, dest);
    Vector3f v = new Vector3f(0, 0, 1);
    dest.transform(v);
    assertEquals(1.0f, v.length(), 1E-6f);
    TestUtil.assertVector3fEquals(new Vector3f(2.0f/3.0f, -1.0f/3.0f, 2.0f/3.0f), v, 1E-6f);
}
 
Example #27
Source File: Matrix4x3fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testPositiveYRotateX() {
    Vector3f dir = new Vector3f();
    Matrix4x3f m = new Matrix4x3f()
            .rotateX((float) Math.toRadians(90));
    m.positiveY(dir);
    TestUtil.assertVector3fEquals(new Vector3f(0, 0, -1), dir, 1E-7f);
}
 
Example #28
Source File: Matrix4x3dTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testPositiveYRotateX() {
    Vector3d dir = new Vector3d();
    Matrix4x3dc m = new Matrix4x3d()
            .rotateX((float) Math.toRadians(90));
    m.positiveY(dir);
    TestUtil.assertVector3dEquals(new Vector3d(0, 0, -1), dir, 1E-7f);
}
 
Example #29
Source File: Matrix4dTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testPerspectiveFov() {
    Matrix4d m = new Matrix4d()
    .perspective((float) Math.toRadians(45), 1.0f, 0.1f, 100.0f);
    double fov = m.perspectiveFov();
    assertEquals(Math.toRadians(45), fov, 1E-5);

    m = new Matrix4d()
    .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f)
    .lookAt(6, 0, 1, 
            0, 0, 0, 
            0, 1, 0);
    fov = m.perspectiveFov();
    assertEquals(Math.toRadians(90), fov, 1E-5);
}
 
Example #30
Source File: Matrix4fTest.java    From JOML with MIT License 5 votes vote down vote up
public static void testPositiveXPerspectiveRotateY() {
    Vector3f dir = new Vector3f();
    Matrix4f m = new Matrix4f()
            .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f)
            .rotateY((float) Math.toRadians(90));
    m.positiveX(dir);
    TestUtil.assertVector3fEquals(new Vector3f(0, 0, -1), dir, 1E-7f);
}