use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Matrix4Test method testSetToTranslationFromVector3.
@Test
public void testSetToTranslationFromVector3() throws Exception {
final double[] expected = new double[] { 1d, 0d, 0d, 0d, 0d, 1d, 0d, 0d, 0d, 0d, 1d, 0d, 1d, 2d, 3d, 1d };
final Matrix4 m = new Matrix4();
m.zero();
final Matrix4 out = m.setToTranslation(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);
}
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Matrix4Test method testTranslateWithVector3.
@Test
public void testTranslateWithVector3() throws Exception {
final double[] expected = new double[] { // Col 0
1d, // Col 0
0d, // Col 0
0d, // Col 0
0d, // Col 1
0d, // Col 1
1d, // Col 1
0d, // Col 1
0d, // Col 2
0d, // Col 2
0d, // Col 2
1d, // Col 2
0d, // Col 3
1d, // Col 3
2d, // Col 3
3d, // Col 3
1d };
final Matrix4 m = new Matrix4();
m.identity();
final Matrix4 out = m.translate(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);
}
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Matrix4Test method testGetScalingInVector3.
@Test
public void testGetScalingInVector3() throws Exception {
final double[] from = new double[] { 1d, 0d, 0d, 0d, 0d, 2d, 0d, 0d, 0d, 0d, 3d, 0d, 0d, 0d, 0d, 1d };
final Vector3 expected = new Vector3(1, 2, 3);
final Vector3 setIn = new Vector3(0, 0, 0);
final Matrix4 m = new Matrix4(from);
final Vector3 out = m.getScaling(setIn);
assertNotNull(out);
assertTrue(out == setIn);
assertTrue(expected.equals(out, 1e-14));
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Matrix4Test method testSetAllFromPositionScaleRotation.
@Test
public void testSetAllFromPositionScaleRotation() throws Exception {
final double[] expected = new double[] { 0.6603582554517136, 1.4039252336448595, -0.26724299065420565, 0d, -0.55803738317757, 1.3932710280373835, 0.4511214953271028, 0d, 0.5027570093457944, -0.2977570093457944, 0.8515732087227414, 0d, 2d, 3d, 4d, 1d };
final Quaternion rotation = new Quaternion(0.8958236433584459, -0.16744367165578425, -0.2148860452915898, -0.3516317104771469);
final Vector3 position = new Vector3(2d, 3d, 4d);
final Vector3 scale = new Vector3(1d, 2d, 1d);
final Matrix4 m = new Matrix4();
final Matrix4 out = m.setAll(position, scale, rotation);
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 testGetXAxis.
@Test
public void testGetXAxis() 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.getXAxis();
assertNotNull(v);
assertEquals(0.6634139481689384, v.x, 1e-14);
assertEquals(0.6995333323392336, v.y, 1e-14);
assertEquals(-0.2655843563187949, v.z, 1e-14);
}
Aggregations