Search in sources :

Example 1 with Vector3

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

the class RajawaliVRExampleRenderer method initScene.

@Override
public void initScene() {
    DirectionalLight light = new DirectionalLight(0.2f, -1f, 0f);
    light.setPower(.7f);
    getCurrentScene().addLight(light);
    light = new DirectionalLight(0.2f, 1f, 0f);
    light.setPower(1f);
    getCurrentScene().addLight(light);
    getCurrentCamera().setFarPlane(1000);
    getCurrentScene().setBackgroundColor(0xdddddd);
    createTerrain();
    try {
        getCurrentScene().setSkybox(R.drawable.posx, R.drawable.negx, R.drawable.posy, R.drawable.negy, R.drawable.posz, R.drawable.negz);
        LoaderAWD loader = new LoaderAWD(getContext().getResources(), getTextureManager(), R.raw.space_cruiser);
        loader.parse();
        Material cruiserMaterial = new Material();
        cruiserMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
        cruiserMaterial.setColorInfluence(0);
        cruiserMaterial.enableLighting(true);
        cruiserMaterial.addTexture(new Texture("spaceCruiserTex", R.drawable.space_cruiser_4_color_1));
        Object3D spaceCruiser = loader.getParsedObject();
        spaceCruiser.setMaterial(cruiserMaterial);
        spaceCruiser.setZ(-6);
        spaceCruiser.setY(1);
        getCurrentScene().addChild(spaceCruiser);
        spaceCruiser = spaceCruiser.clone(true);
        spaceCruiser.setZ(-12);
        spaceCruiser.setY(-3);
        spaceCruiser.setRotY(180);
        getCurrentScene().addChild(spaceCruiser);
        loader = new LoaderAWD(getContext().getResources(), getTextureManager(), R.raw.dark_fighter);
        loader.parse();
        Material darkFighterMaterial = new Material();
        darkFighterMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
        darkFighterMaterial.setColorInfluence(0);
        darkFighterMaterial.enableLighting(true);
        darkFighterMaterial.addTexture(new Texture("darkFighterTex", R.drawable.dark_fighter_6_color));
        Object3D darkFighter = loader.getParsedObject();
        darkFighter.setMaterial(darkFighterMaterial);
        darkFighter.setZ(-6);
        getCurrentScene().addChild(darkFighter);
        CatmullRomCurve3D path = new CatmullRomCurve3D();
        path.addPoint(new Vector3(0, -5, -10));
        path.addPoint(new Vector3(10, -5, 0));
        path.addPoint(new Vector3(0, -4, 8));
        path.addPoint(new Vector3(-16, -6, 0));
        path.isClosedCurve(true);
        SplineTranslateAnimation3D anim = new SplineTranslateAnimation3D(path);
        anim.setDurationMilliseconds(44000);
        anim.setRepeatMode(RepeatMode.INFINITE);
        // -- orient to path
        anim.setOrientToPath(true);
        anim.setTransformable3D(darkFighter);
        getCurrentScene().registerAnimation(anim);
        anim.play();
        loader = new LoaderAWD(getContext().getResources(), getTextureManager(), R.raw.capital);
        loader.parse();
        Material capitalMaterial = new Material();
        capitalMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
        capitalMaterial.setColorInfluence(0);
        capitalMaterial.enableLighting(true);
        capitalMaterial.addTexture(new Texture("capitalTex", R.drawable.hullw));
        capitalMaterial.addTexture(new NormalMapTexture("capitalNormTex", R.drawable.hulln));
        capital = loader.getParsedObject();
        capital.setMaterial(capitalMaterial);
        capital.setScale(18);
        getCurrentScene().addChild(capital);
        path = new CatmullRomCurve3D();
        path.addPoint(new Vector3(0, 13, 34));
        path.addPoint(new Vector3(34, 13, 0));
        path.addPoint(new Vector3(0, 13, -34));
        path.addPoint(new Vector3(-34, 13, 0));
        path.isClosedCurve(true);
        anim = new SplineTranslateAnimation3D(path);
        anim.setDurationMilliseconds(60000);
        anim.setRepeatMode(RepeatMode.INFINITE);
        anim.setOrientToPath(true);
        anim.setTransformable3D(capital);
        getCurrentScene().registerAnimation(anim);
        anim.play();
    } catch (Exception e) {
        e.printStackTrace();
    }
    lookatSphere = new Sphere(1, 12, 12);
    Material sphereMaterial = new Material();
    sphereMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
    sphereMaterial.enableLighting(true);
    lookatSphere.setMaterial(sphereMaterial);
    lookatSphere.setColor(Color.YELLOW);
    lookatSphere.setPosition(0, 0, -6);
    getCurrentScene().addChild(lookatSphere);
    initAudio();
}
Also used : LoaderAWD(org.rajawali3d.loader.LoaderAWD) Material(org.rajawali3d.materials.Material) Vector3(org.rajawali3d.math.vector.Vector3) NormalMapTexture(org.rajawali3d.materials.textures.NormalMapTexture) Texture(org.rajawali3d.materials.textures.Texture) NormalMapTexture(org.rajawali3d.materials.textures.NormalMapTexture) SplineTranslateAnimation3D(org.rajawali3d.animation.SplineTranslateAnimation3D) TextureException(org.rajawali3d.materials.textures.ATexture.TextureException) Object3D(org.rajawali3d.Object3D) Sphere(org.rajawali3d.primitives.Sphere) CatmullRomCurve3D(org.rajawali3d.curves.CatmullRomCurve3D) DirectionalLight(org.rajawali3d.lights.DirectionalLight) DiffuseMethod(org.rajawali3d.materials.methods.DiffuseMethod)

