Search in sources :

Example 76 with Vector3

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

the class Vector3Test method testLerpAndCreate.

@Test
public void testLerpAndCreate() throws Exception {
    final Vector3 v = new Vector3(1d, 0d, 0d);
    final Vector3 vp = new Vector3(0d, 1d, 0d);
    final Vector3 v1 = Vector3.lerpAndCreate(v, vp, 0d);
    assertNotNull(v1);
    assertEquals(1d, v1.x, 0);
    assertEquals(0d, v1.y, 0);
    assertEquals(0d, v1.z, 0);
    final Vector3 v2 = Vector3.lerpAndCreate(v, vp, 1d);
    assertNotNull(v2);
    assertEquals(0d, v2.x, 0);
    assertEquals(1d, v2.y, 0);
    assertEquals(0d, v2.z, 0);
    final Vector3 v3 = Vector3.lerpAndCreate(v, vp, 0.5);
    assertNotNull(v3);
    assertEquals(0.5d, v3.x, 0);
    assertEquals(0.5d, v3.y, 0);
    assertEquals(0d, v3.z, 0);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 77 with Vector3

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

the class WallpaperRenderer method initScene.

@Override
protected void initScene() {
    ALight light = new DirectionalLight(-1, 0, -1);
    light.setPower(2);
    getCurrentScene().addLight(light);
    getCurrentCamera().setPosition(0, 0, 7);
    getCurrentCamera().setLookAt(0, 0, 0);
    try {
        Cube cube = new Cube(1);
        Material material = new Material();
        material.enableLighting(true);
        material.setDiffuseMethod(new DiffuseMethod.Lambert());
        material.addTexture(new Texture("rajawaliTex", R.drawable.rajawali_tex));
        material.setColorInfluence(0);
        cube.setMaterial(material);
        getCurrentScene().addChild(cube);
        Vector3 axis = new Vector3(3, 1, 6);
        axis.normalize();
        Animation3D anim = new RotateOnAxisAnimation(axis, 0, 360);
        anim.setDurationMilliseconds(8000);
        anim.setRepeatMode(Animation.RepeatMode.INFINITE);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setTransformable3D(cube);
        getCurrentScene().registerAnimation(anim);
        anim.play();
    } catch (ATexture.TextureException e) {
        e.printStackTrace();
    }
}
Also used : Material(org.rajawali3d.materials.Material) Vector3(org.rajawali3d.math.vector.Vector3) ATexture(org.rajawali3d.materials.textures.ATexture) Texture(org.rajawali3d.materials.textures.Texture) Animation3D(org.rajawali3d.animation.Animation3D) Cube(org.rajawali3d.primitives.Cube) RotateOnAxisAnimation(org.rajawali3d.animation.RotateOnAxisAnimation) DirectionalLight(org.rajawali3d.lights.DirectionalLight) ATexture(org.rajawali3d.materials.textures.ATexture) DiffuseMethod(org.rajawali3d.materials.methods.DiffuseMethod) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ALight(org.rajawali3d.lights.ALight)

Example 78 with Vector3

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

the class Matrix4Test method testSetAllFromAxesAndPosition.

@Test
public void testSetAllFromAxesAndPosition() throws Exception {
    final double[] expected = new double[] { 1d, 0d, 0d, 0d, 0d, 1d, -1d, 0d, 0d, 1d, 1d, 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.setAll(Vector3.X, up, forward, position);
    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 79 with Vector3

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

the class Matrix4Test method testSetToLookAtPositionTargetUp.

@Test
public void testSetToLookAtPositionTargetUp() 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(Vector3.ZERO, new Vector3(0, 10d, 10d), 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 80 with Vector3

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

the class Matrix4Test method testRotateVector.

@Test
public void testRotateVector() throws Exception {
    final Matrix4 m = new Matrix4(new Quaternion(Vector3.X, 45d));
    final Vector3 v = new Vector3(0d, 1d, 0d);
    m.rotateVector(v);
    assertEquals(0d, v.x, 1e-14);
    assertEquals(0.7071067811865475, v.y, 1e-14);
    assertEquals(-0.7071067811865475, 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