use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Vector3Test method testSetAllFromAxis.
@Test
public void testSetAllFromAxis() throws Exception {
final Vector3 v = new Vector3();
assertNotNull(v);
final Vector3 outX = v.setAll(Vector3.Axis.X);
assertNotNull(outX);
assertTrue(outX == v);
assertEquals(1d, v.x, 0);
assertEquals(0d, v.y, 0);
assertEquals(0d, v.z, 0);
final Vector3 outY = v.setAll(Vector3.Axis.Y);
assertNotNull(outY);
assertTrue(outY == v);
assertEquals(0d, v.x, 0);
assertEquals(1d, v.y, 0);
assertEquals(0d, v.z, 0);
final Vector3 outZ = v.setAll(Vector3.Axis.Z);
assertNotNull(outZ);
assertTrue(outZ == v);
assertEquals(0d, v.x, 0);
assertEquals(0d, v.y, 0);
assertEquals(1d, v.z, 0);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Matrix4Test method testSetToWorld.
@Test
public void testSetToWorld() throws Exception {
final double[] expected = new double[] { -1d, 0d, 0d, 0d, 0d, 0.7071067811865476, -0.7071067811865476, 0d, 0d, -0.7071067811865475, -0.7071067811865475, 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.setToWorld(position, forward, up);
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 testSetToLookAtDirectionUp.
@Test
public void testSetToLookAtDirectionUp() 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(lookAt, 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 QuaternionTest method testConstructorVector3AxisAngle.
@Test
public void testConstructorVector3AxisAngle() throws Exception {
final Quaternion q = new Quaternion(new Vector3(1d, 2d, 3d), 60);
assertNotNull(q);
assertEquals(0.86602540378443864676372317075294, q.w, 1e-14);
assertEquals(0.13363062095621219234227674043988, q.x, 1e-14);
assertEquals(0.26726124191242438468455348087975, q.y, 1e-14);
assertEquals(0.40089186286863657702683022131963, q.z, 1e-14);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class QuaternionTest method testGetZAxis.
@Test
public void testGetZAxis() 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.getZAxis();
assertNotNull(v);
assertEquals(0.5, v.x, 1e-14);
assertEquals(-0.1503837331804353, v.y, 1e-14);
assertEquals(0.8528685319524432, v.z, 1e-14);
}
Aggregations