Search in sources :

Example 16 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class Vector3Test method testSetAllFromAxis.

@Test
public void testSetAllFromAxis() throws Exception {
    final Vector3 v = new Vector3();
    assertNotNull(v);
    final Vector3 outX = v.setAll(Vector3.Axis.X);
    assertNotNull(outX);
    assertTrue(outX == v);
    assertEquals(1d, v.x, 0);
    assertEquals(0d, v.y, 0);
    assertEquals(0d, v.z, 0);
    final Vector3 outY = v.setAll(Vector3.Axis.Y);
    assertNotNull(outY);
    assertTrue(outY == v);
    assertEquals(0d, v.x, 0);
    assertEquals(1d, v.y, 0);
    assertEquals(0d, v.z, 0);
    final Vector3 outZ = v.setAll(Vector3.Axis.Z);
    assertNotNull(outZ);
    assertTrue(outZ == v);
    assertEquals(0d, v.x, 0);
    assertEquals(0d, v.y, 0);
    assertEquals(1d, v.z, 0);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 17 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class Matrix4Test method testSetToWorld.

@Test
public void testSetToWorld() throws Exception {
    final double[] expected = new double[] { -1d, 0d, 0d, 0d, 0d, 0.7071067811865476, -0.7071067811865476, 0d, 0d, -0.7071067811865475, -0.7071067811865475, 0d, 2d, 3d, 4d, 1d };
    final Vector3 position = new Vector3(2d, 3d, 4d);
    final Vector3 forward = new Vector3(0d, 1d, 1d);
    final Vector3 up = new Vector3(0d, 1d, -1d);
    final Matrix4 m = new Matrix4();
    final Matrix4 out = m.setToWorld(position, forward, up);
    assertNotNull(out);
    assertSame(out, m);
    final double[] result = out.getDoubleValues();
    assertNotNull(result);
    for (int i = 0; i < expected.length; ++i) {
        assertEquals("Result: " + Arrays.toString(result), expected[i], result[i], 1e-14);
    }
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 18 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class Matrix4Test method testSetToLookAtDirectionUp.

@Test
public void testSetToLookAtDirectionUp() throws Exception {
    final Quaternion q = new Quaternion(1d, 2d, 3d, 4d);
    final Vector3 lookAt = Vector3.subtractAndCreate(new Vector3(0, 10d, 10d), Vector3.ZERO);
    q.lookAt(lookAt, Vector3.Y);
    final double[] expected = q.toRotationMatrix().getDoubleValues();
    final Matrix4 m = new Matrix4();
    final Matrix4 out = m.setToLookAt(lookAt, Vector3.Y);
    assertNotNull(out);
    assertSame(out, m);
    final double[] result = out.getDoubleValues();
    assertNotNull(result);
    for (int i = 0; i < expected.length; ++i) {
        assertEquals("Result: " + Arrays.toString(result), expected[i], result[i], 1e-14);
    }
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 19 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class QuaternionTest method testConstructorVector3AxisAngle.

@Test
public void testConstructorVector3AxisAngle() throws Exception {
    final Quaternion q = new Quaternion(new Vector3(1d, 2d, 3d), 60);
    assertNotNull(q);
    assertEquals(0.86602540378443864676372317075294, q.w, 1e-14);
    assertEquals(0.13363062095621219234227674043988, q.x, 1e-14);
    assertEquals(0.26726124191242438468455348087975, q.y, 1e-14);
    assertEquals(0.40089186286863657702683022131963, q.z, 1e-14);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 20 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class QuaternionTest method testGetZAxis.

@Test
public void testGetZAxis() throws Exception {
    final Quaternion q = new Quaternion();
    q.fromAngleAxis(Axis.X, 10);
    q.multiply((new Quaternion()).fromAngleAxis(Axis.Y, 30));
    q.multiply((new Quaternion()).fromAngleAxis(Axis.Z, 40));
    final Vector3 v = q.getZAxis();
    assertNotNull(v);
    assertEquals(0.5, v.x, 1e-14);
    assertEquals(-0.1503837331804353, v.y, 1e-14);
    assertEquals(0.8528685319524432, v.z, 1e-14);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Aggregations

Vector3 (org.rajawali3d.math.vector.Vector3)166 SmallTest (android.test.suitebuilder.annotation.SmallTest)106 Test (org.junit.Test)106 Material (org.rajawali3d.materials.Material)9 SkeletonJoint (org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)6 Matrix4 (org.rajawali3d.math.Matrix4)6 Object3D (org.rajawali3d.Object3D)5 BoundingBox (org.rajawali3d.bounds.BoundingBox)5 DiffuseMethod (org.rajawali3d.materials.methods.DiffuseMethod)4 Quaternion (org.rajawali3d.math.Quaternion)4 ArrayList (java.util.ArrayList)3 DirectionalLight (org.rajawali3d.lights.DirectionalLight)3 ParsingException (org.rajawali3d.loader.ParsingException)3 FileNotFoundException (java.io.FileNotFoundException)2 FloatBuffer (java.nio.FloatBuffer)2 Stack (java.util.Stack)2 BoneVertex (org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D.BoneVertex)2 BoneWeight (org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D.BoneWeight)2 BoundingSphere (org.rajawali3d.bounds.BoundingSphere)2 IBoundingVolume (org.rajawali3d.bounds.IBoundingVolume)2