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);
}
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();
}
}
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);
}
}
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);
}
}
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);
}
Aggregations