Search in sources :

Example 21 with Vector3

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

the class QuaternionTest method testMultiplyVector3.

@Test
public void testMultiplyVector3() throws Exception {
    final Quaternion q = new Quaternion();
    final Vector3 v = new Vector3(Vector3.X);
    v.multiply(2.0);
    final Vector3 out = q.multiply(v);
    assertNotNull(out);
    assertTrue(out != v);
    assertEquals(Double.doubleToRawLongBits(2d), Double.doubleToRawLongBits(out.x));
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(out.y));
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(out.z));
    q.fromAngleAxis(Axis.Z, 45.0);
    final Vector3 out1 = q.multiply(v);
    assertNotNull(out1);
    assertTrue(out1 != v);
    assertEquals(1.4142135623730951, out1.x, 1e-14);
    assertEquals(1.4142135623730951, out1.y, 1e-14);
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(out1.z));
    q.fromAngleAxis(1d, 0d, 1d, 45d);
    q.normalize();
    final Vector3 out2 = q.multiply(v);
    assertNotNull(out2);
    assertTrue(out2 != v);
    assertEquals(1.7071067811865477, out2.x, 1e-14);
    assertEquals(0.9999999999999998, out2.y, 1e-14);
    assertEquals(0.29289321881345237, out2.z, 1e-14);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 22 with Vector3

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

the class QuaternionTest method testFromAngleAxisVector3Angle.

@Test
public void testFromAngleAxisVector3Angle() throws Exception {
    final Quaternion q = new Quaternion();
    // Test X
    Quaternion out = q.fromAngleAxis(new Vector3(1, 0, 0), 60);
    assertNotNull(out);
    assertSame(q, out);
    assertEquals(0.86602540378443864676372317075294, q.w, 1e-14);
    assertEquals(0.5, q.x, 1e-14);
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(q.y));
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(q.z));
    // Test Y
    q.identity();
    out = q.fromAngleAxis(new Vector3(0, 1, 0), 60);
    assertNotNull(out);
    assertSame(q, out);
    assertEquals(0.86602540378443864676372317075294, q.w, 1e-14);
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(q.x));
    assertEquals(0.5, q.y, 1e-14);
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(q.z));
    // Test Z
    q.identity();
    out = q.fromAngleAxis(new Vector3(0, 0, 1), 60);
    assertNotNull(out);
    assertSame(q, out);
    assertEquals(0.86602540378443864676372317075294, q.w, 1e-14);
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(q.x));
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(q.y));
    assertEquals(0.5, q.z, 1e-14);
    // Test 0
    q.identity();
    out = q.fromAngleAxis(new Vector3(0, 0, 0), 45d);
    assertNotNull(out);
    assertSame(q, out);
    assertEquals(Double.doubleToRawLongBits(1d), Double.doubleToRawLongBits(q.w));
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(q.x));
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(q.y));
    assertEquals(Double.doubleToRawLongBits(0d), Double.doubleToRawLongBits(q.z));
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 23 with Vector3

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

the class QuaternionTest method testGetAxis.

@Test
public void testGetAxis() 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));
    Vector3 v = q.getAxis(Axis.X);
    assertNotNull(v);
    assertEquals(0.6634139481689384, v.x, 1e-14);
    assertEquals(0.6995333323392336, v.y, 1e-14);
    assertEquals(-0.2655843563187949, v.z, 1e-14);
    v = q.getAxis(Axis.Y);
    assertNotNull(v);
    assertEquals(-0.5566703992264195, v.x, 1e-14);
    assertEquals(0.6985970582110141, v.y, 1e-14);
    assertEquals(0.44953333233923354, v.z, 1e-14);
    v = q.getAxis(Axis.Z);
    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)

Example 24 with Vector3

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

the class Vector3Test method testRotateZ.

@Test
public void testRotateZ() throws Exception {
    final Vector3 v1 = new Vector3(Vector3.X);
    final Vector3 v2 = new Vector3(Vector3.Y);
    final Vector3 v3 = new Vector3(Vector3.Z);
    v3.rotateZ(Math.PI);
    v1.rotateZ(Math.PI);
    v2.rotateZ(Math.PI / 2.0);
    assertEquals(Vector3.Z.x, v3.x, 0);
    assertEquals(Vector3.Z.y, v3.y, 0);
    assertEquals(Vector3.Z.z, v3.z, 0);
    assertEquals(Vector3.NEG_X.x, v1.x, 1e-14);
    assertEquals(Vector3.NEG_X.y, v1.y, 1e-14);
    assertEquals(Vector3.NEG_X.z, v1.z, 1e-14);
    assertEquals(Vector3.NEG_X.x, v2.x, 1e-14);
    assertEquals(Vector3.NEG_X.y, v2.y, 1e-14);
    assertEquals(Vector3.NEG_X.z, v2.z, 1e-14);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 25 with Vector3

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

the class Vector3Test method testProjectFromVector3.

@Test
public void testProjectFromVector3() throws Exception {
    final Vector3 a = new Vector3(1d, 1d, 0d);
    final Vector3 b = new Vector3(2d, 0d, 0d);
    final Vector3 v = b.project(a);
    assertNotNull(v);
    assertTrue(v == b);
    assertEquals(1d, v.x, 0);
    assertEquals(0d, v.y, 0);
    assertEquals(0d, v.z, 0);
}
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