Search in sources :

Example 96 with Vector3

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

the class QuaternionTest method testLookAt.

@Test
public void testLookAt() throws Exception {
    final Quaternion q = new Quaternion(1d, 2d, 3d, 4d);
    final Vector3 lookAt = Vector3.subtractAndCreate(new Vector3(0, 10d, 10d), Vector3.ZERO);
    final Vector3 up = Vector3.Y;
    Quaternion out = q.lookAt(lookAt, up);
    assertNotNull(out);
    assertSame(q, out);
    assertEquals(0.9238795325112867, out.w, 1e-14);
    assertEquals(0.3826834323650898, out.x, 1e-14);
    assertEquals(0d, out.y, 1e-14);
    assertEquals(0d, out.z, 1e-14);
    lookAt.subtractAndSet(new Vector3(10d, 0, 10d), Vector3.ZERO);
    out = q.lookAt(lookAt, up);
    assertNotNull(out);
    assertSame(q, out);
    assertEquals(0.9238795325112867, out.w, 1e-14);
    assertEquals(0d, out.x, 1e-14);
    assertEquals(-0.3826834323650898, out.y, 1e-14);
    assertEquals(0d, out.z, 1e-14);
    lookAt.subtractAndSet(new Vector3(0d, 10d, 0d), Vector3.ZERO);
    out = q.lookAt(lookAt, Vector3.Y);
    assertNotNull(out);
    assertSame(q, out);
    assertEquals(0.7071067811865475, out.w, 1e-14);
    assertEquals(0d, out.x, 1e-14);
    assertEquals(0d, out.y, 1e-14);
    assertEquals(0.7071067811865475, out.z, 1e-14);
    lookAt.subtractAndSet(new Vector3(0d, 10d, 0d), Vector3.ZERO);
    out = q.lookAt(lookAt, Vector3.NEG_Y);
    assertNotNull(out);
    assertSame(q, out);
    assertEquals(0.7071067811865475, out.w, 1e-14);
    assertEquals(0d, out.x, 1e-14);
    assertEquals(0d, out.y, 1e-14);
    assertEquals(-0.7071067811865475, out.z, 1e-14);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 97 with Vector3

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

the class QuaternionTest method testGetYAxis.

@Test
public void testGetYAxis() 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.getYAxis();
    assertNotNull(v);
    assertEquals(-0.5566703992264195, v.x, 1e-14);
    assertEquals(0.6985970582110141, v.y, 1e-14);
    assertEquals(0.44953333233923354, v.z, 1e-14);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 98 with Vector3

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

the class QuaternionTest method testLookAtAndCreate.

@Test
public void testLookAtAndCreate() throws Exception {
    final Vector3 lookAt = Vector3.subtractAndCreate(new Vector3(0, 10d, 10d), Vector3.ZERO);
    final Vector3 up = Vector3.Y;
    Quaternion out = Quaternion.lookAtAndCreate(lookAt, up);
    assertNotNull(out);
    assertEquals(0.9238795325112867, out.w, 1e-14);
    assertEquals(0.3826834323650898, out.x, 1e-14);
    assertEquals(0d, out.y, 1e-14);
    assertEquals(0d, out.z, 1e-14);
    lookAt.subtractAndSet(new Vector3(10d, 0, 10d), Vector3.ZERO);
    out = Quaternion.lookAtAndCreate(lookAt, up);
    assertNotNull(out);
    assertEquals(0.9238795325112867, out.w, 1e-14);
    assertEquals(0d, out.x, 1e-14);
    assertEquals(-0.3826834323650898, out.y, 1e-14);
    assertEquals(0d, out.z, 1e-14);
    lookAt.subtractAndSet(new Vector3(0d, 10d, 0d), Vector3.ZERO);
    out = Quaternion.lookAtAndCreate(lookAt, Vector3.Y);
    assertNotNull(out);
    assertEquals(0.7071067811865475, out.w, 1e-14);
    assertEquals(0d, out.x, 1e-14);
    assertEquals(0d, out.y, 1e-14);
    assertEquals(0.7071067811865475, out.z, 1e-14);
    lookAt.subtractAndSet(new Vector3(0d, 10d, 0d), Vector3.ZERO);
    out = Quaternion.lookAtAndCreate(lookAt, Vector3.NEG_Y);
    assertNotNull(out);
    assertEquals(0.7071067811865475, out.w, 1e-14);
    assertEquals(0d, out.x, 1e-14);
    assertEquals(0d, out.y, 1e-14);
    assertEquals(-0.7071067811865475, out.z, 1e-14);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 99 with Vector3

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

the class Loader3DSMax method readTexCoords.

protected void readTexCoords(InputStream buffer) throws IOException {
    int numVertices = readShort(buffer);
    ArrayList<Vector3> texCoords = new ArrayList<Vector3>();
    for (int i = 0; i < numVertices; i++) {
        float x = readFloat(buffer);
        float y = 1 - readFloat(buffer);
        texCoords.add(new Vector3(x, y, 0));
    }
    mTexCoords.add(texCoords);
}
Also used : ArrayList(java.util.ArrayList) Vector3(org.rajawali3d.math.vector.Vector3)

Example 100 with Vector3

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

the class Loader3DSMax method calculateFaceNormal.

private Vector3 calculateFaceNormal(int[] vertexIDs) {
    ArrayList<Vector3> vertices = mVertices.get(mObjects);
    Vector3 v1 = vertices.get(vertexIDs[0]);
    Vector3 v2 = vertices.get(vertexIDs[2]);
    Vector3 v3 = vertices.get(vertexIDs[1]);
    Vector3 vector1 = Vector3.subtractAndCreate(v2, v1);
    Vector3 vector2 = Vector3.subtractAndCreate(v3, v1);
    Vector3 normal = Vector3.crossAndCreate(vector1, vector2);
    normal.normalize();
    return normal;
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3)

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