use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class QuaternionTest method testLookAt.
@Test
public void testLookAt() throws Exception {
final Quaternion q = new Quaternion(1d, 2d, 3d, 4d);
final Vector3 lookAt = Vector3.subtractAndCreate(new Vector3(0, 10d, 10d), Vector3.ZERO);
final Vector3 up = Vector3.Y;
Quaternion out = q.lookAt(lookAt, up);
assertNotNull(out);
assertSame(q, out);
assertEquals(0.9238795325112867, out.w, 1e-14);
assertEquals(0.3826834323650898, out.x, 1e-14);
assertEquals(0d, out.y, 1e-14);
assertEquals(0d, out.z, 1e-14);
lookAt.subtractAndSet(new Vector3(10d, 0, 10d), Vector3.ZERO);
out = q.lookAt(lookAt, up);
assertNotNull(out);
assertSame(q, out);
assertEquals(0.9238795325112867, out.w, 1e-14);
assertEquals(0d, out.x, 1e-14);
assertEquals(-0.3826834323650898, out.y, 1e-14);
assertEquals(0d, out.z, 1e-14);
lookAt.subtractAndSet(new Vector3(0d, 10d, 0d), Vector3.ZERO);
out = q.lookAt(lookAt, Vector3.Y);
assertNotNull(out);
assertSame(q, out);
assertEquals(0.7071067811865475, out.w, 1e-14);
assertEquals(0d, out.x, 1e-14);
assertEquals(0d, out.y, 1e-14);
assertEquals(0.7071067811865475, out.z, 1e-14);
lookAt.subtractAndSet(new Vector3(0d, 10d, 0d), Vector3.ZERO);
out = q.lookAt(lookAt, Vector3.NEG_Y);
assertNotNull(out);
assertSame(q, out);
assertEquals(0.7071067811865475, out.w, 1e-14);
assertEquals(0d, out.x, 1e-14);
assertEquals(0d, out.y, 1e-14);
assertEquals(-0.7071067811865475, out.z, 1e-14);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class QuaternionTest method testGetYAxis.
@Test
public void testGetYAxis() 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.getYAxis();
assertNotNull(v);
assertEquals(-0.5566703992264195, v.x, 1e-14);
assertEquals(0.6985970582110141, v.y, 1e-14);
assertEquals(0.44953333233923354, v.z, 1e-14);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class QuaternionTest method testLookAtAndCreate.
@Test
public void testLookAtAndCreate() throws Exception {
final Vector3 lookAt = Vector3.subtractAndCreate(new Vector3(0, 10d, 10d), Vector3.ZERO);
final Vector3 up = Vector3.Y;
Quaternion out = Quaternion.lookAtAndCreate(lookAt, up);
assertNotNull(out);
assertEquals(0.9238795325112867, out.w, 1e-14);
assertEquals(0.3826834323650898, out.x, 1e-14);
assertEquals(0d, out.y, 1e-14);
assertEquals(0d, out.z, 1e-14);
lookAt.subtractAndSet(new Vector3(10d, 0, 10d), Vector3.ZERO);
out = Quaternion.lookAtAndCreate(lookAt, up);
assertNotNull(out);
assertEquals(0.9238795325112867, out.w, 1e-14);
assertEquals(0d, out.x, 1e-14);
assertEquals(-0.3826834323650898, out.y, 1e-14);
assertEquals(0d, out.z, 1e-14);
lookAt.subtractAndSet(new Vector3(0d, 10d, 0d), Vector3.ZERO);
out = Quaternion.lookAtAndCreate(lookAt, Vector3.Y);
assertNotNull(out);
assertEquals(0.7071067811865475, out.w, 1e-14);
assertEquals(0d, out.x, 1e-14);
assertEquals(0d, out.y, 1e-14);
assertEquals(0.7071067811865475, out.z, 1e-14);
lookAt.subtractAndSet(new Vector3(0d, 10d, 0d), Vector3.ZERO);
out = Quaternion.lookAtAndCreate(lookAt, Vector3.NEG_Y);
assertNotNull(out);
assertEquals(0.7071067811865475, out.w, 1e-14);
assertEquals(0d, out.x, 1e-14);
assertEquals(0d, out.y, 1e-14);
assertEquals(-0.7071067811865475, out.z, 1e-14);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Loader3DSMax method readTexCoords.
protected void readTexCoords(InputStream buffer) throws IOException {
int numVertices = readShort(buffer);
ArrayList<Vector3> texCoords = new ArrayList<Vector3>();
for (int i = 0; i < numVertices; i++) {
float x = readFloat(buffer);
float y = 1 - readFloat(buffer);
texCoords.add(new Vector3(x, y, 0));
}
mTexCoords.add(texCoords);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Loader3DSMax method calculateFaceNormal.
private Vector3 calculateFaceNormal(int[] vertexIDs) {
ArrayList<Vector3> vertices = mVertices.get(mObjects);
Vector3 v1 = vertices.get(vertexIDs[0]);
Vector3 v2 = vertices.get(vertexIDs[2]);
Vector3 v3 = vertices.get(vertexIDs[1]);
Vector3 vector1 = Vector3.subtractAndCreate(v2, v1);
Vector3 vector2 = Vector3.subtractAndCreate(v3, v1);
Vector3 normal = Vector3.crossAndCreate(vector1, vector2);
normal.normalize();
return normal;
}
Aggregations