Example 2 with Vector3

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

the class Matrix4Test method testSetToScaleFromVector3.

@Test
public void testSetToScaleFromVector3() throws Exception {
    final double[] expected = new double[] { 1d, 0d, 0d, 0d, 0d, 2d, 0d, 0d, 0d, 0d, 3d, 0d, 0d, 0d, 0d, 1d };
    final Matrix4 m = new Matrix4();
    m.zero();
    final Matrix4 out = m.setToScale(new Vector3(1, 2, 3));
    assertNotNull(out);
    assertTrue(out == m);
    final double[] result = m.getDoubleValues();
    assertNotNull(result);
    for (int i = 0; i < expected.length; ++i) {
        assertEquals(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 3 with Vector3

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

the class Matrix4Test method testProjectVector.

@Test
public void testProjectVector() throws Exception {
    final double[] m = new double[] { 1d, 0d, 0d, 0d, 0d, 1d, 0d, 0d, 0d, 0d, 1d, 1d, 0d, 0d, 0d, 0d };
    Vector3 v = new Vector3(2d, 3d, 4d);
    final Matrix4 matrix = new Matrix4(m);
    final Vector3 out = matrix.projectVector(v);
    assertNotNull(out);
    assertSame(out, v);
    assertEquals(0.5, out.x, 1e-14);
    assertEquals(0.75, out.y, 1e-14);
    assertEquals(1d, out.z, 1e-14);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 4 with Vector3

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

the class Matrix4Test method testSetToTranslationAndScalingFromVector3s.

@Test
public void testSetToTranslationAndScalingFromVector3s() throws Exception {
    final double[] expected = new double[] { // Col 0
    1d, // Col 0
    0d, // Col 0
    0d, // Col 0
    0d, // Col 1
    0d, // Col 1
    2d, // Col 1
    0d, // Col 1
    0d, // Col 2
    0d, // Col 2
    0d, // Col 2
    3d, // Col 2
    0d, // Col 3
    3d, // Col 3
    2d, // Col 3
    1d, // Col 3
    1d };
    final Matrix4 m = new Matrix4();
    m.zero();
    final Matrix4 out = m.setToTranslationAndScaling(new Vector3(3, 2, 1), new Vector3(1, 2, 3));
    assertNotNull(out);
    assertTrue(out == m);
    final double[] result = m.getDoubleValues();
    assertNotNull(result);
    for (int i = 0; i < expected.length; ++i) {
        assertEquals(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 5 with Vector3

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

the class Matrix4Test method testScaleFromVector3.

@Test
public void testScaleFromVector3() throws Exception {
    final double[] expected = new double[] { 2d, 0d, 0d, 0d, 0d, 3d, 0d, 0d, 0d, 0d, 4d, 0d, 0d, 0d, 0d, 1d };
    final Matrix4 m = new Matrix4();
    m.identity();
    final Matrix4 out = m.scale(new Vector3(2, 3, 4));
    assertNotNull(out);
    assertTrue(out == m);
    final double[] result = m.getDoubleValues();
    assertNotNull(result);
    for (int i = 0; i < expected.length; ++i) {
        assertEquals(expected[i], result[i], 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